On Jul 9, 9:08 am, ole...@gmail.com (marcos rebelo) wrote: > > On Fri, Jul 9, 2010 at 3:42 PM, Chas. Owens <chas.ow...@gmail.com> wrote: > > On Fri, Jul 9, 2010 at 09:22, Chas. Owens <chas.ow...@gmail.com> wrote: > > snip > >> { > >> my @temp = split /\n/, "first\nsecond\nthird"; > >> xpto @temp; > >> } > > snip > > > Or you use the [CountOf secret operator][1] to count the number of > > items split returns, but not well the use of a -1 limit on the split. > > If you don't provide a negative limit, then split will optimize itself > > for returning to an empty list and the result will be 1 regardless of > > the input (well, an empty string will still return 0). > > > xpto( ()= split /\n/, "first\nsecond\nthird", -1 ); > > > [1]:http://cowens.github.com/perlopquick/perlopquick.html#()=-X > > The idea is really to count the lines, This will run in a test and > seems to me the most clear code. > > the original code is +-: > is( scalar( split( /\n/, $trap->stdout ) ) ), 15); > > The lines have no special order. >
Hm, wouldn't you'd still get the warning: "Use of implicit split to @_ is deprecated" and the implicit split clobbers @_ which can be a problem in some cases. I'd go with Chas.'s suggestion to use 'tr' which avoids the warning. It's faster, more idiomatic, and clearer IMO: is( $trap->stdout =~ tr/\n//, 15 ); -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/