Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: disable functions if module not installed

by pileofrogs (Priest)
on Nov 03, 2008 at 22:28 UTC ( #721231=note: print w/replies, xml ) Need Help??


in reply to disable functions if module not installed

You might also want to use a block eval instead of a string eval. Block eval is for exception handling, string eval is for on-the-fly complilation.

If you're trying to debug this while running it as a CGI, you should serously look into CGI::Carp with particular attention to fatalstobrowser. Or you could do one better and debug it at a command line. It's a much better idea to make sure it compiles at a command line and then upload it to your web server.

--Pileofrogs

  • Comment on Re: disable functions if module not installed

Replies are listed 'Best First'.
Re^2: disable functions if module not installed
by lepetitalbert (Monsignor) on Nov 03, 2008 at 22:40 UTC

    Hi almut and pileofrogs,

    almut your code gave me an out of memory too.

    pileofrogs fatalstobrowser is on. An example of one of these block eval's ?

    Thank you.

    "There is only one good, namely knowledge, and only one evil, namely ignorance." Socrates
      almut your code gave me an out of memory too.

      Weird.  Can you just plain load the module with use Image::Magick; (or require Image::Magick;)?  In case the machine (or user limit) doesn't provide sufficient memory to load the module (which in theory could be possible), I'd expect that you get "out of memory" either way.

      An example of one of these block eval's ?
      eval { require Image::Magick }; my $is_magick = $@ ? 0 : 1;

        Hi again

        use Image::Magick; works like a charm, am using it for weeks.

        eval { require Image::Magick }; my $is_Magick = $@ ? 0 : 1;

        produces out of memory too :(

        I have : XP, 2Gb ram, perl 5.10, IM 6.4.4-2, PerlMagick installed with IM installer

        Thanls again.

        "There is only one good, namely knowledge, and only one evil, namely ignorance." Socrates

      Read up on eval in [perlfunc].

      Short answer:

      Block

      eval { die "You commie!" };

      String

      my $death = 'die'; eval "$death \"You commie!\";"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://721231]
help
Chatterbox?
[Yaerox]: I feel like i'm not seeing the forest for the trees. Can someone give me a hint how to research converting all kinds of files into ansi? If origin file is utf8 convert to ansi, is origin file is ansi then skip file.
[1nickt]: Yaerox probably best to whip up an SSCCE demonstrating the failure in what you have now and post to SoPW as a question.
[Corion]: Yaerox: That's a somewhat hard problem. Encode solves the conversion part, but for guessing what encoding a file is in, that's the hard part

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-03-28 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (331 votes). Check out past polls.