Posted by Frank Hale on 1999-11-12
--- Dan Boger <dan@xxxxx.xxxxxxxxxx.xxx> wrote:
> you could just do the following:
>
> Replace :
>
> if ($ARGV[0]) {
> $commandlineparms = $ARGV[0];
>
> &stripcr($commandlineparms);
> } ........
>
> With:
>
> while (defined($ARGV[0])) {
> $commandlineparms = shift;
>
> &stripcr($commandlineparms);
> } ........
>
> Untested code, but should work fine :)
>
Well thank you for helping but your solution didn't
work as expected. Here is the solution I've come up
with now:
#!/usr/bin/perl
#
# Strips those nasty carraige returns off of windows
text files.
# useful when looking at those text files on a Unix
system.
#
# Frank Hale
# frankhale@xxxxx.xxx
# 12 Nov 1999
#
# This script is released under the terms of the GNU
public license
# version 2 or later. Please refer to www.gnu.org for
a copy of the license.
############################################################################
my @commandlineparms;
&main;
sub main {
for (@ARGV) {
$commandlineparms = $_;
print $commandlineparms."\n";
&stripcr($commandlineparms);
}
if (not defined(@ARGV)) {
print "\nstripcr - Strips the carraige returns from
Windows text files.\n";
print "By: Frank Hale\n";
print "Date: 10 Oct 1999\n";
print
" print "usage: stripcr.pl [windows text file]\n";
}
}
sub stripcr {
my $file = $_[0];
my @fileBuffer = ();
open(FILE, "< $file") or die "Couldn't read from
file: $!\n";
@fileBuffer = <FILE>;
close FILE;
open(FIX_FILE, "> $file") or die "Couldn't read from
file: $!\n";
foreach $line (@fileBuffer)
{
$line =~ s/\r//g;
print FIX_FILE $line;
}
close FIX_FILE;
}
Thanks!!!
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com
Previous post | Next post | Timeline | Home