Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: One liner: split fixed-width field into equal length chunks...

by pfaut (Priest)
on Mar 21, 2003 at 03:09 UTC ( #244791=note: print w/replies, xml ) Need Help??


in reply to One liner: split fixed-width field into equal length chunks...

#!/usr/bin/perl -w use strict; sub fixedsplit { my ($data,$len) = @_; ($data =~ /(.{1,$len})/g); } my $data = "abcdefghijklmnopqrstuvwxyz"; my @fields; @fields = fixedsplit($data,4); print "@fields\n"; @fields = fixedsplit($data,6); print "@fields\n";

Produces:

abcd efgh ijkl mnop qrst uvwx yz abcdef ghijkl mnopqr stuvwx yz
--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

Replies are listed 'Best First'.
Re: Re: One liner: split fixed-width field into equal length chunks...
by mr. jaggers (Sexton) on Mar 25, 2003 at 04:42 UTC
    Yes, this is clearer, and is actually pretty close to what I settled on (before the latter Monks replied). Thanks, pfaut!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://244791]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2021-04-11 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?