|No such thing as a small change|
Re: variable scope affects variables in crace shell escapesby DaveH (Monk)
|on Mar 30, 2003 at 11:03 UTC ( #246714=note: print w/replies, xml )||Need Help??|
I did a double take on this one, because at first it wasn't at all clear to me what was happening. I think that most of this confusion was because you called "" (double quotes) shell escapes. What you are referring to is not "shell escaping", it is "double quote interpolation".
Anyway, the problem you are having seems to be related to Perl's DWIM ("Do What I Mean") attitude to string interpolation, and it auto-vivifying arrays when you don't want them. In your example code, you are auto-vivifying two arrays: @a and @c. If you want to know more details, I suggest inserting the following at the top of your script:
Fortunately, there is a very simple solution - if you don't want Perl to treat square brackets ("[" and "]") as array subscripts, then escape them with a backslash ("\") in your strings.
(As an aside, you should really try to avoid $a and $b as variable names. Whilst I'm sure they were used just as an illustration, these are reserved variables which are used in the 'sort' built-in function. Although "use strict" won't complain about them, there is a good reason for this: they are always package global symbols. Moral: always use 'my' and stay away from $a and $b.)
I hope that helps.
-- Dave :-)
In Section Seekers of Perl Wisdom