in reply to Whats quicker - passing along as variable to sub, or global var?
my $bigref = bigget; ... do something ... do_something_more( $bigref ); sub bigget { local $/ = undef(); # disable carriage control locally open my $fh, $ENV{BIG_STUFF} or die "$!: \$ENV{BIG_STUFF}\n"; my $slurp = <$fh>; close $fh; \$slurp; # return the reference to $slurp, which also keeps it ali +ve outside this scope!!! } sub do_something_more { my $bigref = shift; # copying the ref not the string $$bigref =~ /^\s+(\S+)/; # using a dereference my $first_word = $1; ... do more ... }
One world, one people
|
|---|