Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: newbie question

by indapa (Monk)
on Jan 23, 2002 at 04:22 UTC ( #140767=note: print w/replies, xml ) Need Help??


in reply to newbie questions on array access and control loops

Well from the looks of it, and if I understand your question, you want to print all the lines in the file that matched your regular expression. Try this:
#!/apps/bin/perl -w use strict; my @lines_that_matched = (); while (<>) { chomp; if (/PAGE: 2/) { push (@lines_that_matched, $_); } } foreach my $line (@lines_that_matched) { print "$line\n"; }
So if the current line being read has a successful match of the regex, add it to the array of matched lines. After you have read thru the entire file, print each line that matched.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2019-12-14 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?