in reply to variable declaration shortcut question

The following will extract the leading digits from $fields[0] and place them in $maid:

my ($maid) = $fields[0] =~ /^(\d*)/;

In scalar context, the match op would return a value indicating whether the match was successful or not. That's useless to you since the pattern will always match. In list context, the match operator returns a list of a all the captures.

The parens around $maid are necessary to select the list assignment operator which places the match operator in list context.

Replies are listed 'Best First'.
Re^2: variable declaration shortcut question
by lomSpace (Scribe) on Feb 03, 2009 at 17:18 UTC
    That's it! Thanks I!