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

Re: Is there any way to make an array non-greedy?

by sk (Curate)
on Oct 14, 2005 at 16:53 UTC ( #500301=note: print w/replies, xml ) Need Help??


in reply to Is there any way to make an array non-greedy?

Did you mean to do this?

use strict; use warnings; my $string = join('x', ('a')x20); ### NOTE the ()'s print $string,$/; my (@foo, $foo); (@foo[0..18], $foo) = split('x', $string); print $foo[0],$/; print "Success!\n" if $foo eq "a"; __END__ axaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxaxa a Success!

I don't quite understand your  join('x', 'a'x20); otherwise. Why join a scalar?

cheers

SK

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2016-08-31 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (426 votes). Check out past polls.