Hi Deane.Rothenmaier -
At 2005-10-19, 10:42:55 you wrote:
>This is going to be a head-slapper, I know, but it's late and my brain
>hurts... I've got a script that has a sub that accepts a hash of
>arguments, one of which happens to be an array. If I pass the array as a
>reference, everything works fine.
>
>Now for the head slapping part, how do I handle things INSIDE the sub so I
>don't have to pass the array as a reference? Code and desired output are
>below.
Sorry, No way. when you say:
my %args = ( -s1 => undef,
-s2 => undef,
-ar => undef,
@_
);
perl uses @_ as part ot the hash and will assign
$_[0] => $_[1],
$_[2] => $_[3],
...
and so on. In fact, if @_ has an odd number of elements
perl issues a warning (try it). Arrays within hashes must be
references.
You got a problem with references? :)
>
>Thanks,
>
>Deane
>
>use strict;
>use warnings;
>
>sub do_smthng{
>my %args = ( -s1 => undef,
> -s2 => undef,
> -ar => undef,
> @_
> );
>
> print " s1: $args{-s1}\n";
> print " s2: $args{-s2}\n";
> print "ary[0]: $args{-ar}->[0]\n";
> print "ary[1]: $args{-ar}->[1]\n";
> print "ary[2]: $args{-ar}->[2]\n";
>}
>
>
>my @arg_ary = ( 'alpha', 'bravo', 'charlie' );
>
>do_smthng( -s1 => 42,
> -s2 => 96,
> -ar => [EMAIL PROTECTED] ); # I wanna lose the "\" here
>
>
>Desired output:
> s1: 42
> s2: 96
>ary[0]: alpha
>ary[1]: bravo
>ary[2]: charlie
>_______________________________________________
>ActivePerl mailing list
>[email protected]
>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>No virus found in this incoming message.
>Checked by AVG Anti-Virus.
>Version: 7.0.344 / Virus Database: 267.12.4/143 - Release Date: 10/19/2005
Aloha => Beau;
[EMAIL PROTECTED]
2005-10-19
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs