[22095] in Perl-Users-Digest
Perl-Users Digest, Issue: 4317 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 27 18:06:08 2002
Date: Fri, 27 Dec 2002 15:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 27 Dec 2002 Volume: 10 Number: 4317
Today's topics:
C Backend (Jeff Mott)
Re: C Backend <bart.lateur@pandora.be>
e-mail address tester? <spark@dcwis.nodurnspam.com>
Re: e-mail address tester? <me@privacy.net>
Re: e-mail address tester? (Tad McClellan)
Re: Free Program <renz-t@web.de>
Re: generate a line of code on the fly (Anno Siegel)
IE uploads result in zero length files using CGI.pm <phignuton@_No#SpAm#_hotmail.com>
kill() - invalid argument? <Peter.Dintelmann@dresdner-bank.com>
Re: kill() - invalid argument? (Anno Siegel)
Re: kill() - invalid argument? <Peter.Dintelmann@dresdner-bank.com>
Re: kill() - invalid argument? <mgjv@tradingpost.com.au>
Re: kill() - invalid argument? (Anno Siegel)
Re: missing Net/SMTP and PPM search shows nothing. (Helgi Briem)
Re: missing Net/SMTP and PPM search shows nothing. <renz-t@web.de>
qr, spliting.. <mpapec@yahoo.com>
Re: qr, spliting.. (Anno Siegel)
Re: The Superiority of PHP over Perl <murat.uenalan@gmx.de>
Re: The Superiority of PHP over Perl (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
Re: The Superiority of PHP over Perl <bart.lateur@pandora.be>
Re: The Superiority of PHP over Perl <tassilo.parseval@post.rwth-aachen.de>
Re: The Superiority of PHP over Perl <goldbb2@earthlink.net>
vbs from perl <janne.saarinen@disnet.fi>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 27 Dec 2002 13:57:00 -0800
From: jeffmott@twcny.rr.com (Jeff Mott)
Subject: C Backend
Message-Id: <f9c0ce19.0212271357.1d46f08a@posting.google.com>
When I try to compile my Perl program into a C source file ( perlcc
test.pl ) I get the following messages:
Note (probably harmless): No library found for 'oldnames.lib'
Note (probably harmless): No library found for 'kernal32.lib'
Note (probably harmless): No library found for 'user32.lib'
Note (probably harmless): No library found for 'gdi32.lib'
etc.
'cl' is not recognized as an internal or external command, operable
program or batch file.
???
Running ActivePerl 5.6.1 on Win32 machine.
------------------------------
Date: Fri, 27 Dec 2002 22:26:49 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: C Backend
Message-Id: <tskp0v0oujt3g0ktkn4jde9sb9uncj7ac0@4ax.com>
Jeff Mott wrote:
>'cl' is not recognized as an internal or external command, operable
>program or batch file.
It's the command line compiler from Visual C.
--
Bart.
------------------------------
Date: Fri, 27 Dec 2002 14:33:16 -0600
From: spark <spark@dcwis.nodurnspam.com>
Subject: e-mail address tester?
Message-Id: <MPG.1876750b92115d03989691@news-central.giganews.com>
Is there a perl module which will test an e-mail address to see if it's
valid, or if there are any other problems with it (such as mailbox is
full)? I'm looking for something in perl so that I can use it in a
mailer script I've written in perl. Any help is appreciated.
spark
------------------------------
Date: Sat, 28 Dec 2002 08:02:38 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: e-mail address tester?
Message-Id: <auif5h$79vi6$1@ID-172104.news.dfncis.de>
"spark" <spark@dcwis.nodurnspam.com> wrote in message
news:MPG.1876750b92115d03989691@news-central.giganews.com...
> Is there a perl module which will test an e-mail address to see if it's
> valid, or if there are any other problems with it (such as mailbox is
> full)? I'm looking for something in perl so that I can use it in a
> mailer script I've written in perl. Any help is appreciated.
Ooooh, you almost qualify for a SAQ with those carefully crafted words
"e-mail address and valid".
See CPAN modules Email::Valid or Mail::CheckUser or Mail::Verify or
Mail::RFC822::Address and
of course the Perl FAQ
perldoc -q "valid mail"
------------------------------
Date: Fri, 27 Dec 2002 15:10:15 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: e-mail address tester?
Message-Id: <slrnb0pgdn.57k.tadmc@magna.augustmail.com>
spark <spark@dcwis.nodurnspam.com> wrote:
> Is there a perl module which will test an e-mail address to see if it's
> valid, or if there are any other problems with it (such as mailbox is
> full)?
There are many modules that can send an email message (eg. Mail::Mailer).
Use it to send an email message and ask for a reply, then see
if you get a reply (or a bounce).
If you get the requested reply, the test passed.
> I'm looking for something in perl so that I can use it in a
> mailer script I've written in perl.
Oh. So you probably already know how to send an email, why not
just send one then?
Or maybe you just didn't check the Perl FAQ before posting
to the Perl newsgroup?
perldoc -q mail
"How do I check a valid mail address?"
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 27 Dec 2002 13:55:10 +0100
From: "Tobias Renz" <renz-t@web.de>
Subject: Re: Free Program
Message-Id: <auhij5$guq$1@news.online.de>
I know it's free and seems quite funny,
i'll take a look at it, but do you have something like a documentation
remarks etc. for it?
--
Greetings
Tobias Renz
"Zarathustra" <varat@ix.netcom.com> schrieb im Newsbeitrag
news:3E0777F2.4060303@ix.netcom.com...
> I am writing an adventure game. It is pretty simple. I have gotten as
> far as I can but I don't know how to pick up treasure and use items. I
> will give this program away for free.
>
----------------------------------------------------------------------------
----
> #! usr/bin/perl -w
>
> use strict;
> use integer;
>
> my @maze=(
> [ qw( e sew we ws )],
> [ qw(ne new sw ns ) ],
> [ qw( ns - ns wn ) ],
> [ qw(ne w ne w )],
> );
> my %direction = (n=> [ -1, 0], s=> [1, 0], e => [0, 1], w => [0, -1]);
>
> my %full=( e => 'East', n => 'North', w=>'West', s =>'South');
> my($curr_x, $curr_y, $x, $y)=(0,0,3,3);
> my $move;
>
> my $num;
> my $n;
> my $c;
> my @p=(" ",10,1,0,7,6);
> my @m;
> my $mhp = $p[1];
> my @weapon;
> my @armor;
>
> sub disp_loc {
> my($cx, $cy)=@_;
> print "You may move ";
> while($maze [$cx] [$cy]=~/([nsew])/g) {
> print "$full{$1} ";
> }
> print "($maze[$cx][$cy])\n";
> }
> sub move_to {
> my($new, $xref, $yref)=@_;
>
> $new=substr(lc($new),0,1);
> if ($maze[$$xref] [$$yref]!~/$new/) {
> print "Can't go that way $new!\n";
> return;
> }
> $$xref += $direction{$new}[0];
> $$yref += $direction{$new}[1];
> }
>
> sub xps {
> my ($hp, $lv, $xp, $mxp) = @_;
> print "You got $mxp XP for the battle \n";
> $xp = $xp + $mxp;
> if ($xp > 100) {
> $lv++;
> $xp = $xp - 100;
> ($hp, $mhp) = nlv ($hp, $mxp);
> }
> return $hp, $lv, $xp;
> }
>
> sub nlv {
> my ($hp, $mhp) = @_;
> my $num;
>
> $num = (int(rand(10))+1);
> $hp = $hp + $num;
> $mhp = $mhp + $num;
> return $hp, $mhp;
> }
>
> sub atk {
> my ($hd, $ac) = @_;
> my $roll;
> my $hit;
> my $thaco;
>
> $roll = int(rand(20))+1;
> $thaco = 19 - $hd;
> if ($roll > ($thaco - $ac)) {
> $hit=1;
> print "Hit! \n";
> } else {
> print "Missed... \n";
> $hit=0;
> }
> return $hit;
> }
> sub fight {
>
> my $ht;
> my ($md, $pd) = @_;
> print "$$pd[0] is Fighting a $$md[0] \n";
> print "You have $$pd[1] HP, it has $$md[2] HP\n";
> $ht = atk ($$pd[2], $$md[3]);
> if ( $ht == 1 ) {
> $$md[2] = $$md[2] - (int(rand($$pd[5]))+1);
> }
> print "Now the $$md[0] attacks \n";
> $ht = atk ($$md[1], $$pd[2]);
> if ( $ht == 1 ) {
> $$pd[1] = $$pd[1] - (int(rand($$md[3]))+1);
> }
> return $$md[2], $$pd[1];
> }
>
> sub choosmon {
>
> my $x;
> my $v;
> my $rm;
> my $hp;
> my @mm = ();
> my @ml = (
> [ "Orc",1,0,6,15 ],
> [ "Gobblin",1,0,4,10 ],
> [ "Hobgobblin",2,0,6,25 ],
> [ "Skelliton",1,0,4,10 ],
> [ "Dragon!",4,0,7,100 ],
> [ "Wolf",2,0,3,20 ],
> );
>
> $rm = int(rand(6));
>
> for ($x=0; $x <= 5; $x++) {
> $mm[$x] = $ml[$rm][$x];
> }
>
> $v=$mm[1];
>
> for ($x=0; $x <= $v; $x++ ) {
> $hp = $hp + int(rand(6))+1;
> }
>
> print "You see a $mm[0] \n";
>
> $mm[2] = $hp;
> return @mm;
> }
>
>
> sub run {
> my ($hp)=@_;
> print "Running\n";
> $hp++;
> return $hp;
>
> }
>
> print "What is your name?";
> $p[0]=<STDIN>; chomp $p[0];
>
>
> until ( $curr_x == $x and $curr_y ==$y ) {
> disp_loc($curr_x, $curr_y);
> print "Which way? ";
> $move=<STDIN>; chomp $move;
> exit if ($move=~/^q/);
> move_to($move, \$curr_x, \$curr_y);
>
> $num = int(rand(4))+1;
> print " $num";
> if ($num == 1) {
> @m = choosmon (@m);
> CBT: while ( $p[1] > 0 ) {
>
> if ( $p[1] > $mhp ) {
>
> $p[1] = $mhp;
>
> }
>
>
> print "You have $p[1]/$mhp HP it has $m[2] \n";
> print "Do you want to f ight, r un d ie: ";
> $c=<STDIN>; chomp $c;
> if ( $c eq "f" ) {
> ($m[2], $p[1]) = fight(\@m, \@p);
> }
>
>
> if ($c eq "r" ) {
> $p[1] = run($p[1]);
> }
>
> if ( $c eq "l" ) {
> ($p[2], $mhp) = nlv ($p[2], $mhp);
> }
>
> if ( $m[2] <= 0 ) {
> print "You killed the $m[0] \n";
> ($p[1], $p[2], $p[3]) = xps ($p[1], $p[2], $p[3], $m[4]);
> last CBT;
> }
>
> if ( $c eq "d" ) {$p[1] = 0;
> }
>
>
>
> }
>
>
> if ( $p[1] <= 0 ) {
> print "You are dead";
> die; }
>
> }
> }
> print "You made it!\n";
>
------------------------------
Date: 27 Dec 2002 21:02:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: generate a line of code on the fly
Message-Id: <auif5h$nm7$1@mamenchi.zrz.TU-Berlin.DE>
According to squillion <squillion@hotmail.com>:
> my subroutine get_ref returns a reference to an anonymous subroutine.
> sometimes the parameters to be passed to the anonymous subroutine are
> known at compile time. sometimes the parameters to be passed to the
> anonymous subroutine are not known until runtime. get_ref caters for
> the two cases thusly:
>
> use strict;
> use warnings;
>
> my $f1=get_funcref("compile-time");
> my $f2=get_funcref();
>
> $f1->("this string is ignored");
> $f2->("run-time");
>
> sub get_funcref {
> my $arg=shift();
> if ($arg) {
> sub {
> print "compile time arg: >$arg<\n";
> };
> }else{
> sub {
> my $arg=shift();
> print "runtime arg: >$arg<\n";
> }
> }
> }
>
> output -
> compile time arg: >compile-time<
> runtime arg: >run-time<
>
> this does what i need. but in reality the two anonymous subroutines
> which can be returned by get_funcref are huge and identical except for
> the sole difference that the second anonymous subroutine has as its
> first line
>
> my $arg=shift();
>
> whereas the first anonymous subroutine does not. so i would like for
> get_funcref to generate that line dynamically depending upon whether
> an argument was supplied to get_funcref. conceptually it would look
> something like this:
>
> sub get_funcref {
> my $arg=shift();
> my $line=$arg?"":"my \$arg=shift()";
> sub {
> $line;
> print "arg: >$arg<\n";
> };
> }
>
> but that doesn't work as written, nor can i find a way to do it with
> eval ... can it be done?
If I understand you right, this is better solved using a closure than
eval (you mean string-eval, don't you?). Here is one (untested) way to
do it:
{
my $arg;
sub _big_fat_ugly {
# no attempt to set $arg, uses whatever it is
}
sub get_funcref {
if ( @_ ) {
# have an argument. set $arg to value given,
# return function that accepts $arg as is
$arg = shift;
return \ &_big_fat_ugly;
} else {
# no arg, return caller stub that sets $arg
return sub {
$arg = shift;
goto &_big_fat_ugly;
}
}
}
}
Note that both the large routine and the little caller stub have
access to the lexical $var. The purpose of the bare block is to
give $var some privacy.
You could as well pack the scope of $var (and the definition of
_big_fat_ugly) inside get_funcref and do away with the bare block.
Instead of "goto &..." a normal subref call could also be used, with
slight differences with respect to caller().
Anno
------------------------------
Date: Fri, 27 Dec 2002 14:24:16 -0600
From: Chris Kolosiwsky <phignuton@_No#SpAm#_hotmail.com>
Subject: IE uploads result in zero length files using CGI.pm
Message-Id: <5ldp0v4ahbvcad34t2g67aqjfb4o2nchnk@4ax.com>
Hello All...
While I realize that the CGI.pm docs clearly state the following:
"The file upload feature doesn't work with every combination of
browser and server. The various versions of Netscape and Internet
Explorer on the Macintosh, Unix and Windows platforms don't all seem
to implement file uploading in exactly the same way. I've tried to
make CGI.pm work with all versions on all platforms, but I keep
getting reports from people of instances that break the file upload
feature."
I was wondering if there is a workaround for the following situation:
A cgi script accepts a file name for upload. The script untaints the
file name, munges it to a predetermined name and writes the file to
disk.
Using Mozilla, K-Meleon, Netscape, Phoenix, IE 5.1 for the Mac, and
Galeon the file is uploaded and written just fine. However, using the
dreaded IE (versions 5 and 6) for the PC results in a zero length
file.
I'm using the following syntax for the file open:
open (UPLOADEDFILE, ">$uldir/$renamed");
while (<$uploadedfile>)
{
print UPLOADEDFILE;
}
Can someone perhaps suggest a better way to do this that would work
with IE and Netscape based browsers? The server is a RedHat 7.3 box
running apache 1.3.22 with perl 5.6.0 and CGI.pm 2.89.
I have searched Google Groups for someone with a similar problem, but
no one seems to have the exact same problem. If this is something
exceptionally obvious, I do apologize in advance. I think I've been
looking at this problem for a little bit TOO long.
Thanks
Chris Kolosiwsky
------------------------------
Date: Fri, 27 Dec 2002 10:29:16 +0100
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: kill() - invalid argument?
Message-Id: <auh5eb$e4f427@news-1.bank.dresdner.net>
Hi,
can someone please explain why
$ perl -wle 'kill 0 => $$;print $!'
produces the output "Invalid argument"? Any other (valid) signal
number/name does not seem to set $! in this one-liner.
TIA,
Peter Dintelmann
------------------------------
Date: 27 Dec 2002 11:09:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: kill() - invalid argument?
Message-Id: <auhcdv$r0$1@mamenchi.zrz.TU-Berlin.DE>
According to Dr. Peter Dintelmann <Peter.Dintelmann@dresdner-bank.com>:
> Hi,
>
> can someone please explain why
>
> $ perl -wle 'kill 0 => $$;print $!'
>
> produces the output "Invalid argument"? Any other (valid) signal
It doesn't for me. What Perl and what OS are you running?
> number/name does not seem to set $! in this one-liner.
Anno
------------------------------
Date: Fri, 27 Dec 2002 13:10:33 +0100
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: kill() - invalid argument?
Message-Id: <auheso$e4h449@news-1.bank.dresdner.net>
> It doesn't for me. What Perl and what OS are you running?
$ uname -a
SunOS OIKBM03 5.8 Generic_108528-16 sun4u sparc SUNW,Ultra-5_10
$ perl -v
This is perl, v5.8.0 built for sun4-solaris-thread-multi
Do you need the complete perl -V output?
Peter
------------------------------
Date: Fri, 27 Dec 2002 23:11:14 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: kill() - invalid argument?
Message-Id: <slrnb0ogr2.4tt.mgjv@martien.heliotrope.home>
On Fri, 27 Dec 2002 10:29:16 +0100,
Dr. Peter Dintelmann <Peter.Dintelmann@dresdner-bank.com> wrote:
> Hi,
>
> can someone please explain why
>
> $ perl -wle 'kill 0 => $$;print $!'
>
> produces the output "Invalid argument"? Any other (valid) signal
> number/name does not seem to set $! in this one-liner.
Printing $! is only meaningful after there has been an error. Try:
$ perl -wle 'kill 0, $$ or print $!'
and you see that there is no reason for $! to be set to anything
sensible, since C<kill 0, $$> will always succeed.
Just for reference: If I do:
$ perl -wle 'kill 0, $$; print $!'
on my platform, I simply get an empty line.
Martien
--
|
Martien Verbruggen | Blessed are the Fundamentalists, for they
| shall inhibit the earth.
|
------------------------------
Date: 27 Dec 2002 17:20:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: kill() - invalid argument?
Message-Id: <aui24u$epb$1@mamenchi.zrz.TU-Berlin.DE>
According to Dr. Peter Dintelmann <Peter.Dintelmann@dresdner-bank.com>:
> > It doesn't for me. What Perl and what OS are you running?
>
> $ uname -a
> SunOS OIKBM03 5.8 Generic_108528-16 sun4u sparc SUNW,Ultra-5_10
> $ perl -v
>
> This is perl, v5.8.0 built for sun4-solaris-thread-multi
Umm, sorry. The question wasn't really called for.
As Martien has pointed out, the content of $! is unpredictable and
irrelevant unless an error has occurred, so varying behavior must be
expected.
> Do you need the complete perl -V output?
That much detail is rarely needed in the context of a posting to clpm.
Anno
------------------------------
Date: Fri, 27 Dec 2002 10:35:22 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: missing Net/SMTP and PPM search shows nothing.
Message-Id: <3e0c2cb0.6033665@news.cis.dfn.de>
On 23 Dec 2002 22:19:32 -0800, flateyjarbok@yahoo.com (R
Solberg) wrote:
>Hi,
>I have activeperl, and my pgm for email sending says that
>
>Can't locate Net/SMTP.pm in @INC (@INC contains: C:/perl/lib
>C:/perl/site/lib .)
> at c:\perl\myapps\mail0104.pl line 4.
>THen I checked PPM and it shows that I have the following. Then I ran
>ppm search and nothing comes back. How do I get NET::SMTP from PPM?
>THanks much.
My guess is that you have another Perl installed that
is being called by default. Activeperl does *not* uninstall
older perls. You have to do that yourself.
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: Fri, 27 Dec 2002 14:07:16 +0100
From: "Tobias Renz" <renz-t@web.de>
Subject: Re: missing Net/SMTP and PPM search shows nothing.
Message-Id: <auhj9q$hde$1@news.online.de>
Hey,
here's the link to the CPAN-Archiv where the module is located just copy the
SMTP.pm file in one of your directorys
which you find in the @INC-array (print @INC;).
http://search.cpan.org/author/GBARR/libnet-1.12/Net/SMTP.pm
Create there the subdirectory Net in one of the INC-dirs (because of the
modules name: Net::SMTP),
and copy the SMTP.pm in there.
Done; from now on you can use it regulary.
The package doesn't seem to be available by ppm.
Hth
--
Greetings
Tobias Renz
"R Solberg" <flateyjarbok@yahoo.com> schrieb im Newsbeitrag
news:386cc483.0212232219.45745be1@posting.google.com...
> Hi,
> I have activeperl, and my pgm for email sending says that
>
> Can't locate Net/SMTP.pm in @INC (@INC contains: C:/perl/lib
> C:/perl/site/lib .)
> at c:\perl\myapps\mail0104.pl line 4.
>
> The program is like this:
>
> #!/usr/bin/perl -w
> #from FAQ 9 in my active perl files. R. solberg
>
> use Net::SMTP;
>
> $smtp = Net::SMTP->new('attbi.com'); # connect to an SMTP
> server
> $smtp->mail( 'fromuser@attbi.com' ); # use the sender's
> address here
> $smtp->to('touser@attbi.com'); # recipient's address
> $smtp->data(); # Start the mail
>
> # Send the header.
> $smtp->datasend("To: touser@attbi.com\n");
> $smtp->datasend("From: fromuser@attbi.com\n");
> $smtp->datasend("\n");
>
> # Send the body.
> $smtp->datasend("Hello, World!\n");
> $smtp->dataend(); # Finish sending the mail
> $smtp->quit; # Close the SMTP
> connection
>
> # Create a subject and a body.
> #
> $msg->{Subject} = "Test Message";
> $msg->{Text} = <<EOF;
> This is a sample test message.
>
> Cheers,
>
> Mr. Email
>
> EOF
>
>
> THen I checked PPM and it shows that I have the following. Then I ran
> ppm search and nothing comes back. How do I get NET::SMTP from PPM?
> THanks much.
>
>
>
>
> PPM interactive shell (2.0) - type 'help' for available commands.
> PPM> query
> Archive-Tar [0.072] module for manipulation of tar archives.
> Compress-Zlib [1.03 ] Interface to zlib compression library
> HTML-Parser [2.23 ] SGML parser class
> MIME-Base64 [2.11 ] Encoding and decoding of base64 strings
> PPM [2 ] Perl Package Manager: locate, install, upgrade
> software
> packages.
> URI [1.04 ] Uniform Resource Identifiers (absolute and
> relative)
> XML-Element [1.07 ] Base element class for XML elements
> XML-Parser [2.27 ] A Perl module for parsing XML documents
> libwin32 [0.16 ] A collection of extensions that aims to provide
> comprehensive access to the Windows API.
> libwww-perl [5.45 ] Library for WWW access in Perl
> PPM>
------------------------------
Date: Fri, 27 Dec 2002 20:01:26 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: qr, spliting..
Message-Id: <6p6p0vcaa9kr35t26tqe3ik4dve2f1otkh@4ax.com>
Greetings,
are there some benefits when using split and user field separator defined
within qr? I would also like to implement parameters which should tell
subroutine what to do with sorting instances, i.e. when calling something
like:
&SSort(x,x,x, \uc);
SSort should be somehow able to call 'uc' upon $a->[1] and $b->[1]
tnx!
#!/usr/bin/perl -w
use strict;
my @str2 = ('eir 11 9 2 6 3 1 1 81% 63% 13',
'oos 10 6 4 3 3 0 4 60% 70% 25',
'hrh 10 6 4 5 1 2 2 60% 70% 215',
'spp 10 6 4 3 3 1 3 60% 60% 14',
);
my @str = ('eir||11||9||2||6||3||1||1||81%||63%||beta||',
'oos||10||6||4||3||3||0||4||60%||70%||alfa||',
'hrh||10||6||4||5||1||2||2||60%||70%||delta||',
'spp||10||6||4||3||3||1||3||60%||60%||theta||',
);
print join("\n",
&SSort(\@str, qr/\|\|/, -1),
&SSort(\@str2, qr/\s+/, -1, sub{$a->[1] <=> $b->[1]}),
), "\n\n";
sub SSort {
######################################
#
# schwartz. sort
#
######################################
my($ra, $sep, $field, $ssub) = @_;
$ssub = sub { $a->[1] cmp $b->[1] } unless $ssub;
return
map { $_->[0] }
sort $ssub
map {
[ $_, (split /$sep/)[$field] ]
} @$ra;
}
--
Matija
------------------------------
Date: 27 Dec 2002 20:21:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: qr, spliting..
Message-Id: <auicnr$m9f$1@mamenchi.zrz.TU-Berlin.DE>
According to Matija Papec <mpapec@yahoo.com>:
>
> Greetings,
>
> are there some benefits when using split and user field separator defined
> within qr?
Benefits compared to what? Since you don't say what the purpose of your
computation is, and in which way the input data can vary, there is little
to go by.
A more conventional approach would split both sets of strings once (on
input, if they come from files), then sort the array of arrays as required,
and probably recover the strings only for output. That way you do
"openly" what happens in the Schwartz Transform anyway and put it in a
sequence that is easier to follow. You also get the responsibility for
splitting the input out of the sort routine, which is a good thing.
> I would also like to implement parameters which should tell
> subroutine what to do with sorting instances, i.e. when calling something
> like:
>
> &SSort(x,x,x, \uc);
Ugh. SSort() is suffering from hyper-parametosis already :)
> SSort should be somehow able to call 'uc' upon $a->[1] and $b->[1]
Well, you can't take references to Perl operators, the smallest unit of
code is a block, disguised as a sub. If you must, you can write "sub
{ uc shift }" and use the coderef as you please in the sorting routine,
but the design would improve if SSort() got rid of parameters instead
of acquiring new ones.
Thirdly, there are modules on CPAN that deal with this kind of data.
Look for the keyword "csv" (comma-separated values) to find them. Without
having looked at them in detail I'd expect you to find much of the
functionality you are implementing.
The code I snipped looks like a correct application of the ST to me
(without running it). My only remarks are, don't call subroutines
as "&SSort(\@str, qr/\|\|/, -1)" unless you know what the ampersand
does. It doesn't make much of a difference here, but may make a dramatic
one if prototypes are involved. Otherwise, good for using strict and
warnings. It makes it far more likely that your code will actually be
read (which I did) by establishing a certain confidence level.
Anno
------------------------------
Date: Fri, 27 Dec 2002 14:55:17 +0100
From: "Murat Ünalan" <murat.uenalan@gmx.de>
Subject: Re: The Superiority of PHP over Perl
Message-Id: <auhm4t$itv$06$1@news.t-online.com>
> Every sub in a class is a method for that class. There is no
> distinction in perl.
Nonsense. When is introspect a class, i just want to distinct "methods"
of that class, not helper-functions or just noise.
package A;
sub aMethod
{
my $self = shift;
}
sub printHello
{
print "Hello";
}
printHello is just a stupid function which swims in the A:: package, nothing
else. No method !
> As I said, every function/sub *is* a method.
s.a.
> As to attributes... In perl, modules don't really have 'attributes' --
Nonsense. Perl classes do have attributes.
> Unless you consider stuff like $object->{foo} to be an attribute, in
I do, as my OO-books aren't wrong.
> which case you can examine it by, err, examining it (with keys(),
> values(), and/or each() on %$object).
There is no general syntax for them. This is russian bullets. So you
have no chance getting information you would need. Every hacker
has his own blessed 'something'.
Introspection is good for a lot (generic otf object-mappers etc.), but this
doesn't counts for perl. It is virtually
absent.
> What kind of incompatibility? If it's because of [lack of] using
Lack of passing required tests during installation.
> Or if you use that broken code *without* looking at the CPAN-testers
> test results for the platforms you're using it on, you consider that
> *Perl's* fault?
Yes, perl-community fault. This could be prevented somehow (clean
guidelines, abstraction).
Murat
------------------------------
Date: 27 Dec 2002 18:57:20 +0100
From: mru@users.sourceforge.net (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
Subject: Re: The Superiority of PHP over Perl
Message-Id: <yw1xvg1fny4f.fsf@gladiusit.e.kth.se>
Benjamin Goldberg <goldbb2@earthlink.net> writes:
> > I bang my head nearly weekly against my monitor, because *nix-vs-win
> > compability.
>
> What kind of incompatibility? If it's because of [lack of] using
> binmode() on those filehandles which contain binary data, then I would
> *not* in any way consider it perl's fault -- it's ignorance/stupidity.
Yes, the ignorance of the authors of MSWindows. I believe that if
they would choose to switch to sane behavior regarding line ends, the
only ones that would even notice would be happy about it.
--
Måns Rullgård
mru@users.sf.net
------------------------------
Date: Fri, 27 Dec 2002 18:06:59 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: The Superiority of PHP over Perl
Message-Id: <ca5p0vgl3g28jjgbiiqop00ntc3mnj1il3@4ax.com>
Egg Troll wrote:
>* Outstanding database support. PHP supports virtually every DB under
>the sun (although Berkeley DB is missing, oddly enough.) Perl seems
>limited to MySQL and PostgreSQL, and its really a kludge for the
>later. I've heard that this will be fixed in upcoming versions of Perl
>though.
In PHP, every database has its own interface. In Perl, there's one
unified interface for all databases: DBI. And Perl has palceholders.
>* Speed. PHP is one of the fastest languages I've ever used. While it
>won't be replacing assembly or C, its definitely faster than Perl in
>almost every case, particularly in regex which has long been Perl's
>strongest point. I'm sure there are cases where Perl is equal to PHP,
>but I can't think of any at the moment.
In Perl, a regex is a precompiled primitive. In PHP, it's a string, so
it needs to be recompiled every single time you match anything.
>* Data Structures. Under PHP you can create any type of datastructure
>you need: Linked lists, binary trees, hash tables, queues, inverse
>Reiser-biased recursion trees, etc. Under Perl you're extremely
>limited in what you can do. This is because Perl isn't OO (so you
>can't create Node classes, for example, usefull in a linked list) and
>because it lacks pointers. Some of you may notice that PHP lacks
>pointers, but look deeper! Behind the scenes, hidden from the user
>pointers are used. Because of this, PHP can support complex data
>structures.
There's nothing you can do in PHP you can't do in Perl. Quite the
contrary.
The one thing PHP has over Perl WRT data structures, IMO, is that
"hashes" remain ordered.
--
Bart.
------------------------------
Date: 27 Dec 2002 18:35:42 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: The Superiority of PHP over Perl
Message-Id: <aui6hu$89l$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Murat Ünalan:
>> Every sub in a class is a method for that class. There is no
>> distinction in perl.
>
> Nonsense. When is introspect a class, i just want to distinct "methods"
> of that class, not helper-functions or just noise.
>
> package A;
>
> sub aMethod
> {
> my $self = shift;
> }
>
> sub printHello
> {
> print "Hello";
> }
>
> printHello is just a stupid function which swims in the A:: package, nothing
> else. No method !
It is a method, no matter how you call it. In Perl there is simply no
distinction between a class method, an instance method and a function
caller-wise. Weren't it a method, you couldn't do the following:
$object->printHello;
But you can also do:
A->printHello;
which shows that it is also a class-method. In both cases there's a
hidden first argument in $_[0] (in the first case it is the blessed
referent, in the second the package name). Only if you call it as
function this argument disappears:
A::printHello();
>> As I said, every function/sub *is* a method.
>
> s.a.
>
>> As to attributes... In perl, modules don't really have 'attributes' --
>
> Nonsense. Perl classes do have attributes.
Debatable. In this case the distinction between class- and instance-data
does matter. A package global could be called a class-attribute while
the things you store in a blessed hash might be considered
instance-attributes. But unlike other languages, Perl allows you to add
attributes from the outside world:
my $obj = A->new;
$obj->{new_attribute} = 1;
$A::another_attribute = 1;
Since you can even add methods that way you can extend a class easily:
package main;
sub A::get_attribute { shift->{new_attribute} }
sub A::get_another_attribute { $A::another_attribute }
>> Unless you consider stuff like $object->{foo} to be an attribute, in
>
> I do, as my OO-books aren't wrong.
But I guess your OO-books also told you that you can't that easily add
or remove attributes. In Perl this is possible since (per default) there
is no strong encapsulation of data. If you want that you can use
closures in which case you get even stronger encapsulation than most
other object-oriented languages.
>> which case you can examine it by, err, examining it (with keys(),
>> values(), and/or each() on %$object).
>
> There is no general syntax for them. This is russian bullets. So you
> have no chance getting information you would need. Every hacker
> has his own blessed 'something'.
You are right here. There is no way to get to the data when for instance
closures are used. That might have been done on purpose to prevent
people from peeking into the object. Yet this is rather uncommon in the
world of Perl: freedom to do whatever you want is preferred in the world
of Perl (even if it is freedom to shoot yourself into the leg).
>> What kind of incompatibility? If it's because of [lack of] using
>
> Lack of passing required tests during installation.
>
>> Or if you use that broken code *without* looking at the CPAN-testers
>> test results for the platforms you're using it on, you consider that
>> *Perl's* fault?
>
> Yes, perl-community fault. This could be prevented somehow (clean
> guidelines, abstraction).
How? Have you ever written a Perl module for the CPAN? You'll stumble over
incompatibility issues a lot without this being Perl's fault. You can't
blame a language that Windows does not know about flocking, can you?
It's an infinite list really. Every Perl module that interacts with the
operating system potentially suffers from these problems in some way.
I'd really like to know how you'd solve that through abstraction or
stricter guidelines.
Tassilo
PS: newsgroups trimmed to c.l.perl.m and c.l.php but follow-up suggested
since this thread is gradually moving away from PHP.
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Fri, 27 Dec 2002 15:49:36 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: The Superiority of PHP over Perl
Message-Id: <3E0CBCE0.F1351055@earthlink.net>
Måns Rullgård wrote:
>
> Benjamin Goldberg <goldbb2@earthlink.net> writes:
>
> > > I bang my head nearly weekly against my monitor, because
> > > *nix-vs-win compability.
> >
> > What kind of incompatibility? If it's because of [lack of] using
> > binmode() on those filehandles which contain binary data, then I
> > would *not* in any way consider it perl's fault -- it's
> > ignorance/stupidity.
>
> Yes, the ignorance of the authors of MSWindows. I believe that if
> they would choose to switch to sane behavior regarding line ends, the
> only ones that would even notice would be happy about it.
And how does this solve compatability problems for the X million people
who have the current versions of windows? Sure, if they introduced a
new version with sane line endings, that would be nice, but that will
only help those who install that new windows.
Also, binmode() isn't *only* for line-endings. The newest versions of
RedHat Linux have the LANG environment variable set to utf8, meaning
that every program which deals with text needs to deal with utf8
characters, *not* bytes. By default, perl opens files in text mode. If
your LANG indicates that text files are utf8, then perl puts a ":utf8"
encoding layer onto every file opened in text mode -- which is vital if
you're printing text to that handle, but probably disastrous if your
data is binary stuff. In other words, on RedHat, you need to binmode
your filehandles the same as you would on Windows, or else your data
will be corrupted.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Fri, 27 Dec 2002 22:42:42 +0200
From: "Janne Saarinen / HTV" <janne.saarinen@disnet.fi>
Subject: vbs from perl
Message-Id: <auidvl$lbe$1@nyytiset.pp.htv.fi>
is it possible to run allkind vbscript commands from perl scripts?
i need to make vbscript eo exe and perl can. so if perl can run vbs
commands, could i do exe file from my perl script?
vbs script cant build to exe, this is my major problem.
-janne saarinen
------------------------------
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 4317
***************************************