Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Perl Idioms Explained - my $count = () = /.../g

by truedfx (Monk)
on Feb 07, 2006 at 15:27 UTC ( #528530=note: print w/replies, xml ) Need Help??


in reply to Perl Idioms Explained - my $count = () = /.../g

Just to have it mentioned: another way to do it is given in perldoc -f scalar:
#!perl -l my $str = "here are some words"; my $count = @{[ $str =~ /\S+/g ]}; print $count;
Personally, I think this makes the meaning clearer, but I'm sure others may disagree.

Replies are listed 'Best First'.
Re^2: Perl Idioms Explained - my $count = () = /.../g
by japhy (Canon) on Feb 07, 2006 at 15:40 UTC
    I'd say "but that builds up and then destroys an array referencce", but I don't know which takes more time, and then I'd say "benchmark it", but this would be a case of micro-optimizing. So I will agree with your intent: use whichever construct is clearer to you.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://528530]
help
Chatterbox?
[Lady_Aleena]: paco is a little over 2 years before my time.
[Discipulus]: you can try tachyon's iterative approach Re: Win32 Recursive Directory Listing
[Lady_Aleena]: I'm on Linux/
[beech]: isn't 2 year about standard recovery time for that kind of surgery?
[Discipulus]: if you hate FIle::Find
[Lady_Aleena]: I don't hate it, it just drives me crazy.
[Discipulus]: LA the solution is portable to whatever
[Lady_Aleena]: File::Find doesn't have a simple sub wanted example, like get the name of the file.
[Discipulus]: there is also find2perl with your perl installation

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2017-04-23 20:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.