Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Strange regular expression warning

by LeeC79 (Acolyte)
on Jul 15, 2004 at 14:33 UTC ( [id://374662]=perlquestion: print w/replies, xml ) Need Help??

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

I've written a simple script that searches a directory for a file with a certain extension. The script then does *stuff* with those files. It runs fine on my machine, but we've recently scheduled the script to run on our server and it fails. Here's the code:
opendir DIR, $dir; my @file = grep {/^*.ORD_API_log$/} readdir DIR; closedir DIR;
Here's the error we get on our server:
{/^*.ORD_API_log$/: regexp *+ operand could be empty at ....
Just looking for what that error means. Thanks.

janitored by ybiC: Retitle from less-than-descriptive "What's Wrong?" for better site search results

Replies are listed 'Best First'.
Re: Strange regular expression warning
by gellyfish (Monsignor) on Jul 15, 2004 at 14:39 UTC

    It means you have an old version of Perl , I mean really old like Perl 4 , on the server.

    I would recommend upgrading the Perl or using a more recent one if available but swapping round the *. to .* in your regular expression will fix it.

    /J\

      perl4 wouldn't take a block as an operand to grep.

      We're not really tightening our belts, it just feels that way because we're getting fatter.
Re: Strange regular expression warning
by elusion (Curate) on Jul 15, 2004 at 15:31 UTC
    From the looks of things, I believe (meaning this is untested) the reason you're getting this error is because * has a special meaning inside of a regex. It denotes the previous character as something that may occur zero or more times. Unfortunately, your's is empty -- it doesn't have anything to match. (Maybe your *. is in the wrong order?)

    Try putting something in front: /^.*\.ORD_API_log$/ That would matching anything that ended in .ORD_API_log. Of course, as someone else mentioned, it'd be easier to check the end and just forget about the beginning: /\.ORD_API_log$/ Hope this helps,

Re: Strange regular expression warning
by delirium (Chaplain) on Jul 15, 2004 at 15:23 UTC
    I'll comment on the regex: If you are interested in how the filename ends, you don't need to worry about how it starts. Try using:

    /\.ORD_API_log$/

    ...which doesn't root the match to the beginning of the string (and explicitly looks for a period before the extension).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-20 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found