[23327] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5547 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 23 06:05:51 2003

Date: Tue, 23 Sep 2003 03:05:10 -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           Tue, 23 Sep 2003     Volume: 10 Number: 5547

Today's topics:
        .Net Web Services and Perl (Ian B)
    Re: [Simple] Function arguments and return value <abigail@abigail.nl>
        A one-liner: Why doesn't alarm interrupt <> ? (David Morel)
    Re: A one-liner: Why doesn't alarm interrupt <> ? (Sam Holden)
        basic subroutine question. (fabre)
    Re: basic subroutine question. (Anno Siegel)
    Re: basic subroutine question. <kuujinbo@hotmail.com>
    Re: Capturing a data squirt. <terrylr@blauedonau.com>
    Re: CGI.pm <notavailable@nospamplease.com>
    Re: Decrpyt CPAN RC4 under Windows 2000. <kalinabears@iinet.net.au>
        for; while loop interations <prakashREMOVE@CAPITALSece.arizona.edu>
    Re: for; while loop interations <mooseshoes@gmx.net>
    Re: for; while loop interations <krahnj@acm.org>
    Re: for; while loop interations <kasp@epatra.com>
    Re: for; while loop interations <kasp@epatra.com>
        how to find the biggest ???? <mkl.tw@ttt.com>
    Re: how to find the biggest ???? (Anno Siegel)
    Re: how to find the biggest ???? <kasp@epatra.com>
    Re: how to find the biggest ???? <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 23 Sep 2003 02:54:03 -0700
From: i_best@hotmail.com (Ian B)
Subject: .Net Web Services and Perl
Message-Id: <69c58cd1.0309230154.75fe9759@posting.google.com>

I am in the process of building an XML web service, using VB.Net which
will be called over the internet by clients on various platforms.

Does anyone have any experience of consuming a .Net web service using
Perl or writing a .Net web service to be consumed by Perl?  If so, I'd
like to hear of any problems you may have encountered or hints you may
have that I might learn from before I continue.

One thing in particular is, the type of data that will be returned by
the method calls.  Say a method needs to return both a numeric code
and a message; I could keep it simple and return just a string
containing both the number and message concatenated that could then be
examined by the client or I could return a serialized class with a
number and a string property.  Is one easier for the client than the
other?

Thanks in advance

Ian


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

Date: 23 Sep 2003 09:39:07 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: [Simple] Function arguments and return value
Message-Id: <slrnbn055r.v2i.abigail@alexandra.abigail.nl>

Gao Chao (gaochao@voila.fr) wrote on MMMDCLXXIV September MCMXCIII in
<URL:news:c5a22ad.0309221554.6f1b32e8@posting.google.com>:
??  I don't know how to write a function with arguments and return values
??  that are not scalars. I have learn to write something like
??  
??  sub foo {
??    my $arg1 = shift;
??    my $arg2 = shift;
??  
??    return $bar;
??  }
??  
??  but I cannot pass lists or file handles like that. Can somebody
??  explain me how to pass lists and file handles as arguments and return
??  values of a function?


man perlsub



Abigail
-- 
#!/opt/perl/bin/perl -w
$\ = $"; $; = $$; END {$: and print $:} $SIG {TERM} = sub {$ := $_}; kill 15 =>
fork and ($; == getppid and exit or wait) foreach qw /Just another Perl Hacker/


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

Date: 22 Sep 2003 21:55:44 -0700
From: altalingua@hotmail.com (David Morel)
Subject: A one-liner: Why doesn't alarm interrupt <> ?
Message-Id: <60c4a7b1.0309222055.4ac99dd6@posting.google.com>

Hi all,

Why doesn't the following program terminate?

alarm 1;
<STDIN>;

It seems that alarm does not interrupt the <> operator. Why not? And
more importantly, is there any way to interrupt the general <handle>?
Surely there must be a way... thanks in advance,

David Morel

p.s.
I am running Perl on Windows


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

Date: 23 Sep 2003 05:02:39 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: A one-liner: Why doesn't alarm interrupt <> ?
Message-Id: <slrnbmvkvf.m2g.sholden@flexal.cs.usyd.edu.au>

On 22 Sep 2003 21:55:44 -0700, David Morel <altalingua@hotmail.com> wrote:
> Hi all,
> 
> Why doesn't the following program terminate?

It works fine for me... Under linux and Solaris.

