skyler has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
I've created a script that reads a file and parses the fields into a pipe(|) delimited, then puts it back to another file. I'm doing it becuase of the last line segment within the file is a path which gets transform as the file is read line by line. (C:\(directory1)\(directory2)\(directory3)) My question is: I would like to take the first line segment put it into an array or hash and check to see if it repeats while reading the file, If it does, then rename it to itself plus append a letter to it (a,b,c..so forth) as instances of the segment repeats. For example 56789a,56789b,56789c...so forth). Do you have any hints??
Here is the code so far.
#! perl -w use strict; use File::Copy; my $cnt; my $infile = "C:\\(directory1)\\file1.chr"; my ( $yr, $mo, $dy ) = (localtime)[5,4,3]; my $outfile = sprintf( "C:\\(Directory1)\\%04d%02d%02d.txt",$yr+1900,$ +mo+1,$dy ); my $staticdir = "C:\\(directory1)\\(directory2)\\"; open IN, "<$infile" or die "Couldn't open $infile, $!"; open OUT,">$outfile" or die "Couldn't open $outfile, $!"; $cnt++; while (<IN>) { chomp; my @fields = split /\|/; my $newfile = $fields[0]; my $path_str = $fields[20]; do { warn "Empty field 19"; next } unless $path_str; my @path = split /\\/, $path_str; my $dir = join "\\", @path[ 0, 1, 2, 3, 4, 5, 6 ]; $newfile =~ s/$/.rtf/; my $out = join ('|', @fields[0..19]) . "@@" . $staticdir . $newfil +e; print OUT "$out\n"; Print "$cnt\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Checking for Duplicates
by rchiav (Deacon) on Feb 25, 2004 at 17:59 UTC | |
by CountZero (Bishop) on Feb 25, 2004 at 20:56 UTC | |
by rchiav (Deacon) on Feb 25, 2004 at 21:05 UTC | |
by Anonymous Monk on Feb 25, 2004 at 19:00 UTC |
Back to
Seekers of Perl Wisdom