Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: array splitting

by CColin (Scribe)
on Jun 05, 2007 at 12:26 UTC ( #619366=note: print w/ replies, xml ) Need Help??


in reply to Re: array splitting
in thread array splitting

I note the code I posted actually didn't even work for the first list. I note this code does work and there's a few things in this that I don't know well, so good for learning, thank you.
if (! @times) presumably means if there is nothing in the array? This is a general confusion I have with perl, about what tests for a value being present in a variable and what "undef" means. I assume the exclamation mark I can always use to determine if values are (not) present in a variable from now on? Colin


Comment on Re^2: array splitting
Download Code
Re^3: array splitting
by blazar (Canon) on Jun 05, 2007 at 18:09 UTC
    if (! @times) presumably means if there is nothing in the array?

    Yes. Alternatively you could use

    unless (@times) { # ...

    which may be clearer to understand naively, based on the rationale that a full thingy is true and an empty one is false.

    This is a general confusion I have with perl, about what tests for a value being present in a variable and what "undef" means.

    undef is a builtin function which can take a variable and give it a special value which is also its own return value. The latter is thus in turn also called undef: in fact the function is often used with no argument in which case it simply returns it. undef is a particular false value, precisely the one that also have variables which have not been initialized at all.

    I assume the exclamation mark I can always use to determine if values are (not) present in a variable from now on?

    The exclamation mark is simply a logical "not" that turns a true value into a false one and vice versa.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-08-29 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls