in reply to Re: Split a string into items of constant length
in thread Split a string into items of constant length
Hi,
Or more dynamic, but note the little 'empty' problem.
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { my $line = $_; chomp $line; my @chunks = unpack "(A5)*", $line; print @chunks . "\n"; # beware, the last 'entry' in chunks is empty, note the < and >! foreach my $i (@chunks) { print ">" . $i . "<\n"; } } __DATA__ a(b)cd(e)fg(h)i j(k)lm(n)o
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Split a string into items of constant length
by blazar (Canon) on Oct 04, 2005 at 10:44 UTC |