in reply to Values passed into a sub routine

If I follow, the syntaxcalling convention is

build_url($account, [ $transaction, [ $location, ] ] $fname, $lname);

where square brackets denote optional parameters. You could use

sub build_url { my $lname = pop; my $fname = pop; my ($account, $transaction, $location) = @_; ... }
or
sub build_url { my $account = shift; my $transaction = @_>=4 ? shift : undef; my $locaton = @_>=3 ? shift : undef; my $fname = shift; my $lname = shift; ... }
or
sub build_url { splice(@_, 1, 0, (undef)x(5-@_)) my ($account ,$transaction, $location, $fname, $lname) = @_; ... }

Replies are listed 'Best First'.
Re^2: Values passed into a sub routine
by Anonymous Monk on Apr 19, 2011 at 17:18 UTC
    I like this way as you stated, but:
    build_url( $account,[$fname], [$lname]); sub build_url { my $lname = pop; my $fname = pop; print "$lname and $fname\n"; my ($account ,$transaction, $location) = @_; ... }

    If a run this I am getting this:
    Lname=ARRAY(0x8967f28) and Fname=ARRAY(0x8967748)
    Any suggestion? Thanks!

      To put it differently, I understood that you want to support the following three calling conventions and only those three calling conventions:

      build_url($account, $fname, $lname); build_url($account, $transaction, $fname, $lname); build_url($account, $transaction, $location, $fname, $lname);

      If so, all three alternatives I provided should work.

      What about this:
      build_url( account => $account, fname => $fname, lname => $lname], ); sub build_url { my (%args) = @_; my $account = $args{account} || ''; my $fname = $args{fname} || ''; my $lname = $args{lname} || ''; my $other = $args{other} ||''; ... }

      There, it should prevent it to be out of order right?