Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monk's
I noticed that I come across the same problem over and over again
Repeating the same code isn't a good practice IMHO but How it could be eliminated in this example?
my @arr = ''; open(F,"x.txt") or die $!; while (<F>) { chomp; my $Field = (split/\,/)[1]; push(@arr,$Field); } close(F); print "Listing data for:" . (join '/', @arr) . "\n"; open(F,"x.txt") or die $!; while (<F>) { chomp; print join(' ' , split /,/) . "\n"; } close(F);
What's up there:
Your help/advice is greatly appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to eliminate duplicated code?
by graff (Chancellor) on May 22, 2009 at 00:52 UTC |