Test for eval() without using eval() ?? 
Author Message
 Test for eval() without using eval() ??

Some web servers disable eval() in perl scripts, for whatever reason.

My question is... how can I test whether or not eval() exists, without using
eval() to trap any errors?



Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??

<URL::">
?? Some web servers disable eval() in perl scripts, for whatever reason.
??
?? My question is... how can I test whether or not eval() exists, without using
?? eval() to trap any errors?

perl -le 'print "Nope" if `perl -e "eval()" 2>&1` =~ /Undefined/';

Abigail
--
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi

  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----



Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??
This is not a workable solution from within a perl script, unfortunately.
(and it doesn't work from NT, either)

I would like a way to do this without spawning a new perl process and
trapping the output, if it exists.


Quote:

> <URL::">
> ?? Some web servers disable eval() in perl scripts, for whatever reason.
> ??
> ?? My question is... how can I test whether or not eval() exists, without
using
> ?? eval() to trap any errors?

> perl -le 'print "Nope" if `perl -e "eval()" 2>&1` =~ /Undefined/';

> Abigail
> --

%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)(
(.)
Quote:
> (.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of
Hanoi

>   -----------== Posted via Newsfeeds.Com, Uncensored Usenet News
==----------
>    http://www.newsfeeds.com       The Largest Usenet Servers in the World!
> ------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers

==-----


Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??
You know, if you'd just put your replies after what you're replying to,
it'd make a lot more sense.  I've taken the libery of reordering the
replies so that a human being can understand them.

Quote:



> > perl -le 'print "Nope" if `perl -e "eval()" 2>&1` =~ /Undefined/';

> This is not a workable solution from within a perl script, unfortunately.

Sure it is-- ever hear of backticks, or system()?

Quote:
> (and it doesn't work from NT, either)

Sure it does-- I just did it.  You just have to read the FAQ, and quote
appropriately.

Quote:
> I would like a way to do this without spawning a new perl process and
> trapping the output, if it exists.

You Can't Get There From Here.

-=Eric
--
"Cutting the space budget really restores my faith in humanity.  It
eliminates dreams, goals, and ideals and lets us get straight to the
business of hate, debauchery, and self-annihilation."
                -- Johnny Hart



Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??

<URL::">

DO NOT POST IN REVERSE ORDER AND DO NOT QUOTE THE ENTIRE ARTICLE,
INCLUDING SIGNATURE, MORON.


|| >
|| > perl -le 'print "Nope" if `perl -e "eval()" 2>&1` =~ /Undefined/';

|| This is not a workable solution from within a perl script, unfortunately.

Sure it is.

    #!/opt/perl/bin/perl -w

    use strict;

    print "Nope\n" if `perl -e "eval()" 2>&1` =~ /Undefined/;

    __END__

|| (and it doesn't work from NT, either)

Eh? Why not? Just install a Bourne shell look-alike for NT. There
are toolkits with most major shell utilities for NT. I've developed
complicated shell scripts on Solaris that were harder to port to HP-UX
than to NT.  (In fact, the port to NT didn't require more than replacing
the occurances of /tmp.)

[And before you complain "my provider doesn't have such a shell",
 that's to frigging bad. If you choose a provider that gives you NT,
 but without a decent shell, and a crippled Perl, that's your problem,
 not ours. Pick a better provider.]

|| I would like a way to do this without spawning a new perl process and
|| trapping the output, if it exists.

Well, aren't you getting a bit picky? You don't want to use eval, you
don't want to spawn processes... what's next, you want to do it without
using vowels?

Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54\n" and s/<<EOT/<<EOT/ee and print;
"Just another Perl Hacker"
EOT

  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----



Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??

Quote:

> Some web servers disable eval() in perl scripts, for whatever reason.

That's amazing. I didn't know that that was possible, in general. However
do they do it? Via Safe, perhaps? Hmmm....

And why should they do it? If a program is made more secure by disabling
eval, it should be even more secure by disabling print and open. :-)

Seriously, if you can't trust the programmer to use eval correctly, how
can you trust her to use the rest of perl correctly? I don't see the
wisdom here.

Quote:
> My question is... how can I test whether or not eval() exists, without
> using eval() to trap any errors?

Well, if only eval STRING is disabled, you could use eval BLOCK. But if
neither eval is available, maybe this subroutine will do something useful.
Notice that it intentionally breaks a normally vital rule.

    sub eval_avail ($) {
        # Pass the name of the perl interpreter to be checked.
        # Returns true if that perl seems to allow eval.
        my $perl = shift;
        my $rc = system $perl, '-e',
            'BEGIN { open STDERR, ">/dev/null" } eval "exit"';
        !$rc;
    }

    print eval_avail($^X) ? "It works!\n" : "No eval.\n";

Of course, you may need to call this from a BEGIN block if you will need
to abort your own compilation before compiling an eval call....

Good luck with it!

--
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??

Quote:

> DO NOT POST IN REVERSE ORDER AND DO NOT QUOTE THE ENTIRE ARTICLE,
> INCLUDING SIGNATURE, MORON.

Wow, what a {*filter*} you are.
My newsreader which I do not normally use did this and I didn't notice.
I wonder how much better it is to write in all caps and hurl flames?

Quote:
> || This is not a workable solution from within a perl script,
unfortunately.
> Sure it is.
>     #!/opt/perl/bin/perl -w
>     use strict;
>     print "Nope\n" if `perl -e "eval()" 2>&1` =~ /Undefined/;
>     __END__

It's technically possible, but not a workable solution. If the web
server disables eval() it most certainly disables back-ticks and system
().

Quote:
> || (and it doesn't work from NT, either)
> Eh? Why not?

Because not every OS works exactly how you want it to.

Quote:
> Just install a Bourne shell look-alike for NT.
> [And before you complain "my provider doesn't have such a shell",
>  that's to frigging bad. If you choose a provider that gives you NT,
>  but without a decent shell, and a crippled Perl, that's your problem,
>  not ours. Pick a better provider.]

I often wonder what happened to people like you in childhood to lead to
such a pissy attitude.

My question is for CGI scripts which will be distributed to many
people. I do not have control over their environment. Telling them to
install certain tools is not an option. I write code that is designed
to run without any dependencies at all.

Quote:
> || I would like a way to do this without spawning a new perl process
and
> || trapping the output, if it exists.
> Well, aren't you getting a bit picky? You don't want to use eval, you
> don't want to spawn processes... what's next, you want to do it
without
> using vowels?

A simple "I don't know how to do this" would have sufficed. If my needs
are too complex for you to understand, just don't respond.

In fact, please put me on your auto-kill list if you have one, so you
never have the urge to respond to my postings again.

Thanks.

--
Matt Kruse

http://www.*-*-*.com/

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??

Quote:
>>> mkruse  writes:

  mk> It's technically possible, but not a workable solution. If the
  mk> web server disables eval() it most certainly disables back-ticks
  mk> and system ().

        i think you're a bit confused: web servers do not disable perl
        commands; web servers and perl interpreters are not related
        entities.  one can turn on (or off) the server side includes
        directive "eval" on a netscape enterprise server -- perhaps
        this is what you mean?

        cheers,
        k.

--

kevin montuori            
interactive web services
northeastern university



Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??

Quote:

> It's technically possible, but not a workable solution. If the web
> server disables eval() it most certainly disables back-ticks and system
> ().

Hmm. Interesting. You tell us one thing and when a solution to that is
presented, you say that it should 'most certainly' not work because of
other reasons.

Quote:
> My question is for CGI scripts which will be distributed to many
> people. I do not have control over their environment. Telling them to
> install certain tools is not an option. I write code that is designed
> to run without any dependencies at all.

I predict difficulties there. I would think that CGI scripts need
- A working Computer
- A webserver
- Some means to put the program on the computer
- Some means to run it and see it's output
- If they are in Perl, something to run them (eg. perl or mod_perl)

all commands that read other Perl files (use, do, require) are some sort
of eval. If those don't work either, I don't think it is of much use to
work with that.

Quote:
> In fact, please put me on your auto-kill list if you have one, so you
> never have the urge to respond to my postings again.

Don't worry, you most probably are there already. Abigail is very
generous with places in her killfile

- Alex



Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??


Quote:
> i think you're a bit confused: web servers do not disable perl
> commands; web servers and perl interpreters are not related
> entities.  one can turn on (or off) the server side includes
> directive "eval" on a netscape enterprise server -- perhaps
> this is what you mean?

No, I'm not confused. I've been doing this stuff for 6 years. This is the
first time that I've encountered crippled versions of Perl on a web server,
though.

There are sites that exist that have a "crippled" version of perl running
for CGI scripts. I'm not sure how they accomplish it, and I'm not sure how
it works. All I know is that I've had a number of people tell me that a
script won't run because Perl will not do eval() or system() or back-ticks
with CGI scripts on their server. It's odd, yes. Makes no sense to me. I was
just wondering if there was a way to check for this situation within the
limits of the environment.

Matt Kruse

http://www.mattkruse.com/



Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??

Quote:
> Hmm. Interesting. You tell us one thing and when a solution to that is
> presented, you say that it should 'most certainly' not work because of
> other reasons.

I'm just trying to find a solution, man. It's not my environment I'm trying
to fix, it's other peoples'. They have a weird environment, and I'm trying
to make things work without breaking. That's it.

Quote:
> I write code that is designed to run without any dependencies at all.
> I predict difficulties there. I would think that CGI scripts need
> ...

What I meant by this is no modules, no required files, no 'standard'
modules, etc.
I've found that when creating a script that will be used by thousands of
people in every environment you can comprehend, it's best to not rely on
them having ANYTHING that I think they should.


Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??

<URL::">
~~
~~ What I meant by this is no modules, no required files, no 'standard'
~~ modules, etc.
~~ I've found that when creating a script that will be used by thousands of
~~ people in every environment you can comprehend, it's best to not rely on
~~ them having ANYTHING that I think they should.

Then don't assume they have perl. In fact, I bet there are hundreds
of times more people that don't have perl on their web server than
there are that have a crippled perl.

And why stop at assuming they don't have 'eval', 'system' or backticks?
They might lack open, fork and exec. They might not have print. Perhaps
some servers don't allow switches on the she-bang line, while others
require -T. Some might only do addition, while others only allow
multiplication.

Abigail
--

             "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".

  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----



Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??

Quote:

> And why stop at assuming they don't have 'eval', 'system' or backticks?
> They might lack open, fork and exec.

Actually, I wrap any fork in an eval, I wrap flock in an eval, etc. For
systems that do not support operations like these.

I don't really care if you don't share my objective. I wasn't asking for
your opinion on whether or not I should be trying to make the script work
transparently in most environments. It's something I want to do, and it
works beautifully right now.

My script will work on almost any OS and web server without a single line
needing changed or a single bit of configuration needing to be done. It
relies on no modules existing on the server (even relying on CGI.pm isn't
safe - there are thousands of users without it on their web server). This
benefits me because I don't need to answer as many questions from users
trying to make it work. It just works, no matter what environment they have.

I was curious to know if I could extend support to users who cannot use eval
(not many people, I've heard from maybe .01% out of 15,000 downloads). If
it's not possible, that's fine. That's a simple answer.

Don't assume that my goal is stupid and erroneous if you don't understand
it. Don't automatically cut me down as if I'm clueless simply because you
don't find my goal interesting or worthwhile.

Matt Kruse

http://www.mattkruse.com/



Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??




:
: > DO NOT POST IN REVERSE ORDER AND DO NOT QUOTE THE ENTIRE ARTICLE,
: > INCLUDING SIGNATURE, MORON.
:
: Wow, what a {*filter*} you are.

Why, after reading this exchange, did I expect someone to bust out
with an adaptation of "Kyle's Mom is a {*filter*}"? :-)

Is that you, Burnore? :-)

Greg
--
Irrationality is the square root of all evil.
    -- Douglas Hofstadter



Wed, 18 Jun 1902 08:00:00 GMT  
 Test for eval() without using eval() ??

Quote:
> My question is for CGI scripts which will be distributed to many
> people. I do not have control over their environment. Telling them to
> install certain tools is not an option. I write code that is designed
> to run without any dependencies at all.

Without any dependencies AT ALL! This is the most amazing thing I've heard
all week, and I've already heard Randal Schwartz proclaim "Today is My
Birthday!" on at least three separate days. (My theory: Compared to last
week, he's at least three years older.)

Since you're posting to a newsgroup about Perl, I can presume that your
code runs properly without being dependent upon a current version of Perl.
In fact, based upon the problem you posted at the start of this thread, it
sounds as if your programs don't even need Perl to be properly installed
so that all of its features are available.

But certainly these programs don't even depend upon Perl at all! Maybe
your programs are coded in some hypermetalanguage which is at the same
time source code and its own binary, so you won't be dependent upon any
compiler nor any interpreter. (And when you print the source/binary out in
132 columns, it makes an ASCII-art wall{*filter*} as a tastefully-done {*filter*}
portrait of that girl who does "Sabrina the {*filter*}-Age Witch".)

Wait! If there are no dependencies, then your code must run on Windows and
VMS, as well as Unix and the Mac. (With BeOS and Plan9 support coming in
version 4, in Q2 of '00.) It supports all standard browsers, and the
non-standard ones as well. In fact, the lucky remote user doesn't have to
have a properly-installed browser - your program will upgrade them on the
spot, even if they are using 'telnet 80'.

But surely your program is dependent upon some hardware. I mean, you can
probably emulate a 1024x800 display from a single pixel output device, if
you can get the user to spasmodically twitch and sneeze at the proper sync
frequency. But I'd think that you'd have to worry that, sooner or later,
you'll run out of paper tape for the underlying Turing machine, wouldn't
you? I mean, it is only _theoretically_ infinitely long.

Now, at this point, I can't see how you could possibly be dependent upon
any answers from this newsgroup. But if you ever decide to make slightly
less-capable programs, ones which require some smidgin of a prerequisite,
you might consider requesting that someone either (A) install a working
version of perl, or (B) name what they are using, say, "fake-perl". At
that point, there would be the slightest chance that if a program were to
peek at the $^X variable and see "fake-perl", it could know to abandon all
hope and die with an error message which can be read equally well by a
user fluent in English, Urdu, or Braille.

Hope this helps!

-- Tom, who wonders how well your programs run on a Nintendo GameBoy
powered by a 220v 50Hz diesel generator fueled with corn squeezins.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. problem using eval with array of file test operators

2. sort eval doesn't eval

3. eval or not eval

4. loading a module without eval

5. (Un)marshalling objects without eval-ing ?

6. eval("sub test ...") strangeness

7. Understanding eval { ... } vs eval '...' vs eval ...

8. Schemelike qqq function? reinterpolation without eval; weak eval?

9. reinterpolation without eval; weak eval; qqq/STRING/ ?

10. s// using lexicals and refs in an eval'ed string

11. Using eval() for subroutine unwind

12. using here document with eval fails

 

 
Powered by phpBB® Forum Software