bipinbalan has asked for the wisdom of the Perl Monks concerning the following question:
I given the two scripts below. the two scripts will give the same output. But in the first one, I used pass by reference and the second, I used "local".
#### Script 1 : #####
#!/usr/bin/perl -w use strict; &foo1; sub foo1 { my $first=1; &foo2(\$first); print "$first\n"; } sub foo2 { my $second=shift; print "$$second\n"; $$second++; }
#### Script 2 : #####
#!/usr/bin/perl -w use strict; use warnings; &foo1; sub foo1 { local $b=1; &foo2; print "$b\n"; } sub foo2 { print "$b\n"; $b++; }
My doubt is that which program is more efficient ? Whether we can use "local" instead of "pass by reference" ?
Hoping for the reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using local and pass by reference method
by ysth (Canon) on Feb 11, 2008 at 11:33 UTC | |
|
Re: using local and pass by reference method
by hipowls (Curate) on Feb 11, 2008 at 10:56 UTC | |
|
Re: using local and pass by reference method
by stiller (Friar) on Feb 11, 2008 at 12:02 UTC | |
|
Re: using local and pass by reference method
by Narveson (Chaplain) on Feb 11, 2008 at 14:55 UTC |