Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: taking sections out of a file and put it in an array

by Chief of Chaos (Friar)
on Dec 06, 2002 at 09:00 UTC ( [id://218015]=note: print w/replies, xml ) Need Help??


in reply to Re: taking sections out of a file and put it in an array
in thread taking sections out of a file and put it in an array

starts with $FILES and ends with $ :
my @arr; while (<FILE>) { push @arr, $1 if /^\$FILES(.*?)\$$/; }
(inserted '^' and '$' to mark start and end)

Replies are listed 'Best First'.
Re(3): Inserting sections of a file into an array
by cjf-II (Monk) on Dec 06, 2002 at 09:03 UTC

    Check juo's example, there will be more data after the $ so you'll need to leave of the second $ (as davorg did) or it won't match.

    open DATA, "junk.txt" or die $!; my @arr; while (<DATA>) { # add the extra $ and it won't print anything push @arr, $1 if /\$FILES(.*?)\$/; } close DATA; print $_, "\n" for @arr;

    Try it out.

    Update: I think I misinterpreted Chief of Chaos's post. If you want to ensure there's no data before the $FILE or after the $ then he is correct.

    Update: If you want each CSV as an individual array element, substitute the push line above with:

    push @arr, split(/, /, $1) if /\$FILES(.*?)\$/;

    Otherwise they'll all read into one element.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-23 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found