Firstly, you're not using strict or warnings. That's bad™
Secondly, you do an opendir, but then you do nothing with the directory handle. That's a bit pointless.
Next, in your open line, you refer to $infilename - which has not been previously defined (strict and warnings would have alerted you to this).
So... here is a canonical way to achieve what you seem to be asking (untested):
#!/usr/bin/perl use strict; use warnings; my $file = '/path/to/file.txt'; open IN, "<", $file or die "Could not open $file:$!\n"; my $wanted; while (my $line = <IN>) { if ($line =~ /(All avg = \d+)/) { $wanted = $1; last; # get rid of this if you need/expect to match multiple + lines } }
That should be enough to get you going.
Update: added the "last" to the code, as per suggestion from ikegami
Cheers,
Darren :)
In reply to Re: Extract specific word from a phrase
by McDarren
in thread Extract specific word from a phrase
by clsyee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |