SlideShare a Scribd company logo
1 of 20
Perl Brown Bag


           Datalog Parsing

               Shaun Griffith
              March 27, 2006



05/13/12         ATI Confidential   1
Agenda


           •Setting a goal
           •Step by step




05/13/12                     2
Setting a Goal




           What should the output look like?
           •Barcode, Package ID, Wafer, Die ID
           •Hard Bin, Soft Bin, LKG010, Failing Test



05/13/12                                               3
…And Another Goal




           Retests?
             •Print all?
             •Keep first?
             •Average or aggregate?
             •Keep last!
05/13/12                              4
…And Even More
           •More than 1 input file
           •Wildcards in DOS
           •Error checking




05/13/12                             5
Step by Step

Program Template
    •header
    •DOS wildcards
    •error checking
    •main loop
    •print loop
05/13/12                         6
Template Breakdown
Header
    •Perl 5:
           •use strict;
           •use warnings
    •Perl 4: -w
Wildcards for DOS
    •Which operating system: $^O
    •Match to Windows: =~ /win/i
    •Command line: @ARGV
    •Expand wildcards: glob
Error checking
    •Count of items: @ARGV in scalar context
05/13/12                                       7
Finding Data
Split Arguments:
    •Delimiter (match)
           • ‘ ‘ (blank) is special (and default)
           •like /s+/, but no leading null field
    •Target, default is $_
    •Always catch in array
           •@fields = split;




05/13/12                                            8
Handling Data
Is it a barcode line?
    •if ( /^barcode=/i )
    •{ do_something_here }

Fields
    •($barcode) = $fields[0] =~ /=(d+)/;
    •$pkgid = $fields[1];
    •$softbin = $fields[2];
    •$hardbin = $fields[3];
    •$test_fail = $fields[-1];
    •# clear other variables (if needed)


05/13/12                                    9
Regular Expressions
Regex Metacharacters
Anchors
    •^             start of string if /^.../
    •$             end of string if /...$/

Quantifiers
    •?             zero or one of preceding
    •+             one or more of preceding
    •*             any number of preceding
    •{x,y}         at least x, no more than y of preceding
           •{x}    exactly x
           •{x,}   at least x
           •{,y}   no more than y
05/13/12                                                     10
Regexes…
Regex Metacharacters…
Character Class
    •[abc1-7] match one of “a”, “b”, “c”, or a digit 1 to 7

Alternation
    •|            “or” – either the left or right pattern
    • abc|def either “abc” or “def”
Grouping & Captures
    •(abc)        capture “abc”
    •(abc)+       capture “abc”, at least one must occur
    •(?:abc)+ “abc” at least once, but don’t capture
    •(?i)         case insensitive flag [ (?-i) to change back ]

05/13/12                                                           11
Regexes…
Regex Metacharacters…
Character Class Shortcuts
    •swhitespace (blank, tab, newline, carriage return)
    •w“word” characters, same as [A-Za-z_]
    •ddigits [0-9]
Special Character Shortcuts
    •ttab
    •nnewline
    •xAB        hex “AB”
    •Xescape any special character X


05/13/12                                                   12
Handling Data…
Is it a wafer line?
    •if ( /wafer_ids+=s+(d+)/i )
    •{ $wafer = $1; }

Is it a die id line?
    •if ( /die_ids+=s+(d+)/I )
    •{ $die_id = $1; }

Is it a leakage line?
    •if ( /leakage_all0=(-?d+(.d+))/ )
    •{ $lkg_all0 = $1; }



