Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Can PERL know a line without matching?

by bikeNomad (Priest)
on Jul 27, 2001 at 20:28 UTC ( #100357=note: print w/replies, xml ) Need Help??


in reply to Can PERL know a line without matching?

If you set $/ to "" you will read paragraphs at a time. That is, you will read a block of lines that are separated by 1 or more blank lines. Then you can split on newline boundaries:
$/ = ""; # read paragraphs while (my $para = <>) { my $lastHeading; my @lines = split(/\n/, $para); if (@lines == 1) # heading? { $lastHeading = $lines[0]; next; } my $hitMe; if ($lastHeading eq 'MEANINGLESS TEXT') { $hitMe = $lines[4]; # fifth line } elsif ($lastHeading eq 'ALTERNATIVE TEXT') { $hitMe = $lines[5]; # sixth line } # now do something... }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2021-05-17 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (170 votes). Check out past polls.

    Notices?