[ABE.pm] A little programming help
Faber J. Fedor
faber at linuxnj.com
Wed Sep 5 10:04:47 PDT 2007
On 05/09/07 12:23 -0400, Ricardo SIGNES wrote:
> * "Faber J. Fedor" <faber at linuxnj.com> [2007-09-05T11:01:39]
> > Here are two attemtps to do the same thing, but I'm stuck on both.
> >
> > Objective: parse the string
> >
> > q( my @prereqs = ("forddaily", "processdailydata"); )
>
> Isn't there some way you can NOT have to parse Perl code?
No. The information I am looking for is in Perl code.
> Do you always trust that the incoming string is NOT malicious?
Well, let's see... first, I wrote all of the code being searched; second,
I'm the only one who touches/understands/writes the code; and third, if
the source code were modified, other things would break and be noticed
long before the current project is (re)run.
So, yeah. I think I trust myself.
> I would NOT screw around here. Do one of two things:
>
> (a) if you trust the code, use eval $string and Data::Dumper
I can see where that would work, but I don't like the idea of eval-ing a
string in this context.
> (b) if you do not, use PPI
That looks interesting.
> Alternately, define a very specific grammar that the code must match. Then a
> regex will be easy.
I ended up doing the second method (parsing at the '(' first) and then
running a map across the second created array like this:
map{$_ = $1 if m/"([a-z]+)"/ } @prereqs;
--
Regards,
Faber Fedor
President
Linux New Jersey, Inc.
908-320-0357
800-706-0701
http://www.linuxnj.com
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the ABE-pm
mailing list