in reply to Re: run-time syntax checking
in thread run-time syntax checking

You're in for a surprise if $code contains a closing curly too much, though.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^2: run-time syntax checking
by Pardus (Pilgrim) on Feb 01, 2003 at 14:17 UTC
    root@Captain:/home/pardus# perl my $string = "print 'some string'; }"; my $sub = eval "sub { $string }"; print $@; Unmatched right curly bracket at (eval 1) line 1, at end of line syntax error at (eval 1) line 1, near "} }"
    So where is the surprise ?
    --
    Jaap Karssenberg || Pardus (Larus)? <pardus@cpan.org>
    >>>> Zoidberg: So many memories, so many strange fluids gushing out of patients' bodies.... <<<<
      How about
      my $string = '}{ print "Bwahaha!\n"; system("rm -rf /")';

      Makeshifts last the longest.

        Hmmm - I *really* should do development as a non-root user ...

        But say I do pre-parse the string to check for unmatched curlies, I check for BEGIN and END blocks and I strip comments. Is eval "sub { $string }" usefull under these conditions ?

        I don't care for security really -- I trust users to not intentionally fuck up the system.
        --
        Jaap Karssenberg || Pardus (Larus)? <pardus@cpan.org>
        >>>> Zoidberg: So many memories, so many strange fluids gushing out of patients' bodies.... <<<<