Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Regular Expression

by Noame (Beadle)
on Apr 02, 2008 at 16:13 UTC ( [id://677992]=perlquestion: print w/replies, xml ) Need Help??

Noame has asked for the wisdom of the Perl Monks concerning the following question:

Hi, How can i check if one of the following file is existing using regular + expresiions: ${DIR}/TEST-246.92.00.tar.gz ${DIR}/TEST-246.92.00-INTERNAL.tar.gz Thanks.

Replies are listed 'Best First'.
Re: Regular Expression
by apl (Monsignor) on Apr 02, 2008 at 17:02 UTC
    You wouldn't use regular expressions to test for the existance of the files.

    if ( -f $DIR.'/TEST-246.92.00.tar.gz' or -f ${DIR}.'/TEST-246.92.00-IN +TERNAL.tar.gz') { # your processing goes here }
Re: Regular Expression
by CountZero (Bishop) on Apr 02, 2008 at 16:45 UTC
    Please do not put your whole node in <code>-tags, but only the code part of it.

    Answering your question: it is much easier and clearer to have an if test for these two strings.

    if ($file eq '${DIR}/TEST-246.92.00.tar.gz' or $file eq '${DIR}/TEST-2 +46.92.00-INTERNAL.tar.gz') { ... }
    You will have to replace ${DIR} by its real value of course, unless it is a variable, which I did not assume.

    If you must have a regex the following will do:

    m/\${DIR}/TEST-246.92.00.tar.gz|\${DIR}/TEST-246.92.00-INTERNAL.tar.gz +/
    (Again if necessary replacing ${DIR})

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Regular Expression
by ww (Archbishop) on Apr 02, 2008 at 16:45 UTC
    You could start by reading the documentation, including
    perldoc perlre
    after which, you might come back with what you've tried, if you still have questions.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-16 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found