Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^2: asterisk use

by madbombX (Hermit)
on Jan 10, 2007 at 21:59 UTC ( #594021=note: print w/ replies, xml ) Need Help??

in reply to Re: asterisk use
in thread asterisk use

To slightly extend davido's explanation with a more concrete example (because that's how I learn anyway):

This first example uses the full variable name to find all instances of mail.log.* in the current directory and pushes the results on @files.

use File::Find; find( sub { push @files, $File::Find::name if -f && /mail.log.*/ }, '. +');

This second example does the same thing only using the glob'd version of the variable name.

use File::Find; use vars qw/*name/; *name = *File::Find::name; find( sub { push @files, $name if -f && /mail.log.*/ }, '.');

Comment on Re^2: asterisk use
Select or Download Code
Replies are listed 'Best First'.
Re^3: asterisk use
by smist (Acolyte) on Jan 11, 2007 at 14:19 UTC
    In the subroutine named "wanted" that find2perl creates there is usage of the "&&" operator. If I understand it correctly, it's evaluating each expression, and if they evaluate to "true" it prints $name. Is the last "&&" necessary? There are no expressions after it; just goes to the print statement.

    sub wanted { my ($dev,$ino,$mode,$nlink,$uid,$gid); (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -d _ && print("$name\n"); }
      $foo && $bar && print "something"; is equivalent to print "something" if $foo && $bar;. The last && is necessary in your code because only that makes the whole thing one expression.

      -- Hofmator

      Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re^3: asterisk use
by smist (Acolyte) on Jan 11, 2007 at 13:38 UTC
    Thanks guys. I knew I read about this somewhere before. I just couldn't remember what it was. I haven't used globbing yet and I'm pretty new to Perl.

    Your help is appreciated!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2015-11-27 08:33 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (722 votes), past polls