Hughes, Andrew wrote:
This is a newbie observation, but aren't you not supposed to name one of
your own variables with a number as the first value after a $, @, or % as in
the case of $2?  Could this be part of the problem?


Just to make sure this doesn't slip through, in his case $2 refers to the second match in the previous regular expression so he was using it correctly. This is a variable automagically set by Perl during the regular expression operation he had based on the grouping ().


So for example:

if ($string =~ /^(\d*)65(\d*)/) {

within this block $1 will be set to anything that matched before the '65' and $2 will be set to anything matched after the '65'. And so on...

}

Because of these types of special cases you shouldn't use variable names such as $1, $2, $3, $a, $b (see 'sort'), etc.

You will also find in the case of the numbers, that the variable is a global so 'my'ing will fail, and on top of that you will most likely get a bareword found where operator expected syntax error (though there may be ways around that). So your suggestion not to use that type of variable name is correct, for your own variables, but there are times when you will want to use Perl's builtin variables, which was the case here...

http://danconia.org


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to