in reply to Extracting an array from a module

Retrieving @_ outside a sub indeed looks wrong to me. I wouldn't do it. I use @_ only inside subroutines. If you use a lexical filehandle, you can drop the close
use Fcntl ':flock'; # import LOCK_* constants sub gencli { open my $fh, '<', $gencli or die "Can't open $gencli $!"; flock ($fh, LOCK_EX) or die "Can't lock $gencli for reading: $!"; wantarray ? <$fh> : [<$fh>]; } my $gencli_ref = gencli(); # both of these my @gencli_ary = gencli(); # work
since it is done implicitly (and the lock removed) at subroutine return.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: Extracting an array from a module
by jonnyfolk (Vicar) on Oct 14, 2007 at 06:55 UTC
    I quite agree with the 'looks wrong' of the second example. I shall follow your advice re LOCK_* constants. Thank you.