Making the subs shorter will maybe help a little in the speed of processing
but it will make it a lot more difficult for the person that gets to take
over the maintanace. When you know what you are doing and why it is easy to
read it, but when you get a big program written like that and are asked to
support it... you will go looking for the guy that wrote it and give him a
good old kick in the .... because of all the headache he cost you.
So unless this is a very personal script that will not ever be handed over
to anyone and your memory is good enough to remember what you are doing
where and why please make sure you do not write subs like that unless you
are very good at documenting your code as you are writting it.


On 11/25/05, John Doe <[EMAIL PROTECTED]> wrote:
>
> Lorenzo Caggioni am Freitag, 25. November 2005 11.04:
> > Attached you can find the code an a input file to try it.
> >
> > I'm sorry if the code is not realy commented and if it is no real clear,
> > but i have to delete some line because it is base on a database....
>
> From a short view into the code, I see optimization potential
> (some may have quite an effect, others may not...) in:
>
> a) main::SplitRowByLength:
>
> instead of substr, you could try and benchmark direct extraction of the
> fields
> with a single regex along the lines my @fields=$line=~/(.{1})(.{4})/;
>
> unpack may be better; not much experience with it.
>
> b) in the top level while loop:
>
> avoid the repeated eval (can't see a purpose for that...). I may have
> overlooked something, but why
>
> $xFieldValue  = '($cdr[0]';
> $xFieldValue .= ',[EMAIL PROTECTED],\$cdrsline,\$dbh)';
> eval ("fmtTLGInternationalFormatTelegramTEST".$xFieldValue);
>
> instead of a simple
>
> fmtTLGInternationalFormatTelegramTEST($cdr[0],[EMAIL 
> PROTECTED],\$cdrsline,\$dbh)
>
> (where the ref to $dbh is unneccessary since it is an object, and $cdr[0]
> could be replaced by a preceeding my $cdr0=$cdr[0] and then use $cdr0)
>
> ?
>
> Then, first make a my variable instead of using the same hash lookup
> several
> times. F.i $globalParameters{"OutputFileFieldDelimiter"} is used many
> times.
>
>
> c) generally
>
> Avoid most of the string interpolation where not necessary (hash keys,
> around
> integers, left from '=>' etc.)
>
> d) shorten some subs
>
> sub fmtCurrencyCodeTEST {
>        my($xCurr) = "EUR";
>        return $xCurr;
> }
> =>
> sub fmtCurrencyCodeTEST {'EUR'}
>
> sub fmtTLGATTR2_int_natTEST {
>        my ($xServiceCode,$xInputCDR) = @_;
>        return $xInputCDR->[20];
> }
> =>
> sub fmtTLGATTR2_int_natTEST {$_[1]->[20]}
>
> etc.
>
> e) fmtTLGConvertDateTEST
>
> here the many substr could be avoided
>
>
> Since I'm still a beginner, be carful with my advices...
> hopefully at least 2 cents,
>
> joe
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>

Reply via email to