in reply to understanding eval in HPOJ

letting us know where you found that snippet (ie: URL) would be helpful

(It really does look like bash to me too)

Replies are listed 'Best First'.
Re: Re: understanding eval in HPOJ
by GhodMode (Pilgrim) on Apr 04, 2004 at 20:49 UTC

    The code is from the file hpoj (no extension), which is installed as part of the hpoj-0.90-14 RPM for RedHat Linux 9. It's 1339 lines long, but here are lines one through six: unchanged...

    #!/usr/bin/perl # LANG=C is a work around for bug 82652. # The easier work-around of setting LANG=C in perl script itself didn' +t # work. It's probably too late by then. eval '(exit $?0)' && eval 'exec env LANG=C $0 ${1+"$@"}' if $ENV{"LANG"} != "C";

    Really?! No one is familiar with exec and eval?

    eval "evaluates" perl code or an expression and exec terminates the currently running Perl script and executes it's arguments in the current shell, ie: without creating a new process ID.

    There is no eval command in Bash, but the exec command does work in a similar fashion, executing it's arguments without creating a new process.

    I think both execs are actually based on a similar function in the standard programming library for Unix-like operating systems.

    --
    -- GhodMode
    

      First of all, it's not an issue of being familiar with eval or exec .. I know what those do, it's the some of the crazy syntax/variables it's trying to use in ways that make no sense.

      Second, bash most certainly has an "eval" see the "SHELL BUILTIN COMMANDS" section of "man bash"

      Third, reading RedHat bug#82652 indicates a couple of important things:

      • /etc/rc.d/init.d/hpoj is evidently a symlink to /usr/sbin/ptal-init
      • The lines you quoted seem to come from a patch attached to ALEXANDRE's comment#7
      • The same ALEXANDRE submitted another patch with comment#8 indicating that her first patch: "...isn't even correct perl."
      I would read the rest of that bug, and take a look at the most recent release of your software.

      There is certainly an eval command in bash. My One-liner japh is a bash script and it uses the eval builtin.