Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Why must you use the array @files? This strikes me as a rather pointless constraint. What are you trying to do?

Dealing with your attempt to read the files in your directory: as said by moritz, use glob. It's what it's made for. Your first step would look something like this:

my $files = join(" ", (glob("0[89]-*.txt")));#I suffer from parentheti +caphilia. sorry
@files will now contain a blank-separated list of files which start with 08 or 09, followed by a hyphen and ending with '.txt'. You could then pass this to your ls -l command (the one in the backticks) and do the post-processing from your hash.pl routine.

Alternatively, you could use opendir, readdir, and grep, resulting in something like this:

opendir(my $DH, "."); # opens pwd @files = grep {/^0[89]-.+\.txt$} readdir($DH); closedir($DH);

But it would be a really good idea to tell the Monks–many of whom actually like explaining the nuances of Perl if the question is couched appropriately–what your goal is.


Information about American English usage here and here. Floating point issues? Please read this before posting. — emc


In reply to Re: Array problem......PLEASE HELP! by swampyankee
in thread Array problem......PLEASE HELP! by green_lakers

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 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?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-03-28 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found