Hello,

I am trying to read the username(first column), batchID(second column) and filename(third column). Filename may contain space,number,letters. I define the split pattern as two space before and after numbers as following. It works. The downside is I have to run split twice in order to read batchID. Is there more efficient way?

thanks,

use strict; use warnings; while (<DATA>) { chomp; print "Use character position for name - $NAME1\n"; my $batchID = (split/[ ]+/)[1]; my ( $Name,$File) = (split/[ ]+[ ]+[0-9]+[ ]+[ ]+/)[0,1]; print "$Name has $File and BatchID is $batchID\n\n"; } #username BatchID Filename size + Date Status Owner __DATA__ user1 1718 test2.txt.542 46 + 11/07/08-15:45 CREMFZ roadtest user1 1715 MIGRATE.DLL.698 40960 + 11/07/08-15:46 CREMFY roadtest user1 1712 New Microsoft Word Docu 35840 + 11/07/08-15:46 CREMFY roadtest user2 1707 amanda test 1 .doc.411 24064 + 11/07/08-15:47 CREMFY roadtest user2 1706 amanda test 1 .doc.544 24064 + 11/07/08-15:47 CREMFY roadtest user2 1705 amanda test 1 .doc.55 24064 + 11/07/08-15:47 CREMFY roadtest user3 1702 amanda test 2 .doc.322 24064 + 11/07/08-15:47 CREMFY roadtest user3 1701 amanda test 2 .doc.610 24064 + 11/07/08-15:47 CREMFY roadtest user3 1699 amanda test 2.doc.829 24064 + 11/07/08-15:47 CREMFY roadtest

In reply to read the filename column by roadtest

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.