Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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] } };


Comment on Re: Dereferencing %hash that does not exist. (conditional)
Select or Download Code
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 !

    Regards,
    Darren
      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/LogSimple.pm

      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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1052278]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-12-27 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls