Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^5: Counting the number of items returned by split without using a named array

by blazar (Canon)
on May 04, 2006 at 10:49 UTC ( #547386=note: print w/replies, xml ) Need Help??


in reply to Re^4: Counting the number of items returned by split without using a named array
in thread Counting the number of items returned by split without using a named array

Adding use warnings; results in

Use of uninitialized value in split at foo.pl line 9.

Hmmm... adding (-l and) print $entries to both subs results in:

Use of uninitialized value in split at foo.pl line 9. 0 Use of uninitialized value in pattern match (m//) at foo.pl line 14. 0

Now,

#!/usr/bin/perl use strict; use warnings; use Benchmark qw(:all :hireswallclock); my $str="This is an example string with several words bla bla bla"; sub test1 () { local $_=$str; my $entries = @{[ split ]}; } sub test2 () { local $_=$str; my $entries = () = /\S+/g; } cmpthese -10, { deref => \&test1, goatse => \&test2, }; __END__

results in

Rate goatse deref goatse 16325/s -- -42% deref 28017/s 72% --

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2021-01-19 02:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?