Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

IP addresses?

by phroggy (Monk)
on Aug 18, 2005 at 02:22 UTC ( #484657=obfuscated: print w/replies, xml ) Need Help??

It occurred to me that a mostly-deobfuscated version of a previous JAPH I did still seems pretty odd. Top of page 68 in the camel book, if you're confused...
#!/usr/bin/perl use strict; use warnings; my @ips=( 74.117.115.116, 32.97.110.111, 116.104.101.114, 32.80.101.114, 108.32.104.97, 99.107.101.114, 44.32.32.10, ); print for @ips;

Replies are listed 'Best First'.
Re: IP addresses?
by cristian (Hermit) on Aug 18, 2005 at 14:59 UTC
    Simply Example 1: without "for" my @ips=( 74.117.115.116, 32.97.110.111, 116.104.101.114, 32.80.101.114, 108.32.104.97, 99.107.101.114, 44.32.32.10, ); print @ips; Example 2: whithout @ips print ( 74.117.115.116, 32.97.110.111, 116.104.101.114, 32.80.101.114, 108.32.104.97, 99.107.101.114, 44.32.32.10, ); This is the end. Just another Perl hacker,
      Ahh, good call - I hadn't thought of removing "for". As for removing @ips, I thought leaving it in would add just a tiny bit of misdirection, making the reader think of IP addresses....

      perl -e '($,,@_)=("er",",\n","l Hack"," P","Just anoth"); print reverse @_;'
Re: IP addresses?
by 5mi11er (Deacon) on Aug 18, 2005 at 14:32 UTC
    Interesting. So, what exactly is perl doing?
      DB<11> p 74.117.115.116;
    Just
      DB<12> p 74;
    74
      DB<13> p 74.117;
    74.117
      DB<14> p 74.117.115;
    Jus
      DB<15> p 74.117.32.32.44.115;
    Ju  ,s
    
    The dot operator is used to concatenate strings together, so as long as it doesn't look like a normal integer or floating point number, it assumes they are "strings", and perl is storing them as single byte integers (characters), rather than, for example, the string "74". When printed, out come their ascii representations.

    Is this a good description of what's going on internally, or is there some further magic to be explained?

    -Scott

      Good observations, but your guesses are completely wrong. See "Version Strings" in perldoc perldata. Looks like support for these is going away after 5.8...

      perl -e '($,,@_)=("er",",\n","l Hack"," P","Just anoth"); print reverse @_;'
        Ah, version strings. I'd forgotten about those.

        It's a nice side effect that "raw" IP addresses end up getting stored like that.

        But, is it portable between big and little endian machines?

        -Scott

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://484657]
Approved by Tanalis
Front-paged by cfreak
help
Chatterbox?
[Corion]: marto: Oh, I'm jealous. I'm going to see DM in Frankfurt, but it's a stadium full of people, so, rather a big thing where you mostly get to see the band on screens ;)
[marto]: yes, the last time I saw them was in Berlin a few years ago, at the old Olympic stadium
[marto]: After Sunday I don't think I'll go see them again :)
[LanX]: Corion: come on, people are people! ;)
[Corion]: Naah, I think it's still an OK show so far. Their new songs aren't exactly great, but I'm not going there for new material anyway ;)
[marto]: I got the feeling from the last show that for big sections of it, they were not really into what they were doing
[Corion]: LanX: Sure, they can bask in my Halo
[marto]: more so than the previous show I saw
[Corion]: marto: Well, I think they go a tour every two years and I think it's hard to even get a connection with the crowd at a 20k people concert... But maybe after this time I'll stop too ;)
[Corion]: I still have to see the Pet Shop Boys live before they stop touring at all

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2017-03-24 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (301 votes). Check out past polls.