tags:

views:

93

answers:

3

What is the $1? Is that the match found for (\d+)?

$line =~ /^(\d+)\s/; 
next if(!defined($1) ) ;
$paperAnnot{$1} = $line;
+3  A: 

you are right, $1 means the first capturing group, in your example that is (\d+)

knittl
+2  A: 

Yep, anything captured in parentheses is assigned to the $1, $2, $3... etc magic variables. If the regexp doesn't match they'll be undefined.

Mikesname
+2  A: 

Yep! It's a group match. Seeing the next there, it's probably in a loop. However, a better way of handling what you have there would be to use a conditional and test the regex:

if ( $line =~ /^(\d+)\s/ )
{
    $paperAnnot{$1} = $line;
}

or even better, give $1 a name to make it self documenting:

if ( $line =~ /^(\d+)\s/ )
{
    my $index = $1;
    $paperAnnot{$index} = $line;
}

Also, you can find more about $1, and its brethren in perldoc perlvar.

Robert P