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


In reply to Re: script optimization by MidLifeXis
in thread script optimization by tannx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.