Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: push

by malaga (Pilgrim)
on Jan 31, 2001 at 04:12 UTC ( #55404=note: print w/replies, xml ) Need Help??


in reply to Re: push
in thread push

the thing without the push, as you said, it's working fine, except that i need it to continue through the rows, and get each row that matches. i don't know how to do that (it seems like using foreach is the thing, but can't get it to work), or where to put the rows - push them all into one array, or into different arrays - but then i don't know how to name them.

i've looked through all my reference books, and online, and can't find anything exactly like this. either i just don't know the syntax well enough or i'm approaching it wrong. for example, should i make this a sub routine because of the my statements?

thanks for the help.

Replies are listed 'Best First'.
Re: Re: Re: push
by arturo (Vicar) on Jan 31, 2001 at 18:58 UTC

    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.

    HTH

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2022-01-21 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (59 votes). Check out past polls.

    Notices?