[29148] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 392 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 29 14:09:43 2007

Date: Sun, 29 Apr 2007 11:09:07 -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           Sun, 29 Apr 2007     Volume: 11 Number: 392

Today's topics:
        a problem about  function returning point <havel.zhang@gmail.com>
    Re: a problem about function returning point <klaus03@gmail.com>
    Re: Cant open a file with just a relative path <bik.mido@tiscalinet.it>
    Re: Cant open a file with just a relative path <bik.mido@tiscalinet.it>
    Re: Cant open a file with just a relative path <bik.mido@tiscalinet.it>
        CGI module redirect defaults to 302 -- why? Mott.Jeff@gmail.com
        Interval Timers on Windows <cbkihong@hotmail.com>
    Re: Interval Timers on Windows <no@email.com>
    Re: Interval Timers on Windows <m@rtij.nl.invlalid>
    Re: Interval Timers on Windows <cbkihong@hotmail.com>
    Re: Interval Timers on Windows <m@rtij.nl.invlalid>
    Re: Perl routine for cluster detection <wahab-mail@gmx.de>
        perl Write filehandle blocks. kiranmn@my-deja.com
    Re: perl Write filehandle blocks. <tadmc@augustmail.com>
    Re: perl Write filehandle blocks. kiranmn@my-deja.com
    Re: Rounding up to the next .5 <justin.0704@purestblue.com>
    Re: Top Turds of comp.lang.perl.misc (2007) <bik.mido@tiscalinet.it>
    Re: Top Turds of comp.lang.perl.misc (2007) <1usa@llenroc.ude.invalid>
        Using one methods variable value in another method insi <hara.acharya@gmail.com>
    Re: Weird error after a configuration change <nikos1337@gmail.com>
    Re: Weird error after a configuration change <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 29 Apr 2007 07:00:50 -0700
From: "havel.zhang" <havel.zhang@gmail.com>
Subject: a problem about  function returning point
Message-Id: <1177855250.191615.93040@n76g2000hsh.googlegroups.com>

hi everyone:

    Today I came cross a strange problem about function returning
point.

I have a function for replace chinses character to english character.

sub replace_par{
     my $str =3D shift;
     $str =3D~ s/\xA3\xA8/\(/;
     $str =3D~ s/\xA3\xA9/\)/;
     return $str;
}

Then I calling this function in a subroutine. as follows:
 .=2E. ...
### first we open a text file, and read line by line:
open(F,"<aaa.txt");
while(<F>){
 .=2E. ...
#according the context we have read, we named function name.
  my $progName =3D $conf->{'feedname'} . '_slicecheck';
#calling the named function
  my ($ret,$outline) =3D &$progName($conf,$data,$store);

  if ($ret =3D=3D 2){
    ... ...
  };
     print OUTPUT "$outline\n" if ($ret=3D=3D0);
}
close(F);
close(OUTPUT);

exit(0);

#the calling function name is p4sup=EF=BC=9A
#
sub p4sup_slicecheck{
     my $conf =3D shift;
     my $data =3D shift;
     my $store =3D shift;

#calling function replace_par,replace the chinese character
$data->{'english_name'} =3D replace_par($data->{'english_name'}) if
$data->{'english_name'} =3D~ /\xA3\xA8/
$l =3D length($data->{'english_name'});
$data->{'english_name'} .=3D ' ' x (100 - $l) if ($l < 100);

 .=2E. ...
}

then, after calling function replace_par, system should return to
subroutine:p4sup_slicecheck. But the system return to "close(OUTPUT)"
where the line before exit(0) !

Anyone hit this situation?

Thank u in advanced.

Havel Zhang



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

Date: 29 Apr 2007 08:40:07 -0700
From: Klaus <klaus03@gmail.com>
Subject: Re: a problem about function returning point
Message-Id: <1177861207.225590.108660@c35g2000hsg.googlegroups.com>

On Apr 29, 4:00 pm, "havel.zhang" <havel.zh...@gmail.com> wrote:
>     Today I came cross a strange problem about function returning
> point.

Like with every strange problem in Perl, first try the following, put
the following two lines at the beginning of your program:

use strict;
use warnings;

Correct all errors (if any) and all warnings (if any) and re-run your
program.

If the problem persists, then proceed as follows:

[ subroutine snipped ]

