[22386] in Perl-Users-Digest
Perl-Users Digest, Issue: 4607 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 22 18:06:49 2003
Date: Sat, 22 Feb 2003 15:05:10 -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 Sat, 22 Feb 2003 Volume: 10 Number: 4607
Today's topics:
Re: (not 1) and (!1) yield zero length string ctcgag@hotmail.com
Re: 1 form insert into multiple tables ctcgag@hotmail.com
automating an ftp transfer (Voigt Lander)
Re: automating an ftp transfer <mbudash@sonic.net>
Re: automating an ftp transfer <ian@WINDOZEdigiserv.net>
Re: automating an ftp transfer <ian@WINDOZEdigiserv.net>
Re: automating an ftp transfer <peakpeek@purethought.com>
compiling perlcc generated c code with gcc <nospam_stigerikson@yahoo.se>
Re: Creating a variable from 3 other variables <REMOVEsdnCAPS@comcast.net>
Re: Crypt Question <spam@thecouch.homeip.net>
Re: date::calc <goldbb2@earthlink.net>
Re: date::calc <mbudash@sonic.net>
Re: date::calc <tore@aursand.no>
Re: FileDialog not working <bik.mido@tiscalinet.it>
LaTeX::TOM <wobh@helium.barsoom.invalid>
Re: Mail::POP3Client password <goldbb2@earthlink.net>
Re: map two lists <goldbb2@earthlink.net>
Re: map two lists <REMOVEsdnCAPS@comcast.net>
Re: map two lists <goldbb2@earthlink.net>
Re: parens () <racsw@frontiernet.net>
Re: parens () <goldbb2@earthlink.net>
Re: parens () <jurgenex@hotmail.com>
Re: Perl Library to execute stored procedures in MS-SQL <goldbb2@earthlink.net>
Re: Problem with buffering on non-blocking socket under <dodgynewsgroups@ewildgoose.demon.co.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 22 Feb 2003 19:31:36 GMT
From: ctcgag@hotmail.com
Subject: Re: (not 1) and (!1) yield zero length string
Message-Id: <20030222143136.851$p0@newsreader.com>
Salvador_Fandiño_García <sfandino@yahoo.com> wrote:
>
> if you are using numbers it is not very consistent because
>
> !0 ==> 1 # ok
> !1 ==> '' # most people would expect 0
Why? Would most people expect !!"dog" to give "dog"?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: 22 Feb 2003 19:44:34 GMT
From: ctcgag@hotmail.com
Subject: Re: 1 form insert into multiple tables
Message-Id: <20030222144434.324$0T@newsreader.com>
"Bob Van Der Ploeg" <bob@vdpcorp.com> wrote:
> My insert script parses the data from the HTML form a single hash
> %ele=mymodule::cgiparse(); {field->value}
>
> Then then I pass the entire hash to an insert subroutine in my module
> ($last_insert_id)=mymodule::insert($ele{table},%ele);
>
> I need a dynamic insert script that will parse the html form, and put the
> values entered into the correct fields of multiple tables.
This just doesn't make much sense unless all the multiple tables
are logically one table. In which case they should be one table.
> My problem is that I can figure out how to write the script without hard
> coding the table names or manully create seperate hashes that corespond
> to the colums in that table.
Well, that's what you should do. How are you creating the form without
knowing what tables and what columns it is for, in the first place?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: 22 Feb 2003 12:36:23 -0800
From: voigt691@netscape.net (Voigt Lander)
Subject: automating an ftp transfer
Message-Id: <3b89567.0302221236.376bb0cf@posting.google.com>
Would perl be a good tool for this??
I need to connect to an ftpsite each night and pull down a file.
username/password login required. File name is predictable since it's
name is datestamped. (job can be run as a cron).
Years ago when I did something like this I used an expect script. Is
that still the way to go, or is there a quick and dirty perl script
out there that will do the job?
Any thoughts, or links to related material? Alternate suggestions?
thanks
~Voigt
------------------------------
Date: Sat, 22 Feb 2003 21:11:06 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: automating an ftp transfer
Message-Id: <mbudash-03E5BE.13110522022003@typhoon.sonic.net>
In article <3b89567.0302221236.376bb0cf@posting.google.com>,
voigt691@netscape.net (Voigt Lander) wrote:
> Would perl be a good tool for this??
>
> I need to connect to an ftpsite each night and pull down a file.
> username/password login required. File name is predictable since it's
> name is datestamped. (job can be run as a cron).
>
> Years ago when I did something like this I used an expect script. Is
> that still the way to go, or is there a quick and dirty perl script
> out there that will do the job?
>
> Any thoughts, or links to related material? Alternate suggestions?
>
> thanks
>
> ~Voigt
have a look at the perl module Net::FTP
hth-
------------------------------
Date: Sat, 22 Feb 2003 21:15:15 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: automating an ftp transfer
Message-Id: <dspf5v8u802kq4fpdgf21r3csffjcmrmet@4ax.com>
Keywords: Remove WINDOZE to reply
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
In a fit of excitement on 22 Feb 2003 12:36:23 -0800,
voigt691@netscape.net (Voigt Lander) managed to scribble:
> Would perl be a good tool for this??
>
> I need to connect to an ftpsite each night and pull down a file.
> username/password login required. File name is predictable since
> it's name is datestamped. (job can be run as a cron).
>
> Years ago when I did something like this I used an expect script.
> Is that still the way to go, or is there a quick and dirty perl
> script out there that will do the job?
>
> Any thoughts, or links to related material? Alternate suggestions?
>
> thanks
>
> ~Voigt
Check out the LWP modules to do this.
I recently wrote a Perl/Tk app to connect to F-Prot's site and
download their AV update files. I created the GUI for the more
"modern" user friends that I have that get confused at the mere
mention of the word "console".
It's definitely possible, and there's also an Archive::Zip or
Archive::Tar module available too if you're file is archived.
I used the following modules in my script to achieve this (it was a
first attempt, so please excuse any of the modules I might not
necessarily _had_ to include):
use Net::HTTP;
use LWP::Simple;
use LWP::UserAgent;
use URI();
use HTTP::Date();
I found all the info required to use these modules in the Perldoc
documentation.
HTH.
Regards,
Ian
-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0
iQA/AwUBPlfoYWfqtj251CDhEQJVHwCfYwyrp0Gb6kv8HX1UP9hK49EdPm8AnRgI
iAHeGj80WR1yFCuW5+Ae/oru
=3KJz
-----END PGP SIGNATURE-----
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Scripting, Web design, development & hosting.
------------------------------
Date: Sat, 22 Feb 2003 21:16:41 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: automating an ftp transfer
Message-Id: <64qf5votgiobg1k3oi88h6229gmt7nbp1i@4ax.com>
Keywords: Remove WINDOZE to reply
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
In a fit of excitement on Sat, 22 Feb 2003 21:15:15 GMT, "Ian.H [dS]"
<ian@WINDOZEdigiserv.net> managed to scribble:
> I used the following modules in my script to achieve this (it was a
> first attempt, so please excuse any of the modules I might not
> necessarily _had_ to include):
>
>
> use Net::HTTP;
> use LWP::Simple;
> use LWP::UserAgent;
> use URI();
> use HTTP::Date();
>
>
> I found all the info required to use these modules in the Perldoc
> documentation.
Just realised after hitting 'send' that this was for HTTP (although
the final request on the server goes to an FTP server).
Net::FTP will be the module you're after for straight FTP transfers.
Apologies for any confusion.
Regards,
Ian
-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0
iQA/AwUBPlfot2fqtj251CDhEQIe+ACdGCDw/sYZ1MBR5fYCuSVPz5YwjoQAn1rh
ayUdYEF1uolorKN4cJYZS22R
=P5++
-----END PGP SIGNATURE-----
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Scripting, Web design, development & hosting.
------------------------------
Date: Sat, 22 Feb 2003 21:19:36 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: automating an ftp transfer
Message-Id: <s4qf5vssphqleks4l9nf26m1j16gqd7eu2@4ax.com>
On 22 Feb 2003 12:36:23 -0800, in comp.lang.perl.misc, voigt691@netscape.net (Voigt Lander) wrote:
>Would perl be a good tool for this??
Probably not
>I need to connect to an ftpsite each night and pull down a file
Use a good command-line FTP client ...
lftp
ncftp
curl
and many more
--
Sharon
------------------------------
Date: Sat, 22 Feb 2003 23:09:24 +0100
From: stig <nospam_stigerikson@yahoo.se>
Subject: compiling perlcc generated c code with gcc
Message-Id: <b38sh7$qhb$1@oden.abc.se>
hi
i recently read that one can make perlcc create a c code file and compile
it.
well, i tried to compile with perlcc, worked fine, no major (less then 5%)
change in execution time.
however, it is possible to generate c code with perlcc
so i did, using perl 5.8.0
perlcc -c myprogram.pl
it generates the file myprogram.c
then i thought it might be possible to compile it with gcc.
so i made a small Makefile:
--start---
OBJS = myprogram.o
#for gcc compiler ....
CC = gcc
CFLAGS = -g -Wall
#naming executable
EXEC = myprogram
all: $(EXEC)
%.o:%.c
$(CC) $(CFLAGS) -c $<
$(EXEC): $(OBJS)
$(CC) -o $@ $(OBJS)
@echo "Compiling completed on `date | cut -c1-19`"
---end---
and then i run: make
as gcc begins to parse the c file it generates 4-5 lines of warnings per
line c code, and ends in error
this is how the errors and warnings begin
myprogram.c:1:20: EXTERN.h: No such file or directory
myprogram.c:2:18: perl.h: No such file or directory
myprogram.c:3:18: XSUB.h: No such file or directory
myprogram.c:11: syntax error before "void"
myprogram.c:11: parse error before "CV"
should i send some extra switches to the compiler?
perhaps some library?
any hints?
thanks
stig
------------------------------
Date: Sat, 22 Feb 2003 15:53:07 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Creating a variable from 3 other variables
Message-Id: <Xns932AABAC3270Asdn.comcast@216.166.71.239>
"Mikey" <PleaseDontThrowSpam@Me.com> wrote in news:b37sp8$r6h$1
@wisteria.csv.warwick.ac.uk:
> If I try the following, I will get errors:
> my $date = "$year$month$day";
Really? That's surprising. What errors?
--
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
------------------------------
Date: Sat, 22 Feb 2003 15:39:39 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Crypt Question
Message-Id: <heR5a.2273$Bf1.53891@weber.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
w i l l wrote:
> I'm looking for a module, or technology that would allow me to Encrypt
> some string data with a key, and then to decrypt with a different
> Decrypt key.
You want Assymmetric encryption.
> Is PGP what I want?
Quite possibly, yes. PGP is an implementation of assymmetric encryption
(along with other stuff too). Also, PGP is not the only option.
> If so, how do i go about getting it?
Since you're posting in a perl newsgroup I'm assuming you're interested
in a perl implementation of PGP. Head over to:
http://search.cpan.org
and do a search for "PGP"
For PGP and alikes, see:
http://www.pgp.com/
http://www.gnupg.org/
You might also be interested in some an "assymetric cryptography for
beginners" sort of tutorial so you can grasp the concepts behind any
perl modules you find at CPAN.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+V+APeS99pGMif6wRAqfJAJwIoRUAhXcs60g9AdZhIE5ZZBdN3wCcCBJv
BNQzviFpcxue+55kfmTvHVo=
=N3X0
-----END PGP SIGNATURE-----
------------------------------
Date: Sat, 22 Feb 2003 14:43:14 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: date::calc
Message-Id: <3E57D2D2.BD6DE2E3@earthlink.net>
w i l l wrote:
>
> Is there a way of using date::calc or some other module to get the
> time format 20030215 (YYYYMMDD) into Feb 15 2003 ?
>
> TIA!!!!!!!!!!!!!!!!
my @montsh = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my ($yyyy, $mm, $dd) = unpack 'a4 a2 a2', $input;
print "$months[$mm-1] $dd $yyyy\n";
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Sat, 22 Feb 2003 19:34:08 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: date::calc
Message-Id: <mbudash-31A82C.11340722022003@typhoon.sonic.net>
In article <ghhf5vk039ah0cuvfohcej8q6ljld8a9p6@4ax.com>,
w i l l <will@com.yahoo> wrote:
> Is there a way of using date::calc or some other module to get the
> time format 20030215 (YYYYMMDD) into Feb 15 2003 ?
>
> TIA!!!!!!!!!!!!!!!!
mr. goldberg gace you one answer. alternatively, if you'd really like to
use Date::Calc type:
perldoc Date::Calc
and scan for 13) for suggestions.
hth-
------------------------------
Date: Sat, 22 Feb 2003 22:10:39 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: date::calc
Message-Id: <pan.2003.02.22.21.07.53.461974@aursand.no>
On Sat, 22 Feb 2003 14:43:14 -0500, Benjamin Goldberg wrote:
>> Is there a way of using date::calc or some other module to get the
>> time format 20030215 (YYYYMMDD) into Feb 15 2003 ?
> my @montsh = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
> my ($yyyy, $mm, $dd) = unpack 'a4 a2 a2', $input;
> print "$months[$mm-1] $dd $yyyy\n";
Ooh! I normally don't say this in a newsgroup (at least not a technical
one), but that answer _almost_ gave me an Perlgasm. :)
<cartman> Cute! </cartman>
--
Tore Aursand - tore@aursand.no - http://www.aursand.no/
------------------------------
Date: Sat, 22 Feb 2003 23:57:07 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FileDialog not working
Message-Id: <lble5vkfnvav600n4r07v4e50jfe34b668@4ax.com>
First of all let me point out that my followup to your previous post
was intended just as a comment on a minor point, while I *mostly*
agree with you and with what you say here.
On Fri, 21 Feb 2003 10:21:45 -0700, Ron Smith
<rdsmith@sedona.intel.com> wrote:
>My real point is that it is stated clearly that globbing is a platform
>dependent operation whereas readdir is not, and that this is true for
No, it *shouldn't*, see "perldoc -f glob":
> glob EXPR
[...]
> Beginning with v5.6.0, this operator is implemented using the
> standard "File::Glob" extension. See the File::Glob manpage for
> details.
OTOH, one of the entries from "perldoc -q glob" warns:
[slightly edited]
> Your port may include proprietary globbing
> functions as well. Check its documentation for details.
But this doesn't (seem to) mean that glob() itself is port-dependent.
>the most popular "stable" release, 5.6.1. The particular module does a
>readdir, then throws away all of that information and does a glob. This
Actually this is strange indeed. BTW: I don't even know the module
you're talking about, but I guess it implements a file selection
dialog, then I wonder, too, why it uses glob() at all, when a
readdir() would have been all that is needed...
>substituted a platform independent solution for a platform dependent one
>for the probable reason that it made "*.*" easy to implement. Obviously
^^^^
I don't think so: if the aim is really a "*.*"-selection or something
of that kind, grepping (e.g.) through a regex would have been ways
easier to implement...
>a better solution would be to use regular expressions instead on the
>readdir already done, either by forcing the user to enter perl regular
>expressions in the glob entry or to morph "*.*" into "^.*\..*$". There
^^^^^^^
BTW: (if this is just for a match) /\./ would suffice!
However, the "morphing" you hint at is precisely what "find2perl" does
(for the -name option), but then I *guess* it is also what File::Glob
does... (and then it should not be worth to reinvent the wheel!)
>are clear and obvious differences between the commonly used glob
>expressions and perl regular expressions and globs will clearly work
>differently between Unix like systems and Windoze systems.
Not quite so, see again "perldoc -q glob":
[slightly edited]
> Why doesn't glob("*.*") get all the files?
>
> Because even on non-Unix ports, Perl's glob function follows
> standard Unix globbing semantics. You'll need "glob("*")" to get
> all (non-hidden) files.
>Frankly this is the less interesting question to me. Personally I
>really want to know why adding quotes to the glob argument
><"$path$pat"> worked *at all*. I wonder specifically because
>glob("$path$pat") does *not* work (I tried) and yet they appear on the
>surface to be the same.
All I can say is that "perldoc File::Glob" yields the following
paragraph:
> Since v5.6.0, Perl's CORE::glob() is implemented in terms of bsd_glob().
> Note that they don't share the same prototype--CORE::glob() only accepts
> a single argument. Due to historical reasons, CORE::glob() will also
> split its argument on whitespace, treating it as multiple patterns,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> whereas bsd_glob() considers them as one pattern.
So your claim (if true!) would imply some (possibly) undocumented
difference between the glob() and <> constructs.
>However, the original point is that the dialog should not have used
>globbing at all if it expected to be platform independent.
Agreed, independently of the conditional claim (as of recent perls).
Since I'm only a newbie, I crossposted to clpm, to hear the opinion of
the experts there.
Michele
--
Liberta' va cercando, ch'e' si' cara,
Come sa chi per lei vita rifiuta.
[Dante Alighieri, Purg. I, 71-72]
I am my own country - United States Confederate of Me!
[Pennywise, "My own country"]
------------------------------
Date: 22 Feb 2003 19:46:36 GMT
From: William Clifford <wobh@helium.barsoom.invalid>
Subject: LaTeX::TOM
Message-Id: <slrnb5fjrl.3r0.wobh@helium.barsoom>
[crossposted to comp.text.tex and comp.lang.perl.misc. No follow-ups
set, sorry.]
With apologies to the latex2html guys, but I really hate the output of
latex2html and I could use something more generic besides.
Fortunately I found a LaTeX parsing perl module here:
http://elaine.dlib.vt.edu/latex_tom/index.html
which looks like I might be able to get it to talk to HTML::Treebuilder
which would be most fine. Has anyone used this module at all? I'm still
feeling my way around it.
I tried the code in the documentation and so far I've learned that:
1) the method "parsefile" has been renamed "parseFile".
2) the basic latex file I'm trying this on gives me a lot of "Use of
uninitialized value in concatenation (.) or string at
/home/wobh/lib/Perl/LaTeX/TOM/Parser.pm line 813."
Thanks in advance!
--
William Clifford wobh@mindspring.com http://wobh.home.mindspring.com
------------------------------
Date: Sat, 22 Feb 2003 14:31:02 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Mail::POP3Client password
Message-Id: <3E57CFF6.8421E39B@earthlink.net>
Veera Venkataramani wrote:
[snip]
> However, if I dont replace "mypassword" with my cleartext password,
> this doesnt work. I dont think this is how people use this
> package. How do I use this without having my password in cleartext in
> a script file?
Prompt the user for the password?
Or, write the password into a seperate file which you then chmod() to
*only* be readable by the user, and then chmod() the script file to be
setuid, in order for it to read that file.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Sat, 22 Feb 2003 14:37:04 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: map two lists
Message-Id: <3E57D160.579D00BD@earthlink.net>
Johannes Fürnkranz wrote:
> Barry Kimelman wrote:
> > @result = map { &function($list1[$_],$list2[$_]) } (0..$#list1);
>
> Yep, I guess it can't get any shorter than this, and probably not more
> efficient either.
It can get a little shorter and more efficient:
@result = map function($list1[$_], $list2[$_]), 0 .. $#list1;
Changing the block to an expression eliminates a scope-enter and
scope-exit.
You can improve the efficiency a bit more at the cost of aesthetics:
my $i = 0; @result = map function($_, $list2[$i++]), @list1;
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Sat, 22 Feb 2003 15:58:21 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: map two lists
Message-Id: <Xns932AAC8EE9D97sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Johannes Fürnkranz <johannes.fuernkranz@t-online.de> wrote in
news:b37uvi$9an$01$1@news.t-online.com:
> Hi,
>
> I frequently have the following problem:
> I would like to run a map over two lists that are aligned, i.e.,
> something like:
>
> @result = map2 { function($1,$2} } @list1, @list2;
>
> This, of course, doesn't work, but maybe there is something similar?
> ($1 and $2 are meant to refer to corresponding arguments in the two
> lists).
Here's a function from my own library. Help yourself:
- ----------CUT HERE----------
=item pairwise
@c = pairwise {code} @a, @b;
Applies C<{code}> to each pair of elements of C<@a>, C<@b> in turn.
Returns a list of the results of that evaluation. The pairs are
assigned to C<$a> and C<$b> before invoking the code.
Examples:
@a = (1, 2, 3); @b = (2, 4, 6);
@c = pairwise {$a + $b} @a, @b; # returns (3, 6, 9)
@d = pairwise {$a * $b} @a, @b; # returns (2, 8, 18)
=cut
#---> @c = pairwise {code} @a, @b;
#
# Change History:
# 06/27/2002 EJR First version
sub pairwise (&\@\@)
{
my $op = shift;
my ($A, $B) = @_;
my $limit = @$A;
$limit = @$B if @$B > @$A;
my $i;
my @result;
no strict 'refs';
my $pkg = (caller)[0]; # caller's package
my ($old_a,$old_b) = (${"$pkg\::a"},${"$pkg\::b"}); # "localize"
for ($i=0; $i<$limit; $i++)
{
${"$pkg\::a"} = $A->[$i];
${"$pkg\::b"} = $B->[$i];
push @result, $op->();
}
(${"$pkg\::a"},${"$pkg\::b"}) = ($old_a,$old_b); # restore
return @result;
}
- ----------CUT HERE----------
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPlfyPGPeouIeTNHoEQK7CQCg9xXdb92jK+zm0L2x/m5UaZw0RSoAnR2N
1Nl6O5owZ1/wyVZuCq3FFYBH
=W2IP
-----END PGP SIGNATURE-----
------------------------------
Date: Sat, 22 Feb 2003 18:09:15 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: map two lists
Message-Id: <3E58031B.7674838E@earthlink.net>
"Eric J. Roode" wrote:
[snip]
Your pairwise function could be written a bit more efficiently:
use strict;
use vars qw(@alist @blist);
sub the_op ();
sub pairwise(&\@\@) {
local (*the_op, *alist, *blist) = @_;
my ($aglob, $bglob) = do {
my $pkg = caller();
no strict 'refs';
\*{$pkg.'::a'}, \*{$pkg.'::b'};
};
local( *$aglob, *$bglob );
map {
( *$aglob, *$bglob ) = \( $alist[$_], $blist[$_] );
the_op();
} 0 .. (@alist > @blist ? $#alist : $#blist);
}
__END__
[untested]
Accessing the two arrays through dynamic aliases to the arrayrefs is
faster than accessing the arrayrefs directly. I'm not sure if the same
thing applies to calling the coderef, but it probably does.
Factoring the $pkg.'::a' and the $pkg.'::b' out of the loop provides
some increase in speed, and obtaining a globref in a do block also
allows strict refs to be turned off for a much smaller scope.
Aliasing *{$pkg.'::a'} to \$alist[$_] instead of assigning the contents
of $alist[$_] to ${$pkg.'::a'} (and likewise with b) means that if the
coderef chooses to alter $a and $b, it will alter the array elements.
This is a Good Thing.
Using local on *{$pkg.'::a'} and *{$pkg.'::b'} means that if the coderef
that was passed in die()s, they will automaticaly restored by perl,
without our needing to catch the exception, restore, and rethrow.
Since the passed in subroutine is called as the last expression in the
map block, and the map block is the last expression in the subroutine,
the coderef will receive the same context as the pairwise() function
itself was called in. This means that in scalar context, no
intermediate array needs to be built. Also, perhaps more importantly,
the results of coderef get placed directly on the return stack, rather
than being copied to a temp array, which would then get put onto the
return stack.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Sat, 22 Feb 2003 16:45:07 -0500
From: Robert Krueger <racsw@frontiernet.net>
Subject: Re: parens ()
Message-Id: <v5frr523k2r71@corp.supernews.com>
Robert Krueger wrote:
> Hi,
> Why does this work:
> print (( 2 * 3 ) * 8 );
>
> and this doesn't?
> print ( 2 * 3 ) * 8;
>
> Thanks,
> Robert
Well, I apologize for not being more specific, I was in a rush before going
to work.
I always enable warnings, and I receive this warning:
"Useless use of integer multiplication (*) in void context at <line #>"
In C or C++, I would never get a warning for this syntax, but regardless,
the order of precedence remains the same with or without the parens(), so
why does Perl take issue with this?
Thanks to all, BTW,
Robert
------------------------------
Date: Sat, 22 Feb 2003 17:13:39 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: parens ()
Message-Id: <3E57F613.E34724CB@earthlink.net>
Robert Krueger wrote:
>
> Robert Krueger wrote:
>
> > Hi,
> > Why does this work:
> > print (( 2 * 3 ) * 8 );
> >
> > and this doesn't?
> > print ( 2 * 3 ) * 8;
> >
> > Thanks,
> > Robert
>
> Well, I apologize for not being more specific, I was in a rush before
> going to work.
> I always enable warnings, and I receive this warning:
>
> "Useless use of integer multiplication (*) in void context at
> <line #>"
>
> In C or C++, I would never get a warning for this syntax,
Sure -- but don't you wish you could get such a warning. How often, in
C or C++, do you ever want to multiply the return value of the printf()
function by something?
> but regardless, the order of precedence remains the same with or
> without the parens(), so why does Perl take issue with this?
Because the presence of parentheses *does* change the order of
precedence.
Specifically, the code
print( ( 2 * 3 ) * 8 );
Parses as, '( 2 * 3 ) * 8' is the argument to print.
And this code:
print( 2 * 3 ) * 8;
Parses as '2 * 3' is the argument to print. Multiply the result of
print by 8.
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Sat, 22 Feb 2003 22:12:14 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: parens ()
Message-Id: <2BS5a.9356$ep5.6131@nwrddc02.gnilink.net>
Robert Krueger wrote:
> Robert Krueger wrote:
> I always enable warnings, and I receive this warning:
>
> "Useless use of integer multiplication (*) in void context at <line
> #>"
>
> In C or C++, I would never get a warning for this syntax, but
> regardless, the order of precedence remains the same with or without
> the parens(), so why does Perl take issue with this?
>> Why does this work:
>> print (( 2 * 3 ) * 8 );
This is the same as "print 48;"
>> and this doesn't?
>> print ( 2 * 3 ) * 8;
This is the same as "8 * print 6"
That's nothing special at all. Just imagine using any monadic operator
instead of print, e.g. sin.
Function calls bind tighter than multiplication.
jue
------------------------------
Date: Sat, 22 Feb 2003 15:13:19 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl Library to execute stored procedures in MS-SQL Server
Message-Id: <3E57D9DF.57CA90B7@earthlink.net>
"Ye H. Aung" wrote:
>
> Hello,
>
> I am trying to write Perl wrapper to run stored procedure in MS SQL
> Server. I am looking at the following two Perl modules:
>
> (1) Win32::ODBC
> (2) MSSQL::SQLLIB
Instead of those, try using DBI.pm, and DBD::Sybase.
use DBI ();
use DBD::Sybase ();
my $dsn = "DBI:Sybase:...";
my $dbh = DBI->connect(
$dsn, $userid, $password,
{ RaiseError => 1 },
) or die $DBI::errstr;
my $sth = $dbh->prepare(q[
exec my_procedure(?, ?, ?, ?);
]);
$sth->execute( $arg1, $arg2, $arg3, $arg4 );
while( my @results = $sth->fetch ) {
# process @results.
}
__END__
[untested]
--
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print
------------------------------
Date: Sat, 22 Feb 2003 21:26:51 GMT
From: "Ed W" <dodgynewsgroups@ewildgoose.demon.co.uk>
Subject: Re: Problem with buffering on non-blocking socket under win32
Message-Id: <vWR5a.594528$1y5.4197641@news.easynews.com>
> Ok. I'm imagining a 200Kb email. What I see happening is that all the
> data is read almost immediately, and all the data is written to the
> outgoing socket almost immediately (though not all of it is sent yet
> over the wire). The program closes the reading socket, and closes the
> writing socket.
>
> In the background, the OS transmits the data that you wrote over the
> slow modem.
>
> What's the problem?
That's the whole purpose of my program.... Email clients implement
protocols and the protocols in question usually talk about, then listen,
then talk a bit, etc. I don't know whether certain outcomes were successful
or not until the data is fully written to the far end, and if I bufffer the
whole lot then the client might get bored and assume failure.
OK, your suggestion below was to "assume" success and then email any
failures. However, this fails for a number of reasons, for example, under
windows (and other OS) the email client can dial and hangup the phone
automatically, so what will happen is that the email client will assume that
everything is done and hangup the phone, however, we haven't finished
writing yet...
Also, consider IMAP where we want to move a message to a subfolder, etc.
You don't really want to fudge success under those circumstances and start
trying to email warnings (email could get lost, ie the move fails, but the
delete succeeds...)
Anyway, lots of reasons. However, the whole point of this email proxy is to
reduce the latency wherever possible.
> Thus, no matter how slowly you read the data, your email client will
> manage to write all of it's to you nearly instantly, and will then be
> waiting for a response.
Yep, and will get bored or hangup the phone if we don't keep it
interested....
> It seems to me that you should just read the data as fast as you can,
> and write to the client an 'ok' message of some sort, and close the
> client's connection. If, after the data fully transmits over the slow
> modem, you discover that there was an error, send yourself an email
> saying so.
Not always possible in many protocols.
> Syswrite always accepts *at least some* data, because if the OS buffer
> is full, it will of course *block* until the OS buffer is *no longer*
> full. I have not ever said anything to the contrary.
Erm? Perhaps we are talking cross purposes. My point was that win32 NEVER
blocks? It just keeps accepting data forever...
However, can_write returns false after a certain amount of data is written,
however, this doesn't cause blocking to occur...
> If you call $socket->sync, then your program will block until the OS
> buffer is empty, if your operating system implements the fsync(fd) C
> function. If your email client calls this occasionally on the handle to
> you, and if you call it occasionally on the handle to the slow modem,
> then you might be able to avoid whatever timeout problems you're having.
Doesn't seem to be implemented on win32. At least not under ActiveState
perl... I will do a google search to see if there is a workaround.
However, I need to multiplex several simultaneous sockets so I probably have
little use for this.
Thanks for you help. The key thing is how to write ONLY enough that the
slow socket *ought* to start blocking (in fact it doesn't ever block on
win32, but I would like to *simulate* writing just enough that under linux
(say) it would *just* avoid blocking)
Ed
------------------------------
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 4607
***************************************