in reply to Re: script optimization
in thread script optimization

my ($fi, $fo) = ("/in.CSV", "/out.ins"); open my $hi, "<", $fi or die "$fi: $!\n"; open my $ho, ">", $fo or die "$fo: $!\n";

just my 2cents... apart of the chomp-chop issue and the other things said, can't see the point on to create two extra variables here, why simply not do this?

open my $hi, "<", "/in.CSV" or die $!; open my $ho, ">", "/out.ins" or die $!;

You could also do something with this:

if ($array[0] eq "\"Branchno\"") { next; } if ($array[0] eq "\"\"" ) {next;}

You want to discard this lines?, then do it as early as you can, put both before the substitution lines. In a very big file this can make a difference.

While(<INST>) { next if /^\"(Branchno|)\"/; s/...

Replies are listed 'Best First'.
Re^3: script optimization
by Tux (Canon) on Dec 15, 2011 at 14:49 UTC

    Because the die message does not include the file name.

    Another reason to do so, is that when you would do it really neat, you'd also check the close calls, and you'd still have the filenames ready for the diagnostics if those fail.

    A third reason for this would be that it is now easy to rewrite the script to take arguments from the command line and replace the default names.


    Enjoy, Have FUN! H.Merijn