in reply to regex or split

Your second example doesn't work as you expect: it misses the word "example" -which you would had if you were reading from a file:

$str=" this is a string example"; @data= ( $str =~ /(.*?\n)/g ); print map "[$_]",@data ;

prints:

[ ][this ][is ][a string ]

Besides, you are using $str at the beginning and $data elsewhere. You weren't using strict, but we had you :-)

Ciao!
--bronto


The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz