SlideShare a Scribd company logo
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

More Related Content

PDF
TLPI - 6 Process
PDF
Diving into HHVM Extensions (Brno PHP Conference 2015)
PPT
Buffer OverFlow
DOCX
Perl 20tips
PDF
Perl Programming - 02 Regular Expression
PDF
3 1. preprocessor, math, stdlib
ODP
OpenGurukul : Language : PHP
PDF
Perl 5.10 in 2010
TLPI - 6 Process
Diving into HHVM Extensions (Brno PHP Conference 2015)
Buffer OverFlow
Perl 20tips
Perl Programming - 02 Regular Expression
3 1. preprocessor, math, stdlib
OpenGurukul : Language : PHP
Perl 5.10 in 2010

What's hot (19)

PDF
Linux shell script-1
PDF
runtimestack
PPT
Php Operators N Controllers
PPT
Advanced php
PDF
7 functions
PDF
Yapc::NA::2009 - Command Line Perl
PDF
4 operators, expressions &amp; statements
PDF
Github.com anton terekhov-orientdb-php
PPTX
Write Your Own Compiler in 24 Hours
PPTX
Python Programming Essentials - M16 - Control Flow Statements and Loops
PPTX
Understand more about C
PDF
實戰 Hhvm extension php conf 2014
PPTX
Functuon
ODP
The promise of asynchronous PHP
PDF
SymfonyCon 2017 php7 performances
PDF
C++ idioms by example (Nov 2008)
PPTX
C++17 std::filesystem - Overview
PDF
6 c control statements branching &amp; jumping
Linux shell script-1
runtimestack
Php Operators N Controllers
Advanced php
7 functions
Yapc::NA::2009 - Command Line Perl
4 operators, expressions &amp; statements
Github.com anton terekhov-orientdb-php
Write Your Own Compiler in 24 Hours
Python Programming Essentials - M16 - Control Flow Statements and Loops
Understand more about C
實戰 Hhvm extension php conf 2014
Functuon
The promise of asynchronous PHP
SymfonyCon 2017 php7 performances
C++ idioms by example (Nov 2008)
C++17 std::filesystem - Overview
6 c control statements branching &amp; jumping
Ad

Similar to Perl Intro 4 Debugger (20)

PPT
Introduction to Perl
PPT
Perl Intro 3 Datalog Parsing
PPT
Perl training-in-navi mumbai
ODP
Perl one-liners
PDF
Lecture19-20
PDF
Lecture19-20
ODP
Perl In The Command Line
PDF
Bash production guide
KEY
Good Evils In Perl (Yapc Asia)
ODP
Devel::hdb debugger talk
PPT
Bioinformatica 29-09-2011-p1-introduction
PPT
C Tutorials
PPT
Plunging Into Perl While Avoiding the Deep End (mostly)
ODP
Programming in perl style
PDF
Lecture 22
PPTX
Bash Shell Scripting
PPT
Shell Scripting
PPT
Introduction to perl scripting______.ppt
PPT
Perl Intro 9 Command Line Arguments
PPT
Introduction to Perl
Introduction to Perl
Perl Intro 3 Datalog Parsing
Perl training-in-navi mumbai
Perl one-liners
Lecture19-20
Lecture19-20
Perl In The Command Line
Bash production guide
Good Evils In Perl (Yapc Asia)
Devel::hdb debugger talk
Bioinformatica 29-09-2011-p1-introduction
C Tutorials
Plunging Into Perl While Avoiding the Deep End (mostly)
Programming in perl style
Lecture 22
Bash Shell Scripting
Shell Scripting
Introduction to perl scripting______.ppt
Perl Intro 9 Command Line Arguments
Introduction to Perl
Ad

More from Shaun Griffith (6)

PPT
Perl one liners
PPT
Perl Intro 8 File Handles
PPT
Perl Intro 7 Subroutines
PPT
Perl Intro 5 Regex Matches And Substitutions
PPT
Perl Intro 6 Ftp
PPT
Perl Intro 2 First Program
Perl one liners
Perl Intro 8 File Handles
Perl Intro 7 Subroutines
Perl Intro 5 Regex Matches And Substitutions
Perl Intro 6 Ftp
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