develooper Front page | perl.beginners | Postings from October 2009

Re: split n characters into n chunks

Thread Previous | Thread Next
From:
Shawn H Corey
Date:
October 26, 2009 07:46
Subject:
Re: split n characters into n chunks
Message ID:
4AE5B659.7010803@gmail.com
Dr.Ruud wrote:
> Shawn H Corey wrote:
> 
> 
>>     push @list, (unpack( "A${i}A$size", $word ))[1];
> 
> Be careful with unpack "A", because it rtrims.
> 
> 
> Best use "x" to skip, and "a" to capture.
> 
>   push @list, unpack "x${_}a$size", $word for 0 .. $max;
> 
> 
> Funnily enough, that is somehow&what faster than
> 
>   push @list, map unpack( "x${_}a$size", $word ), 0 .. $max;
> 
> 

You don't need the push:

  my @list = map unpack( "x${_}a$size", $word ), 0 .. $max;


-- 
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About