Don't ask to ask, just ask | |
PerlMonks |
Readonly error on $_ again (better format, mehopes)by jeroenes (Priest) |
on Jan 05, 2001 at 16:10 UTC ( [id://50037]=perlquestion: print w/replies, xml ) | Need Help?? |
jeroenes has asked for the wisdom of the Perl Monks concerning the following question: Note: My previous posting looks terrible, but I can't update it... so I reposted. If someone could remove the ugly one, please do so. I encountered something that puzzles me. I have a workaround, but I'd like to know why it happens. If you would be so kind to share your wisdom with me, or at least point me to some docs, I'd be very grateful. It's my very first OOP project in perl, so please be patient with me. In short, a function that does a SWITCH:{$_ = .... gets an error 'Modification of a read-only value attempted' when when two function calls back a $_ was passed as the first parameter. It's getting lengthy here, so.... Let's start with the last function. After two hard-to-debug errors, I decided to write a module that checks whether a method was called with a $self->. This module is exports the function selfcontrol and contains the following code: Normally, this works. I call this function in the first line of a method this way: because I fear the selfcontrol will slow things up when it's called too often, and I have a feeling that using modules to find out the caller would not greatly improve on speed. $bugfree is a global scalar declared with use vars. Well, somewhere in my actual class (well, at line 300 of over 1100) I use a for loop: The findTokenPos first does the selfcontrol magic, and it gets beaten like hell: This is my workaround: And hey, no errors any more! Could anyone please telling me why the first for loop doesn't work? Thanks a lot! Jeroen
Back to
Seekers of Perl Wisdom
|
|