in reply to Re^2: Passing variables to subroutines using Getopt::Long
in thread Passing variables to subroutines using Getopt::Long
use strict; use warnings; use Getopt::Long; @ARGV = qw( --user user --password pass --fetch bob ); { my $user; my $password; my $fetch; GetOptions( 'fetch' => sub { my( $n, $k, $v ) = @_; print qq~ name = $n key = $k value = undef ~; $fetch = $k ; }, 'user=s' => \$user, 'password=s' => \$password, ); SOMETHING( $user, $password, $fetch ); die "THE END"; } sub SOMETHING { my( $user, $password, $fetch ) = @_; print qq~ user = $user password = $password fetch = $fetch ~; } __END__ $ perl f.pl name = fetch key = 1 value = undef user = user password = pass fetch = 1 THE END at f.pl line 27.
|
|---|