in reply to Re: passing string to sub and string split
in thread passing string to sub and string split
Marshall's advice can also be applied to when the OP wants to pass multiple arg hashes they can be passed as refs and looped over (avoiding the nasty splitting of args!):
#!usr/bin/perl -w ## shamelessly copied from Marshall use strict; use Data::Dumpe qw/Dumper/; ## pass two anon hash refs to the sub Some_subroutine( { 'NAME' => 'name222', 'COLOR' => 'yellow', 'SIZE' => 'big', }, { 'NAME' => 'name444', 'COLOR' => 'yellow444', 'SIZE' => 'big444', }, ); sub Some_subroutine { ## collect the refs passed to the sub my @list = @_; ## just to see what we got print Dumper \@list; ## loop through each ref passed and process as before for my $ref (@list){ foreach my $key (keys %$ref) { print "key $key \tvalue is $ref->{$key}\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: passing string to sub and string split
by Marshall (Canon) on Aug 02, 2009 at 14:36 UTC |