> alarm 1;
><STDIN>;
> 
> It seems that alarm does not interrupt the <> operator. Why not? And
> more importantly, is there any way to interrupt the general <handle>?
> Surely there must be a way... thanks in advance,
> 
> David Morel
> 
> p.s.
> I am running Perl on Windows

perldoc perlport says:

          alarm SECONDS
          alarm   Not implemented. (Win32)

In my docs. Which would probably cause it not to work.

-- 
Sam Holden



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

Date: Tue, 23 Sep 2003 08:39:14 +0100
From: pedro.fabre.NO-SPAM@gen.gu.se (fabre)
Subject: basic subroutine question.
Message-Id: <pedro.fabre.NO-SPAM-2309030839140001@192.168.0.5>

Dear all these references are killing me,

I have background in java and now I am trying ot move to perl. The way I
have to call the references is still really fuzzy for me. I am trying to
learn the way perl handle the references and how to reuse some code.

This is my code:

#!/usr/local/bin/perl

use strict;
use Data::Dumper;

my @LoL = (
    [1,2,3,4,5],
    [2,10,7,15,14]);

my @removed=[0, 2];

print Dumper (@removed);

MyPrint(\@LoL);

remove_col (\@LoL,\@removed);

MyPrint(\@LoL);

my @removed=[0,1];

remove_col (\@LoL,\@removed);

MyPrint(\@LoL);

######################subs######################
sub MyPrint{
    for ( @{shift()} ) {
        print join( "\t", @$_), "\n";
    }
}

sub remove_col{
    my ($LoL,$removed)=@_;

    for (my $i=0;$i<(scalar @{$LoL});$i++){
        my $counter=0;
        for(my $k=0;$k<$#removed+1;$k++){
            print "remove value :  $removed[$k]\n";
            splice @{$LoL[$i]}, ($removed[$k]-$counter),1;
            $counter++;
        }
    }

    MyPrint $LoL;
    MyPrint ($removed);

}


My intention is:

1       2       3       4       5
2       10      7       15      14

take out columns 0 and 2

2       4       5
10      15      14

and after that remove 0 and 1

returning:

5
14


I am confuse because the program returns

$VAR1 = [
          0,
          2
        ];
1       2       3       4       5
2       10      7       15      14
1       2       3       4       5
2       10      7       15      14
0       2
1       2       3       4       5
2       10      7       15      14
remove value :  ARRAY(0x7b894)
remove value :  ARRAY(0x7b894)
1       2       3       4       5
2       10      7       15      14
0       1
1       2       3       4       5
2       10      7       15      14


giving me that $removed[$k] is a reference to one array and instead the
element to the array. Were I should start for to get de idea about
references, how to call elements from a multilevel array and how if I pass
those as value or as references. A second question, this sub &remove_col
can be used even if the name  in the maim module differs from the name
into the sub module, do I need to return something or that is just when
you pass it as value.


Sorry for the long mail and thanks for any help you could give me.
P


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

Date: 23 Sep 2003 09:26:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: basic subroutine question.
Message-Id: <bkp3jh$d4d$1@mamenchi.zrz.TU-Berlin.DE>

fabre <pedro.fabre.NO-SPAM@gen.gu.se> wrote in comp.lang.perl.misc:
> Dear all these references are killing me,
> 
> I have background in java and now I am trying ot move to perl. The way I
> have to call the references is still really fuzzy for me. I am trying to
> learn the way perl handle the references and how to reuse some code.
> 
> This is my code:
> 
> #!/usr/local/bin/perl
> 
> use strict;
> use Data::Dumper;
> 
> my @LoL = (
>     [1,2,3,4,5],
>     [2,10,7,15,14]);
> 
> my @removed=[0, 2];
> 
> print Dumper (@removed);
> 
> MyPrint(\@LoL);
> 
> remove_col (\@LoL,\@removed);
> 
> MyPrint(\@LoL);
> 
> my @removed=[0,1];
> 
> remove_col (\@LoL,\@removed);
> 
> MyPrint(\@LoL);
> 
> ######################subs######################
> sub MyPrint{
>     for ( @{shift()} ) {
>         print join( "\t", @$_), "\n";
>     }
> }
>
> sub remove_col{
>     my ($LoL,$removed)=@_;
> 
>     for (my $i=0;$i<(scalar @{$LoL});$i++){
>         my $counter=0;
>         for(my $k=0;$k<$#removed+1;$k++){
>             print "remove value :  $removed[$k]\n";
>             splice @{$LoL[$i]}, ($removed[$k]-$counter),1;
>             $counter++;
>         }
>     }
> 
>     MyPrint $LoL;
>     MyPrint ($removed);
> 
> }

