in reply to Readonly error on $_ again (better format, mehopes)
The problem it that in selfcontrol you assign to $_. In the for loop in your calling code $_ has been aliased to 'Operator' and you are trying to assign to that. In effect you are trying to do 'Operator' = 'foo'; which is not allowed.
The actual problem is that $_ is by default global between all subs in all packages (a topic which has been discussed on this site several times). The solution: start subs where you use $_ with local $_; or avoid $_ in non innermost loops (like your workaround did) or in this case use a different switch method such as:
Which works because for loops automatically localize $_.for ($ref) { last unless $_; last if /REF/; return $self; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2: Readonly error on $_ again (better format, mehopes)
by tilly (Archbishop) on Jan 05, 2001 at 17:01 UTC | |
|
Re: Re: Readonly error on $_ again (better format, mehopes)
by jeroenes (Priest) on Jan 05, 2001 at 17:08 UTC |