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

Re: split n characters into n chunks

Thread Previous | Thread Next
From:
Dr.Ruud
Date:
October 26, 2009 06:36
Subject:
Re: split n characters into n chunks
Message ID:
20091025221311.7189.qmail@lists.develooper.com
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;


-- 
Ruud

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