in reply to Eliminating substr warnings

You know that your usage is ok, so there's no objection to just turning off the warning. I'll show a trick for eliminating some temporary variables, too.

my @substrings; { my $size = 10; no warnings 'substr'; push @substrings, substr($string, 0, $size, '') while $string; }
If you want nondestructive treatment of $string, you can make a copy inside the curlies and work on that.

Update: Here's yet another way to do it in 5.8+,

my @substrings = do { local $/ = \10; open my $fh, '<', \$string; <$fh> };

After Compline,
Zaxo

Replies are listed 'Best First'.
•Re^2: Eliminating substr warnings
by merlyn (Sage) on Aug 13, 2004 at 00:56 UTC
      Perl stuffs parens around the whole thing (with /g), according to perlop:
      my @substrings = $string =~ /.{1,10}/gs;
      Two bytes saved. 189 bytes of bandwidth used.