~~David~~ has asked for the wisdom of the Perl Monks concerning the following question:
The _wafer_parse sub has a while loop in it. If I call $obj->wafer( '01' ) a single time, all is well. If I call $obj->wafer( '05' ) a second time with a new value, I get this error:before 'wafer' => sub{ my $self = shift; if ( ! $self->_wafer_parse_complete ){ $self->_wafer_parse }; };
I have found that by changing the while loop to a foreach loop, the problem goes away. I am using the while loop to read through a file, so I don't want to use foreach.Use of uninitialized value in subroutine entry at Class/MOP/Method/Wra +pped.pm line 47 Can't use string ("") as a subroutine ref while "strict refs" in use a +t Class/MOP/Method/Wrapped.pm line 47.
If I removed the open command, the subroutine runs fine.sub _wafer_parse { my $self = shift; open my $FILE, "<", $self->{file}; while ( <$FILE> ){}; close $FILE; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: While Loop in Before Modifier Gives Error
by morgon (Priest) on Jun 23, 2009 at 23:27 UTC | |
by ~~David~~ (Hermit) on Jun 24, 2009 at 14:48 UTC | |
|
Re: While Loop in Before Modifier Gives Error
by ikegami (Patriarch) on Jun 24, 2009 at 16:05 UTC | |
by ~~David~~ (Hermit) on Jun 24, 2009 at 21:33 UTC |