[19841] in Perl-Users-Digest
Perl-Users Digest, Issue: 2036 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 30 09:10:32 2001
Date: Tue, 30 Oct 2001 06:10:15 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004451015-v10-i2036@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 30 Oct 2001 Volume: 10 Number: 2036
Today's topics:
File handle leak- how bad? <bill.kemp@wire2.com>
Re: File handle leak- how bad? <krahnj@acm.org>
Re: File handle leak- how bad? <ilya@martynov.org>
Re: File handle leak- how bad? <bernard.el-hagin@lido-tech.net>
Re: File handle leak- how bad? <bill.kemp@wire2.com>
FTP,Mail Modules for ActivePerl <bol@adv.magwien.gv.at>
Re: FTP,Mail Modules for ActivePerl <bart.lateur@skynet.be>
Re: How to delete the last link <adustipujo1@mediaone.net>
Is File::Temp broken when using -T switch? (EED)
Re: Is File::Temp broken when using -T switch? (EED)
Re: Is File::Temp broken when using -T switch? (Rafael Garcia-Suarez)
Re: Is File::Temp broken when using -T switch? (EED)
Re: Is File::Temp broken when using -T switch? (Rafael Garcia-Suarez)
Re: Is File::Temp broken when using -T switch? (EED)
Re: Is File::Temp broken when using -T switch? (Rafael Garcia-Suarez)
Matching the input line <martin_andersen_90@yahoo.com>
Re: Matching the input line <bernard.el-hagin@lido-tech.net>
Re: Matching the input line <bernard.el-hagin@lido-tech.net>
perlish way to read/write absolute sectors from PC disk (John Stumbles)
perlsub <justin.devanandan.allegakoen@intel.com>
Re: perlsub <simon.oliver@umist.ac.uk>
Re: question of Perl style using map <goldbb2@earthlink.net>
Re: Regexp for email address (Glenn White)
What is .... <Al@yahoo.com>
Re: What taints my data? (EED)
Re: What taints my data? (EED)
Yapp: anybody understand .output file? <rtrahan@monmouth.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 30 Oct 2001 09:37:50 -0000
From: "W K" <bill.kemp@wire2.com>
Subject: File handle leak- how bad?
Message-Id: <6zuD7.1284$t97.13740@news.uk.colt.net>
I have found (someone else's) code that effectively does this:
while (1){
open (AFILE,"afile.txt") or die $!;
#read it
sleep 60;
}
Now obviously there is a close missing, and if you keep on opening file
handles you end up in trouble.
Two questions:
1) Will it keep on opening new file handles, or will the fact that they
always have the same name (AFILE) mean that Perl does something more
sensible than the person that wrote this.
2) What would this leak be liable to do? Its a PC with other potentially
leaky software on it that causes it to crash.
Would it crash the box? Oh its NT in case you hadn't guessed already
------------------------------
Date: Tue, 30 Oct 2001 10:46:45 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: File handle leak- how bad?
Message-Id: <3BDE85C4.4E29EAE7@acm.org>
W K wrote:
>
> I have found (someone else's) code that effectively does this:
>
> while (1){
> open (AFILE,"afile.txt") or die $!;
> #read it
> sleep 60;
> }
>
> Now obviously there is a close missing, and if you keep on opening file
> handles you end up in trouble.
>
> Two questions:
> 1) Will it keep on opening new file handles, or will the fact that they
> always have the same name (AFILE) mean that Perl does something more
> sensible than the person that wrote this.
>
> 2) What would this leak be liable to do? Its a PC with other potentially
> leaky software on it that causes it to crash.
> Would it crash the box? Oh its NT in case you hadn't guessed already
perldoc -f close
close FILEHANDLE
close Closes the file or pipe associated with the file
handle, returning true only if stdio successfully
flushes buffers and closes the system file
descriptor. Closes the currently selected
filehandle if the argument is omitted.
You don't have to close FILEHANDLE if you are
immediately going to do another `open' on it,
because `open' will close it for you. (See
`open'.) However, an explicit `close' on an input
file resets the line counter (`$.'), while the
implicit close done by `open' does not.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 30 Oct 2001 13:55:23 +0300
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: File handle leak- how bad?
Message-Id: <877ktdjt2c.fsf@abra.ru>
>>>>> On Tue, 30 Oct 2001 09:37:50 -0000, "W K" <bill.kemp@wire2.com> said:
W> I have found (someone else's) code that effectively does this:
W> while (1){
W> open (AFILE,"afile.txt") or die $!;
W> #read it
W> sleep 60;
W> }
W> Now obviously there is a close missing, and if you keep on opening file
W> handles you end up in trouble.
Acording 'perldoc -tf close'
close FILEHANDLE
close [..skip..]
You don't have to close FILEHANDLE if you are immediately going
to do another "open" on it, because "open" will close it for
you. (See "open".) However, an explicit "close" on an input file
resets the line counter ("$."), while the implicit close done by
"open" does not.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) TIV.net (http://tiv.net/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Tue, 30 Oct 2001 10:58:23 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: File handle leak- how bad?
Message-Id: <slrn9tt1gl.3nk.bernard.el-hagin@gdndev25.lido-tech>
On Tue, 30 Oct 2001 09:37:50 -0000, W K <bill.kemp@wire2.com> wrote:
> I have found (someone else's) code that effectively does this:
>
> while (1){
> open (AFILE,"afile.txt") or die $!;
> #read it
> sleep 60;
> }
>
> Now obviously there is a close missing, and if you keep on opening file
> handles you end up in trouble.
You don't really need a close in this case.
> Two questions:
> 1) Will it keep on opening new file handles, or will the fact that they
> always have the same name (AFILE) mean that Perl does something more
> sensible than the person that wrote this.
>
> 2) What would this leak be liable to do? Its a PC with other potentially
> leaky software on it that causes it to crash.
> Would it crash the box? Oh its NT in case you hadn't guessed already
What do you mean by "leak"? The only thing this code does is open the
same file over and over again. An explicit close of the filehandle in
this case does nothing special and there's no reason why the above code
should crash your system. For example,
while(1){
open( FILE, 'blah.txt' ) or die $!;
print <FILE>;
sleep(60);
}
will just keep printing 'blah.txt' every 60 seconds for all eternity
(or until you get bored and kill the process).
What is it exactly that you're trying to do?
Cheers,
Bernard
------------------------------
Date: Tue, 30 Oct 2001 12:05:55 -0000
From: "W K" <bill.kemp@wire2.com>
Subject: Re: File handle leak- how bad?
Message-Id: <ZJwD7.1292$t97.13824@news.uk.colt.net>
> What do you mean by "leak"?
Its probably from seeing bad C code that would kill a box if it kept on
creating file handles without closing them.
If new file handles were being created (to open the same file), the number
could keep growing.
>The only thing this code does is open the
> same file over and over again. An explicit close of the filehandle in
> this case does nothing special and there's no reason why the above code
> should crash your system. For example,
>
>
> while(1){
> open( FILE, 'blah.txt' ) or die $!;
> print <FILE>;
> sleep(60);
> }
>
>
> will just keep printing 'blah.txt' every 60 seconds for all eternity
> (or until you get bored and kill the process).
From the perldoc (sorry BTW )
"You don't have to close FILEHANDLE if you are
immediately going to do another `open' on it,
because `open' will close it for you."
So really the answer is that perl IS doing something more sensible than the
original coder.
The file does remain open for the spare 60 seconds.
>
> What is it exactly that you're trying to do?
Well its not mine, but it reads a pid file. The code was paraphrased.
It does mean, though, that if 100 files are checked every minute, there will
be 100 files open for no good reason.
(in reality there are only 6 or so)
------------------------------
Date: Tue, 30 Oct 2001 12:29:39 +0100
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: FTP,Mail Modules for ActivePerl
Message-Id: <1004441265.541345@mozart.adv.magwien.gv.at>
Hi to all,
I'm looking for modules like Mail::Mailer and Net::FTP, to use on NT4
systems with Active Perl. Seems that these modules are not distributed with
ActivePerl. I also looked at CPAN but didn't find them.
Can someone point in the right direction?
MTIA and kind greetings,
Ferry
--
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: bol@adv.magwien.gv.at
------------------------------
Date: Tue, 30 Oct 2001 13:45:38 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: FTP,Mail Modules for ActivePerl
Message-Id: <b7btttserb4l80r8652jiqeku0i3ttcooo@4ax.com>
Ferry Bolhar wrote:
>I'm looking for modules like Mail::Mailer and Net::FTP, to use on NT4
>systems with Active Perl. Seems that these modules are not distributed with
>ActivePerl. I also looked at CPAN but didn't find them.
<http://www.activestate.com/PPMpackages/5.6/>
Mail::Mailer is in MailTools. As for Net::FTP... I'd expect to find it
in libnet. It's not in the above directory... Hmm... I've got it, it
appears to come with IndigoPerl.
Well, this looks like it's an ordinary perl module, so you should be
able to use it straight from CPAN:
<http://search.cpan.org/search?dist=libnet>
--
Bart.
------------------------------
Date: Tue, 30 Oct 2001 12:04:54 GMT
From: "Pujo C A" <adustipujo1@mediaone.net>
Subject: Re: How to delete the last link
Message-Id: <GHwD7.47224$bK.568271@typhoon.mw.mediaone.net>
Thank you Jon,
I didn't know a bout URI before but its really nice. where can get the
documentation, I want to know more..
Thanks again,
--
Pujo C Agustiyanto
http://www.geocities.com/pujoca
<!-- The richest person in this universe is the person who appreciate what
she/he has-->
"Jonathan Stowe" <gellyfish@gellyfish.com> wrote in message
news:9reuu7$jnr$1@plutonium.btinternet.com...
> Jonathan Stowe <gellyfish@gellyfish.com> wrote:
> > Pujo C A <adustipujo1@mediaone.net> wrote:
> >>
> >> Does any body know how to do this?
> >> I want to delete the character from the last / occurence until html
> >> ex: http://www.yahoo.com/shopping.html
> >> I want to delete only shopping.html( I mean any number of word after
the
> >> last /)
> >> I tried this one:
> >> $url =~s/\w{8}\.html//i;
> >> but this is too rigid, I want something more flexible.
> >>
> >
> > You might find that the module URI will make doing this easier as it
> > has methods to decompose the URI into its component parts.
> >
>
> The overkill method of doing this with URI might be like :
>
> #!/usr/bin/perl -w
>
>
> use strict;
>
> use URI;
> use File::Basename;
>
> my $uri = URI->new('http://some.server.com/some/path/to/file.html');
>
> my ($file, $path, $suffix ) = fileparse($uri->path());
>
> $uri->path($path);
>
> print $uri->as_string();
>
>
> /J\
> --
> Jonathan Stowe |
> <http://www.gellyfish.com> | This space for rent
> |
------------------------------
Date: Tue, 30 Oct 2001 11:49:53 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Is File::Temp broken when using -T switch?
Message-Id: <3BDE85D1.3CC9147B@eed.ericsson.se>
Sorry for using the "provoking" subject, but I think my original
posting had too much code in it. I have reduced my problem to the
following, can someone please explain to me, why -T thinks it's insecure?
oche150:eedalf {108} cat temp.pl
#!/opt/local/perl-5.6.0/bin/perl -wT
BEGIN { $ENV{PATH} = $ENV{IFS} = ''; }
use File::Temp qw (tempdir);
$tempdir = tempdir (CLEANUP => 1);
print "$tempdir\n";
system ("/bin/touch $tempdir/xxx") and die $!;
oche150:eedalf {109} ./temp.pl
/tmp/o37L4Z83vp
Insecure dependency in unlink while running with -T switch at /opt/local/perl-5.6.0/lib/5.6.0/File/Path.pm line 220.
END failed--call queue aborted.
------------------------------
Date: Tue, 30 Oct 2001 11:57:55 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: Is File::Temp broken when using -T switch?
Message-Id: <3BDE87B3.89FB37D@eed.ericsson.se>
"Alexander Farber (EED)" wrote:
>
> BEGIN { $ENV{PATH} = $ENV{IFS} = ''; }
BEGIN { $ENV{PATH} = $ENV{IFS} = $ENV{TMPDIR} = ''; }
doesn't help too...
------------------------------
Date: 30 Oct 2001 11:01:48 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Is File::Temp broken when using -T switch?
Message-Id: <slrn9tt25e.otr.rgarciasuarez@rafael.kazibao.net>
Alexander Farber (EED) wrote in comp.lang.perl.misc:
> Sorry for using the "provoking" subject, but I think my original
> posting had too much code in it. I have reduced my problem to the
> following, can someone please explain to me, why -T thinks it's insecure?
>
>
> oche150:eedalf {108} cat temp.pl
> #!/opt/local/perl-5.6.0/bin/perl -wT
>
> BEGIN { $ENV{PATH} = $ENV{IFS} = ''; }
Works for me (perl 5.6.1, linux) when you also do $ENV{BASH_ENV} = ''.
> use File::Temp qw (tempdir);
>
> $tempdir = tempdir (CLEANUP => 1);
> print "$tempdir\n";
> system ("/bin/touch $tempdir/xxx") and die $!;
>
>
> oche150:eedalf {109} ./temp.pl
> /tmp/o37L4Z83vp
> Insecure dependency in unlink while running with -T switch at /opt/local/perl-5.6.0/lib/5.6.0/File/Path.pm line 220.
> END failed--call queue aborted.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
This theory has become known as the waste of time theory and was
abandoned in 1956. -- Monty Python, Penguins
------------------------------
Date: Tue, 30 Oct 2001 12:40:57 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: Is File::Temp broken when using -T switch?
Message-Id: <3BDE91C9.7F5AA552@eed.ericsson.se>
Rafael Garcia-Suarez wrote:
> Works for me (perl 5.6.1, linux) when you also do $ENV{BASH_ENV} = ''.
Hmm, it's still doesn't work for me on Solaris 8 even if I do:
#!/opt/local/perl-5.6.0/bin/perl -wT
BEGIN { %ENV = () }
use File::Temp qw (tempdir);
$tempdir = tempdir (CLEANUP => 1);
$tempdir = $1 if $tempdir =~ /(\S*)/;
print "$tempdir\n";
system ("/bin/touch $tempdir/xxx") and die $!;
------------------------------
Date: 30 Oct 2001 12:01:32 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Is File::Temp broken when using -T switch?
Message-Id: <slrn9tt5ld.p3h.rgarciasuarez@rafael.kazibao.net>
Alexander Farber (EED) wrote in comp.lang.perl.misc:
> Rafael Garcia-Suarez wrote:
> > Works for me (perl 5.6.1, linux) when you also do $ENV{BASH_ENV} = ''.
>
> Hmm, it's still doesn't work for me on Solaris 8 even if I do:
>
>
> #!/opt/local/perl-5.6.0/bin/perl -wT
>
> BEGIN { %ENV = () }
>
> use File::Temp qw (tempdir);
>
> $tempdir = tempdir (CLEANUP => 1);
>
> $tempdir = $1 if $tempdir =~ /(\S*)/;
> print "$tempdir\n";
> system ("/bin/touch $tempdir/xxx") and die $!;
Ok, looks like you just found a bug in File::Temp. I can see that also
(solaris 8, perl 5.005_03).
I suggest, as a workaround, that you remove the CLEANUP => 1 parameter
and do the cleanup yourself in your own END block.
Additionnally, it's a good idea to use the perlbug utility to send a bug
report to the perl maintainers.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
use lib sub{$_=$_[1];y;_.mp; ,\n;d;print;
open+0;*0};require Just_another_Perl_hacker;1
------------------------------
Date: Tue, 30 Oct 2001 13:42:41 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: Is File::Temp broken when using -T switch?
Message-Id: <3BDEA041.6B18BECC@eed.ericsson.se>
Rafael Garcia-Suarez wrote:
> Ok, looks like you just found a bug in File::Temp. I can see that also
> (solaris 8, perl 5.005_03).
>
> I suggest, as a workaround, that you remove the CLEANUP => 1 parameter
> and do the cleanup yourself in your own END block.
Yes, that's what I use in my scripts currently when working with File::Temp:
system ($RM, '-rf', $tempdir) and die "Can't remove $tempdir: $!\n";
(but it makes me nervous)
> Additionnally, it's a good idea to use the perlbug utility to send a bug
> report to the perl maintainers.
Okay, I've just done it. But by the way it doesn't work on OpenBSD 2.9 with
Perl 5.6.0 too. Are you sure it works with Perl 5.6.0 on Linux (I can't test):
pref:alex {140} ./temp.pl
/tmp/oQp5wJKtTU
Insecure dependency in unlink while running with -T switch at /usr/libdata/perl5/File/Path.pm line 220.
END failed--call queue aborted.
pref:alex {141} perl -v
This is perl, v5.6.0 built for i386-openbsd
------------------------------
Date: 30 Oct 2001 12:49:28 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Is File::Temp broken when using -T switch?
Message-Id: <slrn9tt8fb.pb7.rgarciasuarez@rafael.kazibao.net>
Alexander Farber (EED) wrote in comp.lang.perl.misc:
> Okay, I've just done it. But by the way it doesn't work on OpenBSD 2.9 with
> Perl 5.6.0 too. Are you sure it works with Perl 5.6.0 on Linux (I can't test):
Hmm, no. I must have made a mistake at some point.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Tue, 30 Oct 2001 10:04:26 +0100
From: "Martin" <martin_andersen_90@yahoo.com>
Subject: Matching the input line
Message-Id: <9rlp7i$g9j$1@newstoo.ericsson.se>
Hi
How could i write an expression that could match if i have an input line as
follows:
my $line1 = "210.168.11.12 HomePC1
";
my $line2 = "210.168.11.13 HomePC2";
my $line3 = "210.168.13.14 HomePC3 # ";
I am reading this data from a file, and i am only interested to get the IP
number and the name ( HomePC1 - 3 ).
Thanks allot Martin
------------------------------
Date: Tue, 30 Oct 2001 09:15:21 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Matching the input line
Message-Id: <slrn9tsrfh.3nk.bernard.el-hagin@gdndev25.lido-tech>
On Tue, 30 Oct 2001 10:04:26 +0100, Martin <martin_andersen_90@yahoo.com>
wrote:
> Hi
>
> How could i write an expression that could match if i have an input line as
> follows:
>
> my $line1 = "210.168.11.12 HomePC1
> ";
> my $line2 = "210.168.11.13 HomePC2";
> my $line3 = "210.168.13.14 HomePC3 # ";
>
> I am reading this data from a file, and i am only interested to get the IP
> number and the name ( HomePC1 - 3 ).
In all three cases you can try:
my ($ip, $home) = $line =~ m/^(\S+)\s+(\S+)/;
print "[$ip]\t[$home]\n";
Cheers,
Bernard
------------------------------
Date: Tue, 30 Oct 2001 09:19:56 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Matching the input line
Message-Id: <slrn9tsro4.3nk.bernard.el-hagin@gdndev25.lido-tech>
On Tue, 30 Oct 2001 10:04:26 +0100, Martin <martin_andersen_90@yahoo.com>
wrote:
> Hi
>
> How could i write an expression that could match if i have an input line as
> follows:
>
> my $line1 = "210.168.11.12 HomePC1
> ";
> my $line2 = "210.168.11.13 HomePC2";
> my $line3 = "210.168.13.14 HomePC3 # ";
>
> I am reading this data from a file, and i am only interested to get the IP
> number and the name ( HomePC1 - 3 ).
[I inadvertently posted before completing my previous reply.]
You can also use split:
my ($ip, $home) = split /\s+/, $line;
Cheers,
Bernard
------------------------------
Date: 30 Oct 2001 04:27:32 -0800
From: john.stumbles@ntlworld.com (John Stumbles)
Subject: perlish way to read/write absolute sectors from PC disk?
Message-Id: <7f40850b.0110300427.ac56cd@posting.google.com>
Is there a way to do this? The bottom line is I'm trying to find a way
to multiboot dozens of PCs between Win32, Linux and Solaris (and
perhaps more) _automatically_ (i.e. without manual intervention at
boot-up time) by issuing a command "reboot into {OS X}" from whichever
OS* is currently running. Plan A is to read and rewrite MBR and/or
boot sectors to acheive this. If there's a Perlish way of doing this
(across all platforms, natch) it would be nice.
(* I'm including Win32 as an 'OS' just to be provocative :-)
John Stumbles
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
------------------------------
Date: Tue, 30 Oct 2001 17:38:13 +0800
From: "Just in" <justin.devanandan.allegakoen@intel.com>
Subject: perlsub
Message-Id: <9rlseb$eii@news.or.intel.com>
Suppose I had a program that has a variable in a subroutine that
I call from other programs by means of require.
Good Perl programming etiquette dictates that I should use strict,
and use warnings - so apart from not using them, just
how exactly am I supposed to use a variable from a sub that I required
from another program, without STDERR crying foul?
I read as far as I could with perlsub, but I sort of lost it . . . Mr
Dominus' perlreftut
was helpful though . . . then again I can't see how it fits in . . . Sorry!
------------------------------
Date: Tue, 30 Oct 2001 12:58:56 +0000
From: Simon Oliver <simon.oliver@umist.ac.uk>
To: Just in <justin.devanandan.allegakoen@intel.com>
Subject: Re: perlsub
Message-Id: <3BDEA410.DD6BF278@umist.ac.uk>
Please expand your senario with a little code for example.
--
Simon
Just in wrote:
>
> Suppose I had a program that has a variable in a subroutine that
> I call from other programs by means of require.
>
> Good Perl programming etiquette dictates that I should use strict,
> and use warnings - so apart from not using them, just
> how exactly am I supposed to use a variable from a sub that I required
> from another program, without STDERR crying foul?
>
> I read as far as I could with perlsub, but I sort of lost it . . . Mr
> Dominus' perlreftut
> was helpful though . . . then again I can't see how it fits in . . . Sorry!
------------------------------
Date: Tue, 30 Oct 2001 07:25:09 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: question of Perl style using map
Message-Id: <3BDE9C25.AA7ABA4D@earthlink.net>
chris wrote:
>
> I am relatively new to Perl and trying to produce code that looks like
> Perl (rather than C). This post is a result of me trying to learn a
> Perl style.
>
> I'm looking at the output of a simulation program, which simulates
> 1000 events at a time. I need at least $required of each possible
> event, and so loop over the simulation, storing the cumulative number
> of each event till I have the required number.
>
> The question is how (Perlishly) to check all elements of this array
> are >= $required?
>
> My first effort is below (using a much smaller @array and $required
> for the example):
[snip]
This [untested] code is probably the most perlish way to do it.
LOOP: {
++$_ for @array;
print "@array\n";
$_ < $required && redo LOOP for @array;
}
--
Klein bottle for rent - inquire within.
------------------------------
Date: Tue, 30 Oct 2001 14:01:37 GMT
From: spam.killer@home.com_nospam (Glenn White)
Subject: Re: Regexp for email address
Message-Id: <Xns914A3D3CCF435ccruizermydejacom@24.0.0.25>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
<9rj7tj$3ak$2@mamenchi.zrz.TU-Berlin.DE>:
>> All I'm trying to do is to take something like the following:
>> TO=FIRST-LAST;CRCG@TESTER.COM;RWBR
>>
>> and turn it into:
>> FIRST-LAST@TESTER.COM;CRCG@TESTER.COM;RWBR@TESTER.COM
>>
>
>It looks like you just want to supply a final "@TESTER.COM" to any
>string that doesn't already contain a "@". That is indeed easy:
>
> join ';', map /@/ ? $_ : "$_.TESTER.COM", split /;/, substr $s, 3;
>
>Anno
>
I tried reading and working through each of the following. Unfortunately,
try as I might, I could not get them to work. I could not get the first two
to add "@tester.com" to the identifiers. What makes it worse, they make
sense to me... but I just could not pick out why they fail.
$line =~ join ';', map /@/ ? $_ : "$_.TESTER.COM", split /;/, substr $s, 3;
or
$line = join ';', grep { !/\@/ && s/$/\@tester.com/ } split /;/, $line;
or
$line =~ s/TO=(.+)(\@\w+\.\w+)/$1/ and $a = $2;
$line =~ s/$_/$_$a/ for split ';',$line;
Even though I could not get "and $a = $2" in the last example to work, it
was easy to learn and modify. I ended up changing my program to include the
following:
$line =~ s/^TO=//;
$line =~ s/\n//;
$line =~ s/(.+)(\@\w+\.\w+)/$1/;
$line =~ s/$_/$_\tester.com/ for split ';',$line;
My solution does not do exactly what I wanted, but it will do some of what
I need. If an address includes anything other than "@tester.com" it will
remove it and replace it.
Thanks for all the help. At least now I can see what I need to work on in
the new furture to get it to work correctly.
------------------------------
Date: Tue, 30 Oct 2001 15:36:08 +0530
From: "Al" <Al@yahoo.com>
Subject: What is ....
Message-Id: <9rlu3b$6qb@nntpb.cb.lucent.com>
Hi ,
When I try to 'configure' one of the downloaded utilities I get this
error..
This is *not* a GNU autoconf-generated configure.
Looking for perl..../configure: test: argument expected
The download doesnot have 'configure.in' so that I can autoconf it again. So
I am stuck. The downloaded utility site dint mention about this problem /
solution.
BTW, What's this perl configure?
Thanks for your help.
-Al
------------------------------
Date: Tue, 30 Oct 2001 10:14:48 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: What taints my data?
Message-Id: <3BDE6F88.17F3A9CB@eed.ericsson.se>
Benjamin Goldberg wrote:
>
> Alexander Farber (EED) wrote:
> >
> > Insecure dependency in unlink while running with -T switch at
> > /opt/local/perl-5.6.0/lib/5.6.0/File/Path.pm line 220. END failed--
> > call queue aborted.
> >
> > when I uncomment the extract_files call below:
> [snip]
> > $archive = $href -> {FILEPATH};
> [snip]
> > $files = list_files ($archive);
> [snip]
> > #extract_files ($archive, $files); # <=== THIS LINE
> > }
> >
> > I wonder what causes it, since the extract_files
> > just extracts some files by opening pipes:
>
> The problem is that the contents of $files is tainted, since it was
> produced as the output of an external program.
But how come they are tainted? Don't I clean them with the $1 below?
sub list_files ($)
{
...
while (<$pipe>)
{ # skip abs. paths
next if $archive =~ /\.t(?:ar|az|gz)/i and /^\//; # in tar-archives
push @files, $1 if /([\w\/.-]+?\.c[lr]\d+)$/i;
}
...
}
------------------------------
Date: Tue, 30 Oct 2001 11:40:09 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Re: What taints my data?
Message-Id: <3BDE8389.F05253C3@eed.ericsson.se>
"Alexander Farber (EED)" wrote:
>
> Benjamin Goldberg wrote:
> >
> > The problem is that the contents of $files is tainted, since it was
> > produced as the output of an external program.
>
> But how come they are tainted? Don't I clean them with the $1 below?
>
> sub list_files ($)
> {
> ...
> while (<$pipe>)
> { # skip abs. paths
> next if $archive =~ /\.t(?:ar|az|gz)/i and /^\//; # in tar-archives
> push @files, $1 if /([\w\/.-]+?\.c[lr]\d+)$/i;
> }
> ...
> }
Also, I get the same error message:
[Tue Oct 30 11:36:20 2001] acastat.pl: Insecure dependency in unlink while running with -T switch at /opt/local/perl-5.6.0/lib/5.6.0/File/Path.pm line 220.
[Tue Oct 30 11:36:20 2001] acastat.pl: END failed--call queue aborted.
if I remove the $files and just have this call:
system ("$UNZIP -p $archive | $TAR xf - ") and die $!;
instead of the original:
system ("$UNZIP -p $archive | $TAR xf - @$files") and die $!;
so I don't think, that $files are tainted. The error message
have something top do with the way File::Temp calls rmtree
for the temp dirs in its END block. But how do I fix it?
Regards
Alex
------------------------------
Date: Tue, 30 Oct 2001 06:09:10 -0800
From: Richard Trahan <rtrahan@monmouth.com>
Subject: Yapp: anybody understand .output file?
Message-Id: <3BDEB486.9A662B7F@monmouth.com>
Does anyone understand the format of the Yapp .output file? (The
one you get with yapp -v.)
For example, consider the lines:
State 1:
digit -> '1' . (Rule 10)
nonzero_digit -> '1' . (Rule 11)
'0' [reduce using rule 11 (nonzero_digit)]
'1' [reduce using rule 11 (nonzero_digit)]
'\n' reduce using rule 11 (nonzero_digit)
$default reduce using rule 10 (digit)
What exactly does "digit -> '1'" mean? Are you in a state that
receives a '1' which becomes a digit? Or, is there a digit on
the stack waiting for a '1', and then acts according to Rule 10?
Is the direction of the -> possibly misleading? What is the dot?
Is it just the period at the end of a sentence?
How are all the lines containing 'reduce' to be interpreted? Why
are two of them in brackets? Why is there a $default reduce rule
that's not even listed in the other lines?
I understand what shift and reduce mean in parsers, but I cannot
fathom the syntax of this file, even when I compare it with the
generated parser and original .yp.
Does anyone have a method for elminating reduce/reduce conflicts,
or even diving them, using these files?
------------------------------
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 2036
***************************************