[16137] in Perl-Users-Digest
Perl-Users Digest, Issue: 3549 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 10 15:12:25 2000
Date: Mon, 10 Jul 2000 12:12:13 -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: <963256333-v9-i3549@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 10 Jul 2000 Volume: 9 Number: 3549
Today's topics:
Array help <howard.jones@icl.com>
Re: Array help (Rafael Garcia-Suarez)
Re: Array help <foo@bar.va>
Re: Array help (Rafael Garcia-Suarez)
Re: Array help <billy@arnis-bsl.com>
Re: Array help (Tad McClellan)
Re: Array help <lr@hpl.hp.com>
Re: Array help <dskillin@home.com>
Associative Arrays in Perl (Martin Doering)
Re: Associative Arrays in Perl (Tad McClellan)
Re: attach file in e-mail <hb@mediastudio.de>
Attn PerlGurus: implementing transaction with MySQL <thierry.metoudi@netcourrier.com>
Re: Attn PerlGurus: implementing transaction with MySQL (Abigail)
Re: Attn PerlGurus: implementing transaction with MySQL (Robert Hallgren)
Re: Attn PerlGurus: implementing transaction with MySQL <thunderbear@bigfoot.com>
Re: Attn PerlGurus: implementing transaction with MySQL <gellyfish@gellyfish.com>
batch ping <tkriz@ats.mcleodusa.net>
Re: batch ping <Petri_member@newsguy.com>
Re: batch ping <gellyfish@gellyfish.com>
Re: batch ping <godzilla@stomp.stomp.tokyo>
Re: batch ping <adetalabi@clara.co.uk>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 5 Jul 2000 16:42:30 +0100
From: "Howard Jones" <howard.jones@icl.com>
Subject: Array help
Message-Id: <8jvl0d$fjj$1@gxsn.com>
Hi,
I'm loading an array with output from the unix 'ls -t' command to populate
it with the files in a directory, as so:
@Filename_array=(<'ls -t foo*'>);
File names beginning foo* are loaded into the array. This works fine with
Perl 5.005_02 on AIX (which is the pre-compiled version available for AIX
4.2.1).
I'm running the same code on the compiled 'stable' version from the Perl web
site (Perl 5.6.0) and the command doesn't work, it simply loads the array
with 'ls' in the first element and '-t' in the second. It does not expand
the command for me.
Can anyone offer an alternative solution.
Thankyou.
------------------------------
Date: Wed, 05 Jul 2000 15:46:35 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Array help
Message-Id: <slrn8m6mb8.4fu.rgarciasuarez@rafael.kazibao.net>
Howard Jones wrote in comp.lang.perl.misc:
>Hi,
>
>I'm loading an array with output from the unix 'ls -t' command to populate
>it with the files in a directory, as so:
>
>@Filename_array=(<'ls -t foo*'>);
@Filename_array='ls -t foo*';
should return the result you want.
You can also use opendir and readdir, and sort the files by yourself.
--
Rafael Garcia-Suarez
------------------------------
Date: Wed, 05 Jul 2000 18:02:06 +0200
From: Marco Natoni <foo@bar.va>
Subject: Re: Array help
Message-Id: <39635BFE.505E9C28@bar.va>
Rafael,
Rafael Garcia-Suarez wrote:
>> I'm loading an array with output from the unix 'ls -t' command
>> to populate it with the files in a directory, as so:
>> @Filename_array=(<'ls -t foo*'>);
> @Filename_array='ls -t foo*';
> should return the result you want.
...and
@Filename=`ls -t foo*`;
returns the best possible results... ;)
> You can also use opendir and readdir, and sort the files by
> yourself.
Of course, making, for example, his script portable across platforms
not having the 'ls' command or the file globbing.
Best regards,
Marco
------------------------------
Date: Wed, 05 Jul 2000 16:10:40 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Array help
Message-Id: <slrn8m6nod.4ih.rgarciasuarez@rafael.kazibao.net>
Marco Natoni wrote in comp.lang.perl.misc:
>Rafael,
>
>Rafael Garcia-Suarez wrote:
>>> I'm loading an array with output from the unix 'ls -t' command
>>> to populate it with the files in a directory, as so:
>>> @Filename_array=(<'ls -t foo*'>);
>> @Filename_array='ls -t foo*';
>> should return the result you want.
>
>...and
>
> @Filename=`ls -t foo*`;
>
>returns the best possible results... ;)
I should definitively increase my font size.
--
Rafael Garcia-Suarez
------------------------------
Date: Wed, 05 Jul 2000 16:42:32 GMT
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: Array help
Message-Id: <8jvohk$ft7$1@nnrp1.deja.com>
In article <8jvl0d$fjj$1@gxsn.com>,
"Howard Jones" <howard.jones@icl.com> wrote:
> Hi,
>
> I'm loading an array with output from the unix 'ls -t' command to
populate
> it with the files in a directory, as so:
>
> @Filename_array=(<'ls -t foo*'>);
>
> File names beginning foo* are loaded into the array. This works fine
with
> Perl 5.005_02 on AIX (which is the pre-compiled version available for
AIX
> 4.2.1).
>
> I'm running the same code on the compiled 'stable' version from the
Perl web
> site (Perl 5.6.0) and the command doesn't work, it simply loads the
array
> with 'ls' in the first element and '-t' in the second. It does not
expand
> the command for me.
>
IMHO, the above code could not work.
If you need globbing, then simply use:
@filename_array = <foo*>;
If you want use ls output, then use backticks:
@filename_array = `ls -t foo*`;
I'd recommend opendir/readdir/closedir anyway.
Hope this helps.
Ilja.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 5 Jul 2000 11:29:44 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Array help
Message-Id: <slrn8m6l38.h51.tadmc@magna.metronet.com>
On Wed, 5 Jul 2000 16:42:30 +0100, Howard Jones <howard.jones@icl.com> wrote:
>
>I'm loading an array with output from the unix 'ls -t' command to populate
>it with the files in a directory, as so:
>
>@Filename_array=(<'ls -t foo*'>);
You are using a wrench to drive a nail.
Using a glob to execute external programs is exceedingly strange.
Use backticks (backwards single quotes) to capture the output
of an external command:
my @Filename_array = `ls -t foo*`;
chomp @Filename_array;
or
chomp(my @Filename_array = `ls -t foo*`);
or
chomp(my @Filename_array = qx/ls -t foo*/);
>File names beginning foo* are loaded into the array. This works fine with
>Perl 5.005_02 on AIX (which is the pre-compiled version available for AIX
>4.2.1).
File globbing executes in a shell. Apparently your shell could
find the 'ls' command to run somehow. I cannot make my system
do that...
>I'm running the same code on the compiled 'stable' version from the Perl web
>site (Perl 5.6.0) and the command doesn't work,
File globbing is not done in the shell anymore, starting with 5.6.
>it simply loads the array
>with 'ls' in the first element and '-t' in the second. It does not expand
>the command for me.
>
>Can anyone offer an alternative solution.
`backticks`, if you insist on running an external program.
But it is nearly always "better" to avoid "shelling out" to
external commands, when you can easily get what you want
in native Perl.
So it's "best" to avoid both globbing _and_ external programs:
opendir(CWD, '.') || die "could not open current directory $!";
my @Filename_array = sort { -M $a <=> -M $b } grep /^foo/, readdir CWD;
closedir(CWD);
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 5 Jul 2000 13:00:23 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Array help
Message-Id: <MPG.13cd33b5f23929d498abaa@nntp.hpl.hp.com>
In article <slrn8m6l38.h51.tadmc@magna.metronet.com> on Wed, 5 Jul 2000
11:29:44 -0400, Tad McClellan <tadmc@metronet.com> says...
...
> opendir(CWD, '.') || die "could not open current directory $!";
> my @Filename_array = sort { -M $a <=> -M $b } grep /^foo/, readdir CWD;
> closedir(CWD);
I can't let that go by without noting that for a 'large' directory the
sort will run slowly, because the files in the directory are stat-ted
many more times than needed. See perlfaq4 or `perldoc -f sort` or other
documentation resources for ways to do this sort more efficiently.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 06 Jul 2000 09:09:41 GMT
From: "Daniel L Quigley-Skillin" <dskillin@home.com>
Subject: Re: Array help
Message-Id: <p1Y85.24688$_54.409462@news1.rdc1.md.home.com>
Don't forget...
@array=qx(command);
Your case...
@Filename_array=qx(ls -t foo*);
Easiest way I can think of without having to remember too much syntax.
D-
> >> I'm loading an array with output from the unix 'ls -t' command
> >> to populate it with the files in a directory, as so:
> >> @Filename_array=(<'ls -t foo*'>);
> > @Filename_array='ls -t foo*';
> > should return the result you want.
>
> ...and
>
> @Filename=`ls -t foo*`;
>
> returns the best possible results... ;)
>
> > You can also use opendir and readdir, and sort the files by
> > yourself.
>
> Of course, making, for example, his script portable across platforms
> not having the 'ls' command or the file globbing.
>
------------------------------
Date: Tue, 04 Jul 2000 14:02:24 GMT
From: doeringm@gmx.de (Martin Doering)
Subject: Associative Arrays in Perl
Message-Id: <3961ecb8.112361797@news.mn.man.de>
Hi!
How does perl get/store normal variable values ($xxx) internally? Are
they stored in an associative array, or are they stored in a more
C-like manner?
Martin Döring
------------------------------
Date: Wed, 5 Jul 2000 23:39:02 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Associative Arrays in Perl
Message-Id: <slrn8m7vqm.if6.tadmc@magna.metronet.com>
On Tue, 04 Jul 2000 14:02:24 GMT, Martin Doering <doeringm@gmx.de> wrote:
>How does perl get/store normal variable values ($xxx) internally? l
It depends on which _kind_ of Perl variable you are talking about.
Perl FAQ, part 7:
"What's the difference between dynamic and lexical (static) scoping?
Between local() and my()?"
>Are
>they stored in an associative array,
That sounds like "dynamic variables".
They are stored in the Symbol Table, which is a hash (see perlmod.pod).
You can see what's in your ST hash if you like:
--------------------------
#!/usr/bin/perl -w
local $localvar = 1;
my $myvar = 0;
foreach ( sort keys %main:: ) {
print "$_ ==> $main::{$_}\n"; # %main:: is the name of the
# ST hash for the "main" package
}
--------------------------
Note that 'myvar' did not show up in the output...
>or are they stored in a more
>C-like manner?
... because it is the "other kind" (lexical) of variable,
which is C-like, and is not in any symbol table.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 04 Jul 2000 11:47:19 +0200
From: Heiko Bentrup <hb@mediastudio.de>
Subject: Re: attach file in e-mail
Message-Id: <3961B2A7.2C647A6E@mediastudio.de>
This is a multi-part message in MIME format.
--------------9BE675D06828A3F724048076
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Hi,
i can't really figure out what you mean. Assuming you want to send a
"MS-Word" (sorry ;-)) Document as an attachement you would want to ad
something like this to your Email Routine.
print MAIL "Content-type: application/msword\n";
print MAIL "Content-Disposition: attachment;
filename=\"${filename}\"\n\n";
while $filename is the filename, you want to appear in the mail.
JL wrote:
> Hi,
> Can anyone tell me how to use perl to attach file like using e-mail in
> yahoo/hotmail?
> Thanks alot.
--
Heiko Bentrup
MediaStudio
für Marketing und Multimedia GmbH
http://www.mediastudio.de
---------------------------------
--------------9BE675D06828A3F724048076
Content-Type: text/x-vcard; charset=us-ascii;
name="hb.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Heiko Bentrup
Content-Disposition: attachment;
filename="hb.vcf"
begin:vcard
n:Bentrup;Heiko
x-mozilla-html:FALSE
url:http://www.mediastudio.de
org:MediaStudio für Marketing und Multimedia GmbH
adr:;;;Bielefeld;;33605;
version:2.1
email;internet:hb@mediastudio.de
title:New Media Producer
fn:Heiko Bentrup
end:vcard
--------------9BE675D06828A3F724048076--
------------------------------
Date: Thu, 06 Jul 2000 05:51:23 +0200
From: TM <thierry.metoudi@netcourrier.com>
Subject: Attn PerlGurus: implementing transaction with MySQL
Message-Id: <3964023B.4B57EFD4@netcourrier.com>
Hi,
I wonder if it is possible to implement or emulate transaction on a
mysql RDBMS (which doesn't have this feature built in) from some perl
hack.
Thanks
TM.
------------------------------
Date: 06 Jul 2000 01:31:46 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Attn PerlGurus: implementing transaction with MySQL
Message-Id: <slrn8m87fm.ibb.abigail@alexandra.delanet.com>
TM (thierry.metoudi@netcourrier.com) wrote on MMDI September MCMXCIII in
<URL:news:3964023B.4B57EFD4@netcourrier.com>:
::
:: I wonder if it is possible to implement or emulate transaction on a
:: mysql RDBMS (which doesn't have this feature built in) from some perl
:: hack.
Undoubtely, although it would be a horrible and gross hack. To do this
more or less properly without more overhead than the entire dataset plus
some, you require a lot of knowledge of MySQL.
It's really a question you should ask in a MySQL group. It would be
quite a task to implement transactions correctly and efficiently.
In which language you do this is only a tiny implementation detail.
If you don't want to spend too much resources on implementing this,
you'd be better off with a full featured database server.
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: Thu, 06 Jul 2000 07:17:11 GMT
From: sandhall@swipnet.se (Robert Hallgren)
Subject: Re: Attn PerlGurus: implementing transaction with MySQL
Message-Id: <slrn8m8c7v.ps.sandhall@poetry.lipogram>
On Thu, 06 Jul 2000 05:51:23 +0200,
TM <thierry.metoudi@netcourrier.com> wrote:
> I wonder if it is possible to implement or emulate transaction
> on a mysql RDBMS (which doesn't have this feature built in) ...
<URL: http://www.mysql.com/documentation/mysql/bychapter/
manual_Table_types.html#BDB>
Robert
--
Robert Hallgren <sandhall@swipnet.se>
PGP: http://www.lipogram.com/pgpkey.asc
5F1E 95C2 F0D8 25A3 D1BE 0F16 D426 34BD 166A 566C
------------------------------
Date: Thu, 06 Jul 2000 10:58:45 +0200
From: =?iso-8859-1?Q?Thorbj=F8rn?= Ravn Andersen <thunderbear@bigfoot.com>
Subject: Re: Attn PerlGurus: implementing transaction with MySQL
Message-Id: <39644A45.56ECC711@bigfoot.com>
TM wrote:
> I wonder if it is possible to implement or emulate transaction on a
> mysql RDBMS (which doesn't have this feature built in) from some perl
> hack.
If you need transactions, you need it inside the database.
Get another database.
--
Thorbjørn Ravn Andersen "...plus...Tubular Bells!"
http://bigfoot.com/~thunderbear
------------------------------
Date: Thu, 06 Jul 2000 11:29:59 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Attn PerlGurus: implementing transaction with MySQL
Message-Id: <X4_85.1469$iP2.141592@news.dircon.co.uk>
On Thu, 06 Jul 2000 07:17:11 GMT, Robert Hallgren Wrote:
> On Thu, 06 Jul 2000 05:51:23 +0200,
> TM <thierry.metoudi@netcourrier.com> wrote:
>
>> I wonder if it is possible to implement or emulate transaction
>> on a mysql RDBMS (which doesn't have this feature built in) ...
>
> <URL: http://www.mysql.com/documentation/mysql/bychapter/
> manual_Table_types.html#BDB>
>
Sounds like an experimental feature to me.
------------------------------
Date: Tue, 04 Jul 2000 10:51:24 -0500
From: "Timothy R. Kriz" <tkriz@ats.mcleodusa.net>
Subject: batch ping
Message-Id: <396207FC.BBA79864@ats.mcleodusa.net>
I have the need to ping over 3000 machines once a day to check for
connections.
I can make my script ping 1 machine at a time, but would like to issue,
say, 50 pings a time.
Is this a fork, or is there a more simple way?
Any suggestions appreciated.
Tim
------------------------------
Date: 4 Jul 2000 10:31:57 -0700
From: Petri Oksanen <Petri_member@newsguy.com>
Subject: Re: batch ping
Message-Id: <8jt72d$19s0@edrn.newsguy.com>
In article <396207FC.BBA79864@ats.mcleodusa.net>, "Timothy says...
> I have the need to ping over 3000 machines once a day to
> check for connections.
> I can make my script ping 1 machine at a time, but would
> like to issue, say, 50 pings a time.
>Is this a fork, or is there a more simple way?
system("ping $host"); is not a good idea, it would probably take all day to ping
your hosts.
>Any suggestions appreciated.
Use Net::Ping instead.
Type this at a shell prompt: perldoc Net::Ping
This module is very simple and easy to use and the documentation provides good
examples.
In case you don't already have the module installed, here's a cut from the doc:
$p = Net::Ping->new("icmp");
foreach $host (@host_array)
{
print "$host is ";
print "NOT " unless $p->ping($host, 2);
print "reachable.\n";
sleep(1);
}
$p->close();
Petri Oksanen
------------------------------
Date: 5 Jul 2000 10:04:32 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: batch ping
Message-Id: <8jutn0$msh$1@orpheus.gellyfish.com>
On Tue, 04 Jul 2000 10:51:24 -0500 Timothy R. Kriz wrote:
> I have the need to ping over 3000 machines once a day to check for
> connections.
> I can make my script ping 1 machine at a time, but would like to issue,
> say, 50 pings a time.
> Is this a fork, or is there a more simple way?
> Any suggestions appreciated.
>
Unless you can find a way of doing a multicast ping then I think you are
going to want to go with forking a bunch of processes yes, although of
course having loads of processes all pnging at once may well effect your
results ....
/J\
>
--
** This space reserved for venue sponsor for yapc::Europe **
<http://www.yapc.org/Europe/>
------------------------------
Date: Wed, 05 Jul 2000 02:12:27 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: batch ping
Message-Id: <3962FBFB.6D32829D@stomp.stomp.tokyo>
"Timothy R. Kriz" wrote:
> I have the need to ping over 3000 machines once a day to
> check for connections.
> I can make my script ping 1 machine at a time, but would
> like to issue, say, 50 pings a time.
> Is this a fork, or is there a more simple way?
> Any suggestions appreciated.
A suggestion, a rather logical suggestion.
Running three thousand ping operations will take a
bit of time, is a guarantee of frustration by having
to double check failed pings and, hmmm, wasteful of
man hours. Basically you are setting yourself up
for a serious headache and a never ending job.
Crontab all three thousand machines to request a
test page from your server, staggered time frames
to prevent unintentional packet flooding, then
parse your log records for your machines of interest.
Setting aside staggered timing, you could have your
results in less than thirty seconds, which includes
your personal typing speed.
My presumption is you are in charge of all three
thousand machines. This presumption is based on
this logic. If you are in a position of needing
to check three thousand connections and are not
in charge of those machines, it doesn't matter if
you can connect or not. If these machines are not
under your control, there is nothing you can do
about failed connections; you have no control.
Thus, logic dictates you have authority control
over all three thousand machines or you would not
be bothered with pinging them. Have those machines
report to you rather than you be a servant to them.
Thirty seconds, your job is done and you have done
nothing more than enter a command line argument to
parse your log records for requests from those
specific machines of interest within a selected
time frame.
Godzilla!
------------------------------
Date: Wed, 05 Jul 2000 10:24:47 +0100
From: Ade Talabi <adetalabi@clara.co.uk>
Subject: Re: batch ping
Message-Id: <3962FEDF.9B54D4F4@clara.co.uk>
you either set up a matrix of 30x100 and use 30 threads to ping each
column...
the pinging would take you at most 5 mins...
a pinging along the 30 columsn with 100 threads would probably take
about 2 mins....
happy pinging...
"Timothy R. Kriz" wrote:
>
> I have the need to ping over 3000 machines once a day to check for
> connections.
> I can make my script ping 1 machine at a time, but would like to issue,
> say, 50 pings a time.
> Is this a fork, or is there a more simple way?
> Any suggestions appreciated.
>
> Tim
--
We see, whatever we want to see, whether visible or not
- AT. June 2000.
------------------------------
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 3549
**************************************