Paav has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to write a script, that will be recieving information from a file. When I compile it I get an error, that stats, "Use of uninitialiexed value at ./filehandlers1.pl line 1.". Why is that?? The program is supposed to parse the line with total in it. there is file rows there. i need to use the las two, the one with the total.
..... ..... .... .... .... ..... ..... .... .... .... total 1234 1234 5678 7894
I need to use the the numbers "5678" and "7894", and graph them in excel everyday. The graph would be "day" vs "total". I hope this makes what I am trying to do a little easier to understand. Now my code reads...
#!/usr/local/bin/perl -w my($currentLine, $name, $infilename); chomp ($infilename = "temp1.pl"); if ($ currentLine =~ /^ \$name:/) { print $currentLine; }
Thanks alot, Paav

Replies are listed 'Best First'.
RE: parsing from a file
by jjhorner (Hermit) on Jun 15, 2000 at 04:33 UTC

    I think you posted to the wrong section, but oh well.

    Your code should read something like this:

    #!/usr/local/bin/perl -w use strict; # never, never leave home without it. my ($currentLine, $name); #not needed because not used!! my $infilename = "temp1.pl"; open (INFILE, "$infilename") || die "Thanks for pointing this out chromatic: $!"; while (<INFILE>) { if (/^Total/) { my @values = split; #do something with $value[3] and $value[4]; } }

    Didn't I answer this on another node?

    J. J. Horner
    Linux, Perl, Apache, Stronghold, Unix
    jhorner@knoxlug.org http://www.knoxlug.org/