Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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


Comment on Re: Extracting string from a file
Download Code
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).

    Mike

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-09-19 10:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (135 votes), past polls