use strict; use warnings; mysub(; mysub(; mysub(; mysub(; mysub(; mysub(; mysub(; sub mysub { print $_[0]; }

I'm posting this as an obfu, but it might well be a SOPW. I ran into it the hard way. My test was passing an IP address - - to a sub in the intended module. The test was failing. When I looked at the value of the param in the sub with Data::Dumper, I got, but when I printed the param, nothing appeared. I was wasting time looking at my sub when I should have been looking at the test. I had left out the quotes around the IP address.

I know what my code is doing. What I don't know is why. This construct certainly doesn't DWIM and I can't see why it should be what anyone else would mean. Is there a sensible explanation? And let me add my usual question - is this documented anywhere?


John Davies

Replies are listed 'Best First'.
Re: Parameter-driven confusion
by ikegami (Pope) on Dec 21, 2019 at 14:12 UTC
Re: Parameter-driven confusion
by shmem (Chancellor) on Dec 22, 2019 at 00:25 UTC

    What Ikegami says. And there's the "%v" template (vector flag) for sprintf. So, since this is in obfuscation, here's a golfed cidr calculator:

    #!/usr/bin/perl # file $m=pack B32,pop=~'/'x$';printf"$` network %vd broadcast %vd netmask %v +d\n",($z=eval$`)&$m,$z|~$m,$m
    Note the eval$` bit, which is essentially what happens in your code. Usage example:
    shmem [qwurx] ~ > network broadcast netmask +

    This cidr appeared one long gone day on IRC in the perlgolf channel iirc.
    I guess it is off the keyboard of tybalt89, but I might be wrong.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'