bowei_99 has asked for the wisdom of the Perl Monks concerning the following question:
With this code:hostname: / level=incr, 1015 MB 00:00:54 + 26137 files hostname: /boot level=incr, 3731 KB 00:00:13 + 8 files hostname: /directory1 level=incr, 2796 MB 00:01:28 71 + files hostname: /directory2 level=incr, 1369 MB 00:5 +3:51 36 files --->truncated here<--
and it catches the first line OK and prints the captured values. However, it's not doing that for the other lines else after that, i.e. hits the 'else' and prints "here ->...". I've checked the input file for special characters, of which there are none. In fact, I don't see anything differentiating the format of the lines, i.e. don't know why only the first line is parsed correctly.use constant HOST_LINE => qr{ \s+ \w+: \s [\/\w+] \s+ # host, partition level=\w+, \s+ # backup level (\d+) \s+ (\w+) \s+ # amt backed up \d+:\d+:\d+ \s+ # Time (\d+) \s+ files # num. files }xms ; my @lines = <STDIN>; for my $line (@lines) { if ( $line =~ HOST_LINE ) { my ($files, $units, $amt_backed_up) = ($3, $2, $1); print "line - $line, units - $units, amt - $amt_backed_up, fil +es $files\n"; } else { print "here -> $line" } }
Thoughts, anyone?
-- Burvil
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regexp parses only first line correctly
by NetWallah (Canon) on Aug 16, 2008 at 19:03 UTC | |
Re: Regexp parses only first line correctly
by broomduster (Priest) on Aug 16, 2008 at 19:10 UTC | |
by NetWallah (Canon) on Aug 16, 2008 at 19:22 UTC | |
by broomduster (Priest) on Aug 16, 2008 at 19:38 UTC |