arcnon has asked for the wisdom of the Perl Monks concerning the following question:
### original post ####!/usr/bin/perl -w use strict; system('clear'); my $test = first(); two($test); sub first{ my @data; my %objREF; $data[2] = 'hi there'; $objREF{poker} = \$data[2]; } sub two{ my $objREF = shift; #print "$objREF{'poker'}"; #print "$$objREF{'poker'}"; #print "$objREF->{'poker'}"; #print "$$objREF->{'poker'}"; #print "$$$objREF{'poker'}"; #print "$$$$objREF{'poker'}"; #print "${$objREF{'poker'}}\n"; print "$${$objREF->{'poker'}}\n"; }
#!/usr/bin/perl -w use strict; system('clear'); my @data; $data[2] = 'hi there'; my %objREF; $objREF{poker} = \$data[2]; print "struct example\n"; print "======================================\n"; print "original value:\n"; print_me(); print "change by array value:\n"; $data[2] = 'joker'; print_me(); print "change value by ref:\n"; ${$objREF{poker}} = 'batman'; print_me(); print "change the array\n"; $data[2] = 'robin'; print_me(); sub print_me{ print "array is: $data[2]\n"; print "Ref is: ${$objREF{poker}}\n\n"; }
Edit by castaway - restored original content
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: code sample: possible improvements
by davido (Cardinal) on Jan 10, 2005 at 03:44 UTC | |
by arcnon (Monk) on Jan 10, 2005 at 03:57 UTC | |
by davido (Cardinal) on Jan 10, 2005 at 04:12 UTC | |
|
Re: code sample: possible improvements
by Errto (Vicar) on Jan 10, 2005 at 04:50 UTC | |
|
Re: code sample: possible improvements
by NetWallah (Canon) on Jan 10, 2005 at 01:43 UTC | |
by arcnon (Monk) on Jan 10, 2005 at 02:42 UTC |