The sub "remove_col" is much more complicated than it has to be.
I haven't looked too closely, but you are using far too many indices.
That is rarely necessary in Perl.  I haven't analyzed it beyond that.

> My intention is:
> 
> 1       2       3       4       5
> 2       10      7       15      14
> 
> take out columns 0 and 2
> 
> 2       4       5
> 10      15      14
> 
> and after that remove 0 and 1
> 
> returning:
> 
> 5
> 14
> 
> 
> I am confuse because the program returns

[snip confusion]

This works as you intended:

    sub remove_col {
        my ( $lol, $remove) = @_;
        for my $col ( reverse @$remove ) {
            print "removing column $col\n";
            splice @$_, $col, 1 for @$lol;
        }
    }

The only non-obvious bit is "reverse" in the for-loop control.  It makes
sure that the last columns are removed first, so as not to upset the
index positions of columns not yet removed.  This assumes that columns
are given in ascending order in the first place.

Anno


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

Date: Tue, 23 Sep 2003 18:37:57 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: basic subroutine question.
Message-Id: <bkp4ck$qnm$1@pin3.tky.plala.or.jp>

fabre wrote:

[snip]

> This is my code:
> 
> #!/usr/local/bin/perl
> 
> use strict;
> use Data::Dumper;
> 
> my @LoL = (
>     [1,2,3,4,5],
>     [2,10,7,15,14]);
> 
> my @removed=[0, 2];
> 
> print Dumper (@removed);
> 
> MyPrint(\@LoL);
> 
> remove_col (\@LoL,\@removed);
> 
> MyPrint(\@LoL);
> 
> my @removed=[0,1];
> 
> remove_col (\@LoL,\@removed);
> 
> MyPrint(\@LoL);
> 
> ######################subs######################
> sub MyPrint{
>     for ( @{shift()} ) {
>         print join( "\t", @$_), "\n";
>     }
> }
> 
> sub remove_col{
>     my ($LoL,$removed)=@_;
> 
>     for (my $i=0;$i<(scalar @{$LoL});$i++){
>         my $counter=0;
>         for(my $k=0;$k<$#removed+1;$k++){
>             print "remove value :  $removed[$k]\n";
>             splice @{$LoL[$i]}, ($removed[$k]-$counter),1;
>             $counter++;
>         }
>     }
> 
>     MyPrint $LoL;
>     MyPrint ($removed);
> 
> }
> 
> 
> My intention is:
> 
> 1       2       3       4       5
> 2       10      7       15      14
> 
> take out columns 0 and 2
> 
> 2       4       5
> 10      15      14
> 
> and after that remove 0 and 1
> 
> returning:
> 
> 5
> 14

[snip]

> giving me that $removed[$k] is a reference to one array and instead the
> element to the array. Were I should start for to get de idea about
> references, how to call elements from a multilevel array and how if I pass
> those as value or as references. A second question, this sub &remove_col
> can be used even if the name  in the maim module differs from the name
> into the sub module, do I need to return something or that is just when
> you pass it as value.

How about something like this:

#!/usr/bin/perl -w
use strict;

my @LoL = (
     [1,2,3,4,5],
     [2,10,7,15,14]);

@LoL = to_remove(\@LoL, [0, 2]);
print "@$_\n" foreach (@LoL);

@LoL = to_remove(\@LoL, [0, 1]);
print "@$_\n" foreach (@LoL);

# make sure you pass in an array reference as the second argument
sub to_remove {
   my($ar, $ar_remove) = @_;
   foreach my $element(@$ar) {
     foreach (@$ar_remove) {
       my $to_remove = $_ ? $_ - 1 : 0;
       splice(@$element, $to_remove, 1);
     }
   }
   return @$ar;
}

1. 'perldoc -f splice' - not explicitly related to your question, but 
used in the sub.
2. perldoc perllol
3. 'perldoc perldsc' is especially good - teaches you how to handle 
complex data structures (hash/array references).

You need to be *really* aware of how you use references. You assigned an 
anonymous array reference when you declared @removed (used square 
brackets instead of parenthesis), that was the start of the problem.

HTH - keith



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

