Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Dereferencing %hash that does not exist. (conditional)

by Anonymous Monk
on Sep 04, 2013 at 10:13 UTC ( #1052278=note: print w/replies, xml ) Need Help??

in reply to Dereferencing %hash that does not exist.

:D perlintro#if
my( $ref ) = @_; my %revmod; if( ref $ref ){ %revmod = %$ref; } ...

Or  my %revmod = eval { %{ $_[0] } };

Replies are listed 'Best First'.
Re^2: Dereferencing %hash that does not exist. (conditional)
by perldarren (Novice) on Sep 04, 2013 at 10:30 UTC

    Cool problem solved, thanks very much

    Never fails to amaze me how I sometimes just seem to have no grasp on something so fundamental :(

    I keep on trying though !

      Ok, so I implemented the eval variant of this and it seems to work well, thank you guys.
      I now have a slightly different issue.

      my::module::exit_routine is also passed into a simple logging module that I put together like this:
      my $log = LogSimple->new(logdir => $logdir, logfile => $logfile, exit +=> \&my::module::exit_routine )
      In this particular script whenever my::module::exit_routine is called I need to pass the %modifier dispatch table so I need to setup the $log object like this:
      my $log = LogSimple->new(logdir => $logdir, logfile => $logfile, exit +=> \&my::module::exit_routine(\%modifier) )
      Except this does not work, the error is:
      Not a CODE reference at /usr/local/lib/perl5/site_perl/5.10.1/

      I have to admit that my OOP is really in it's infancy.

      Really not sure on this one so any help much appreciated.

      Cheers, Darren

        The expression  \&my::module::exit_routine is evaluated at compile time and so, of course, cannot 'take' an argument (although the LogSimple module, to which you offer no link and which doesn't appear on CPAN or MetaCPAN, may provide a way around this; see its documentation). A typical work-around would be something like (untested)
            exit => sub { return my::module::exit_routine(\%modifier); }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1052278]
and cookies bake in the oven...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (1)
As of 2018-05-26 03:23 GMT
Find Nodes?
    Voting Booth?