Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of nicholas (3034)

Friday April 14, 2006
05:39 PM

Who needs string eval?

[ #29330 ]

use strict;
use warnings;
require PerlIO::scalar;

unshift @INC, sub {
    my $file = $_[1];
    if (ref $file) {
        my $fh;
        open $fh, "<", $file or die $!;
        return $fh;
    }
};

do \('print "Hello ' . (shift || "world") . '\n"');

No string eval there. No sir. I wonder if it circumvents things like Safe...

Update:

This is terser. You don't need the BEGIN block, but it demonstrates that the technique is robust and automatically lets regular filenames through. (In this case PerlIO/scalar.pm)

use strict;
use warnings;

BEGIN {
    unshift @INC, sub {
        $_[1];
    };
}

require PerlIO::scalar;

open my $fh, "<", \('print "Hello ' . (shift || "world") . '\n"');
do $fh;

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.