in reply to Passing a hash into a subroutine
You could do this:
Or you could do as someone already suggested and use the anonymous hash constructor curly braces (which creates a reference to an anonymous hash), like this:use Converter; my $document = new Converter; my %convert_args_hash = ( 'MIME-Type' => 'application/ms-word', 'Input' => '[In file]', 'Output' => '[Out file]' ); my $convert_args_hashref = \%convert_args_hash; my $status = $document->convert($convert_args_hashref);
and then in the "convert" method (subroutine) you would just accept the hashref as the one and only argument, something like this:my $status = $document->convert( { 'MIME-Type' => 'application/ms-word', 'Input' => '[In file]', 'Output' => '[Out file]' } );
Hopefully you get the idea.sub convert { my $args_hashref = shift; print "The MIME-Type parameter = $args_hashref->{'MIME-Type'}\n" +; ### blah blah ### } # end sub convert
|
|---|