/ Published in: Perl
Use anonymous hash to keep arguments to a sub sane
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!perl use strict; use warnings; use Data::Dumper; my @a = (16, 32); #call main main(); #program execution stops here #subroutine main sub main { #call subroutine "function1" with a hash as args function1( arg1 => 'foo', arg2 => 'bar', arg3 => \@a, ); } sub function1 { my (%args) = @_; #define the output record separator and the array separator for printing #can be used in strings without spaces #sometimes the inline dereferences get ugly, so you can deref to a var if you want my @ref3 = @{$args{arg3}}; #use Data Dumper (core module) to print everything. Can be evaled in from a file to recreate struct }