Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Split - Not using arguments

by lemming (Priest)
on Feb 14, 2001 at 04:54 UTC ( [id://58269]=note: print w/replies, xml ) Need Help??


in reply to How do I use Split

You missed reading in the argument for your subroutine. hint: @_

Replies are listed 'Best First'.
Re: Split
by fastkeys (Novice) on Feb 14, 2001 at 04:59 UTC
    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
      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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://58269]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-20 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found