Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Help Parsing a Text File

by YuckFoo (Abbot)
on Mar 23, 2004 at 19:10 UTC ( [id://339124]=note: print w/replies, xml ) Need Help??


in reply to Help Parsing a Text File

Prime,

I think you want an Array of Arrays (AoA). Read about them in perldsc and perlref.

YuckFoo

Here is one way to go:

#!/usr/bin/perl use strict; use Data::Dumper; my @parts = ([]); while (my $line = <DATA>) { chomp $line; if ($line =~ /^\d-\d\d-ABC\d\d/) { push (@parts, []); } push (@{$parts[-1]}, $line) } print Dumper \@parts; __DATA__ 1-11-ABC22 (12:12) ABC 12 Foo Bar Foo Bar Foo Bar Foo Bar 2-15-ABC33 (12:12) ABC 12 Foo Bar Foo Bar Foo Bar Foo Bar -- 1-11-ABC33 (12:12) ABC 12 Foo Bar Foo Bar Foo bar Foo Bar -- 1-11-ABC33 (12:12) ABC 12 Foo Bar Foo Bar Foo abr Foo bar Foo Bar Foo Bar Foo Bar -- 2-15-ABC45 (12:12) ABC 12 Foo Bar Foo Bar Foo Bar Foo Bar 3-33-ABC15 (12:12) ABC 12 Foo Bar Foo Bar

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found