in reply to Substitution all parts of an array...

#!/usr/bin/perl -w use strict; open IN, "myfile.txt" || die "Couldn't open myfile: $!\n"; open OUT, ">myresults.txt" || die "Couldn't open output: $!\n"; my @array; while (<IN>) { chomp; $_ =~ s/://g; print OUT $_ ."\n"; } close IN; close OUT; or while(<IN>) { chomp; push(@array, $_); } close IN; foreach my $num (@array) { $num =~ s/://g; print $num ."\n"; }
HTH
'Fect

Replies are listed 'Best First'.
Re: Re: Substitution all parts of an array...
by CukiMnstr (Deacon) on Mar 14, 2003 at 08:21 UTC
    while (<IN>) { chomp; $_ =~ s/://g; print OUT $_ ."\n"; }

    you can get rid of the chomp; and then you don't need to append "\n" when printing.

    in the second option, iterating twice on the data (once for reading the file and then another time for the substitution) can get pretty inefficient if the file is big.

    just my 2 cents.