Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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]
[moritz]: at this time, a migration could consist of only migrating the rendered HTML of nodes
[moritz]: to a forum software that supports raw HTML input for legacy threads, and uses sane markup for everything else
[holli]: yeah, then vroom will personally stab me in the back at night
[holli]: exactly, moritz
[moritz]: with a big table of redirects to support the old links
[LanX]: do it
[holli]: well if you put some cleverness into the migration you can auto convert most of the links as well
[LanX]: Let's Make PerlMonks Great Again!
[holli]: but you know what? i don't think i'd fancy that. I like PM as it is.
[holli]: Alone the chatterbox and everybody writes his own cb client tradition

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2017-11-20 19:33 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (292 votes). Check out past polls.