It's not possible for us to run your example, as you didn't provide the code to populate the database.

Moreover, the code is not the same. In the "works" case, you're using $transseqchk->{transchk} as the key in %actionsw, but it contains a hash reference, so the if condition is false and the code dereference is not executed.

Update: If you're curious how I discovered it, here's the code I used. I mocked the database as I guessed it's irrelevant to the question.

#!/usr/bin/perl use warnings; use strict; my $dbh = bless {}, 'My::Mock'; sub My::Mock::selectrow_array { {cmd => 'transref_seq_add'} } sub works { my %transseqchk; my $transref_chksql = 'blah'; my $transseqchk->{transchk}= ( $dbh->selectrow_array($transref_chksql) )[0]; $transseqchk->{transref_seq_add}{cmd} = sub{ my $encode_transref_seqmsql = 'blah'; $dbh->do($encode_transref_seqmsql); }; warn "CMD: $transseqchk->{transchk}->{cmd}."; if ($transseqchk->{transchk}{cmd}){ warn "DOES $transseqchk->{transchk}->{cmd}."; &{$transseqchk->{transchk}->{cmd}}; } } sub doesnt { my $transref_chksql = 'blah'; my $transseqchk->{transchk} = ( $dbh->selectrow_array($transref_chksql) )[0]; my %actionsw = ( transref_seq_add => { cmd => sub { my $encode_transref_seqmsql = 'blah'; $dbh->do($encode_transref_seqmsql); } } ); warn "KEY: $transseqchk->{transchk}."; warn "CMD: $actionsw{ $transseqchk->{transchk} }->{cmd}."; if ($actionsw{ $transseqchk->{transchk} }->{cmd}){ warn "DOESNT $actionsw{$transseqchk->{transchk}}->{cmd}."; &{$actionsw{$transseqchk->{transchk}}->{cmd}}; } } eval { works(); 1 } or warn "w: $@"; eval { doesnt(); 1 } or warn "n: $@";

Output:

CMD: transref_seq_add. at ./1.pl line 18. DOES transref_seq_add. at ./1.pl line 20. w: Can't use string ("transref_seq_add") as a subroutine ref while "st +rict refs" in use at ./1.pl line 21. KEY: HASH(0x563da0230d58). at ./1.pl line 35. Use of uninitialized value in concatenation (.) or string at ./1.pl li +ne 36. CMD: . at ./1.pl line 36.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Re: When is strict 'refs triggered by choroba
in thread When is strict 'refs triggered by redtux

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.