in reply to script optimization

A couple of comments fist:

#!/usr/local/bin/perl -w # $fn1 = '/in.CSV'; # Useless stringification, and check your errors # open (INST,"$fn1") open(INST, '<', $fn1) or die "Unable to open '$fn1' for reading: $!"; # Preference, but possibly a better habit # consider: open(ABI, ">$foo") where $foo # contains ">blah". # Also - check your errors # open (ABI,">/out.ins"); open(ABI,">", "/out.ins") or die "Unable to open /out.ins: $!"; while (<INST>) { # Moved from below - fail fast [1] next if /^"Branchno"\t/; next if /^""\t/; # Not necessary [3] # chomp; # Fishy - does this remove the last \t? [2] # chop; s/\õ/\ä/g; s/\"-/\"Ä/g; s/\--/\-Ä/g; s/\ - /\*-*/g; s/\ -/\ Ä/g; s/\*-*/\ - /g; s/\"_/\"Ü/g; s/\ _/\ Ü/g; s/\__/\_Ü/g; s/\³/\ü/g; s/\§/\õ/g; # @array = ' '; # Not necessary, useless # no longer necessary [1,2] # @array = split(/\t/); # Moved to top of loop - fail fast [1] # if ($array[0] eq "\"Branchno\"") { next; } # if ($array[0] eq "\"\"" ) {next;} # No longer necessary, assuming chop above removed \t [2] # $result = join ("|",@array)."|"; # Replace split / join with another s/// [2] s/\t/|/g; # Work on $_, no longer need $result # $result =~ s/\"//g; # print ABI $result,"\n"; s/"//g; # newline not necessary since chomp removed [3] print; } close (INST); close (ABI);

  1. If you fail fast, you can avoid doing the s/// on the discarded lines.
  2. If "\t" was removed by the chop, this will handle it as well
  3. If you don't chomp, you don't need to print the newline, as it is still there

There are also some tr/// uses that could possibly make this faster (see trizen's post above). However given the type of input data I am assuming from your code, this is a very fragile solution.

--MidLifeXis