Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Substitution all parts of an array...

by Ineffectual (Scribe)
on Mar 14, 2003 at 00:33 UTC ( [id://242908]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://242908]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-25 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found