BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
Why does the relative positioning of these code elements matter?
C:\test>type t-Moose.pl #! perl -slw use strict; { package test; use Moose; has x => ( is => 'rw' ); sub doit { my( $self ) = @_; print $self->{ x }; print ${ $self->{ x } }; } } our @c = 12345; my $o = test->new( x => \$c[ 0 ] ); $o->doit; C:\test>perl t-Moose.pl SCALAR(0x229cd4) 12345
Invert the ordering and:
C:\test>type t-Moose.pl #! perl -slw use strict; our @c = 12345; my $o = test->new( x => \$c[ 0 ] ); $o->doit; { package test; use Moose; has x => ( is => 'rw' ); sub doit { my( $self ) = @_; print $self->{ x }; print ${ $self->{ x } }; } } C:\test>perl t-Moose.pl Use of uninitialized value in print at t-Moose.pl line 14. Can't use an undefined value as a SCALAR reference at t-Moose.pl line +15.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Do Mooses always want to face north?
by ferreira (Chaplain) on Jun 14, 2008 at 13:00 UTC | |
|
Re: Do Mooses always want to face north?
by dragonchild (Archbishop) on Jun 14, 2008 at 13:59 UTC | |
|
Re: Do Mooses always want to face north?
by ikegami (Patriarch) on Jun 14, 2008 at 16:40 UTC | |
by BrowserUk (Patriarch) on Jun 14, 2008 at 18:12 UTC | |
by Popcorn Dave (Abbot) on Jun 14, 2008 at 18:30 UTC | |
by swampyankee (Parson) on Jun 14, 2008 at 19:04 UTC | |
by Popcorn Dave (Abbot) on Jun 14, 2008 at 19:19 UTC | |
by Gavin (Archbishop) on Jun 15, 2008 at 09:42 UTC | |
|
Re: Do Mooses always want to face north?
by moritz (Cardinal) on Jun 14, 2008 at 14:10 UTC | |
by zentara (Cardinal) on Jun 14, 2008 at 16:50 UTC |