Feed on
Posts
Comments

perl sometimes is just too easy. so easy that it’s confusing.

for instance, to print the length of an array @my_array, you don’t need a length command or anything. instead, just code:

print @my_array;

(no way i’m ever going to remember a command that simple.)


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

3 Responses to “get the length of a perl array”

  1. on 25 Sep 2009 at 11:12 am some_user

    Yes, you got this wrong.

    “print @array” actually prints the contents of the array, not the length.

  2. on 12 Feb 2010 at 7:01 am ITtuition.com

    Agreed, this will print the contents of the array, not the length.

  3. on 17 Feb 2010 at 7:42 pm Taurus Olson

    Hi,
    I think you can do something like this to get the length of an array:

    my $length;
    $length = @my_array;
    print $length;

    Really perlish.

Did I get this wrong? Let me know!

Trackback URI | Comments RSS

More blogs about http://desk.stinkpot.org:8080/tricks.