Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^2: reading file into an array

by vassago (Novice)
on Dec 05, 2008 at 21:26 UTC ( #728388=note: print w/replies, xml ) Need Help??

in reply to Re: reading file into an array
in thread reading file into an array

Sorry, it starts on line 15. Thanks for the reply. It is working now. And I like your way of the while loop much better than what I used. However, I'm new to perl and don't fully understand your for loop. I assume the "13 .." just means start at 14 but why is there a '#' in front of the fileContents and why $ instead of @? Java was my first language so perl is very different and its taking a lot of getting used to. Thanks for the replies!

Replies are listed 'Best First'.
Re^3: reading file into an array
by McDarren (Abbot) on Dec 05, 2008 at 21:52 UTC
    $# (not #$) refers to the index of the last element of an array.

    The "at-sign" sigil (@) is used when you refer to two or more elements of an array. If you are accessing (or referring to) a single element of an array, then the "dollar-sign" ($) sigil is used.

    For example:

    my @foo = qw/a b c/; print "$foo[1]\n"; # Prints b print "@foo\n"; # Prints a b c print "$foo[$#foo]\n"; # Prints c (but you would probably never do th +is) print "$foo[-1]\n"; # Also prints c (a better way than the previou +s) print "@foo[0,2]\n"; # Prints a c

    Darren :)

Re^3: reading file into an array
by gwadej (Chaplain) on Dec 05, 2008 at 21:41 UTC

    For an array @array, $#array gives the index of the last item in the array. It's a minor piece of cryptic Perl syntax.

    G. Wade

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://728388]
and the sunlight beams...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2018-07-21 19:31 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (450 votes). Check out past polls.