Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Parsing a file

by allolex (Curate)
on Jan 22, 2004 at 18:07 UTC ( [id://323264]=note: print w/replies, xml ) Need Help??


in reply to Parsing a file

You're not quite there with filehandles, yet. First you are telling Perl to get each line (actually record) in a file, one at a time, using while. Then you're making a reference to that same filehandle again while the line you want is already in the special variable $_.

Try this (untested) code:

print header, start_html('log parsing'); open(FILE, "<", 'log.txt') or die "Cannot open file: $!"; while (<FILE>) { # $_ is your message, but you could also # say "while my $message ..." to store # each line in $message chomp; # gets rid of newlines, etc. if ( m/(^Alberta226:)\s+(.*)/ ) { # you just need # the one anchor print "$1: $2<br>\n"; # add a newline for HTML output legibility } } close (FILE) or die "Cannot close file: $!";

--
Allolex

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-24 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found