Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: OO Design Question with Hashes of Arrays

by ahackney (Initiate)
on Jun 26, 2013 at 13:23 UTC ( #1040779=note: print w/ replies, xml ) Need Help??


in reply to Re: OO Design Question with Hashes of Arrays
in thread OO Design Question with Hashes of Arrays

Thanks for the input everyone. I do understand (somewhat) hashes of arrays data structure.

I have looked into moose and others as suggested. My needs are so small at this point (I'm almost done) that I think I'm going to keep hacking away at the base perl system.

Anonymous Monk, thank you so much. This was just what I needed and it works exactly as you demonstrated. I am ignorant of some of the syntax that you used and I was wondering if you could point me to an article that explains the syntax usage? I googled and could not find anyone using the syntax quite this way in my searches.

Specifically...

 = $_ for @_;

I'm guessing this is shorthand for a for loop, but, again, my searches have been fruitless and the man pages have not been helpful.

Thank you again monks for the assistance!


Comment on Re^2: OO Design Question with Hashes of Arrays
Download Code
Re^3: OO Design Question with Hashes of Arrays
by AnomalousMonk (Abbot) on Jun 26, 2013 at 17:09 UTC
    ... an article that explains the syntax usage ...
     = $_ for @_;
    I'm guessing this is shorthand for a for loop ...

    This is the statement modifier form of a for-loop. It iterates over the elements of a  LIST and 'topicalizes' (or aliases with localization) the default scalar  $_ (see perlvar) to each element in turn. Because  $_ is aliased, elements of an array can be altered "in place", which can be very helpful, even essential, in dealing with large arrays.

    >perl -wMstrict -le "$_ = 'same as it ever was'; ;; my @ra = (1, 2, 3, 4); ;; $_ = $_ + 990 for @ra; print qq{@ra}; ;; print 880 + $_ for 1, 2, 3, 4; ;; print $_; " 991 992 993 994 881 882 883 884 same as it ever was

    (For some insight into the difference between a list and an array, try executing the statement
        $_ = $_ + 990 for 1, 2, 3, 4;
    instead.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2014-12-25 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls