roadtest has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: read the filename column
by AnomalousMonk (Archbishop) on Jul 09, 2011 at 17:35 UTC | |
by roadtest (Sexton) on Jul 09, 2011 at 17:48 UTC | |
|
Re: read the filename column
by Anonymous Monk on Jul 09, 2011 at 17:01 UTC | |
by AnomalousMonk (Archbishop) on Jul 09, 2011 at 18:14 UTC | |
by Anonymous Monk on Jul 09, 2011 at 18:53 UTC | |
by AnomalousMonk (Archbishop) on Jul 09, 2011 at 20:59 UTC | |
by Anonymous Monk on Jul 09, 2011 at 22:01 UTC | |
| |
by roadtest (Sexton) on Jul 09, 2011 at 17:38 UTC | |
|
Re: read the filename column
by GrandFather (Saint) on Jul 09, 2011 at 23:55 UTC |