Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Re: Re: push by arturo
in thread push by malaga

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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












    Results (73 votes). Check out past polls.

    Notices?