SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Perl Brown Bag


Command Line and Debugger


              Shaun Griffith
               April 3, 2006



05/13/12        ATI Confidential   1
Agenda



           •Command Line
           •Debugger




05/13/12                   2
Command Line
Common Options
    -c             “compile check” – check syntax, but don’t run the program
    -w             turn on basic warnings (-W for *all* warnings)
    -d             load the debugger (with program or -e)
    -e ‘code’      run this code
    -n             wraps this around the –e code:
                             while (<>) { code goes here }
    -p             same as –n, but prints $_ after each iteration:
                             while (<>) {code} continue {print $_}
    -a             “autosplit”, used with –p or –n, puts this in the while (<>) loop:
                             @F = split;          # whitespace, same as split ‘ ‘
    -F/pattern/ used with –a to split on a different pattern
    -h             help summary


05/13/12                                                                                3
Command Line: Examples
Version:

    C:>perl -v

    This is perl, v5.8.7 built for MSWin32-x86-multi-thread
    (with 14 registered patches, see perl -V for more detail)

Compiler Check:
    C:>perl –c dupes.pl
    syntax error at dupes.pl line 17, near "))
    “
    syntax error at dupes.pl line 23, near "}“
    dupes.pl had compilation errors.

Removing a stray right paren:
    C:>perl –c dupes.pl
    dupes.pl syntax OK




05/13/12                                                        4
Command Line: Examples
One-liners: -p and –n
    -n: loop on input, but don’t print unless requested:
           perl –ne “your program here”

    is equivalent to
           while (<>) { your program here }


    -p: loop on input, run “program”, print every line:
           perl –pe “your program here”

    is equivalent to
           while (<>) { your program here; print }


    “Golf”ed line counter
           perl –pe “}{$_=$.}”

                                                   Homework – what does this do?
                                                           perl –MO=Deparse –pe “}{$_=$.}”

05/13/12                                                                                     5
Command Line: Examples
One-liners: -e
    Change all “FAIL”s to “PASS”es:
           perl –pe “s/FAIL/PASS/g” my_input_file


    Print lines with wafer coordinates:
           perl –ne “/d+,d+/ and print” my_input_file


    Sum the 7th column if the last column matches “Buy”
           perl –ane “$sum+= $F[6] if ($F[-1]=~/buy/i);
              print qq(sum=$sumn) if eof” my_input_file


    For DOS, use double-quotes, and qq() to double-quote in programs.
    For Unix, use single quotes, and q() to single-quote in programs.




05/13/12                                                                6
Debugger
Common Options
    l x-y          list lines x to y
    n              single step (over function calls)
    s              single step (into functions)
    <enter>        repeat last n or s
    c x            continue (execute) to line x
    b x            break on line x
    b x condition               break on line x when condition is true
                   e.g., /barcode/ (same as $_ =~ /barcode/)
    B x            delete breakpoint on line x (or * to delete all breakpoints)
    p expression print expression, with newline
    x expression eXamine expression, including nested structure
                   x $scalar or x @array or x %hash
    h              help
    R              Restart program, rewinding all inputs (doesn’t work on DOS)



05/13/12                                                                          7
Debugger: Examples
Perl Scratch Pad
     C:>perl -demo

     Loading DB routines from perl5db.pl version 1.28
     Editor support available.

     Enter h or `h h' for help, or `perldoc perldebug' for more help.

     main::(-e:1):    mo
       DB<1>

Print shortcut:
      DB<1> p 17+42
     59

Examine a variable
      DB<5> x %hash
     0 HASH(0x1d4cd18)
        'Fred' => HASH(0x1d00a4c)
           'Office' => '1F17'
           'Phone' => 'x1234'
        'George' => HASH(0x1cef8e0)
           'Office' => '2F35'
           'Phone' => 'x9876'
05/13/12                                                                8
Debugger: Examples
Load a program:
      perl –d histo.pl histo.pl
l (“ell”): list program
        DB<1> l 1-11
      1        #!/your/perl/here
      2:       use strict;
      3:       use warnings;
      4
      5==>     my %seen;
      6
      7:       while (<>)
      8        {
      9:               my @fields = split;
      10:              $seen{$fields[0]}++;
      11       }
Break (with condition), and continue
       DB<2> b 10 $. > 5
       DB<3> c
      Use of uninitialized value in hash element at
      histo.pl line 10, <> line 4.
       at histo.pl line 10
      main::(histo.pl:10):            $seen{$fields[0]}++;

 05/13/12                                                    9
Next Time?
Regular Expressions?
     •Matches
     •Substitutions
     •Wildcards
     •Captures
Subroutines?
     •Passing parameters
     •Catching parameters
     •Returning data
Filehandles?
     •Open
     •Close
     •EOF
05/13/12                                 10

Weitere ähnliche Inhalte

Was ist angesagt?

Linux shell script-1
Linux shell script-1Linux shell script-1
Linux shell script-1兎 伊藤
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllersmussawir20
 
Advanced php
Advanced phpAdvanced php
Advanced phpAnne Lee
 
Yapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line PerlYapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line PerlBruce Gray
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statementsMomenMostafa
 
