S
sln
The dollar-digit variables are only set when the pattern match *succeeds*.
Therefore, you should never use the dollar-digit variables unless
you have first ensured that the match in question succeeded:
if ( /(\w+)\W*(\d2).*(\d2).*(\d2)\W*([-|+]\d+).*(\d+\.\d+).*(\d+\.\d+)
.*(-*\d+\.\d+).*(-*\d+\.\d+)\W*(\w+)\W*/x ) {
print "$1\n";
}
else {
print "match failed!\n";
}
I doubt that \d2 does what you think it does.
It matches 2-digit strings where the 2nd digit is a "2".
You probably want \d{2} instead?
I doubt that [-|+] does what you think it does. It matches any of 3
characters: vertical bar, plus sign, minus sign.
You probably want [+-] instead.
You probably want \W+ rather than \W*
You probably want .*? rather than .*
but I don't have output yet.:-(
Don't try to do it all at once. Get it working a little at a time:
/(\w+)\W+/
/(\w+)\W+(\d{2})/
/(\w+)\W+(\d{2}).*?(\d{2})/
etc...
Note that all of this is moot, because pattern matching is
not the Right Tool for what you are trying to accomplish...
I'm inclined to think that this is the way. With your changes, I'm getting
real clean input until I get halfway through:
my $filename = 'eph6.txt';
open(my $fh, '<', $filename) or die "cannot open $filename: $!";
while (<$fh>) {
/(\w+)\W+/;
/(\w+)\W+(\d{2})/;
/(\w+)\W+(\d{2}).*?(\d{2})/;
/(\w+)\W+(\d{2}).*?(\d{2}).*?(\d{2})/;
/(\w+)\W+(\d{2}).*?(\d{2}).*?(\d{2}).*?([-+]\d{2})/;
[snip]
I'm falling down laughing. This is better than the Comedy chanel.
sln