in reply to Re^5: Breaking up a string?
in thread Breaking up a string?

while (length $input > 6){ my $front = substr($input, 0, 6); $input = substr($input, 6); push @sets_of_six, $front; }
This can be done slightly more compactly by having the initial substr remove the leading characters as it retrieves them:
while (length $input > 6){ my $front = substr($input, 0, 6, ''); push @sets_of_six, $front; }
(Or even get rid of $front entirely with
while (length $input > 6){ push @sets_of_six, substr($input, 0, 6, ''); }
if you don't think that's becoming too unreadable.)

Replies are listed 'Best First'.
Re^7: Breaking up a string?
by stiller (Friar) on Feb 19, 2008 at 20:26 UTC
    I think you show the progression from extremely simple to comprehend but overly verbose, gradually into a much more acceptable solution in a very fine way that should be easy to follow and learn from.
    I think that your progression ends at a nice place too, unless one work in a shop where perl is a primary language.
    My preference is unpack, as BrowserUk demonstrates,
    cheers