Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: How to do perl -c inside perl? (quoting)

by BrowserUk (Pope)
on Aug 28, 2012 at 18:49 UTC ( #990304=note: print w/ replies, xml ) Need Help??


in reply to Re^2: How to do perl -c inside perl? (quoting)
in thread How to do perl -c inside perl?

Now pass an arbitrary chunk of Perl code to "perl -e" in a portable manner.

I was only demonstrating that windows supported backticks, not championing the idea of using them and -e as a useful mechanism.

Capture both STDOUT and STDERR from it. Not so trivial.

Capturing stderr also is trivial:

C:\test>perl -E"say `perl -c -Mstrict -we\"my \$l = 365.25*\" 2>&1` " syntax error at -e line 1, at EOF -e had compilation errors.

But I would have thought feeding the code to a piped-open and checking the exit code would suffice if all that is required is a yay or nay.

And if you need to actually capture the error messages produced, then this might do the trick:

#! perl -slw use strict; use Win32::Socketpair qw[ winopen2_5 ]; my( $pid, $sock ) = winopen2_5( 'perl.exe', '-c' ); print $sock <<'EOP'; my $x = 365.25**3; my $y = qx[ perl -c -e"say 'boo'"; ]; my $z = sub { print $sock <<; my $x = 365.25**3; my $y = qx[ perl -c -e"say 'boo'"; ]; my $z = sub { print $sock <<; my $x = 365.25**3; my $y = qx[ perl -c -e"say 'boo'"; ]; my $z = sub { 1; }; }; }; EOP shutdown $sock, 1; print while <$sock>; close $sock; ( $pid, $sock ) = winopen2_5( 'perl.exe', q[-E"say 'hello'; warn; die; +"] ); shutdown $sock, 1; print while <$sock>; close $sock; __END__ C:\test>winopen2_5 - syntax OK Warning: something's wrong at -e line 1. Died at -e line 1. hello

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong

/iblockquote


Comment on Re^3: How to do perl -c inside perl? (quoting)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990304]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2014-12-27 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls