{"id":25,"date":"2008-12-03T13:55:09","date_gmt":"2008-12-03T20:55:09","guid":{"rendered":"http:\/\/www.imaginarybillboards.com\/?p=25"},"modified":"2010-01-27T19:12:54","modified_gmt":"2010-01-28T02:12:54","slug":"another-insane-perl-snippet","status":"publish","type":"post","link":"http:\/\/www.imaginarybillboards.com\/?p=25","title":{"rendered":"Another insane perl snippet"},"content":{"rendered":"
This finds out whether an ip address is within a certain range.<\/p>\n
example:<\/p>\n
between(“192.168.1.29″,”192.168.1.1″,”192.168.1.99”); returns true<\/p>\n
between(“192.168.1.29″,”10.1.1.1″,”10.1.1.254”); returns false<\/p>\n
sub between
\n{
\nmy ($tgt,$small,$big)=@_;
\nif($tgt!~m\/\\.\/)
\n{
\nif($tgt >= $small and $tgt <= $big){return 1;}
\nelse{return 0;}
\n}
\nmy @tg=split(\/\\.\/,$tgt); my $t=shift(@tg); $tgt=join(‘.’,@tg);
\nmy @sm=split(\/\\.\/,$small); my $s=shift(@sm); $small=join(‘.’,@sm);
\nmy @bg=split(\/\\.\/,$big); my $b=shift(@bg); $big=join(‘.’,@bg);
\nif($t!=$s or $t!=$b){return 0;}
\nelse{return &between($tgt,$small,$big);}
\n}<\/p>\n
Recursion is fun!<\/p>\n","protected":false},"excerpt":{"rendered":"
This finds out whether an ip address is within a certain range. example: between(“192.168.1.29″,”192.168.1.1″,”192.168.1.99”); returns true between(“192.168.1.29″,”10.1.1.1″,”10.1.1.254”); returns false sub between { my ($tgt,$small,$big)=@_; if($tgt!~m\/\\.\/) { if($tgt >= $small and $tgt <= $big){return 1;} else{return 0;} } my @tg=split(\/\\.\/,$tgt); my $t=shift(@tg); $tgt=join(‘.’,@tg); my @sm=split(\/\\.\/,$small); my $s=shift(@sm); $small=join(‘.’,@sm); my @bg=split(\/\\.\/,$big); my $b=shift(@bg); $big=join(‘.’,@bg); if($t!=$s or $t!=$b){return […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[10],"_links":{"self":[{"href":"http:\/\/www.imaginarybillboards.com\/index.php?rest_route=\/wp\/v2\/posts\/25"}],"collection":[{"href":"http:\/\/www.imaginarybillboards.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.imaginarybillboards.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.imaginarybillboards.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.imaginarybillboards.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25"}],"version-history":[{"count":2,"href":"http:\/\/www.imaginarybillboards.com\/index.php?rest_route=\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":92,"href":"http:\/\/www.imaginarybillboards.com\/index.php?rest_route=\/wp\/v2\/posts\/25\/revisions\/92"}],"wp:attachment":[{"href":"http:\/\/www.imaginarybillboards.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.imaginarybillboards.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.imaginarybillboards.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}