Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: calling regular expressions returned by functions?

by wallisds (Beadle)
on Mar 29, 2012 at 19:03 UTC ( #962463=note: print w/replies, xml ) Need Help??


in reply to calling regular expressions returned by functions?

  1. Define a variable holding the regex you want to use.
    • my $dot = qr/^[^\.{1,2}]/;
    • This checks to see if the string begins with a period or two (.) or (..)
  2. Check out http://perldoc.perl.org/functions/our.html
  3. for more info... about 'our' and 'my' for defining variables. In your example - my will work fine.
  4. Use your defined variables in the grep, shown below.
Happy grepping, Dawn

my @list = qw(. .. test.xls file100.pl); my $dot = qr/^[^\.{1,2}]/; my @files = grep { /$dot/ } @list; foreach my $file(@files) { print "$item\n"; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2023-01-31 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?