Ben Crane wrote:
>
> Here is a code snippet, and yes I am going to use
> File::Basename to strip the file path/filename once
> I've stripped the entire path from a string.
>
> The string $_ is a line in a text file. I want to use
> File::Basename to pull apart the file path and
> filename, but first I need to extract the string from
> the entire string...
>
> $_="Open Table \"Q:\\OSMAPS\\mapinfo\\gazos_rd\" As
> Gazos_Rd Interactive ReadOnly";
>
> ($path) = /(".*")/i;
>
> print "$path\n";
>
> Now my problem is: when I run this code (yep, I know
> strict isn't on) I get "Q:\OSMAPS\mapinfo\gazos_rd",
>  but I just want what's between the quotation
> marks...how do I match a value in a string but exclude
> the Quotation marks. The quotation marks delineate the
> file path so they're very useful, but I can't have
> them in my $path when it gets put into File::Basename.
>
> Any ideas? If I match on \w or \w+ I get the Open
> Table part (not wanted). The file paths will vary
> greatly so sometimes they'll be a large complex file
> path and otherwise (if in the same folder as the txt
> file, it'll just be "gazos_rd".

Hi Ben.

It looks like the record looks like:

  <quoted string><file path><quoted string>

in which case you can just grab all
three fields like this:

  m/ "(.*?)"  \s*  (.+?)  \s*  "(.*?)" /x
  $path = $2;

(The /x just allows embedded spaces for layout)

This allows for leading and trailing whitespace on the
file path. You can simplify this if you're sure you'll
never need the two strings, but this is a general solution.

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to