Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Re: Re: push

by arturo (Vicar)
on Jan 31, 2001 at 18:58 UTC ( #55473=note: print w/replies, xml ) Need Help??

in reply to Re: Re: push
in thread push

I'm not seeing the problem, unless it has to do with that last at the end of the conditional within the loop that traverses the file. The way your code above is written, you will only ever get one entry, because the last breaks out of the while.

Conceptually, it seems you want a list of the lines in the file that match your criterion, so you definitely should use a single array to hold them all. The way you've written things so far, you want to store those lines not as simple strings (which may or may not be what you should do, depending on the overall aim) but as hashes. Perl doesn't directly support multi-dimensional arrays, or arrays of hashes, but it lets the programmer do it by giving you the ability to store references to any kind of variable any place where you can use a scalar.

To figure out what the implications of that are, and how to use the tools Perl gives you, you're going to need to consult the documentation I pointed to in my posts above. The basic idea: arrays hold scalars; references are a special type of scalar -- you can think of them as arrows that point to data structures (such as hashes), so what you need to do when you've got a value that is a reference is to get at the thing the reference points to; there are a number of ways of doing that, but here's not the place to duplicate the documentation you have available to you.

To perform an operation on every element of an array (such as printing out the elements -- NOTE this won't work as you expect if the members of the array are references) , you will almost always want to use foreach.


Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (1)
As of 2022-01-25 05:29 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (65 votes). Check out past polls.