in reply to Is there any way to make an array non-greedy?
For this case, where you only want one item, reverse your split:
use strict; use warnings; my $string = join('x', ('a') x 20); my (@foo, $foo); ($foo, @foo) = reverse( split('x', $string) ); print "\$foo:$foo\n"; print "\@foo:@foo\n";
Prints
$foo:a @foo:a a a a a a a a a a a a a a a a a a a
Note the fix in your $string line to put 'a' as a list
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|
|---|