Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: what is @$varname in perl

by AppleFritter (Vicar)
on Jul 03, 2014 at 10:38 UTC ( [id://1092140]=note: print w/replies, xml ) Need Help??


in reply to Re^2: what is @$varname in perl
in thread what is @$varname in perl

I'm not entirely sure what your question is, or where the confusion lies. Could you clarify?

As I said above, references are sort of like pointers in C, if you're familiar with that. A data structure lives somewhere in memory; another variable, a scalar (which might in turn be an element of an array or hash, of course) holds a reference to it. A redirect, if you will: "the data you're looking for is found in another location. Walk this way!"

Programming Perl has an entire chapter on references, so if you've got that book, I'd read that. (If you don't have that book, buy it, it's a must-have for any Perl programmer.) Also, see perlref for a less gentle introduction.

Anyhow, to sum it up:

  • $row contains (colloquially: is) a reference to an array, i.e. the one that split returns.
  • That array does not have a name of its own; i.e., it's not @array or any such thing.
  • However, you can use the reference in $row -- "walk this way", as it were, following the directions it contains -- by dereferencing the reference. For an array reference, this is done by adding the array sigil, @: @$row.
  • The same applies to $sheet2 and @$sheet2.
  • Finally, @$sheet2 -- an array, remember! -- is used to store a list of references, each of which points to another array: one for each row.

So you have something like this for each line:

$row @$row +---+ +-----+-----+-----+-- | *-----> | ... | ... | ... | ... +---+ +-----+-----+-----+--

and something like this for the entire file:

$sheet2 @$sheet2 (each of the @$row's) +---+ +---+ | | +-----+-----+-----+-- | *-----> | *-----> | ... | ... | ... | ... +---+ | | +-----+-----+-----+-- +---+ | | +-----+-----+-----+-- | *-----> | ... | ... | ... | ... | | +-----+-----+-----+-- +---+ | . | .

Does that make it clearer?

Replies are listed 'Best First'.
Re^4: what is @$varname in perl
by sandy105 (Scribe) on Jul 03, 2014 at 10:59 UTC

    thank you !!!! ..that cleared up my doubts.

    guess i bought the wrong book :learning perl -O'reilly.

    It does'nt have the topics which i have had problems with since starting with perl like map,threads,queue,reference :(

      ...guess i bought the wrong book :learning perl -O'reilly...

      Maybe not! Learning Perl is also a great book directed towards beginner in Perl. Maybe that is not the book you would have wanted since you have understanding in programming.
      You might then look at Beginning Perl by Ovid and Modern Perl by Chromatic. Am those will get you the lift you are looking for... :).

      Welcome to the realm of all possibilities, welcome to Perl Programming. Timtoday!!!

      Update:

      Let me also add that there is Intermediate Perl by the same Authors who wrote Learning Perl, that should be the one you wanted.

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me

      Glad to have been able to help! *tips hat*

      And Learning Perl is a good book, really -- but it's not a complete reference (no pun intended) for the language.

      Re: Perl Documentation / Learning Projects has a list of useful books, BTW.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-25 14:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found