> Then I calling this function in a subroutine. as follows:
> ... ...
> ### first we open a text file, and read line by line:
> open(F,"<aaa.txt");
> while(<F>){

This probably won't make any difference to your problem, but I mention
it anyway:
The open is better written as:

open my $F, '<', 'aaa.txt' or die "Error read 'aaa.txt', $!";
while (<$F>) {

> ... ...
> #according the context we have read, we named function name.
>   my $progName =3D $conf->{'feedname'} . '_slicecheck';
> #calling the named function

You might have a good reason to call your function indirectly ("&
$progName()"), but if you do so you must accept the increased
complexity of your code.

With regards to your problem, this function call only makes sense if
$progName eq 'p4sup_slicecheck', therefore I stronly recommend to
print out the content of $progName before you actually call the
function, like so:

print STDERR "DEB-01: will call sub $progName\n";

>   my ($ret,$outline) =3D &$progName($conf,$data,$store);

Then give a life sign when you return from the function call, like so:

print STDERR "DEB-02: back from sub $progName\n";

>
>   if ($ret =3D=3D 2){
>     ... ...
>   };
>      print OUTPUT "$outline\n" if ($ret=3D=3D0);}
>
> close(F);

Better:
close $F;

> close(OUTPUT);
>
> exit(0);
>
> #the calling function name is p4sup=EF=BC=9A
> #
> sub p4sup_slicecheck{
>      my $conf =3D shift;
>      my $data =3D shift;
>      my $store =3D shift;
>
> #calling function replace_par,replace the chinese character
> $data->{'english_name'} =3D replace_par($data->{'english_name'}) if
> $data->{'english_name'} =3D~ /\xA3\xA8/

There is no semicolon at the end of the above line. I seriously ask
myself whether you ever compiled your program successfully ?

Anyway, the above function should be written differently to add some
prints, like so:

#calling function replace_par,replace the chinese character
print STDERR "DEB-03: inside p4sup_slicecheck()\n";
if ($data->{'english_name'} =3D~ /\xA3\xA8/) {
    print STDERR "DEB-04: will call sub replace_par()\n";
    $data->{'english_name'} =3D replace_par($data->{'english_name'});
    print STDERR "DEB-05: back from sub replace_par()\n";
}
print STDERR "DEB-06: continue p4sup_slicecheck()\n";

> $l =3D length($data->{'english_name'});
> $data->{'english_name'} .=3D ' ' x (100 - $l) if ($l < 100);
>
> ... ...
>
> }
>
> then, after calling function replace_par, system should return to
> subroutine:p4sup_slicecheck. But the system return to "close(OUTPUT)"
> where the line before exit(0) !

Run the program and watch what STDERR reports, that might be useful.

--
Klaus



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

Date: Sun, 29 Apr 2007 19:58:34 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Cant open a file with just a relative path
Message-Id: <o5n9339i6vj34ir0epp5d3c0bepvi0gh2o@4ax.com>

On 24 Apr 2007 13:04:31 -0700, skieros <nikos1337@gmail.com> wrote:

>open(FILE, ">>/somefolder/somesubfolder/digest.passwd") or die $!;
>     print FILE "$user:$realm:" . Digest::MD5::md5_hex("$user:$realm:
>$pass") . "\n";
>close(FILE);

http://perlmonks.org/?node_id=612657


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 29 Apr 2007 20:00:37 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Cant open a file with just a relative path
Message-Id: <m7n933p33uqoj0eeh5hf2br40fdqbbpc8v@4ax.com>

On Wed, 25 Apr 2007 02:50:01 -0700, merlyn@stonehenge.com (Randal L.
Schwartz) wrote:

>But, we'll always have newbies, I guess.

Newbieness and education are orthogonal, I guess. Or at least they
don't differ much from orthogonality. Well, they shouldn't!


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 29 Apr 2007 20:07:26 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Cant open a file with just a relative path
Message-Id: <sin93353sbnbbtch9pahmrmikl8690km78@4ax.com>

On 27 Apr 2007 04:26:58 -0700, skieros <nikos1337@gmail.com> wrote:

>> And I find it annoying that someone posts the same question to multiple help
>> forums without disclosing such.  It causes an unneeded waste of resources.
>
>yes, Iam sorry, as i explained to pesonal mail i couldnt see those 2
>thread on gougle groups up until today...dont know why....thats also
>why i posted 2 times.

This is a non sequitur: what did prevent you from writing something
along the lines of

: Also posted in PerlMonks at
: 
: http://perlmonks.org/?node_id=611837

in the first place?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 29 Apr 2007 09:37:53 -0700
From: Mott.Jeff@gmail.com
Subject: CGI module redirect defaults to 302 -- why?
Message-Id: <1177864673.241576.129590@y80g2000hsf.googlegroups.com>

        If the 302 status code is received in response to a request
other than GET or HEAD, the
        user agent MUST NOT automatically redirect the request unless
it can be confirmed by the
        user.
        -- HTTP/1.1

For a CGI program that was requested from a POST form, the 302 message
seems to not be what I would want. But 303:

        The response to the request can be found under a different URI
and SHOULD be retrieved
        using a GET method on that resource. This method exists
primarily to allow the output of a
        POST-activated script to redirect the user agent to a selected
resource. The new URI is not a
        substitute reference for the originally requested resource.
        HTTP/1.1

303 seems to be designed *exactly* for redirecting the browser after a
CGI program has run. Why then does the CGI module return a 302
response by default?



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

Date: Sun, 29 Apr 2007 16:40:11 +0800
From: Bernard Chan <cbkihong@hotmail.com>
Subject: Interval Timers on Windows
Message-Id: <46344de2$0$16409$88260bb3@free.teranews.com>


Hi All,

I am writing a script to generate some packets for RTP stream simulation. As
you may know, RTP requires a more-or-less constant packet rate (and hence
UDP is used), and I will need to generate fixed sized packets at regular
intervals, say 20ms, so that will be around 50 packets per second.

On Linux I have tried a version using Time::HiRes ualarm(). On some of my
Linux systems ualarm() can generate a packet rate that approximates 50Hz
pretty well, and the interval variance is infinitesimal. However, I also
have some systems (mostly Fedora) which seem to exhibit increasingly long
intervals after some seconds for reasons unknown to me.

I would also like to have the script usable on Windows that my peers who
have Windows on their systems can perform some tests. There is no ualarm()
in Time::HiRes on Windows, so I tried another approach. I created a
thread-enabled version of the script. A separate thread is created which
does roughly this:

while ($continue) {
        sendPacket();
        select(undef, undef, undef, 20/1000);
}

However, I find that the sleep between each packet tends to be slightly
higher than 20ms, so after not many packets it is already arriving slower
than the drain rate at the receiver side.

So, I would like to know, whether I can do anything to improve this on the
Windows side? I don't need microseconds or even nanoseconds granularity.
1ms would be generally good enough, but I would like a cross-platform
(Win+Linux at least) approach.

Any insights will be much appreciated.

-- 
Regards,
Bernard Chan

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Sun, 29 Apr 2007 10:47:30 +0100
From: Brian Wakem <no@email.com>
Subject: Re: Interval Timers on Windows
Message-Id: <59j7tiF2l5rc5U1@mid.individual.net>

Bernard Chan wrote:

> 
> Hi All,
> 
> I am writing a script to generate some packets for RTP stream simulation.
> As you may know, RTP requires a more-or-less constant packet rate (and
> hence UDP is used), and I will need to generate fixed sized packets at
> regular intervals, say 20ms, so that will be around 50 packets per second.
> 
> On Linux I have tried a version using Time::HiRes ualarm(). On some of my
> Linux systems ualarm() can generate a packet rate that approximates 50Hz
> pretty well, and the interval variance is infinitesimal. However, I also
> have some systems (mostly Fedora) which seem to exhibit increasingly long
> intervals after some seconds for reasons unknown to me.
> 
> I would also like to have the script usable on Windows that my peers who
> have Windows on their systems can perform some tests. There is no ualarm()
> in Time::HiRes on Windows, so I tried another approach. I created a
> thread-enabled version of the script. A separate thread is created which
> does roughly this:
> 
> while ($continue) {
>         sendPacket();
>         select(undef, undef, undef, 20/1000);
> }
> 
> However, I find that the sleep between each packet tends to be slightly
> higher than 20ms, so after not many packets it is already arriving slower
> than the drain rate at the receiver side.
>


Surely you would need to time sendPacket() and subtract it from the next
delay?


-- 
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


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

Date: Sun, 29 Apr 2007 12:20:33 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Interval Timers on Windows
Message-Id: <pan.2007.04.29.10.21.09@rtij.nl.invlalid>

On Sun, 29 Apr 2007 10:47:30 +0100, Brian Wakem wrote:

> Surely you would need to time sendPacket() and subtract it from the next
> delay?

Surely time spend in sendPacket is negligible om modern machines?

(I don't really know.I/O and syscalls used to be expensive. Nowadays 
machines are so fast that syscalls are fast too and sending a packet 
generally means -- I assume -- copying it to some internal buffer and 
some pointer fiddling, so that should be very fast).

M4


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

Date: Sun, 29 Apr 2007 19:43:18 +0800
From: Bernard Chan <cbkihong@hotmail.com>
Subject: Re: Interval Timers on Windows
Message-Id: <463478a7$0$13928$88260bb3@free.teranews.com>

Martijn Lievaart wrote:

> On Sun, 29 Apr 2007 10:47:30 +0100, Brian Wakem wrote:
> 
>> Surely you would need to time sendPacket() and subtract it from the next
>> delay?
> 
> Surely time spend in sendPacket is negligible om modern machines?
 
Thanks for your replies.

Actually I have tried a version making similar adjustments to the delay
before, but there was no noticeable improvements (the packet rate is still
highly fluctuating while tending to be slightly < 50Hz in the long term). In
fact the time lag seems to be even more substantial in this version. This is
the exact code of what I tried:

sub sendPacketThread {
        my ($t_s, $t_us);
        while ($continue) {
                ($t_s, $t_us) = (time(), ${[gettimeofday()]}[1]);
                sendPacket();
                my ($t2_s, $t2_us) = (time(), ${[gettimeofday()]}[1]);
                my $workTime = ($t2_s - $t_s)*(10**6) + ($t2_us - $t_us);
                ($t_s, $t_us) = ($t2_s, $t2_us);
                select(undef, undef, undef,
($ptime*1000-$workTime)/(10**6));
        }
}

This subroutine is what was immediately called from thread->new(). In the
test, both the sender and receiver are on localhost so there should not be
any packet transit issue.

Therefore, I am wondering whether there are any "real" timers accessible on
Windows Perl that gives a more accurate timer. Some fluctuations of delay
in between individual packets is acceptable, but the long-term rate should
be very close to 50Hz or the receiver side will start to drop each packet
on arrival ...

-- 
Regards,
Bernard Chan

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Sun, 29 Apr 2007 14:10:44 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Interval Timers on Windows
Message-Id: <pan.2007.04.29.12.11.20@rtij.nl.invlalid>

On Sun, 29 Apr 2007 19:43:18 +0800, Bernard Chan wrote:

> This subroutine is what was immediately called from thread->new(). In
> the test, both the sender and receiver are on localhost so there should
> not be any packet transit issue.

Perl threading is reasonably slow, and I don't know about the granularity 
of taskswitches. Maybe you should test this first without threads to see 
if threading itself isn't the issue.

HTH,
M4


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

Date: Sun, 29 Apr 2007 11:04:37 +0200
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Perl routine for cluster detection
Message-Id: <f11ne4$gl9$1@mlucom4.urz.uni-halle.de>

vincent64@yahoo.com wrote:
> Here is some elementary code to detect the presence of a clustering
> structure in a 2-dimensional dataset. It's more heuristic than
> scientific, so take it with a grain of salt, as even the concept of
> cluster is highly fuzzy.

Before going into details, I'd like to ask what
you think what the following part of your program
does:

  ...
  sub seed {
     local($x,$y)=@_;
     $kmax=1000;

     $x=rand($x)-0.5;
     $y=rand($y)-0.5;

     for ($k=0; $k<$kmax; $k++) {
         print "\t$cluster [$1]\n";
         $x=$x+rand($1)-0.5;
         $y=$y+rand($1)-0.5;
         $px[$k]=$x;
         $py[$k]=$y;
     }
     ...


Aside from beeing not able to run under 'strict',
what's meant with

         $x=$x+rand($1)-0.5;
         $y=$y+rand($1)-0.5;

because '$1' is, at this point, not set.

> The seed routine creates a cluster of 1000 points, saved in
> cluster.txt: each row corresponds to a point; the first column is the
> cluster number, and the next two columns are the x and y coordinates.

Don't do that. The convention in this business is.
First comes x, then y, then z. Because your 'cluster number'
is somehow 'a plane' in your problem space, you should make
it that ('z', third column).

> The cluster number is automatically incremented each time a new call
> to seed is made, resulting in the creation of a new cluster. The
> distance routine computes the distance between two points, for 100
> points randomly selected in the data set previously created
> (cluster.txt). The output is a file dist.txt, with one row per pair
> of points, with two fields: the first column is an indicator and is
> equal to 1 if both points belong to the same cluster; the second column is
> the distance between the two points. This script illustrates that it
> is possible to check whether a data set contains one or two clusters
> by looking at the distribution of distances: a gap in the
> distribution means the presence of distinct clusters. It also suggests 
> that the computational complexity of computing whether a data set contains 
> one of more clusters is well below O(n), possibly O(n0.5), if one uses
> sampling techniques.

Whats the point of that? You have, say 10^7 2D-points, then you
select 100 pair-samples from them, compute their distance and
claim you have 'complexity well below O(n), possibly O(n0.5)'?

I don't get that ...

==>your code was: datashaping.com/cluster_pl.txt

I'd recommend to translate the code from Perl3-style
to Perl5, which is not really that difficult, because
the code does basically almost nothing.

Starting point: ==>

  use strict;
  use warnings;

  my $idclust = 0;

  dmp_seed([1.0,1.0],   1000, $idclust++, '>cluster.txt');
  dmp_seed([25.0,25.0], 1000, $idclust++, '>>cluster.txt');

  distance(100, 'cluster.txt', 'dist.txt'); # nsamp read write


sub distance {
    my ($nsamp, $fn_clust, $fn_dist) = @_;

    open my $fc,'<', $fn_clust  or die "no coord in: $!";
    my @pc = map [/(\S+)/g], <$fc>;
    close $fc;

    open my $fd, '>', $fn_dist or die "no dist out: $!";
    for (1 .. $nsamp) {
       my ($pm, $pn) = ( $pc[int rand @pc], $pc[int rand @pc] );
       printf $fd "%d\t%.8f\n", 1-($pm->[2] == $pn->[2]),
                    sqrt(($pm->[0]-$pn->[0])**2 + ($pm->[1]-$pn->[1])**2)
    }
    close $fd;
}

sub dmp_seed {
    my ($rseed, $nmax, $cluid, $fname_mod) = @_;
    my ($x, $y) = map $_+rand(1)-0.5, @$rseed;

    open my $fh, $fname_mod or die "no way out: $!";
    for(1 .. $nmax) {
       printf $fh "%.8f\t%.8f\t%d\n", $x+=rand(1)-0.5, $y+=rand(1)-0.5, $cluid
    }
    close $fh;
}
<==

Regards

M.


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

Date: 29 Apr 2007 01:11:59 -0700
From: kiranmn@my-deja.com
Subject: perl Write filehandle blocks.
Message-Id: <1177834319.270014.87330@o5g2000hsb.googlegroups.com>

hi,

    First  parent do a fork, parent waits for child to finish , child
runs a command "head" and exits. After waiting parent sleep fror 1
hours and continue doing same thing. when i write a file to t "open2",
write filehandle, it just hangs there, what is the reason.

Following is my code. It stops at " now writing to write fd
". Please help me.

Thanking you,
regards,
kiran
========================================
#!/usr/bin/perl -I../lib


#use strict;
use Carp qw(verbose);
use IPC::Open2;
use Symbol;
my $WTR;
my $RDR;
        while(1)
        {
        if($kid=fork)
        {
            waitpid($kid,0);
        }
        else
        {
        while(<STDIN>)
        {
        $ref->{"mail"}.=$_;
        }
        $WTR = gensym();  # get a reference to a typeglob
        $RDR = gensym();  # and another one
        $pid=open2($RDR, $WTR, "/usr/bin/head  ");
        print "now writing to write fd\n";
        $oo=select $WTR;
        $|=1;
        select $oo;
        print  $WTR "$ref->{\"mail\"}";
        print "closing writing fd\n";
        close($WTR);
        print "going to reader\n";
        while(<$RDR>)
        {
            print "$_";
         }
         print "comming out of while reader\n";
         close($RDR);
         exit;
         }
         sleep (3600);
        }



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

Date: Sun, 29 Apr 2007 07:29:04 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl Write filehandle blocks.
Message-Id: <slrnf393sg.aes.tadmc@tadmc30.august.net>

kiranmn@my-deja.com <kiranmn@my-deja.com> wrote:


> #!/usr/bin/perl -I../lib
>
>
> #use strict;


You lose all of the benefits of strict when you comment it out like that.


>             print "$_";


   perldoc -q vars

       What’s wrong with always quoting "$vars"?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 29 Apr 2007 06:14:58 -0700
From: kiranmn@my-deja.com
Subject: Re: perl Write filehandle blocks.
Message-Id: <1177852498.742392.292580@o5g2000hsb.googlegroups.com>

if  i run the code like "cat passwd|perl head.pl", if size of passwd
file is less it works fine, if it is more than 4k it hangs.


On Apr 29, 1:11 pm, kira...@my-deja.com wrote:
> hi,
>
>     First  parent do a fork, parent waits for child to finish , child
> runs a command "head" and exits. After waiting parent sleep fror 1
> hours and continue doing same thing. when i write a file to t "open2",
> write filehandle, it just hangs there, what is the reason.
>
> Following is my code. It stops at " now writing to write fd
> ". Please help me.
>
> Thanking you,
> regards,
> kiran
> ========================================
> #!/usr/bin/perl -I../lib
>
> #use strict;
> use Carp qw(verbose);
> use IPC::Open2;
> use Symbol;
> my $WTR;
> my $RDR;
>         while(1)
>         {
>         if($kid=fork)
>         {
>             waitpid($kid,0);
>         }
>         else
>         {
>         while(<STDIN>)
>         {
>         $ref->{"mail"}.=$_;
>         }
>         $WTR = gensym();  # get a reference to a typeglob
>         $RDR = gensym();  # and another one
>         $pid=open2($RDR, $WTR, "/usr/bin/head  ");
>         print "now writing to write fd\n";
>         $oo=select $WTR;
>         $|=1;
>         select $oo;
>         print  $WTR "$ref->{\"mail\"}";
>         print "closing writing fd\n";
>         close($WTR);
>         print "going to reader\n";
>         while(<$RDR>)
>         {
>             print "$_";
>          }
>          print "comming out of while reader\n";
>          close($RDR);
>          exit;
>          }
>          sleep (3600);
>         }




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

Date: Sun, 29 Apr 2007 15:38:48 -0000
From: Justin C <justin.0704@purestblue.com>
Subject: Re: Rounding up to the next .5
Message-Id: <slrnf39f0a.qd.justin.0704@satori.local>

In article <slrnf37pe4.d3t.tadmc@tadmc30.august.net>, Tad McClellan wrote:
> Justin C <justin.0704@purestblue.com> wrote:
>> In article <AIKYh.2898$r77.978@trndny08>, Jürgen Exner wrote:
>>> Justin C wrote:
> 
>>>> I'm trying to round weights (with up to two decimal places) up to the
>>>> next half kilo (unless the weight is an exact or .5 kilo already).
> 
>>> For one I am pretty sure there are modules on CPAN that do floor() and 
>>> ceiling() functions.
>>
>> There are that, and, IIRC (from today's Googling for a round() function)
>> they are part of POSIX, and therefore (if my understanding is correct) 
>> already installed.
>>
>> Trouble is, I don't know what those are/do, perldoc wasn't much help, 
>> I suppose they're mathematical functions, I didn't get that far with my
>> education and so didn't understand, 
> 
>    http://en.wikipedia.org/wiki/Ceiling_function

Thanks. I understand most of what that document says, the notation does
my head in though

	Justin.

-- 
Justin C, by the sea.


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

Date: Sun, 29 Apr 2007 18:25:31 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Top Turds of comp.lang.perl.misc (2007)
Message-Id: <tkg933tufp0tf4hmt5lv6use9i2k8e2sh8@4ax.com>

On Sat, 28 Apr 2007 21:37:46 +0200, Martijn Lievaart
<m@rtij.nl.invlalid> wrote:

>Well, just had another look at python today. While I have some serious 
>reservations, I can see why it is so popular. For one, it's actually 
>quite readable.(This comes from someone who has programmed for 20 years 

Certainly it is. It's one of its most known strengths. Certainly one
of the most advertised. The point being that it *forces* you to write
readable code, the way it thinks readable is. Which is the reason why
*generally* Perl programmers don't like it: because Perl *lets* you
write quite readable code. And quite unreadable code too. I suppose
both crowds pursue some sort of beauty. But these are beauties of
diverging kinds. That of TMBOWTDIness on the one side and that of
TMTOWTDIness on the other one.

>in all kinds of languages. Yes, even prolog for those who remember that.)

I believe it is still alive and well, for those who want to have fun
with it, and also -from the professional point of view- in some
specific application areas.

>There are so many tools to get the job done today. Perl is in a competing 
>arena where there are good arguments to use other languages.

I don't by the competing arena metaphor too much, but maybe that's
just me...

>To go into the very languages you state:
>* Python: A very good competitor. Con, not installed by default on many 
>OSses. Pro: Can do about anything that Perl can, in a more readable way.

Nope. Perl can be as readable as Python or more. Python doesn't let
you write unreadable code. (Well, up to some point, I suppose.) And
that may be a plus or a minus depending on one's personal tastes...

>* VB: Is not used very much, except in Windows only shops (which are 
[snip]
>* Java: Java was the hype. Nowadays I see it used a lot, but in very 

Languages with such intrinsically different charachteristics and
*typical* application areas hardly make a sense when compared with
Perl and Python, which OTOH can be compared quite well.

>* PHP: Oh yes. I'm actually somewhat of a php fan, but am finding that in 
>the long run Perl is much better at writing reusable and maintainable 
>programs. However it's a close call.

Although they tell me that now it can be used as a general purpose
language, php still fundamentally remains an application-specific one,
with several limitations and can similarly hardly be compared with
Perl, or Python.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 29 Apr 2007 18:01:48 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Top Turds of comp.lang.perl.misc (2007)
Message-Id: <Xns99218EBF64538asu1cornelledu@127.0.0.1>

Martijn Lievaart <m@rtij.nl.invlalid> wrote in
news:pan.2007.04.28.19.38.20@rtij.nl.invlalid: 

> On Fri, 13 Apr 2007 12:31:17 -0700, cartercc wrote:
> 
>> On Apr 12, 8:45 pm, Tad McClellan <t...@augustmail.com> wrote:
>>> The decline in traffic is due to greater overall efficiency!
>> 
>> Actually, it's because Perl is dying.

I only saw cartercc's comment now (sorry Martijn Lievaart, I have nothing
of substance to add to your post, but thanks for quoting this).

It made me feel lucky that Perl is 'dying' knowing the alternative 
as demonstrated by the following example on Oracle forums:

http://forums.oracle.com/forums/thread.jspa?threadID=499980&start=0&tstart=0 

Enjoy ;-)

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: 29 Apr 2007 06:04:50 -0700
From: king <hara.acharya@gmail.com>
Subject: Using one methods variable value in another method inside a module
Message-Id: <1177851890.135236.214600@h2g2000hsg.googlegroups.com>

The below script if I am writing in a script its working fine but I
want to make this a module.

As the subroutine this (load_school_template ) will store the values
and

the get_course_info will display the values.
But I am not clear about the reference so I am using simple array that
is @template_subject_period. And by using the
same @template_subject_period array in the get_course_info subroutine
I am getting the output as name of the subject and number of periods
by giving input the no of years.

But inside the get_course_info method the @template_subject_period
value is not used.

My requirement is the get_course_info method should give out put as
the subject name and the no. of periods when
i will give input as "periods_1" or periods_2" etc..

this is the XML file from which I am getting the out put.name :
school.xml
===========================================================================
<?xml version="1.0" ?>
<school-template>
<class-templates>
 <class-template marker="1" name="4 *" />
 <class-template marker="2" name="5 *" />
 <class-template marker="3" name="1 *" />
 <class-template marker="4" name="2 *" />
 <class-template marker="5" name="3 *" />
 </class-templates>
<subject-templates>
 <subject-template name="maths" periods_1="5" periods_2="5"
periods_3="4" periods_4="4" periods_5="4" />
 <subject-template name="geography" periods_1="5" periods_2="5"
periods_3="4" periods_4="4" periods_5="4" />
 <subject-template name="physics" periods_1="4" periods_2="4"
periods_3="3" periods_4="3" periods_5="3" />
 <subject-template name="chemistry" periods_1="4" periods_2="4"
periods_3="-" periods_4="-" periods_5="-" />
 <subject-template name="science" periods_1="2" periods_2="2"
periods_3="3" periods_4="3" periods_5="3" />
 </subject-templates>
 </school-template>

===========================================================================
this is the module i want to make: name: TPWizardMgr.pm
=======================================================================
package TPWizardMgr;
use strict;
use XML::DOM;

sub new
{
       my $class = shift;
       my $self = {};
       bless $self, $class;


       # load school types from config file
       $self->{school_types} = [];
       $self->load_config($CONFIG_FILE);
       $self->{load_school_template} = [];
       return $self;
}


sub load_school_template
{
       my $self = shift;
       my $len ;
       my $item;
       my @years;
       my $periods;
       my $subject_name;
       our @template_subject_period;
       my $parser = new XML::DOM::Parser;
       my $doc = $parser->parsefile ("/usr/local/apache2/wizard_data/
school.xml");

       foreach my $school_template($doc-
>getElementsByTagName('subject-templates'))
               {
                       $len =  $school_template-
>getElementsByTagName('subject-template')->getLength() ;
                       @years =
('periods_1','periods_2','periods_3','periods_4','periods_5');
                       for(my $i = 0;$i<$len;$i++)
                       {
                               $item = $school_template-
>getElementsByTagName('subject-template')->item($i);
                               $subject_name = $item-
>getAttribute('name');
                               for my $count (0..4)
                               {
                                       $periods = $item-
>getAttribute($years[$count]);
                                       push
(@template_subject_period, [$subject_name,$years[$count], $periods]);

                               }
                       }
               }

       $doc->dispose();
}

sub get_course_info
{
       my $self = shift;
       my $subject_name = shift;
       my @years = shift;
       my $periods = shift;
       my $count = shift;
       print "Please enter period to get subject and number of
periods \n";
       my $gotperiod = <>;
       chomp($gotperiod);
       for(my $i=0;$i <= $#template_subject_period;$i++)
       {
               #print $#template_subject_period . "\n";
               print $#{$self->{load_school_template}. "\n";
               print "inside for loop\n";
               if($template_subject_period[$i]->[1] eq $gotperiod)
               {
                       push (@template_subject_period, [$subject_name,
$years[$count], $periods]);
                       print "Subject:\t" .
$template_subject_period[$i]->[0]  . $template_subject_period[$i]-
>[2] . "\n";
               }
       }
       return $self->{get_course_info};
}


1;



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

Date: 29 Apr 2007 03:15:43 -0700
From: Nikos <nikos1337@gmail.com>
Subject: Re: Weird error after a configuration change
Message-Id: <1177841742.971452.87330@y5g2000hsa.googlegroups.com>

On Apr 28, 8:41 pm, Brian McCauley <nobul...@gmail.com> wrote:
> On Apr 28, 12:40 am, Nikos <nikos1...@gmail.com> wrote:
>
> > referer is stil 'http://dell'althoughindex.pl posts data to
> > admin.pl....
>
> > As matter of fact i tried to pritn the referrrer var in every script
> > of mine called by another perl cgi script and every tiem the result
> > washttp://dellwhy?!!
>
> This is possibly a feature of the browser you are using. The browser
> can send whtever it likes as a referer.

i want it when i post data from index.pl to admin pl to says the
referrer is index.pl nto dell



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

Date: Sun, 29 Apr 2007 11:27:12 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Weird error after a configuration change
Message-Id: <Xns99214BD7C9963asu1cornelledu@127.0.0.1>

Nikos <nikos1337@gmail.com> wrote in
news:1177841742.971452.87330@y5g2000hsa.googlegroups.com: 

> On Apr 28, 8:41 pm, Brian McCauley <nobul...@gmail.com> wrote:
>> On Apr 28, 12:40 am, Nikos <nikos1...@gmail.com> wrote:
>>
>> > referer is stil 'http://dell'althoughindex.pl posts data to
>> > admin.pl....
>>
>> > As matter of fact i tried to pritn the referrrer var in every
>> > script of mine called by another perl cgi script and every tiem the
>> > result washttp://dellwhy?!!
>>
>> This is possibly a feature of the browser you are using. The browser
>> can send whtever it likes as a referer.
> 
> i want it when i post data from index.pl to admin pl to says the
> referrer is index.pl nto dell
> 

And I want a billion dollars.

As has been pointed out, your question has nothing whatsoever to do with
Perl. 

http://en.wikipedia.org/wiki/Referer

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

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 V11 Issue 392
**************************************


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