in reply to Re^4: Search 2 columns
in thread Search 2 columns

Well, I did try the following test before putting "%$search%" into the snippet suggestion in my own reply:
perl -Mstrict -le 'my $s="blah"; print "%$s%"'
which prints "%blah%". Putting a "%" in front of a scalar variable in a double-quoted string will not turn that variable into a hash ref.

If the variable happens to already be a hash ref, then of course it will be interpolated as such, though not in a way that most folks would consider useful:

perl -Mstrict -le 'my $s={foo=>"bar"}; print "%$s%"'
prints something like "%HASH(0x1801380)%". It's only arrays (and array refs) that get interpolated into the list of values when placed inside double-quotes -- and only if the sigils are right:
perl -Mstrict -le 'my %s=(foo => "bar"); print "%s"' %s perl -Mstrict -le 'my $s=[qw/foo bar/]; print "%$s%"' %ARRAY(0x1801380)% perl -Mstrict -le 'my $s=[qw/foo bar/]; print "@$s@"' foo bar@

Replies are listed 'Best First'.
Re^6: Search 2 columns
by roboticus (Chancellor) on Sep 23, 2007 at 15:50 UTC
    Ah, well, that's what I get when I comment without testing.... ;^(

    I knew I got smashed before with a %, I just thought it was like $ and always messed it up. Thanks for the clarification. Now I can use % in my messages again!

    ...roboticus