Github.com anton terekhov-orientdb-php
Github.com anton terekhov-orientdb-phpGithub.com anton terekhov-orientdb-php
Github.com anton terekhov-orientdb-phpSan jay
 
Write Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursWrite Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursPhillip Trelford
 
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsPython Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsP3 InfoTech Solutions Pvt. Ltd.
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about CYi-Hsiu Hsu
 
實戰 Hhvm extension php conf 2014
實戰 Hhvm extension   php conf 2014實戰 Hhvm extension   php conf 2014
實戰 Hhvm extension php conf 2014Ricky Su
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHPWim Godden
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesjulien pauli
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)Olve Maudal
 
C++17 std::filesystem - Overview
C++17 std::filesystem - OverviewC++17 std::filesystem - Overview
C++17 std::filesystem - OverviewBartlomiej Filipek
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumpingMomenMostafa
 

Was ist angesagt? (19)

Linux shell script-1
Linux shell script-1Linux shell script-1
Linux shell script-1
 
runtimestack
runtimestackruntimestack
runtimestack
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
 
Advanced php
Advanced phpAdvanced php
Advanced php
 
7 functions
7  functions7  functions
7 functions
 
Yapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line PerlYapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line Perl
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
Github.com anton terekhov-orientdb-php
Github.com anton terekhov-orientdb-phpGithub.com anton terekhov-orientdb-php
Github.com anton terekhov-orientdb-php
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Write Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 HoursWrite Your Own Compiler in 24 Hours
Write Your Own Compiler in 24 Hours
 
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsPython Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and Loops
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
 
實戰 Hhvm extension php conf 2014
實戰 Hhvm extension   php conf 2014實戰 Hhvm extension   php conf 2014
實戰 Hhvm extension php conf 2014
 
Functuon
FunctuonFunctuon
Functuon
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performances
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
 
C++17 std::filesystem - Overview
C++17 std::filesystem - OverviewC++17 std::filesystem - Overview
C++17 std::filesystem - Overview
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
 

Ähnlich wie Perl Intro 4 Debugger

Perl Intro 3 Datalog Parsing
Perl Intro 3 Datalog ParsingPerl Intro 3 Datalog Parsing
Perl Intro 3 Datalog ParsingShaun Griffith
 
Perl training-in-navi mumbai
Perl training-in-navi mumbaiPerl training-in-navi mumbai
Perl training-in-navi mumbaivibrantuser
 
Perl one-liners
Perl one-linersPerl one-liners
Perl one-linersdaoswald
 
Perl In The Command Line
Perl In The Command LinePerl In The Command Line
Perl In The Command LineMarcos Rebelo
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
Devel::hdb debugger talk
Devel::hdb debugger talkDevel::hdb debugger talk
Devel::hdb debugger talkabrummett
 
Bioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionBioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionProf. Wim Van Criekinge
 
Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)Roy Zimmer
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl styleBo Hua Yang
 
Lecture 22
Lecture 22Lecture 22
Lecture 22rhshriva
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Perl Intro 9 Command Line Arguments
Perl Intro 9 Command Line ArgumentsPerl Intro 9 Command Line Arguments
Perl Intro 9 Command Line ArgumentsShaun Griffith
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to PerlSway Wang
 
Shell Scripts
Shell ScriptsShell Scripts
Shell ScriptsDr.Ravi
 

Ähnlich wie Perl Intro 4 Debugger (20)

Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Perl Intro 3 Datalog Parsing
Perl Intro 3 Datalog ParsingPerl Intro 3 Datalog Parsing
Perl Intro 3 Datalog Parsing
 
Perl training-in-navi mumbai
Perl training-in-navi mumbaiPerl training-in-navi mumbai
Perl training-in-navi mumbai
 
Perl one-liners
Perl one-linersPerl one-liners
Perl one-liners
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Perl In The Command Line
Perl In The Command LinePerl In The Command Line
Perl In The Command Line
 
Bash production guide
Bash production guideBash production guide
Bash production guide
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Devel::hdb debugger talk
Devel::hdb debugger talkDevel::hdb debugger talk
Devel::hdb debugger talk
 
Bioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionBioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introduction
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl style
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Perl Intro 9 Command Line Arguments
Perl Intro 9 Command Line ArgumentsPerl Intro 9 Command Line Arguments
Perl Intro 9 Command Line Arguments
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
 

Mehr von Shaun Griffith

Perl Intro 8 File Handles
Perl Intro 8 File HandlesPerl Intro 8 File Handles
Perl Intro 8 File HandlesShaun Griffith
 
Perl Intro 7 Subroutines
Perl Intro 7 SubroutinesPerl Intro 7 Subroutines
Perl Intro 7 SubroutinesShaun Griffith
 
Perl Intro 5 Regex Matches And Substitutions
Perl Intro 5 Regex Matches And SubstitutionsPerl Intro 5 Regex Matches And Substitutions
Perl Intro 5 Regex Matches And SubstitutionsShaun Griffith
 
Perl Intro 2 First Program
Perl Intro 2 First ProgramPerl Intro 2 First Program
Perl Intro 2 First ProgramShaun Griffith
 

