in reply to Array regex matching
s/// only works on one scalar at a time, so the right side of =~ gets scalar context (gets interpreted as a scalar). Because it is often convenient, a list assignment (what you have in parentheses) in scalar context results in the number of elements on the right side of the assignment.
So if param() returns 27 values, you will be doing "27" =~ s/\cM//g; (except that gets a "Can't modify" error)
In your case you should have gotten a "Can't modify list assignment in substitution (s///)" compile error. That you didn't is a bug in perl. I note that you can also say things like ++(my @v = foo()) which should also result in an error.
Update: I meant to also say: the correct way to do what you intend is to loop over the array:
Update: spelling mistakemy @values = $q->foo($key); s/\cM//g for @values;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Array regex matching
by Roy Johnson (Monsignor) on Jan 13, 2004 at 16:23 UTC |