[26059] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8266 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 21 14:06:11 2005

Date: Thu, 21 Jul 2005 11:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 21 Jul 2005     Volume: 10 Number: 8266

Today's topics:
        Convert Integer value to IP Address <vikrantREMOVE@DELETEsaysnetsoftDDDD.com>
    Re: Convert Integer value to IP Address <scobloke2@infotop.co.uk>
    Re: Convert Integer value to IP Address <glex_no-spam@qwest-spam-no.invalid>
    Re: How to send a query to the browser from time to tim <dejanews@email.com>
    Re: ithreads & memory xhoster@gmail.com
        Lightning talks deadline extended (Mark Jason Dominus)
    Re: Strange speed-increase by separating "if"s (Anno Siegel)
    Re: Strange speed-increase by separating "if"s <w.n.humann.removethis@agilent.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 21 Jul 2005 18:44:57 +0530
From: Vikrant <vikrantREMOVE@DELETEsaysnetsoftDDDD.com>
Subject: Convert Integer value to IP Address
Message-Id: <dbo770$vo5$1@domitilla.aioe.org>

Hi

Please tell me how do i convert a long integer IP address to dotted quad 
IP address using perl language.

For example:- If  IP address is 167772260 then how do i convert it into 
dotted quad IP address.

I am able to do it by applying some mathematical operations, but i am 
looking for a function in perl the can do the same,because in my code i 
have deal with many IP addresses.

or plz suggest me any other way to do it.


With Regards
Vikrant


------------------------------

Date: Thu, 21 Jul 2005 13:27:02 +0000 (UTC)
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: Convert Integer value to IP Address
Message-Id: <dbo7r6$bea$1@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com>

Vikrant wrote:
> Hi
> 
> Please tell me how do i convert a long integer IP address to dotted quad 
> IP address using perl language.
> 
> For example:- If  IP address is 167772260 then how do i convert it into 
> dotted quad IP address.
> 
> I am able to do it by applying some mathematical operations, but i am 
> looking for a function in perl the can do the same,because in my code i 
> have deal with many IP addresses.
> 
> or plz suggest me any other way to do it.
> 

perldoc -q "IP address"


------------------------------

Date: Thu, 21 Jul 2005 11:51:19 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Convert Integer value to IP Address
Message-Id: <coQDe.22$CS2.3074@news.uswest.net>

Vikrant wrote:
> Hi
> 
> Please tell me how do i convert a long integer IP address to dotted quad 
> IP address using perl language.
> 
> For example:- If  IP address is 167772260 then how do i convert it into 
> dotted quad IP address.
> 
> I am able to do it by applying some mathematical operations, but i am 
> looking for a function in perl the can do the same,because in my code i 
> have deal with many IP addresses.
> 
> or plz suggest me any other way to do it.