Date: Tue, 23 Sep 2003 04:05:17 -0500
From: "Terry L. Ridder" <terrylr@blauedonau.com>
Subject: Re: Capturing a data squirt.
Message-Id: <bkp2ce$4a5gm$1@ID-206651.news.uni-berlin.de>

Richard S Beckett wrote:
> Guys,
> 
> The infra red port on my laptop is com4. When I point my palm pilot at it,
> and send a file it works just fine, and the file is transferred. (Running
> w32)
> 
> I want to capture this data squirt, and store it in a file, so I tried
> this...
> 
> use strict;
> use warnings;
> use Win32::SerialPort;
> open( PORT, "+>COM4" ) or die "Can't open COM4: $!";
> open (FILE, ">file.txt");
> while (1) {
>  my $input = <PORT>;
>   print FILE "$input\n";
> }
> 
> However all I get is a file containing nothing at all.
> 
> Can anyone help me, please?

perldoc perlfaq8

how do i read and write the serial port?

> 
> Thanks.
> 

-- 
terry l. ridder ><>
postmaster at blauedonau.com



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

Date: Tue, 23 Sep 2003 10:51:31 +0100
From: "D Borland" <notavailable@nospamplease.com>
Subject: Re: CGI.pm
Message-Id: <BIUbb.7974$Ne.3174278@newsfep2-win.server.ntli.net>

What r u talking about!???!!!!

Dagmar

"Tore Aursand" <tore@aursand.no> wrote in message
news:pan.2003.09.23.01.07.19.635444@aursand.no...
> On Mon, 22 Sep 2003 22:41:13 +0100, D Borland wrote:
> > OK, dudes i understand - I'm a lazy git, and i really gotta get my head
out
> > my arse and in gear!
>
> While you're at it:  Stop top-posting.
>
>
> -- 
> Tore Aursand <tore@aursand.no>
>
> "You know the world is going crazy when the best rapper is white, the best
>  golfer is black, France is accusing US of arrogance and Germany doesn't
>  want to go to war."




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

Date: Tue, 23 Sep 2003 17:24:20 +1000
From: Sisyphus <kalinabears@iinet.net.au>
Subject: Re: Decrpyt CPAN RC4 under Windows 2000.
Message-Id: <3f6ff5d7$0$23592$5a62ac22@freenews.iinet.net.au>

John South wrote:
> I've found the Crypt::RC4 Perl script on the CPAN site as a easy way
> to encrypt email attachments from my ISP.
> 
> I need to decrypt them on a workstation running Windows 2000.  I've
> tried a Windows API from ZBit but there must be subtle differences in
> the algorithm because it doesn't return the plain text.
> Does anyone know of a tool that would do the job on the workstation.

A Google search for 'RC4 windows' (or something similar) might help.

> Otherwise I will have to find out how to run Perl under Windows 2000.
> 

Not so difficult. Just install the compiled perl binary from 
www.ActiveState.com and use the ppm utility that comes with it to 
install Crypt::RC4. (Looking closer, it seems that Crypt::RC4 is pure 
perl, so you could install the module by simply copying RC4.pm from the 
cpan distro to your perl/site/lib/Crypt/ folder, if need be.)

Cheers,
Rob



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

Date: Mon, 22 Sep 2003 21:00:33 -0700
From: Jayaprakash Rudraraju <prakashREMOVE@CAPITALSece.arizona.edu>
Subject: for; while loop interations
Message-Id: <Pine.GSO.4.50.0309222054050.19064-100000@shellfish.ece.arizona.edu>


Hi,

The following two snippets of code are iterating the while loop same
number of times. I am not able to comprehend the reason. Thanks in advance
for your explanations.

$intv = 1.1;
while ($intv > 0.4) {
	print "$intv\n";
	$intv -= 0.1
}

$intv = 1.1;
while ($intv >= 0.4) {
	print "$intv\n";
	$intv -= 0.1
}

Prakash
--
94.5% of all statistics are made up.


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

Date: Tue, 23 Sep 2003 05:57:46 GMT
From: mooseshoes <mooseshoes@gmx.net>
Subject: Re: for; while loop interations
Message-Id: <uhRbb.5570$I81.1789@newssvr25.news.prodigy.com>

<snip>


