Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Parameter-driven confusion

by davies (Prior)
on Dec 21, 2019 at 14:01 UTC ( #11110472=obfuscated: print w/replies, xml ) Need Help??

use strict; use warnings; mysub(74.117.115.116); mysub(32.97.110.111); mysub(116.104.101.114); mysub(32.69.120.99); mysub(101.108.32.104); mysub(97.99.107.101); mysub(114.46.32.8); 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 - 8.8.8.8 - 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 8.8.8.8, 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?

Regards,

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 cidr.pl $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] ~ > cidr.pl 172.16.242.150/27 172.16.242.150 network 172.16.242.128 broadcast 172.16.242.159 netmask + 255.255.255.224

    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'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2020-04-09 04:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (47 votes). Check out past polls.

    Notices?