Net::Netmask (http://search.cpan.org/~muir/Net-Netmask-1.9012/) contains 
a lot of useful methods pertaining to IP addresses and CIDR notation.

sub int2quad
{
     return join('.',unpack('C4', pack("N", $_[0])));
}


------------------------------

Date: Thu, 21 Jul 2005 14:09:01 GMT
From: samwyse <dejanews@email.com>
Subject: Re: How to send a query to the browser from time to time?
Message-Id: <10ODe.810$LF.95@newssvr27.news.prodigy.net>

Joe Smith wrote:
>> I am creating a chat application like Messenger for the web (using 
>> the  browser) and I'm wondering if there is a way to
>> receive new messages from time to time from the server other than  
>> refreshing the page each 5 sec.
> 
> The HTTP protocol is not interactive.
> The usual way of getting updates like that is to have an HTML
> page with an embedded Java applet running.  There are many
> IRC clients written in Java that run inside a browser window.
> This is not a perl-specific question.

Actually, that's not entirely true.  A. Sinan Unur has already pointed 
out that 'server push' will accomplish the goal.  To keep things on 
topic, I'd also advise reading the perldocs for CGI.pm:
http://perl.active-venture.com/lib/CGI.html#Server-Push

Note that althought you can find lots of comments that Internet Explorer 
doesn't support server push, it apparently has since IE 5.5.


------------------------------

Date: 21 Jul 2005 17:33:10 GMT
From: xhoster@gmail.com
Subject: Re: ithreads & memory
Message-Id: <20050721133310.575$c9@newsreader.com>

Big and Blue <No_4@dsl.pipex.com> wrote:
> xhoster@gmail.com wrote:
>  >
> > On linux, too, the in-the-loop "my" makes it much more memory
> > efficient. I just can't figure out why.
>
>     Adding:
>
>   $th_n = undef;
>
> after the detach also stops it gathering memory.  This implies that what
> your original code did was to continually add threads to $th_n.

Yes and no.  Any given instance of the variable $th_n can only hold one
thread at a time, but there are many instances of $th_n.

Each thread, when it is spawned, inherits a copy of the parents $th_n.  For
all spawned threads other than the first, this variable happens to hold a
ref to the previously spawned thread.  Apparently, a detached thread
doesn't clean itself up until both of two things happen: it finishes, and
it's own refcount goes to zero.  (presumably, a running thread holds a
reference to itself, so its refcount can't go to zero until it finishes).
Without the undef (or "my" inside the loop) the refcount never goes to zero
because there is always some other thread holding a reference to this one.

I would think that once a thread is done, it would decrement the ref counts
of all things it references.  But apparently it doesn't do this upon
finishing, but rather upon destruction.  I guess this isn't a bug, as I
originally thought, but simply unfortunate.


 ...
>
>     Specfically removing $th_n, or implicilty removing it by declaring it
> with my in the loop, does destroy all threads.

It allows the refcount to go to zero, so that it can be destroyed naturally
when its time comes.

>     Presumably it is possible to detach threads and let them continue to
>     run?

Indeed, that is the whole point of detach.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: Thu, 21 Jul 2005 10:20:57 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Lightning talks deadline extended
Message-Id: <dbnsu9$gi0$1@plover.com>


     Lightning Talks at the 2005 O'Reilly Open Source Convention

Because the submissions process opened so late, I will continue to
accept lightning talks submissions up to the last minute.  To submit a
talk proposal, please send your proposed title and an abstract of up
to four sentences to

        osc-lt-2005-submit-perl@plover.com

or contact me in person at OSCON.

For more complete information, visit:

        http://perl.plover.com/lt/osc2005/

Thanks.



------------------------------

Date: 21 Jul 2005 10:22:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Strange speed-increase by separating "if"s
Message-Id: <dbnt0l$41d$1@mamenchi.zrz.TU-Berlin.DE>

Wolfram Humann  <w.n.humann.removethis@agilent.com> wrote in comp.lang.perl.misc:
> I have a script for processing certain eps-files. What it basically does 
> is going through the file looking for "setgray"-lines. If it finds one, 
> it checks if it's followed by lines matching the values in @head and 
> then @dot (plus some coordinate-checks). If all matches, @head remains 
> in the file while @dot is discarded. If the match fails, the file 
> remains unchanged. Here is the script:
> 
> #!/usr/local/bin/perl -w
> use strict;
> 
> my @head = (
>    '^N(\s+\d+)(\s+\d+)(\s+\d+) 0 360 arc sf N$',
>    '^\d+\s+slw$',
> );
> my @dot = (
>    '^(\d+)\s+(\d+)\s+M$',
>    ('^(\d+)\s+(\d+)\s+D$') x 72,
> );
> 
> my @c_head = map qr/$_/, @head;
> my @c_dot  = map qr/$_/, @dot;
> my ($x, $y, $r);
> 
> while(<>)
> {
>    print;
>    if(/^[0-9.]+\s+setgray\s+$/)
>    {
>      my ($h, $d) = (0,0);
>      my $l = "";
>      while(<>)
>      {
>        if ($head[$h])
>        {
>          print;
>          last unless $_ =~ $c_head[$h];
>          ($x, $y, $r) = ($1, $2, $3) if defined $3;
>          $h++;
>        }
>        elsif ($dot[$d])
>        {
>          $l .= $_;
>          if ($_ !~ /$c_dot[$d]/ or
>              $1 < $x - $r - 2 or
>              $1 > $x + $r + 2 or
>              $2 < $y - $r - 2 or
>              $2 > $y + $r + 2 )
>          {
>            print $l;
>            last;
>          }
>          $d++;
>        }
>        else
>        {
>          print $l if /^\d+\s+\d+\s+D$/;
>          print;
>          last;
>        }
>      }
>    }
> }
> 
> I was surprised how long it took and profiled with Devel::SmallProf. 
> This showed that most time is spent in "if (($_ !~ /$c_dot[$d]/) or...". 
> To see if the pattern match or the comparisons took so long, I split the 
> "if" like this:
> 
> if ($_ !~ /$c_dot[$d]/)
> {
>      if ($1 < $x - $r - 2 or
>          $1 > $x + $r + 2 or
>          $2 < $y - $r - 2 or
>          $2 > $y + $r + 2 )
>      {
>          print $l;
>          last;
>      }
> }

The logic of the modified part is different from the original, and
makes no sense.  You are making sure the regex *doesn't* match, and
then go on to use $1 and $2.  In the original, you use them when the
regex *does* match.  If you had warnings switched on, you'd have
noticed.

> To my surprise a test run (without the profiler) ran *at least* twice as 
> fast as the original version.

Different control flow, different runtimes, so no surprise here.

Make your program strict- and warnings-safe and profile again, preferably
with programs that do the same thing.  When benchmarking and profiling,
an important step is to monitor your variants to make sure that you
haven't built in a bug, as has happened to you.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


------------------------------

Date: Thu, 21 Jul 2005 13:37:08 +0200
From: Wolfram Humann <w.n.humann.removethis@agilent.com>
Subject: Re: Strange speed-increase by separating "if"s
Message-Id: <42df88e6$0$20149$9b4e6d93@newsread2.arcor-online.net>

-----Original Message-----
From: Anno Siegel
Sent:  21.07.2005 12:22
> Wolfram Humann  <w.n.humann.removethis@agilent.com> wrote in comp.lang.perl.misc:
> 
>>I have a script for processing certain eps-files. What it basically does 
>>is going through the file looking for "setgray"-lines. If it finds one, 
>>it checks if it's followed by lines matching the values in @head and 
>>then @dot (plus some coordinate-checks). If all matches, @head remains 
>>in the file while @dot is discarded. If the match fails, the file 
>>remains unchanged. Here is the script:
>>
>>#!/usr/local/bin/perl -w
>>use strict;
>>
>>my @head = (
>>   '^N(\s+\d+)(\s+\d+)(\s+\d+) 0 360 arc sf N$',
>>   '^\d+\s+slw$',
>>);
>>my @dot = (
>>   '^(\d+)\s+(\d+)\s+M$',
>>   ('^(\d+)\s+(\d+)\s+D$') x 72,
>>);
>>
>>my @c_head = map qr/$_/, @head;
>>my @c_dot  = map qr/$_/, @dot;
>>my ($x, $y, $r);
>>
>>while(<>)
>>{
>>   print;
>>   if(/^[0-9.]+\s+setgray\s+$/)
>>   {
>>     my ($h, $d) = (0,0);
>>     my $l = "";
>>     while(<>)
>>     {
>>       if ($head[$h])
>>       {
>>         print;
>>         last unless $_ =~ $c_head[$h];
>>         ($x, $y, $r) = ($1, $2, $3) if defined $3;
>>         $h++;
>>       }
>>       elsif ($dot[$d])
>>       {
>>         $l .= $_;
>>         if ($_ !~ /$c_dot[$d]/ or
>>             $1 < $x - $r - 2 or
>>             $1 > $x + $r + 2 or
>>             $2 < $y - $r - 2 or
>>             $2 > $y + $r + 2 )
>>         {
>>           print $l;
>>           last;
>>         }
>>         $d++;
>>       }
>>       else
>>       {
>>         print $l if /^\d+\s+\d+\s+D$/;
>>         print;
>>         last;
>>       }
>>     }
>>   }
>>}
>>
>>I was surprised how long it took and profiled with Devel::SmallProf. 
>>This showed that most time is spent in "if (($_ !~ /$c_dot[$d]/) or...". 
>>To see if the pattern match or the comparisons took so long, I split the 
>>"if" like this:
>>
>>if ($_ !~ /$c_dot[$d]/)
>>{
>>     if ($1 < $x - $r - 2 or
>>         $1 > $x + $r + 2 or
>>         $2 < $y - $r - 2 or
>>         $2 > $y + $r + 2 )
>>     {
>>         print $l;
>>         last;
>>     }
>>}
> 
> 
> The logic of the modified part is different from the original, and
> makes no sense.  You are making sure the regex *doesn't* match, and
> then go on to use $1 and $2.  In the original, you use them when the
> regex *does* match.  If you had warnings switched on, you'd have
> noticed.
> 
Of course you're right. I had the idea that splitting an "if" in two 
parts like that was obvious (when indeed it was just stupid). I do have 
warnings and strict on, but with the file I use, the inner "if" is never 
hit...
If my brain isn't totally drained already the correctly split version 
should be:

if ($_ =~ /$c_dot[$d]/)
{
     if ($1 < $x - $r - 2 or
         $1 > $x + $r + 2 or
         $2 < $y - $r - 2 or
         $2 > $y + $r + 2)
     {
         print $l;
         last;
     }
}
else
{
     print $l;
     last;
}

Naturally, with this the timing is more or less back to what it was. 
According to profiling, the four comparisons take about as much time as 
the pattern match -- hence the speed increase when they never executed :-)

Thanks for the help!


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8266
***************************************


home help back first fref pref prev next nref lref last post