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

comment on

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

It is better to open the file using open INFILE, "<", $ARGV[1] or, even better, open $inFILE_HANDLE, "<", $ARGV[1]. It is not causing you a problem now because open() opens for reading (called the "mode") without explicitly setting mode (e.g. reading: "<")

There is a problem reading the file. First you open a file using open(), for that you get a fileHANDLE, e.g. the INFILE or $inFILE_HANDLE. Then you loop reading from the FILE-HANDLE using the diamond operator while(<$inFILE_HANDLE>){ print $_ } and then you close the file(HANDLE): close $inFILE_HANDLE;. You can't read any file contents from a variable which just stores the fileNAME.

In the case your input is not unique wrt the fourth column you will miss input, all similar column-four lines will go to the hash keyed on column-four overriding any previous line with same column-four key. One solution is not to use a hash but an array of arrays (these are formed in exactly the same way as you do now with the regex) and sort works on arrays.

See Re^3: Sort alphabetically from file and Re^3: Sort alphabetically from file, they already gave you hints for file open/read problems.


In reply to Re^3: Sort alphabetically from file by bliako
in thread Sort alphabetically from file by edujs7

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 taking refuge in the Monastery: (2)
As of 2024-04-19 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found