Hello Wise and Kind Monks:
I need a simple program to parse a text file, and modify the text file. The text looks like this.
1.7 MB | Z: \PeachTree\Forms
601.3 KB | Z: \PeachTree\Reports
149.0 KB | Z: \PeachTree\Letters
593.4 MB | Z: \Marketing Department
425.4 MB | Z: \Marketing Department\Presentations
92.9 MB | Z: \Marketing Department\Other
I need to split it on the "|". And then count the "\" in the right hand string and prefix the right hand side with that number of "|". Want to load the data into excel and make it look pretty.
This is my code.
open ( txtFileIn, $ARGV[0] ) || die ("Could NOT open " . $ARGV[0] .
+ ".\n");
@txtFileIn = <txtFileIn>;
print scalar @txtFileIn ;
foreach $row (@txtFileIn) {
chomp($row);
print "\n" . index ($row , '|');
($size, $item) = split /|/, $row;
print "\n**",$row, $size, $item ;
chomp($size);
chomp($item);
$cnt = $item =~ s/(\\)/$1/gi;
$item .= ('|' x $cnt ) . $item ;
# print "\n" , $size . $item, $cnt;
} #foreach row
close txtFileIn;
The split is not working. I have other code when split works just fine. But I do not see my silly mistake here. This what the code returns.
12
** 1.7 MB | Z: \PeachTree\Forms
12
** 601.3 KB | Z: \PeachTree\Reports
12
** 149.0 KB | Z: \PeachTree\Letters
12
** 593.4 MB | Z: \Marketing Department
12
** 425.4 MB | Z: \Marketing Department\Presentations
12
** 92.9 MB | Z: \Marketing Department\Other
Requesting your kind assistance
kd
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.