I have a script which reads a tab delimited text file. The text file looks something like:
11811   NAME1   AGE1   LOCATION1   12156   NAME2   AGE2   LOCATION2   17899   NAME3   AGE3   LOCATION3 ... and so on I don't have problem reading the file, infact I can successfuly read and store it in an array too. My code is:
open(DAT,"C:\\StudyPerl\\Projects\\tab_file.txt") || die "Could not op +en the file"; my @line; my @array1; while(<DAT>){ @line = split(/\t/,$_); $array1[0]=$line[0]; $array1[1]=$line[1]; $array1[2]=$line[2]; $array1[3]=$line[3]; } foreach $1 (@array1){ print "The element is: $1\n"; }
My problem is: I want the script to treat the variable after every 4 words as a new record.
I mean I want to store: 11811, NAME1, AGE1 & LOCATION1 in array1 and
12156, NAME2, AGE2 & LOCATION2 in array2 and so on.
Also, some words can be blank spaces, I need to handle them too. Basically, whenever there is/are any blank space(s), the array should store it as it is.
Can someone help me on that?

In reply to Perl script to read a tab delimited text file by shilpam

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.