in reply to Values passed into a sub routine

use named Parameter passing concept like

build_url(account => "test",transaction => "test1", location => "India +", fname => "Nikhil", lname => "jain"); build_url(account => "test", fname => "nikhil", lname => "jain"); build_url(account => "test" ,transaction => "test1", fname =>"nikhil", + lname => "jain"); sub build_url { my (%args) = @_; my $fname = $args{fname} || "Bob the Builder"; my $lname = $args{lname} || "none that we know"; }

Replies are listed 'Best First'.
Re^2: Values passed into a sub routine
by believer (Sexton) on Apr 19, 2011 at 18:47 UTC
    This is the way to go imho. Remove the $ in the parameter names though (so account => "test" instead of $account => "test") I like this idiom:
    sub build_url { my %param = ( fname => "default value", ..., @_ ); ... # do stuff with $param{account} etc. }