Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to process variables length fields in delimited file.

by liverpole (Monsignor)
on Oct 06, 2016 at 02:03 UTC ( [id://1173376]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @line_format = (
        [ 'ssn',        qr/(\d{9})/ ],
    ...
        [ 'city',       'COUNT' ],
        [ 'zip',        qr/(\d{5})/ ],
    );
    
  2. or download this
    sub parse_line {
        my ($line, $linenum) = @_;
    ...
    
        return \%parsed;    
    }
    
  3. or download this
        use Data::Dumper::Concise;
        my $line   = "123445678 45612 11 Steve Smith 11012015 16 1001 Main
    + Street GA 7 Atlanta 30553";
        my $result = parse_line($line, 1);
        die Dumper $result;
    
  4. or download this
    {
      city => "Atlanta",
    ...
      state => "GA",
      zip => 30553
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1173376]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-26 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found