in reply to reading var from the file
It seems you want to collect lines until the next line that begins with Temp:. The pattern for this is:
my $temp; while (<>) { chomp; if (s/^Temp:\s*//) { if (defined($temp)) { ...use $temp... }; $temp = $_; } else { $temp .= $_; } } if (defined($temp)) { ...use $temp... }
My original answer:
This just looks for lines that end in a string of digits followed by a slash and assumes it's the information you're looking for.while (<>) { next unless m{(\d+)/$}; my $temp = $1; ...use $temp... }
If it is necessary to find the Temp: prefix on the same line or the line before, then this should work:
while (<>) { next unless /^Temp:/; my $temp; if (m{(\d+)/$}) { $temp = $1; } else { $_ = <>; # read the next line next unless m{(\d+)/$}; $temp = $1; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: reading var from the file
by perlb (Initiate) on May 17, 2008 at 15:33 UTC |