Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Can PERL know a line without matching?

by bikeNomad (Priest)
on Jul 27, 2001 at 20:28 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://100357]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-23 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found