M
Mats
Hi!
I've messed with this problem a while now. I want to parse a file for
declarations (ex: NAME = "myname").
I wan't to extract the phrase/text between the two quotes. BUT If the
last quote isn't available (type/user error) then it should extract
until end of line. If no quotes are there at all, it should extract the
whole line (except NAME=). If there are several double quotes, it should
extract between the first two (that i seem to have achived).
My current testscript looks as below:
---
#!/usr/bin/perl -w
use strict;
$_ = 'NAME = "between quotes" not this" nor this';
print $1."\n" if m/\s*NAME\s*=\s*"*(.*?)"|$/s;
---
This prints out as i want:
between quotes
But if i delete the last two doublequotes and just keep the first it
prints nothing. If i delete the first doublequote also, i get an
"uninitialized value" error.
Anybody knows a smooth solution to this?
Mats
I've messed with this problem a while now. I want to parse a file for
declarations (ex: NAME = "myname").
I wan't to extract the phrase/text between the two quotes. BUT If the
last quote isn't available (type/user error) then it should extract
until end of line. If no quotes are there at all, it should extract the
whole line (except NAME=). If there are several double quotes, it should
extract between the first two (that i seem to have achived).
My current testscript looks as below:
---
#!/usr/bin/perl -w
use strict;
$_ = 'NAME = "between quotes" not this" nor this';
print $1."\n" if m/\s*NAME\s*=\s*"*(.*?)"|$/s;
---
This prints out as i want:
between quotes
But if i delete the last two doublequotes and just keep the first it
prints nothing. If i delete the first doublequote also, i get an
"uninitialized value" error.
Anybody knows a smooth solution to this?
Mats