Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: Help with a regular expression for file name parsing

by bontchev (Sexton)
on Dec 07, 2011 at 13:12 UTC ( #942243=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Help with a regular expression for file name parsing
in thread Help with a regular expression for file name parsing

You checked what? I asked for a regular expression - not for three pages of code and a link to somebody's totally irrelevant custom module!

Meanwhile, I figured out that the horrible BBoard software which this site uses simply mangles the posted code and to get the real stuff, you have to click on the "download" linke (which doesn't download!) and cut-and-paste from the page that opens.

So, I managed to make TJPride's script output something meaningful:

"some file" 'another file' yet\ another\ file

Unfortunately, it is also wrong. This is not the proper output. The proper output, which such data, would be:

some file another file yet another file

Furthermore, I don't want all the stuff loaded into some kind of an array and everything in that array matched simultaneously. I have to do other stuff with each line, you know? I want to process the file line-by-line and, for this particular problem, I need a regular expression that fetches the file name after the "@include" keyword.

Let's make this very simple, shall we? Consider this snippet of code:

my $data = SOME STRING; if ($data =~ SOME EXPRESSION) { print "File name: \"$_\"\n"; }

Question: What should SOME EXPRESSION be, so that if SOME STRING is

"\@include file"

or

"\@include \"some file\""

or

"\@include another\\ file"

the output is respectively

File name: "file"

or

File name: "some file"

or

File name: "another file"

Please do not answer, unless you have tested that your answer actually produces the desired output.


Comment on Re^4: Help with a regular expression for file name parsing
Select or Download Code
Re^5: Help with a regular expression for file name parsing
by Anonymous Monk on Dec 07, 2011 at 13:53 UTC

    Question: What should SOME EXPRESSION be, so that if SOME STRING is...

    Such a regular expression cannot exist, not in an if block

    You can match the filename portion (for which you already got a regex that works), but you have to remove the quotes and escapes afterwards (using s///|substitution operator)

    In short, you want a function that does the job

      Such a regular expression cannot exist, not in an if block

      OK, understood. I'll have to do it in two or more steps, then.

      You can match the filename portion (for which you already got a regex that works), but you have to remove the quotes and escapes afterwards (using s///|substitution operator)

      OK, that's what I'll do, although just removing the backslashes seems too primitive to me. I'll try to find a better solution.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2014-04-20 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls