http://www.perlmonks.org?node_id=58272


in reply to Re: Split - Not using arguments
in thread How do I use Split

Just tried that, now get "-- 1".
sub changedate { my $year=0; my $month=0; my $day=0; ($year, $month, $day) = split(/-/, @_, 3); return $day."-".$month."-".$year; }

It's something but it still aint right :)

Thanks, Alex

Replies are listed 'Best First'.
Re: Re: Split
by mikfire (Deacon) on Feb 14, 2001 at 09:40 UTC
    Just to clarify something here, you got the correct answer for what you asked perl to do. split() expects a scalar, which caused @_ to be evaluated in scalar context. In this case that was 1, since you where sending but one arguement to the subroutine. split() applied your regex and returned (1,undef,undef).

    I might suggest you read up on -w and use strict; as well - it would have at least flagged a warning on that line. It will also save you a lot of grief sooner or later.

    mikfire