[17182] in Perl-Users-Digest
Perl-Users Digest, Issue: 4594 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 12 11:06:22 2000
Date: Thu, 12 Oct 2000 08:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <971363110-v9-i4594@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 12 Oct 2000 Volume: 9 Number: 4594
Today's topics:
'my' quickie <zoo.tv@NOSPAMbtinternet.com>
Re: 'my' quickie <mauldin@netstorm.net>
Re: 'my' quickie (Rafael Garcia-Suarez)
Re: 'my' quickie <mauldin@netstorm.net>
Re: Altered files sometimes go empty! <bart.lateur@skynet.be>
ANNOUNCE: Bit::Vector 6.0 <sb@sdm.de>
Re: challenging problem (Gwyn Judd)
Re: challenging problem paceman97@aol.com
Re: Declaring variable (M.J.T. Guy)
Re: Defining an Operator (not overloading) <ren.maddox@tivoli.com>
Re: hoe to alter @INC? <cen09220@centurytel.net>
Re: hoe to alter @INC? <mauldin@netstorm.net>
Re: hoe to alter @INC? <jeffp@crusoe.net>
Re: hoe to alter @INC? (Rafael Garcia-Suarez)
Re: How to remove all white spaces <ren.maddox@tivoli.com>
Re: html form <jeff@vpservices.com>
Re: imagename.x and imagename.y confusion <ren.maddox@tivoli.com>
Re: Invoking ssh from a script (NP)
K-Shell to PERL converter nandagopalj@hotmail.com
Re: modifying elements in an each() loop (M.J.T. Guy)
Re: passing and returning hashes <ren.maddox@tivoli.com>
Re: passing info with POST <pleduc@ca.ibm.com>
Re: passing info with POST <jeff@vpservices.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 12 Oct 2000 14:38:26 +0100
From: <zoo.tv@NOSPAMbtinternet.com>
Subject: 'my' quickie
Message-Id: <xfjF5.2379$_B5.23756@NewsReader>
Hi,
Just a quickie... is the first example here less eficient than the second
(i.e. does declaring the variables each loop take more time/memory to
complete?
foreach (@arr) {
my ($a,$b) = split /,/;
...etc...
}
or:
my ($a,$b);
foreach (@arr) {
($a,$b) = split /,/;
...etc...
}
Basically, I have been doing things the second way, but is it neccesary?
Cheers,
Pete
------------------------------
Date: Thu, 12 Oct 2000 14:12:24 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: 'my' quickie
Message-Id: <39E5C672.FA657289@netstorm.net>
zoo.tv@NOSPAMbtinternet.com wrote:
>
> Hi,
>
> Just a quickie... is the first example here less eficient than the second
> (i.e. does declaring the variables each loop take more time/memory to
> complete?
>
> foreach (@arr) {
> my ($a,$b) = split /,/;
> ...etc...
> }
>
> or:
>
> my ($a,$b);
> foreach (@arr) {
> ($a,$b) = split /,/;
> ...etc...
> }
>
> Basically, I have been doing things the second way, but is it neccesary?
>
First, a word to the wise. As a general rule, avoid decalaring $a and
$b with my, because they are 'special' global package variables used by
sort and if you "my" them, you can kill your sort routine.
To your question: the issue is not one of efficiency, but the scope of
the variables. Your first example declares two variables whose scope is
the foreach loop, and which cease to exist when it is finished. Your
second example declares two variables that continue to exist after the
foreach loop is finished, and will contain whatever values were assigned
to them during the foreach loop. Try the following and see what
happens:
my ($cat,$dog) = qw(Teiwaz Loki);
&dosomething;
print "$cat $dog\n";
sub dosomething {
my ($cat,$dog) = qw(Keisha Fido);
print "$cat $dog\n";
}
-- Jim
------------------------------
Date: Thu, 12 Oct 2000 14:16:30 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: 'my' quickie
Message-Id: <slrn8ubib1.2nh.rgarciasuarez@rafael.kazibao.net>
zoo.tv@NOSPAMbtinternet.com wrote in comp.lang.perl.misc:
>Hi,
>
>Just a quickie... is the first example here less eficient than the second
>(i.e. does declaring the variables each loop take more time/memory to
>complete?
>
>foreach (@arr) {
> my ($a,$b) = split /,/;
> ...etc...
>}
>
>or:
>
>my ($a,$b);
>foreach (@arr) {
> ($a,$b) = split /,/;
> ...etc...
>}
There is a fine and easy-to-use Benchmark module designed for questions
like this. See 'perldoc Benchmark'.
I'm not convinced that there is a significant performance difference
between the two constructions you propose.
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Thu, 12 Oct 2000 14:54:45 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: 'my' quickie
Message-Id: <39E5D05D.B7000B2@netstorm.net>
Jim Mauldin wrote:
>
> zoo.tv@NOSPAMbtinternet.com wrote:
> >
> > Hi,
> >
> > Just a quickie... is the first example here less eficient than the second
> > (i.e. does declaring the variables each loop take more time/memory to
> > complete?
> >
> > foreach (@arr) {
> > my ($a,$b) = split /,/;
> > ...etc...
> > }
> >
> > or:
> >
> > my ($a,$b);
> > foreach (@arr) {
> > ($a,$b) = split /,/;
> > ...etc...
> > }
> >
> > Basically, I have been doing things the second way, but is it neccesary?
> >
>
> First, a word to the wise. As a general rule, avoid decalaring $a and
> $b with my, because they are 'special' global package variables used by
> sort and if you "my" them, you can kill your sort routine.
>
> To your question: the issue is not one of efficiency, but the scope of
> the variables. Your first example declares two variables whose scope is
> the foreach loop, and which cease to exist when it is finished. Your
> second example declares two variables that continue to exist after the
> foreach loop is finished, and will contain whatever values were assigned
> to them during the foreach loop.
[snip]
Further thoughts: if you're clear on the scope issue, then to answer
the efficiency question, consider the following:
my @animals = qw(cat dog);
foreach (@animals) {
my $pet = $_;
print \$pet, "\n"; # reference to $pet
}
print out:
SCALAR(0x87651dc)
SCALAR(0x87651dc)
In other words, perl is smart enough to create a variable once inside
the loop and reuse it as many times as necessary. It's not like it's
creating a new variable on every iteration. So the penalty is
essentially the same as using 'my' any other place.
-- Jim
------------------------------
Date: Thu, 12 Oct 2000 14:07:05 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Altered files sometimes go empty!
Message-Id: <m7hbusckt82mqpnfg8q1tg8qpb01o9i9ft@4ax.com>
madman wrote:
>wow... a perl god.
>
>I'm reading one of your books now. Pretty good, just wish I was smarter.
Have you seen Randal's website? His collection of magazine columns
(WebTechniques, UnixReview, Linux Magazine) is "pretty good" too.
<http://web.stonehenge.com/merlyn/>
--
Bart.
------------------------------
Date: Wed, 11 Oct 2000 10:35:39 +0200 (MET DST)
From: Steffen Beyer <sb@sdm.de>
Subject: ANNOUNCE: Bit::Vector 6.0
Message-Id: <subhihritj4kea@corp.supernews.com>
=====================================
Package "Bit::Vector" Version 6.0
=====================================
This package is available for download from my web site at
http://www.engelschall.com/u/sb/download/
or from any CPAN (= "Comprehensive Perl Archive Network") mirror server:
http://www.perl.com/CPAN/authors/id/S/ST/STBEY/
Prerequisites:
--------------
Perl version 5.000 or higher, and an ANSI C compiler. (!)
^^^^^^
If you compile under Windows, note that you will need
exactly the same compiler your Perl itself was compiled
with! (This is also true for Unix, but rarely a problem.)
Moreover, you usually cannot build any modules under
Windows 95/98, the Win 95/98 command shell is too dumb.
You will need the Windows NT command shell ("cmd.exe")
or the "4DOS" shell.
If you're using ActivePerl, go look at ActiveState's
web site whether they already have version 6.0 of this
module available!
http://www.activestate.com/ppmpackages/5.005/zips/
http://www.activestate.com/ppmpackages/5.6/zips/
What's new in version 6.0:
--------------------------
+ Splitted the Vector.pm module; separated XS and overloaded Perl
part for improved performance (reduces loading time for XS part).
(See also benchmark.pl in subdirectory "examples".)
+ Corrected the handling of numerical overflow in arithmetic methods
("add()", "subtract()", "Multiply()", "from_Dec()", "new_Dec()").
+ Methods "add()" and "subtract()" now return the carry as well as
the overflow flag if called in list context (only the carry in
scalar context, as before).
+ Added two new methods "inc()" and "dec()", which return the overflow
flag (whereas "increment()" and "decrement()" return the carry flag).
The new methods also allow to copy-and-increment/decrement in addition
to in-place operation.
+ Methods "from_Dec()" and "new_Dec()" now allow you to enter large
positive numbers which will have the MSB set (this was forbidden
previously because these numbers are considered to be negative in
two's complement binary representation).
Abstract:
---------
Bit::Vector is an efficient C library which allows you to handle
bit vectors, sets (of integers), "big integer arithmetic" (e.g.
for cryptography) and boolean matrices, all of arbitrary sizes.
The library is efficient (in terms of algorithmical complexity)
and therefore fast (in terms of execution speed) for instance
through the widespread use of divide-and-conquer algorithms.
The package also includes an object-oriented Perl module for
accessing the C library from Perl, and features overloaded
operators for maximum ease of use.
The C library can nevertheless be used stand-alone, without Perl.
Legal issues:
-------------
This package with all its parts is
Copyright (c) 1995 - 2000 by Steffen Beyer.
All rights reserved.
This package is free software; you can use, modify and redistribute
it under the same terms as Perl itself, i.e., under the terms of
the "Artistic License" or the "GNU General Public License".
The C library at the core of this Perl module can additionally
be used, modified and redistributed under the terms of the
"GNU Library General Public License".
Please refer to the files "Artistic.txt", "GNU_GPL.txt" and
"GNU_LGPL.txt" in this distribution, respectively, for details!
Author's note:
--------------
If you have any questions, suggestions or need any assistance, please
let me know!
Please do send feedback, this is essential for improving this module
according to your needs!
I hope you will find this module beneficial.
Yours sincerely,
--
Steffen Beyer <sb@engelschall.com>
http://www.engelschall.com/u/sb/whoami/ (Who am I)
http://www.engelschall.com/u/sb/gallery/ (Fotos Brasil, USA, ...)
http://www.engelschall.com/u/sb/download/ (Free Perl and C Software)
------------------------------
Date: Thu, 12 Oct 2000 13:53:07 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: challenging problem
Message-Id: <slrn8ubgi0.dho.tjla@thislove.dyndns.org>
I was shocked! How could paceman97@aol.com <paceman97@aol.com>
say such a terrible thing:
>There is a script that takes simple numbers (1-8000) as input and based
>on that sends you to some URL. Is there a way for me to get a list of
>those URL's ?
>Perhaps connect to each one of those url's and find out where its
>leading? (i tried that and it didnt work for me)
Beats me. You need to define the problem a lot better than that I'm
afraid.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The bomb will never go off. I speak as an expert in explosives.
-- Admiral William Leahy, U.S. Atomic Bomb Project
------------------------------
Date: Thu, 12 Oct 2000 10:55:42 -0400
From: paceman97@aol.com
Subject: Re: challenging problem
Message-Id: <39E5D0EE.DC7B932A@aol.com>
I'm using LWP to connect to a link that looks like this
....script.pl?linkid=5
and it connects me to some url that is specified in that script but how can
i find out which url i connected to.
paceman97@aol.com wrote:
> There is a script that takes simple numbers (1-8000) as input and based
> on that sends you to some URL. Is there a way for me to get a list of
> those URL's ?
> Perhaps connect to each one of those url's and find out where its
> leading? (i tried that and it didnt work for me)
>
> Maybe there is some way to do it through Unix ? or another scripting
> language.
>
> Please help.
------------------------------
Date: 12 Oct 2000 13:58:51 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Declaring variable
Message-Id: <8s4g2r$s9v$1@pegasus.csx.cam.ac.uk>
Bernie Cosell <bernie@fantasyfarm.com> wrote:
>Jim Mauldin <mauldin@netstorm.net> wrote:
>}
>} As a general rule, the 'strict' pragma requires that variables either:
>}
>} 1. be declared using the my (or our) function, or
>} 2. be referred to using their fully qualified package name, e.g.
>} $main::variable.
>
>Or
> 3. declared via a "use vars qw(v1 v2 v3 ...)"
Or
4. imported from another module, e.g. "use MyModule qw( $variable );"
Mike Guy
------------------------------
Date: 11 Oct 2000 22:40:18 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Defining an Operator (not overloading)
Message-Id: <m3snq24ti5.fsf@dhcp11-177.support.tivoli.com>
Daniel Yacob <yacob@rcn.com> writes:
> $string = $prefix . $string;
>
> which happens to be a common occurance for me, I expect others as well.
Not an answer to your question, but I thought it worth pointing out
that you can use:
substr($string, 0, 0, $prefix);
or
substr($string, 0, 0) = $prefix;
Obviously, this isn't as syntactically pleasing (YMMV), but at least
it avoids the unnecessary copy of $string, so it should be more
efficient. [apparently NOT... see below]
And if efficiency doesn't matter, you could also use:
$string =~ s/^/$prefix/;
Here's a quick benchmark. Note that making the test strings larger
could have a significant impact, though I doubt it would change the
rankings.
#!/usr/local/bin/perl -w
use strict;
use Benchmark;
our $str = "boy";
our $prefix = "cow";
timethese -5, {
COPY => sub { my $string = $str; $string = $prefix . $str },
SUBSTR_4 => sub { my $string = $str; substr($string, 0, 0, $prefix) },
SUBSTR_3 => sub { my $string = $str; substr($string, 0, 0) = $prefix },
REGEX => sub { my $string = $str; $string =~ s/^/$prefix/ }
};
__END__
Benchmark: running COPY, REGEX, SUBSTR_3, SUBSTR_4, each for at least 5 CPU seconds...
COPY: 5 wallclock secs ( 5.09 usr + 0.00 sys = 5.09 CPU) @ 396070.53/s (n=2015999)
REGEX: 5 wallclock secs ( 5.23 usr + 0.00 sys = 5.23 CPU) @ 76955.83/s (n=402479)
SUBSTR_3: 5 wallclock secs ( 5.25 usr + 0.04 sys = 5.29 CPU) @ 88095.46/s (n=466025)
SUBSTR_4: 7 wallclock secs ( 5.76 usr + -0.12 sys = 5.64 CPU) @ 439930.85/s (n=2481210)
I'm a bit surprised that the 3-argument substr is so much slower,
though I guess it makes sense. The regex, as expected, is the
slowest. I'm also a bit surprised that the copy is so close in speed
to the 4-argument split.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 12 Oct 2000 09:11:55 -0400
From: cen09220 <cen09220@centurytel.net>
Subject: Re: hoe to alter @INC?
Message-Id: <39E5B89B.37AE6762@centurytel.net>
Rafael Garcia-Suarez wrote:
>
> Werner, Wolfgang wrote in comp.lang.perl.misc:
> >hi,
> >how can i change @INC?
> >i wan to have a new dir for modules
> >thans
>
> The preferred way to do this is to add at the beggining of your scripts:
> use lib '/new/dir/for/modules';
Why is that better than pushing the path onto @INC?
------------------------------
Date: Thu, 12 Oct 2000 13:40:06 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: hoe to alter @INC?
Message-Id: <39E5BEE0.1A0006B8@netstorm.net>
cen09220 wrote:
>
> Rafael Garcia-Suarez wrote:
> >
> > Werner, Wolfgang wrote in comp.lang.perl.misc:
> > >hi,
> > >how can i change @INC?
> > >i wan to have a new dir for modules
> > >thans
> >
> > The preferred way to do this is to add at the beggining of your scripts:
> > use lib '/new/dir/for/modules';
>
> Why is that better than pushing the path onto @INC?
Modules specified by a 'use' declaration are loaded during compilation,
before the program begins to execute. So even if you push something
onto @INC as the very first statement of your program, it's already too
late.
-- Jim
------------------------------
Date: Thu, 12 Oct 2000 09:46:06 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: hoe to alter @INC?
Message-Id: <Pine.GSO.4.21.0010120942280.14163-100000@crusoe.crusoe.net>
[posted & mailed]
On Oct 12, cen09220 said:
>Rafael Garcia-Suarez wrote:
>>
>> Werner, Wolfgang wrote in comp.lang.perl.misc:
>> >how can i change @INC?
>>
>> The preferred way to do this is to add at the beggining of your scripts:
>> use lib '/new/dir/for/modules';
>
>Why is that better than pushing the path onto @INC?
Because (as perldoc lib tells you) it will add MORE than one directory to
@INC (specifically, the directory you requested, and an architect-specific
directory) at COMPILE-TIME, which is when it's needed:
use lib "my_modules";
use MyMod;
Doing this:
push @INC, "my_modules";
use MyMod;
will result in a compile-time error, since 'use' is seen LONG before
'push'. Sure, you could wrap it in a BEGIN block:
BEGIN { push @INC, "my_modules" }
use MyMod;
but compare that with the amount of work it takes to just say
use lib "my_modules";
It's 12 less characters, man! *12*
--
Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http://www.perlarchive.com/
CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/
------------------------------
Date: Thu, 12 Oct 2000 13:48:33 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: hoe to alter @INC?
Message-Id: <slrn8ubgmk.2ik.rgarciasuarez@rafael.kazibao.net>
cen09220 wrote in comp.lang.perl.misc:
>Rafael Garcia-Suarez wrote:
>>
>> Werner, Wolfgang wrote in comp.lang.perl.misc:
>> >hi,
>> >how can i change @INC?
>> >i wan to have a new dir for modules
>> >thans
>>
>> The preferred way to do this is to add at the beggining of your scripts:
>> use lib '/new/dir/for/modules';
>
>Why is that better than pushing the path onto @INC?
One reason is: it's more concise. A second reason is given by the
documentation (manpage on my system) for lib.pm : it checks existence of
architecture-specific directories (e.g. yourdir/i386-linux/auto) and
adds them automatically, which can be convient if you have xs modules
installed in a specific path.
--
#!/usr/bin/perl -p
BEGIN { *ARGV=*DATA }
__END__
Just another Perl hacker,
------------------------------
Date: 11 Oct 2000 22:55:41 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: How to remove all white spaces
Message-Id: <m3hf6i4ssi.fsf@dhcp11-177.support.tivoli.com>
James Taylor <james@NOSPAM.demon.co.uk> writes:
> In article <Pine.GSO.4.21.0010111018460.14163-100000@crusoe.crusoe.net>,
> Jeff Pinyan <URL:mailto:jeffp@crusoe.net> wrote:
> >
> > Either use s/// or tr///. I'd suggest
> >
> > $string =~ tr/\r\n\t\f //d;
> >
> > for speed.
>
> Why is tr/\r\n\t\f //d; considered faster than s/\s+//; ?
>
> I would have thought that the tr///d would have to shuffle the string
> tail down in memory for each char it removed whereas the s/// only
> needs to do so for each block of chars it removes. I obviously don't
> know anything about how perl implements this internally so can you
> explain the difference? Thanks.
The basic answer is that it is a much more specialized function, so it
can do its job more efficiently. You are correct, however, that if
there are large chunks to remove, then the "+" aspect will eventually
win out. However, based on my benchmark results, the chunks have to
get *very* large....
perl -MBenchmark <<'__END__' [~]
$str = (' ' x 100 . "asdfasdf") x 1000;
timethese -5, { S => sub { $_ = $str; s/\s+//g },
TR => sub { $_ = $str; tr/ \t\n\r\f//d } }
__END__
Benchmark: running S, TR, each for at least 5 CPU seconds...
S: 5 wallclock secs ( 5.34 usr + 0.00 sys = 5.34 CPU) @ 302.43/s (n=1615)
TR: 6 wallclock secs ( 5.13 usr + 0.15 sys = 5.28 CPU) @ 407.39/s (n=2151)
perl -MBenchmark <<'__END__' [~]
$str = (' ' x 1000 . "asdfasdf") x 100;
timethese -5, { S => sub { $_ = $str; s/\s+//g },
TR => sub { $_ = $str; tr/ \t\n\r\f//d } }
__END__
Benchmark: running S, TR, each for at least 5 CPU seconds...
S: 6 wallclock secs ( 5.30 usr + 0.01 sys = 5.31 CPU) @ 548.21/s (n=2911)
TR: 5 wallclock secs ( 5.27 usr + 0.00 sys = 5.27 CPU) @ 457.69/s (n=2412)
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 12 Oct 2000 07:15:45 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: html form
Message-Id: <39E5C791.369456A3@vpservices.com>
[in the future, please put your response *after* a suitably trimmed
version of the message you are responding to, thanks]
Michael Salleo wrote:
>
> Jeff Zucker wrote:
>
> > Michael Salleo wrote:
> > >
> > > how do i carry over (post) the values from a html from to a cgi script?
> >
> > You use the CGI.pm module. The module and a very comprehensive
> > documentation for it comes standard with modern perls.
>
> how do i call these fields individually? to use with math functions.
As I said, you do it with CGI.pm and you start by reading the
documentation that comes with it. The param() method is used to access
form fields. It accesses both single-value fields like a text input
field and multi-value fields like a checkbox group so you need to be
careful how you call it. There are many examples in the documentation.
Please review the documentation on param() and try it out and if you
experience difficulties come back here showing us what you tried, what
you expected to happen, and what happened instead.
--
Jeff
------------------------------
Date: 11 Oct 2000 22:58:39 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: imagename.x and imagename.y confusion
Message-Id: <m3d7h64snk.fsf@dhcp11-177.support.tivoli.com>
John Tulabing <jtulabing@onebox.com> writes:
> $dummy = $FORM{ImageName.x};
Perhaps you are asking about something else, but this line doesn't do
what you think it does. The magic quoting that occurs for hash keys
only works on things that look like identifiers (same as for "=>").
Having that "." in there forces this to be evaluated as an
expression.
Use $FORM{"ImageName.x"} instead.
Note that use of warnings and/or strict would have caught this
problem.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 12 Oct 2000 14:16:20 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: Invoking ssh from a script
Message-Id: <UIjF5.26905$Ly1.378306@news5.giganews.com>
esper@news.visi.com wrote:
:
: Any other options? Aside from expect's (IMO) clumsy syntax, I'm not going to
: know about the remote system in the sort of detail that expect seems to...
: well... expect. (Some servers ask for passwords, some don't. Perhaps the
Since Expect.pm supports '-re', you should be able to match what the
remote host is sending you with a regex[p].
: host key won't be recognized, so there'll be a prompt for that before a
: password is requested. And heaven help us if we're connecting to an account
: with a nonstandard shell prompt...)
You should be able to test these conditions with Expect.pm.
Basically, what you're proposing will likely raise the same issues no
matter which method you use.
: I could, at least in theory, do this by cutting and pasting from Expect
: until it works. I'd much rather understand what I'm doing.
Or, you could just use chatX.pl or Comm.pl. :-) Seriously, I'd suggest
reviewing both the Expect.pm doc and examples AND the documentation for
the Tcl-based Expect product. That should really clear things up for
you.
--
Nathan Patwardhan
nvp@noopy.org
"The good place for all who are Noopies"
------------------------------
Date: Thu, 12 Oct 2000 14:14:08 GMT
From: nandagopalj@hotmail.com
Subject: K-Shell to PERL converter
Message-Id: <8s4gv9$ede$1@nnrp1.deja.com>
Hello:
Does anyone know of a freeware to convert k-shell
scripts into PERL?
Your help is appreciated.
-Thanks
Nan.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 12 Oct 2000 14:06:21 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: modifying elements in an each() loop
Message-Id: <8s4ggt$soq$1@pegasus.csx.cam.ac.uk>
John Salmon <jsalmon@thesalmons.org> wrote:
>
>man perlfunc says:
>
> each HASH
> <snip>
> If
> you add or delete elements of a hash while you're
> iterating over it, you may get entries skipped or
> duplicated, so don't.
"add or delete elements of a hash" would perhaps be more precisely worded
as "add to or delete from the set of keys in the hash". Changing
the value associated with a given key doesn't count.
Mike Guy
------------------------------
Date: 11 Oct 2000 21:54:37 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: passing and returning hashes
Message-Id: <m3wvfe4vma.fsf@dhcp11-177.support.tivoli.com>
"Dale Emmons" <dale@emmons.dontspamme.com> writes:
> hello,
>
> I'd like to create a subroutine that takes a hash of values as its arguments
> and returns a hash as its value, something like:
>
> %fbsubs_returned_hash = fbsub( foo => 'fooit', bar => 'barit' );
>
> print $fbsubs_returned_hash{foobar};
>
> sub fbsub {
>
> my ($fb, $bf);
>
> ### do something... to give $fb & $bf values from $_{foo} and $_{bar}
>
> return ( foobar => $fb, barfoo => $bf );
> }
>
> I know that this probably isn't close to what would work, but I hope you
> understand what I'm getting at?
Actually, it is pretty close to one of the methods of doing this.
Just change the subroutine as:
sub fbsub {
my %fb = @_;
### do something to %fb
return %fb;
}
The key is to remember that a hash can be treated as a list.
The other, more efficient, way to do this (depending on the exact
need) is:
#!/usr/local/bin/perl -w
use strict;
my $fbsubs_returned_hash_ref = fbsub( { foo => 'fooit', bar => 'barit' });
print $fbsubs_returned_hash_ref->{foobar}, "\n";
sub fbsub {
my $fb_ref = shift;
### do something to %$fb_ref, such as:
$fb_ref->{foobar} = $fb_ref->{foo};
delete $fb_ref->{foo};
$fb_ref->{barfoo} = $fb_ref->{bar};
delete $fb_ref->{bar};
# this seems like too many hoops to jump through, but I don't
# want to rebuild the entire hash, and nothing else comes to
# mind. And my brain refused to cough up a way to make that
# a slice. I suppose this would be a little better:
# delete $fb_ref->{$_} for qw(foo bar);
return $fb_ref;
}
__END__
Note also that this method changes the original hash, which may be
good or bad depending on how it is to be used.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 12 Oct 2000 09:16:31 -0400
From: Paul Leduc <pleduc@ca.ibm.com>
Subject: Re: passing info with POST
Message-Id: <39E5B9AF.25ACF4DC@ca.ibm.com>
Mark-Jason Dominus wrote:
> I strongly recommend that instead of this:
>
> <form method="POST" action="/cgi-bin/sample.cgi?name=value1">
>
> you use this:
>
> <form method="POST" action="/cgi-bin/sample.cgi">
> <input type=hidden name="name" value="value1">
> ...
Holy cow!.. sorry, I didn't mean to start an incident. Was just looking for
some simple advice. And my apologies if some of you felt that my append was
not appropriate for this group.. I thought that since it involved the perl
CGI module (which is used with forms :-) it was on topic.
I was given advice locally, that said I could pass this information in the
manner above.. obviously it was wrong. The hidden field is the way to go.
Alternatively, I could use the value of the button itself.
Thanks for all the responses.. I have the solution working fine now.
------------------------------
Date: Thu, 12 Oct 2000 07:24:54 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: passing info with POST
Message-Id: <39E5C9B6.B3401B79@vpservices.com>
Paul Leduc wrote:
>
> And my apologies if some of you felt that my append was
> not appropriate for this group.. I thought that since it involved the perl
> CGI module (which is used with forms :-) it was on topic.
Well, the thing is that the CGI module (and Perl in general) only prints
the HTML you tell it to print. So if you don't know how to do something
on the HTML end (like in this case, how to create a form with two
buttons, or two forms with a button each :-)) then it's the HTML part
you need advice on, not the Perl part. If you noticed, none of the
answers given to your question had Perl or CGI.pm syntax in them -- they
all invovled different variations on the <form> and <input> tags of
*HTML*. Generally, after you compose a question, look at it and see if
the things you are asking about are about Perl syntax (e.g. print() or
open() or s///) or about HTML syntax (buttons,tags,forms) or about CGI
process (submitting, etc). Only the first of those belong in this
newsgroup.
--
Jeff
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4594
**************************************