Friday, 15 June 2012

Perl class variables -



Perl class variables -

i cannot seem create variable global class , usable in subroutines of class.

i see examples on apparently work, cannot work.

code:

my $test = new player(8470598); bundle player; utilize strict; utilize warnings; utilize const::fast; $player::url = 'asdfasdasurl'; $test3 = '33333333'; our $test4 = '44444444444'; const $player::test0 => 'asdfasdas000'; const $test1 => 'asdfasdas111'; const our $test2 => 'asdfasdas222'; sub new{ print $player::url; print $player::test0; print $test1; print $test2; print $test3; print $test4; return(bless({}, shift)); }

output:

use of uninitialized value $player::url in print @ d:\text\programming\hockey\test.pl line 19. utilize of uninitialized value $player::test0 in print @ d:\text\programming\hockey\test.pl line 20. utilize of uninitialized value $test1 in print @ d:\text\programming\hockey\test.pl line 21. utilize of uninitialized value $player::test2 in print @ d:\text\programming\hockey\test.pl line 22. utilize of uninitialized value $test3 in print @ d:\text\programming\hockey\test.pl line 23. utilize of uninitialized value $player::test4 in print @ d:\text\programming\hockey\test.pl line 24.

what going on here?

while entire code compiled before executed, executable parts happen in order. in particular, new() phone call happens before of assignments or const calls in bundle player.

moving player code player.pm file , invoking use player; cause compiled , executed before new , work expect.

perl

No comments:

Post a Comment