Just some comments:

- Your data separator is apparently the pipe ("|") character. Why are you splitting on the tab ("\t") character?

When you do:

print <FILE>; #Prints entire file
this gets the file handler to the end of the file, so that the next line:
while (<FILE>){
will not get any line.

- You say #Date for the first field of @array, but I fail to see a date in your input data.

- If you are thinking of sorting data, then you probably don't want to use a hash, but rather an array.

What you are trying to do with your code is not entirely clear to me, but this might get you closer to what you want:

#!/usr/bin/perl use strict; use warnings; my $file_name = 'FB_LPWAP.txt'; open my $FILE, '<', $file_name or die "ERROR: Could not open file $!"; + # better syntax for opening a file # print <$FILE>; don't do that, you will get no data in the while loop while (<$FILE>){ my @array = split /\t/, $_; # with the data shown, you should spli +t on pipe or on a pattern such as /\|\s*/ print join "\t", @array, "\n"; } close ($FILE);
But as I said, your program does not seem to match the data you've shown. Also, it does not make much sense to split data on tabs and then to print the fields separated by a tab. There was really no need to split it in the first place (unless you wanted to split on pipes and separate the data with tabs, but, then, there would probably be easier ways to replace pipes by tabs, using regular expressions, for example).

Je suis Charlie.

In reply to Re: Reading Text File into Hash to Parse and Sort by Laurent_R
in thread Reading Text File into Hash to Parse and Sort by Perl_Derek

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.