05/13/12                                    13
Saving Data
What starts a new device?
    •Barcode!
    •if (/^barcode=/i)
    •{ if ( defined($barcode) )
           •{ $data{$barcode} = “$barcode $pkgid $wafer $die_id
           $hardbin $softbin $lkg_all0 $test_fail”; }
           •($barcode) = $fields[0] =~ /=(d+)/;

Use the Barcode as the key
    •Retests will just overwrite the old data
    •(This is the easiest case to handle)
05/13/12                                                      14
Program so far…




05/13/12                     15
Print It Out!
Print header line
    •print “BARCODE PKGID             WAFER NO. “
           •   . ”DIE NO. HWBIN SWBIN LKG010        TESTn”;
           •Note the dot for string concatenation
For loop, Perl style
    •for my $line (values %data)
    •{ print “$linen”; }
values gets all data out of data, in random order
To sort by barcode, use sort and keys:
    •for my $barcode ( sort {$a <=> $b} keys %data)
    •{ print “$data{$barcode}n”; }

05/13/12                                                       16
Questions?
Questions on this material?
  • Template
  • Command line arguments
  • Split
  • Matching
  • Hashes and unique keys

Questions on anything else?




05/13/12                         17
Working Session

             Running Perl
             Perl Debugger




05/13/12                     18
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                                                                                19
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                                                                          20

More Related Content

What's hot

Lecture 22
Lecture 22Lecture 22
Lecture 22rhshriva
 
Modern Perl for Non-Perl Programmers
Modern Perl for Non-Perl ProgrammersModern Perl for Non-Perl Programmers
Modern Perl for Non-Perl ProgrammersDave Cross
 
Contracts in-clojure-pete
Contracts in-clojure-peteContracts in-clojure-pete
Contracts in-clojure-petejessitron
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applicationsJoe Jiang
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1Rakesh Mukundan
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmersAlexander Varwijk
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Michelangelo van Dam
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database ProgrammingAhmed Swilam
 
What You Need to Know about Lambdas
What You Need to Know about LambdasWhat You Need to Know about Lambdas
What You Need to Know about LambdasRyan Knight
 
Glorp Tutorial Guide
Glorp Tutorial GuideGlorp Tutorial Guide
Glorp Tutorial GuideESUG
 
Functional Principles for OO Developers
Functional Principles for OO DevelopersFunctional Principles for OO Developers
Functional Principles for OO Developersjessitron
 

What's hot (20)

Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Modern Perl for Non-Perl Programmers
Modern Perl for Non-Perl ProgrammersModern Perl for Non-Perl Programmers
Modern Perl for Non-Perl Programmers
 
Contracts in-clojure-pete
Contracts in-clojure-peteContracts in-clojure-pete
Contracts in-clojure-pete
 
Perl Programming - 02 Regular Expression
Perl Programming - 02 Regular ExpressionPerl Programming - 02 Regular Expression
Perl Programming - 02 Regular Expression
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
 
c
cc
c
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Scala syntax analysis
Scala syntax analysisScala syntax analysis
Scala syntax analysis
 
Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
 
What You Need to Know about Lambdas
What You Need to Know about LambdasWhat You Need to Know about Lambdas
What You Need to Know about Lambdas
 
Perl
PerlPerl
Perl
 
Glorp Tutorial Guide
Glorp Tutorial GuideGlorp Tutorial Guide
Glorp Tutorial Guide
 
L16 Object Relational Mapping and NoSQL
L16 Object Relational Mapping and NoSQLL16 Object Relational Mapping and NoSQL
L16 Object Relational Mapping and NoSQL
 
Functional Principles for OO Developers
Functional Principles for OO DevelopersFunctional Principles for OO Developers
Functional Principles for OO Developers
 
Clojure 7-Languages
Clojure 7-LanguagesClojure 7-Languages
Clojure 7-Languages
 

Similar to Perl Brown Bag Datalog Parsing

Perl Intro 9 Command Line Arguments
Perl Intro 9 Command Line ArgumentsPerl Intro 9 Command Line Arguments
Perl Intro 9 Command Line ArgumentsShaun 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
 
Learn perl in amc square learning
Learn perl in amc square learningLearn perl in amc square learning
Learn perl in amc square learningASIT Education
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to PerlSway Wang
 
Basic perl programming
Basic perl programmingBasic perl programming
Basic perl programmingThang Nguyen
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Andrea Telatin
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation TutorialLorna Mitchell
 
Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
Our Friends the Utils: A highway traveled by wheels we didn't re-invent. Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
Our Friends the Utils: A highway traveled by wheels we didn't re-invent. Workhorse Computing
 
Perl training-in-navi mumbai
Perl training-in-navi mumbaiPerl training-in-navi mumbai
Perl training-in-navi mumbaivibrantuser
 

Similar to Perl Brown Bag Datalog Parsing (20)

Perl Intro 4 Debugger
Perl Intro 4 DebuggerPerl Intro 4 Debugger
Perl Intro 4 Debugger
 
Perl Intro 9 Command Line Arguments
Perl Intro 9 Command Line ArgumentsPerl Intro 9 Command Line Arguments
Perl Intro 9 Command Line Arguments
 
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
 
Learn perl in amc square learning
Learn perl in amc square learningLearn perl in amc square learning
Learn perl in amc square learning
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Basic perl programming
Basic perl programmingBasic perl programming
Basic perl programming
 
Lecture4
Lecture4Lecture4
Lecture4
 
Ruby quick ref
Ruby quick refRuby quick ref
Ruby quick ref
 
Lecture4
Lecture4Lecture4
Lecture4
 
Perl basics for Pentesters
Perl basics for PentestersPerl basics for Pentesters
Perl basics for Pentesters
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
Short Introduction To "perl -d"
Short Introduction To "perl -d"Short Introduction To "perl -d"
Short Introduction To "perl -d"
 
Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
Our Friends the Utils: A highway traveled by wheels we didn't re-invent. Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
 
Perl one liners
Perl one linersPerl one liners
Perl one liners
 
Perl training-in-navi mumbai
Perl training-in-navi mumbaiPerl training-in-navi mumbai
Perl training-in-navi mumbai
 

Perl Brown Bag Datalog Parsing

  • 1. Perl Brown Bag Datalog Parsing Shaun Griffith March 27, 2006 05/13/12 ATI Confidential 1
  • 2. Agenda •Setting a goal •Step by step 05/13/12 2
  • 3. Setting a Goal What should the output look like? •Barcode, Package ID, Wafer, Die ID •Hard Bin, Soft Bin, LKG010, Failing Test 05/13/12 3
  • 4. …And Another Goal Retests? •Print all? •Keep first? •Average or aggregate? •Keep last! 05/13/12 4
  • 5. …And Even More •More than 1 input file •Wildcards in DOS •Error checking 05/13/12 5
  • 6. Step by Step Program Template •header •DOS wildcards •error checking •main loop •print loop 05/13/12 6
  • 7. Template Breakdown Header •Perl 5: •use strict; •use warnings •Perl 4: -w Wildcards for DOS •Which operating system: $^O •Match to Windows: =~ /win/i •Command line: @ARGV •Expand wildcards: glob Error checking •Count of items: @ARGV in scalar context 05/13/12 7
  • 8. Finding Data Split Arguments: •Delimiter (match) • ‘ ‘ (blank) is special (and default) •like /s+/, but no leading null field •Target, default is $_ •Always catch in array •@fields = split; 05/13/12 8
  • 9. Handling Data Is it a barcode line? •if ( /^barcode=/i ) •{ do_something_here } Fields •($barcode) = $fields[0] =~ /=(d+)/; •$pkgid = $fields[1]; •$softbin = $fields[2]; •$hardbin = $fields[3]; •$test_fail = $fields[-1]; •# clear other variables (if needed) 05/13/12 9
  • 10. Regular Expressions Regex Metacharacters Anchors •^ start of string if /^.../ •$ end of string if /...$/ Quantifiers •? zero or one of preceding •+ one or more of preceding •* any number of preceding •{x,y} at least x, no more than y of preceding •{x} exactly x •{x,} at least x •{,y} no more than y 05/13/12 10
  • 11. Regexes… Regex Metacharacters… Character Class •[abc1-7] match one of “a”, “b”, “c”, or a digit 1 to 7 Alternation •| “or” – either the left or right pattern • abc|def either “abc” or “def” Grouping & Captures •(abc) capture “abc” •(abc)+ capture “abc”, at least one must occur •(?:abc)+ “abc” at least once, but don’t capture •(?i) case insensitive flag [ (?-i) to change back ] 05/13/12 11
  • 12. Regexes… Regex Metacharacters… Character Class Shortcuts •swhitespace (blank, tab, newline, carriage return) •w“word” characters, same as [A-Za-z_] •ddigits [0-9] Special Character Shortcuts •ttab •nnewline •xAB hex “AB” •Xescape any special character X 05/13/12 12
  • 13. Handling Data… Is it a wafer line? •if ( /wafer_ids+=s+(d+)/i ) •{ $wafer = $1; } Is it a die id line? •if ( /die_ids+=s+(d+)/I ) •{ $die_id = $1; } Is it a leakage line? •if ( /leakage_all0=(-?d+(.d+))/ ) •{ $lkg_all0 = $1; } 05/13/12 13
  • 14. Saving Data What starts a new device? •Barcode! •if (/^barcode=/i) •{ if ( defined($barcode) ) •{ $data{$barcode} = “$barcode $pkgid $wafer $die_id $hardbin $softbin $lkg_all0 $test_fail”; } •($barcode) = $fields[0] =~ /=(d+)/; Use the Barcode as the key •Retests will just overwrite the old data •(This is the easiest case to handle) 05/13/12 14
  • 16. Print It Out! Print header line •print “BARCODE PKGID WAFER NO. “ • . ”DIE NO. HWBIN SWBIN LKG010 TESTn”; •Note the dot for string concatenation For loop, Perl style •for my $line (values %data) •{ print “$linen”; } values gets all data out of data, in random order To sort by barcode, use sort and keys: •for my $barcode ( sort {$a <=> $b} keys %data) •{ print “$data{$barcode}n”; } 05/13/12 16
  • 17. Questions? Questions on this material? • Template • Command line arguments • Split • Matching • Hashes and unique keys Questions on anything else? 05/13/12 17
  • 18. Working Session Running Perl Perl Debugger 05/13/12 18
  • 19. 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 19
  • 20. 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 20