I was working on a script that needs to produce foo for the first two lines and bar for the last three. There are two issues i am running into here.
How do I get Perl to ignore the double quotes around the first foo?
How do I get it recognize the backslash as a continuation line? -
Sample input:
reset -name "foo"
quasi_static -name foo
reset \
-name bar
set_case_analysis -name "bar"
My Code:
if (/^\s*set_case_analysis.*\-name\s+(\S+)/)
{
$set_case_analysis{$1}=1;
print "Set Case $1\n";
}
elsif (/^\s*quasi_static.*\-name\s+(\S+)/)
{
$quasi_static{$1}=1;
print "Quasi Static $1\n";
}
elsif (/^\s*reset\s+.*\-name\s+(\S+)/)
{
$reset{$1}=1;
print "Reset $1\n";
}
If you're going through a file line by line, you can keep partial lines in a variable and concatenate them with the next line. Read through the code - I have commented the functionality.
You could make it more compact and neat by doing something like this:
You would get a nested hash structure with the three keys,
set_case_analysis
,quasi_static
, andreset
, and the various different values from-name
.