in reply to Another eval $@ question

system("$command"); will never throw an exception for eval {} to catch. On error, system returns an error code, not an exception. Please refer to the documentation. (By the way, $? is set to system's error code.)

Please please please use a list for system's arguments whenever possible. It is MUCH safer since it doesn't involve the shell. (What if $pdffile contained a "?)

my @command = ('htmldoc', '--webpage', '-f', $pdffile, $htmlfile); my $rv = system(@command); die("Unable to execute htmldoc: $!\n") if $rv == -1; die("htmldoc was unable to complete the request (Exit code = $&)\n") if $rv; ... success! ...

Update: Expanded code to show error handling.

Replies are listed 'Best First'.
Re^2: Another eval $@ question
by ysth (Canon) on Oct 13, 2006 at 05:47 UTC
    system("$command"); will never thrown an exception for eval {} to catch.
    Yes and no:
    $ perl -we'$SIG{CHLD} = sub { die "whoa there" }; eval { system("true" +) }; print "!$@!"' !whoa there at -e line 1. !
A reply falls below the community's threshold of quality. You may see it by logging in.