Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Conditional initialisation

by Akhasha (Scribe)
on May 25, 2004 at 01:44 UTC ( [id://356099]=note: print w/replies, xml ) Need Help??


in reply to Re: Conditional initialisation
in thread Conditional initialisation

Ah, well the last time I used this construct it was for a function that could accept either a unix timestamp as a scalar, or a time vector as returned by localtime() or gmtime().

So I was checking the length of @_ to see if it was greater than 1 (not 0), like this:

sub unix_to_datetime { my @time_vec; @time_vec = @_ if @_>1; unless (@time_vec) { my $time = shift; @time_vec = (defined $time ? localtime($time) : localtime); } return strftime('%Y-%m-%d %H:%M:%S', @time_vec); }

Replies are listed 'Best First'.
Re: Re: Re: Conditional initialisation
by dragonchild (Archbishop) on May 25, 2004 at 02:00 UTC
    Wouldn't the following work just the same?
    sub foo { my @time_vec = @_ > 1 ? @_ : defined $_[0] ? localtime($_[0]) : localtime; return strftime('%Y-%m-%d %H:%M:%S', @time_vec); }

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-19 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found