Re: Question about dereferencing

[email protected] (Rob Dixon)
Newsgroups perl.beginners
Message-ID <[email protected]>
Christopher Yee Mon wrote:
> 
> I have a bit of Perl homework where we got a code sample. I can see what
> the code sample is doing except for two little bits
> 
> There's a part that has $row->[$i] and a part that has @$row . What do
> these two parts mean?
> 
> The code sample turns csv into fixed width so it reads each line of the
> file into an array @rows. Then in a for loop
> 
> for $row (@rows) {
> 
> There's another for loop
> 
> for $row (@rows) {
> ~  for ($i = 0; $i < @$row; i++) {
> ~    $w = length $row->[$i]
> ~    ...
> 
> I'm assuming that the $row is itself another array or can be treated as
> one and @$row can give you a number of the elements in it and $row->[$i]
> is some sort of deferencing mechanism. The perlop page seemed a bit
> cryptic to me as to what the arrow operator does exactly and I could
> search for the use of @ in that context.
> 
> Any assistance would be appreciated.

Since it's homework (thank you for telling us) you should do your own research
so that it sticks in your memory.

Take a look at

  perldoc perlref

and

  perldoc perlreftut

and see if that helps you. If you're still struggling after studying those
documents then we're still here :)

(By the way, the piece of code you've shown breaks a couple of rules that you
may want to ask about when you have solved the problem at hand!)

Rob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.