Thanks for everyone's help with this one, I was stuck and knew I was missing
something simple.. UGH. perldoc -q replace didn't turn me up with anything
either, which was a bummer, but going off the code posted here I was able to
do more with it.
This is what I used:
----------------------------
sub cleanup{
use strict;
my $dirname = "/home/data";
my $file;
my $newfile;
my $line;
opendir (DIR, $dirname) or die "Can't opendir $dirname: $!"; while
(defined($file = readdir(DIR))) {
next if $file =~ /^\.\.?$/;
open (OLDFILE, "< $file");
$newfile = $file . "_nice";
open (NEWFILE, "> $newfile");
while ($line = <OLDFILE>) {
# $line = $line =~ /^\s*(.*)\s*\n$/;
$line =~ s/\s+/ /g;
$line =~ s/^ //;
$line =~ s/ $//;
$line =~ s/\t/|/g;
print NEWFILE "$line\n";
}
close OLDFILE;
close NEWFILE;
}
}
------------------------------------------
I created a cleanup_dir subscript as well to handle removing the old files
but don't remember how to Unconcatenate the files:
-------------------------------------------
sub cleanup_dir {
use strict;
my $dirname = "/home/data";
my $file;
opendir (DIR, $dirname) or die "Can't opendir $dirname: $!"; while
(defined($file = readdir(DIR))) {
system 'chown', 'robert', '$file';
system 'chgrp', 'GCN', '$file';
}
#remove all the files that are not _nice?
system 'rm', '-f' , 's4.idx', 's4.idx_nice'; #removes unneeded files.
}
-------------------------------------------
>On Thu, 04 Sep 2003 11:31:52 -0500 "Perry, Alan" <[EMAIL PROTECTED]>
wrote.
>On Thursday, September 04, 2003 11:11, Marshall, Stephen wrote:
>>
>>Got it working this way fror the important line, but theres probably a
>slicker way of doing it.
>>
>>$line =~ s/(\s) / /g;
>>
>
>This will work, but may leave an extraneous space at the beginning and/or
>end of the line.
>
>This text:
>
>" Test text with lots of extra spaces "
>
>would get changed to:
>
>" Test text with lots of extra spaces "
>
>which may not be what you want.
>
>If you want to eliminate any starting or ending space and trim the rest of
>it down to single spaces, I would suggest this:
>
>$line =~ s/\s / /g; # the parens you had are not necessary
>$line =~ s/^ //; # removes any space from the beginning of the line
>$line =~ s/ $//; # removes any space from the end of the line
>
>You could probably get fancier on the statements, but I prefer the
>simplicity of three separate statements.
>
>HTH,
>
>Alan
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]