Mehr von Shaun Griffith (6)

Perl one liners
Perl one linersPerl one liners
Perl one liners
 
Perl Intro 8 File Handles
Perl Intro 8 File HandlesPerl Intro 8 File Handles
Perl Intro 8 File Handles
 
Perl Intro 7 Subroutines
Perl Intro 7 SubroutinesPerl Intro 7 Subroutines
Perl Intro 7 Subroutines
 
Perl Intro 5 Regex Matches And Substitutions
Perl Intro 5 Regex Matches And SubstitutionsPerl Intro 5 Regex Matches And Substitutions
Perl Intro 5 Regex Matches And Substitutions
 
Perl Intro 6 Ftp
Perl Intro 6 FtpPerl Intro 6 Ftp
Perl Intro 6 Ftp
 
Perl Intro 2 First Program
Perl Intro 2 First ProgramPerl Intro 2 First Program
Perl Intro 2 First Program
 

Perl Intro 4 Debugger

  • 1. Perl Brown Bag Command Line and Debugger Shaun Griffith April 3, 2006 05/13/12 ATI Confidential 1
  • 2. Agenda •Command Line •Debugger 05/13/12 2
  • 3. Command Line Common Options -c “compile check” – check syntax, but don’t run the program -w turn on basic warnings (-W for *all* warnings) -d load the debugger (with program or -e) -e ‘code’ run this code -n wraps this around the –e code: while (<>) { code goes here } -p same as –n, but prints $_ after each iteration: while (<>) {code} continue {print $_} -a “autosplit”, used with –p or –n, puts this in the while (<>) loop: @F = split; # whitespace, same as split ‘ ‘ -F/pattern/ used with –a to split on a different pattern -h help summary 05/13/12 3
  • 4. Command Line: Examples Version: C:>perl -v This is perl, v5.8.7 built for MSWin32-x86-multi-thread (with 14 registered patches, see perl -V for more detail) Compiler Check: C:>perl –c dupes.pl syntax error at dupes.pl line 17, near ")) “ syntax error at dupes.pl line 23, near "}“ dupes.pl had compilation errors. Removing a stray right paren: C:>perl –c dupes.pl dupes.pl syntax OK 05/13/12 4
  • 5. Command Line: Examples One-liners: -p and –n -n: loop on input, but don’t print unless requested: perl –ne “your program here” is equivalent to while (<>) { your program here } -p: loop on input, run “program”, print every line: perl –pe “your program here” is equivalent to while (<>) { your program here; print } “Golf”ed line counter perl –pe “}{$_=$.}” Homework – what does this do? perl –MO=Deparse –pe “}{$_=$.}” 05/13/12 5
  • 6. Command Line: Examples One-liners: -e Change all “FAIL”s to “PASS”es: perl –pe “s/FAIL/PASS/g” my_input_file Print lines with wafer coordinates: perl –ne “/d+,d+/ and print” my_input_file Sum the 7th column if the last column matches “Buy” perl –ane “$sum+= $F[6] if ($F[-1]=~/buy/i); print qq(sum=$sumn) if eof” my_input_file For DOS, use double-quotes, and qq() to double-quote in programs. For Unix, use single quotes, and q() to single-quote in programs. 05/13/12 6
  • 7. Debugger Common Options l x-y list lines x to y n single step (over function calls) s single step (into functions) <enter> repeat last n or s c x continue (execute) to line x b x break on line x b x condition break on line x when condition is true e.g., /barcode/ (same as $_ =~ /barcode/) B x delete breakpoint on line x (or * to delete all breakpoints) p expression print expression, with newline x expression eXamine expression, including nested structure x $scalar or x @array or x %hash h help R Restart program, rewinding all inputs (doesn’t work on DOS) 05/13/12 7
  • 8. Debugger: Examples Perl Scratch Pad C:>perl -demo Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(-e:1): mo DB<1> Print shortcut: DB<1> p 17+42 59 Examine a variable DB<5> x %hash 0 HASH(0x1d4cd18) 'Fred' => HASH(0x1d00a4c) 'Office' => '1F17' 'Phone' => 'x1234' 'George' => HASH(0x1cef8e0) 'Office' => '2F35' 'Phone' => 'x9876' 05/13/12 8
  • 9. Debugger: Examples Load a program: perl –d histo.pl histo.pl l (“ell”): list program DB<1> l 1-11 1 #!/your/perl/here 2: use strict; 3: use warnings; 4 5==> my %seen; 6 7: while (<>) 8 { 9: my @fields = split; 10: $seen{$fields[0]}++; 11 } Break (with condition), and continue DB<2> b 10 $. > 5 DB<3> c Use of uninitialized value in hash element at histo.pl line 10, <> line 4. at histo.pl line 10 main::(histo.pl:10): $seen{$fields[0]}++; 05/13/12 9
  • 10. Next Time? Regular Expressions? •Matches •Substitutions •Wildcards •Captures Subroutines? •Passing parameters •Catching parameters •Returning data Filehandles? •Open •Close •EOF 05/13/12 10