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

Re: Extracting string from a file

by Bindo (Acolyte)
on Nov 19, 2013 at 02:11 UTC ( #1063240=note: print w/replies, xml ) Need Help??

in reply to Extracting string from a file

Thank you very much for all the good advices gentlemen. Guess I owe you all a big apology since I have failed to reply. I was in the hospital due to a small accident and only last night I have been discharged. Now back at feet :)

I tried the following code but the program wont give any output nor any errors. Please can one of you correct this code for me? Please gentlemen Im a beginner who is trying to understand the whole concept of regexes more specifically with files, So be gentle.

my $SYS_HOME = $ENV{'SYSTEM_HOME'}; my $GD_FILE = $SYS_HOME."/GD.log"; my $FH; my @DUMP; open ($FH, '<', $GD_FILE) || die "Cant open : $!"; while (my $line = $FH) { if ($line =~ /~\|(TOTAL.*)/){ #my $tmp = $1; push @DUMP, $1; foreach (@DUMP) { print "$_\n"; } } }

Many thanks in advance! /Bindo

Replies are listed 'Best First'.
Re^2: Extracting string from a file
by RMGir (Prior) on Nov 20, 2013 at 13:09 UTC
    It's a simple bug - you're copying the file handle rather than reading from it.
    while (my $line = $FH) {
    should instead be
    while (my $line = <$FH>) {
    The "<>" around $FH reads from the filehandle (a line at a time, in this context).


      Thank you very much Mike. It worked. :) Really appreciate it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1063240]
and the radiator hisses contentedly...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2018-05-26 09:03 GMT
Find Nodes?
    Voting Booth?