-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256


Hello.


Thanks for your reply.


I remember that i did some performance tests and 

$string = $string ."something"

had better performance than 

$string .= "something"

which matched the results of (link to stack overflow)
http://stackoverflow.com/questions/3104493/performance-with-perl-strings


I'm going to try your suggestions an i will report back.



Best regards,
David Santiago




Em Thu, 30 Jul 2015 16:56:31 -0400
Uri Guttman <u...@stemsystems.com> escreveu:

> On 07/30/2015 04:14 PM, David Emanuel da Costa Santiago wrote:
> >
> > my @YENC_CHAR_MAP = map{($_+42)%256;} (0..0xffff);
> > my $YENC_NNTP_LINESIZE=128;
> >
> > sub _yenc_encode{
> >    my ($string) = @_;
> >    my $column = 0;
> >    my $content = '';
> >
> >    my @hexString = unpack('W*',$string); #Converts binary string to
> > hex 
> >    for my $hexChar (@hexString) {
> >      my $char= $YENC_CHAR_MAP[$hexChar];
> >
> when checking multiple values like this use a hash. it will be
> quicker than all those == ops. or even a array using ord() for the
> index. you can populate it outside the sub like this:
> 
> my @is_special ;
> $is_special[0] = 1 ;    # NUL
> $is_special[10] = 1 ;    #LF
> >     #null || LF || CR || =
> >      if ($char == 0 || $char == 10 || $char == 13 || $char == 61 ||
> >
> >     # TAB || SPC
> >     (($char == 9 || $char == 32) && ($column ==
> > $YENC_NNTP_LINESIZE || $column==0)) ||
> >
> >     ($char==46 && $column==0) # .
> then a single check will do:
> 
>      if ( $is_special[$char] && blah blah ) {
> 
> 
> >     ) {
> >        
> >        $content =$content. '=';
> ever heard of .=? it is one of my favorite perl ops. it just means 
> append. building strings is best done with .=. in fact a rule i use
> is for one sub to build some result string but its caller decides
> what to do with it. that way you can print, log, email, whatever to
> the string and not change the builder code. output should be done
> only when you have the full result as then you can decide what to do
> with the result. too often you see code where text is generated and
> output immediately. when they need to fork the output they have to
> resort to tied handles and other wacky stuff. the rule to remember is
> 
>       print rarely, print late.
> >        $column+=1;
> >        
>      $column++ ;
> >        $char=($char + 64);#%256;
> you used += before so why not there too?
> 
> also use more horizontal white space to make your code easier to read.
> >      }
> >
> >      $content = $content.chr $char;
> like that looks like a .method call but perl doesn't use that
> syntax. .= is the win here again.
> >      
> >      $column+=1;
> >      
> >      if ($column>= $YENC_NNTP_LINESIZE ) {
> you can merge thos two lines:
>          if( ++$column >= $YENC_NNTP_LINESIZE ) {
> >        $column=0;
> >        $content = $content."\r\n";
> .= again. see how common its usage is? because it is a assignment op 
> which some newbies don't learn early on, it is missed. it is just
> append and simple and very needed in almost all code that builds up
> text.
> 
> uri
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJVu158AAoJEJ/OLjwuDYzKOoYH/2SAEQJu2q0j6fcGywhKV+kA
KGOWgtVSCgwiTQyVDqhrOI2EJr2PSW/7/iwVB7pMdVI1OrFsJyH+q0YoGbWMV9Mf
sl6nONanVGobdF/B1liDtdGchr6UtoO2QK5Elz2PWjtHiC2zgQEw2qYw+p72EJtW
4dXA7QdmtXyiABby3WcZr1mZ1D8SbqUtiJ48DWjcR1hA7mAcz8Erda9hm8jT+L5J
yiviE1gieA6BUXT2Ri6VzqX7/ScUO0JVTpHkqu2IGIzaXuqqV7kkOuihCwhN30EB
vV1Dt/WFcsdD/c3KFB4il/HBZxPfiY5/gHDTcsOn4fkqj6xy+qFs0p9vpIwvux0=
=SGdA
-----END PGP SIGNATURE-----

Reply via email to