in reply to partial results in $1 $2 after re failure
The output is#!/usr/bin/perl -w use strict; $_ = "abc def\n"; /^(\w+)\s+(\w+)$/; print "<$1><$2>\n"; $_ = "xyz 6-7\n"; /^(\w+)\s+(\w+)$/; print "<$1><$2>\n"; $_ = "123 456\n"; /^(\w+)\s+(\w+)$/; print "<$1><$2>\n";
Which is what the expected output of your snippet should be. FWIW, replacing the while(<DATA>) with a for(@data) type construct, also producted erroneous results.<abc><def> <abc><def> <123><456>
Before using $1 et all, you really should check to be sure your match succeeded:
while (<DATA>) { if (/^(\w+)\s+(\w+)$/) { print "<$1><$2>\n"; } else { print "Line $. didn't match\n"; } }
-Blake
|
|---|