> $intv = 1.1;
> while ($intv > 0.4) {
> print "$intv\n";
> $intv -= 0.1
> }
> 
> $intv = 1.1;
> while ($intv >= 0.4) {
> print "$intv\n";
> $intv -= 0.1


Have you tried (0.4 <= $intv) ?

Moose


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

Date: Tue, 23 Sep 2003 06:27:03 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: for; while loop interations
Message-Id: <3F6FE7A2.451BD7D8@acm.org>

Jayaprakash Rudraraju wrote:
> 
> Hi,
> 
> The following two snippets of code are iterating the while loop same
> number of times. I am not able to comprehend the reason. Thanks in advance
> for your explanations.
> 
> $intv = 1.1;
> while ($intv > 0.4) {
>         print "$intv\n";
>         $intv -= 0.1
> }
> 
> $intv = 1.1;
> while ($intv >= 0.4) {
>         print "$intv\n";
>         $intv -= 0.1
> }

Try changing the statement:

        print "$intv\n";

To:

        printf "%.20f\n", $intv;

And see what happens.

perldoc -q numbers

Found in /usr/lib/perl5/5.6.0/pod/perlfaq4.pod
       Why am I getting long decimals (eg, 19.9499999999999)
       instead of the numbers I should be getting (eg, 19.95)?



John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 23 Sep 2003 12:53:46 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: for; while loop interations
Message-Id: <bkose8$su6$1@newsreader.mailgate.org>

"mooseshoes" <mooseshoes@gmx.net> wrote in message
news:uhRbb.5570$I81.1789@newssvr25.news.prodigy.com...
> <snip>
> > $intv = 1.1;
> > while ($intv >= 0.4) {
> > print "$intv\n";
> > $intv -= 0.1
>
> Have you tried (0.4 <= $intv) ?
>

What difference does it make ?

-- 
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.




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

Date: Tue, 23 Sep 2003 13:25:23 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: for; while loop interations
Message-Id: <bkov4k$1nc$1@newsreader.mailgate.org>

The problem you are facing is a common problem due to precision loss in
floating point numbers.

Like John has pointed out, you can restrict the decimal places by:
        printf "%.20f\n", $intv;

-- 
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.




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

Date: Tue, 23 Sep 2003 16:16:12 +0800
From: "mkl" <mkl.tw@ttt.com>
Subject: how to find the biggest ????
Message-Id: <bkovge$ld3@netnews.hinet.net>

If I have a file ,named txt

###############
a    (298:298)  (9:9)
b    (2:2)
c    (3:3)
d    (5:5)
############################


how do i select the biggest one and print ?




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

Date: 23 Sep 2003 08:42:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to find the biggest ????
Message-Id: <bkp11r$aa8$2@mamenchi.zrz.TU-Berlin.DE>

mkl <mkl.tw@ttt.com> wrote in comp.lang.perl.misc:
> If I have a file ,named txt
> 
> ###############
> a    (298:298)  (9:9)
> b    (2:2)
> c    (3:3)
> d    (5:5)
> ############################
> 
> 
> how do i select the biggest one and print ?

The biggest what?

Someone is going to suggest sorting the items and taking the last one.
That's inefficient.

Anno


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

Date: Tue, 23 Sep 2003 14:25:10 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: how to find the biggest ????
Message-Id: <bkp1ql$6db$1@newsreader.mailgate.org>

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:bkp11r$aa8$2@mamenchi.zrz.TU-Berlin.DE...
> mkl <mkl.tw@ttt.com> wrote in comp.lang.perl.misc:
> Someone is going to suggest sorting the items and taking the last one.
> That's inefficient.

Quite true. No need for sorting all the numbers when you just need the
largest number in the file.
Extract each number from file and compare it with the "last MAX value" to
check if the new value is bigger or not.
-- 
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.




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

Date: Tue, 23 Sep 2003 11:05:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to find the biggest ????
Message-Id: <bkp2bt$468ee$1@ID-184292.news.uni-berlin.de>

mkl wrote:
> If I have a file ,named txt
> 
> ###############
> a    (298:298)  (9:9)
> b    (2:2)
> c    (3:3)
> d    (5:5)
> ############################
> 
> 
> how do i select the biggest one and print ?

     #!/usr/bin/perl
     use strict;
     use warnings;

     my $value = 0;
     my $biggest;
     open FH, 'txt' or die $!;
     while (<FH>) {
         if ( (/([\d:]+)\)\s*$/)[0] > $value ) {
             $biggest = $_;
             $value = $1;
         }
     }
     close FH;
     print "Biggest record:\n$biggest\n";

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

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.  

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 5547
***************************************


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