in reply to first two words-pattern matching
If that's the case:
use strict; # Don't comment it out. open RERUN, "rerunlrg" or die "Couldn't open input file.\n$!"; while ( my $line = <RERUN> ) { print "Matched:\n$1\n\n" if $line =~ m/^(\S+\s+\S+)/; } close RERUN;
Go ahead and give that a try.
One problem your regexp has is that you're not putting a quantifier after your \w metachars. That means that you're trying to match a single word character, followed by any positive amount of whitespace, followed by a single word character, followed by a single whitespace, followed by any amount of anything. You really want to be matching words of arbitrary length, presumably longer than a single character each.
Another problem your script has is that you're not checking for success when you open the file. You should probably be invoking die if there is a failure to open the file. See the example I provided. You can read up on this issue in perlopentut.
Dave
|
|---|