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


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

Replies are listed 'Best First'.
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.