On Fri, 2008-09-05 at 15:27 +0200, Dr.Ruud wrote:
> Why use $1 if you can get the match by putting the regex in a list
> context?
>
> while ( <$in> ) {
> if( my ($id) = m/^\s*(\d+)/ ) {
> $longz{$id} = $_;
> }
> else {
> die "no ID in line $.: $_";
> }
> }
Habit. You can also use capture variables in a substitution.
Substitutions only return the number of substitutions, not the capture
variables. For example, if you didn't want the student ID in the value:
if( s/^\s*(\d+)\s*// ){
my $id = $1;
$longz{$id} = $_;
}else{
die "no ID in line $.: $_";
}
--
Just my 0.00000002 million dollars worth,
Shawn
"Where there's duct tape, there's hope."
Cross Time Cafe
"Perl is the duct tape of the Internet."
Hassan Schroeder, Sun's first webmaster
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/