[22800] in Perl-Users-Digest
Perl-Users Digest, Issue: 5021 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 21 21:06:24 2003
Date: Wed, 21 May 2003 18:05:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 21 May 2003 Volume: 10 Number: 5021
Today's topics:
Re: Alarm + System zombies <nobody@dev.null>
Re: Code to check which button press <wsegrave@mindspring.com>
Re: concise code competition <jamarier@yahoo.es>
Re: concise code competition <javiermm@telepolis.com>
Re: Crypt-SSLeay & Openssl want a divorce (Sebastien@Patriate)
Re: eval question (Shankar)
Re: eval question <uri@stemsystems.com>
filehandle problem on uploaded file <Rene.Scheibe@gmx.net>
Re: Finding files and moving them in perl <ddunham@redwood.taos.com>
Getting modules to work (newbie) <pvdh@xs4all.nl>
Hilarious locking bug in 5.8.0 (the_rev_dharma_roadkill)
Re: Hilarious locking bug in 5.8.0 <grazz@pobox.com>
html2txt <sten.malmlund@pp.htv.fi>
Re: html2txt <bwalton@rochester.rr.com>
is flock() needed when reading a DB ? (dan baker)
Re: is flock() needed when reading a DB ? <ddunham@redwood.taos.com>
Minimal Linux Perl setup <lasseolsson@myrealbox.com>
o conf urllist <waty@powerup.com.au>
Perl game site. <mail@annuna.com>
ppm3 not working on Redhat 9 (new2redhat)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 21 May 2003 20:19:31 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Alarm + System zombies
Message-Id: <3ECBDECE.5030402@dev.null>
Vinicio Tavares wrote:
> I have this code, it creates zombies, how can I solve this problem? Thanks.
>
> ...
> eval {
> local $SIG {ALRM} = sub { die "..." };
> alarm $timx;
> system "...";
> alarm 0;
> }
> ...
>
>
> Vinicio
>
perldoc -q zombies
will give you some pointers
------------------------------
Date: Wed, 21 May 2003 15:04:04 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Code to check which button press
Message-Id: <bagma9$vgc$1@slb9.atl.mindspring.net>
"ldd" <ddl76@singnet.com.sg> wrote in message
news:bag4mg$8tg$1@mawar.singnet.com.sg...
> Hi all,
>
> I have a HTML form with few buttons. I need to check which button is
pressed
> in my .pl script and then call the respective sub to process the data.
> Anyone any idea?
Use CGI.pm to generate your form.
Then, see "Creating A Submit Button" and related nearby topics in the CGI.pm
documentation.
Cheers.
Bill Segraves
------------------------------
Date: Wed, 21 May 2003 21:27:53 +0000 (UTC)
From: Javier M Mora <jamarier@yahoo.es>
Subject: Re: concise code competition
Message-Id: <bagr0p$t4t$1@nsnmpen2-gest.nuria.telefonica-data.net>
I make it with one-liner.
cp *.txt output/; perl -pie 's/=/\n/g' output/*.txt
En el artículo <CD2xa.4452$1u5.337@afrodite.telenet-ops.be>, joeri escribió:
> Hi folks,
>
> we're having ourselves a little competition here
> on making the following code as concise as possible,
> without loosing any performance. Here's the code as it is now:
>
> opendir(DIR, $dir="c:/dir") or die "$!";
> mkdir("$dir/output");
>
> for(grep(/\.txt$/, readdir(DIR))) {
> open(FILE, "$dir/$_") or die "$!";
> $out = "$dir/output/$_";
> open(OUT, ">$out") if !-e $out || -z $out;
> for(@strings=<FILE>) {
> $_ =~ s/=/\n/g;
> print OUT;
> }
> close OUT;
> close FILE;
> }
>
> So what it does basically is read in all the .txt files from a specified
> directory,
> replace all "=" tokens by a newline, opens an outputfile of the same name in
> a subdirectory
> of the directory where one is reading the files from called "output" and
> writes the text there.
> That's it.
> Any of you guys have a way of writing the above code more compact?
>
> J
>
>
------------------------------
Date: Wed, 21 May 2003 23:38:33 +0200
From: Javier M Mora <javiermm@telepolis.com>
Subject: Re: concise code competition
Message-Id: <pan.2003.05.21.21.38.28.844220@telepolis.com>
El Wed, 21 May 2003 21:27:53 +0000, Javier M Mora dijo:
> I make it with one-liner.
>
> cp *.txt output/; perl -pie 's/=/\n/g' output/*.txt
>
Sorry, it's:
cp *.txt output/; perl -pi -e 's/=/\n/g' output/*.txt
> En el artículo <CD2xa.4452$1u5.337@afrodite.telenet-ops.be>, joeri escribió:
>> Hi folks,
>>
>> we're having ourselves a little competition here
>> on making the following code as concise as possible,
>> without loosing any performance. Here's the code as it is now:
>>
>> opendir(DIR, $dir="c:/dir") or die "$!";
>> mkdir("$dir/output");
>>
>> for(grep(/\.txt$/, readdir(DIR))) {
>> open(FILE, "$dir/$_") or die "$!";
>> $out = "$dir/output/$_";
>> open(OUT, ">$out") if !-e $out || -z $out;
>> for(@strings=<FILE>) {
>> $_ =~ s/=/\n/g;
>> print OUT;
>> }
>> close OUT;
>> close FILE;
>> }
>>
>> So what it does basically is read in all the .txt files from a specified
>> directory,
>> replace all "=" tokens by a newline, opens an outputfile of the same name in
>> a subdirectory
>> of the directory where one is reading the files from called "output" and
>> writes the text there.
>> That's it.
>> Any of you guys have a way of writing the above code more compact?
>>
>> J
>>
>>
------------------------------
Date: 21 May 2003 11:10:36 -0700
From: sebastien@patriate.com.au (Sebastien@Patriate)
Subject: Re: Crypt-SSLeay & Openssl want a divorce
Message-Id: <24827557.0305211010.37ab6de0@posting.google.com>
Hi Rob,
The code you gave me worked.
Now the author of Crypt-SSLeay, Josh Chamas suggested I use a
different certificate.
I have converted the cert.pfx file to a cert.pem file using
openssl pkcs12 -in cert.pfx -out cert.pem
Now how do I generate a key file ? :(
This is what I have set so far in the perl script.
$ENV{HTTPS_CERT_FILE} = './cert.pem';
$ENV{HTTPS_KEY_FILE} = './????.pem'; <-- what do I put here?
If I comment out the last ENV setting, then it does work ... but for
each request prompts me for the password ... :( So I need the key
file.
You can contact me by mail at sebastien@patriate.com.au.
Cheers,
Sebastien
------------------------------
Date: 21 May 2003 12:19:00 -0700
From: SNeelakantan_C@zaplet.com (Shankar)
Subject: Re: eval question
Message-Id: <4a0341c8.0305211119.1400118c@posting.google.com>
> The standard solution to your problem is to use a hash entry $hash{ abc}
> instead of the variable $abc. That way what used to be a variable name
> becomes a hash key, keeping code and data separate.
>
> Anno
Thanks Anno. I think that is an elegant way to fix the problem.
I changed my data struct to look like this:
$c = {
abc => { a => '1', b => '2', c => '3' },
};
$x = "abc";
print "$c->{$x}->{a}\n";
Now I don't have to use eval :)
------------------------------
Date: Wed, 21 May 2003 19:31:09 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: eval question
Message-Id: <x7y9105c77.fsf@mail.sysarch.com>
>>>>> "S" == Shankar <SNeelakantan_C@zaplet.com> writes:
S> Thanks Anno. I think that is an elegant way to fix the problem.
not just elegant but correct, safer, and maintainable.
S> $c = {
S> abc => { a => '1', b => '2', c => '3' },
S> };
S> $x = "abc";
S> print "$c->{$x}->{a}\n";
you can drop the second ->. perl can tell when you have consecutive []
and {} in a deref expression.
S> Now I don't have to use eval :)
you should almost never need eval. eval is a LAST resort thing and not a
first tool to use. newbies in general never need eval, they just think
they do.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Wed, 21 May 2003 22:49:52 +0200
From: "Rene Scheibe" <Rene.Scheibe@gmx.net>
Subject: filehandle problem on uploaded file
Message-Id: <bagoqo$ss4gu$1@ID-65612.news.dfncis.de>
when i upload a file via a html form i can get
its filname and filehandle by:
my $filename = param('file');
my $filehandle = upload('file');
...or not?
and then with:
binmode($filehandle);
open (OUT, ">new_filename.ext");
while (my $line = <$filehandle>)
{
print OUT $line;
}
close OUT;
close $filehandle;
...i can save it to a file.
but what i want is to use the filehandle i got with
upload('file') and work with this. in the special case
i want to use image::magick's read(file=>\*filehandle)
to use this file (image).
but when i do so i just can read in httpd's logs
that it cannot open a file with the filename of
the uploaded file.
so can you give me some advice?
i dont want to save the file first and then open
it to read it by image magick
thanks rene
------------------------------
Date: Thu, 22 May 2003 00:41:09 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Finding files and moving them in perl
Message-Id: <F0Vya.129$r84.6991985@newssvr14.news.prodigy.com>
david <dwlepage@yahoo.com> wrote:
> Im a dufus. I found the answer. I just got frustrated after staring at
> this for 4 hours. Anyways, here is what I came up with:
> #!/usr/bin/perl
> #
> use File::Copy;
> opendir(DIR, ".") or die "Cannot open directory";
> foreach $entry (readdir DIR)
> {
> if ($entry=~m/DF(.*)|QF$1/) {
I'm thinking that regex is a bit strange...
You appear to be relying on the fact that a particular DFx will always
precede the QFx in the directory listing. That's a poor assumption.
> move("$entry","/opt/scripts/testdir");
> }
> }
> closedir(DIR);
perhaps something more like...
my %files;
while (my $filename = readdir(DIR))
{
$files{$filename} = 1;
}
closedir DIR;
foreach my $file (keys %files)
{
next unless (/^DF(.*)$/);
my $digits = $1;
if (exists $files{"QF$digits"})
{
move("DF$digits","/opt/scripts/testdir");
move("QF$digits","/opt/scripts/testdir");
}
}
By reading in all the files, then operating on them as a whole, it
eliminates problems being caused by the files being returned by readdir
in a different order.
This one will also fail to move files if only one (QF or DF) is found.
It would take very little work to have the program print any such files
found.
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: 21 May 2003 21:40:43 GMT
From: Paul van der Heu <pvdh@xs4all.nl>
Subject: Getting modules to work (newbie)
Message-Id: <Xns9382F0E178015pvdhNL@194.134.35.159>
I've been reading up on this, but although I am pretty convinced I got it
installed right I am still unable to use it..
I installed the id3lib wrapper for id3lib.dll
It's on CPAN as MP3::ID3Lib and when I do an install it reports the
install I have is up to date which IMo should mean it is installed
correctly.
I have the ID3Lib.pm in perl\lib\MP3, Frame.pm in perl\lib\MP3\ID3Lib and
id3lib.dll (latest version3.8.3) in perl\lib
However running the included testscript won't compile:
Can't find 'boot_MP3__ID3Lib' symbol in D:/Perl/lib/ID3Lib.dll at
mp3test.pl line 1
Compilation failed in require at mp3test.pl line 1.
BEGIN failed--compilation aborted at mp3test.pl line 1.
the scipt:
use MP3::ID3Lib;
my $id3 = MP3::ID3Lib->new(".\test1.mp3");
foreach my $frame (@{$id3->frames}) {
my $code = $frame->code;
my $description = $frame->description;
my $value = $frame->value;
$frame->set("Orange") if $code eq 'TPE1';
print "$description: $value\n";
}
As said I'm a newbie so be gentle ..:)
--
------------------------------
Date: 21 May 2003 15:20:43 -0700
From: doug.hendricks@tnzi.com (the_rev_dharma_roadkill)
Subject: Hilarious locking bug in 5.8.0
Message-Id: <fb91dbec.0305211420.6e8d9aaf@posting.google.com>
I drove myself crazy(er), but I finally figured it out. Can you find
what is wrong with the following script? I struggled with a bigger
version that tried using IO::File and many different ways of passing
an argument, but whenever I ran two instances of the script, using my
locking subroutine, they would both "grab" the lock. If I used flock
at the top level, the locking would work. See if you know the answer
before I tell you...
#!/usr/bin/perl -w
use strict;
use Fcntl qw(:flock);
open FH, "> lockfile1" or die "open $!";
### the follow commented out code works correctly!
###flock FH, (LOCK_EX|LOCK_NB) or print "flock FH nosub $!\n";
lock(*FH);
print "sleep now\n";
sleep 10000;
# this sub ALWAYS grabs the lock, even when it should not!
sub lock { *FH = shift;
flock FH, (LOCK_EX|LOCK_NB) or print "flock lock1 $!\n"; }
### many different versions of sub lock also grabbed an already locked
file
### tried using local and lexical arguments in sub and main, nothing
worked
### (lock always grabbed, even if already locked by another process)
# end of script
and the answer....? See below...
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
The answer is that unless you define sub lock before you use it, perl
5.8.0 uses a different silently defined lock() that is silently
imported. If I pass lock() no arguments while in the debugger, I get:
###censored###> perl -de 0
Loading DB routines from perl5db.pl version 1.19
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(-e:1): 0
DB<1> lock()
Not enough arguments for lock at (eval
7)[/usr/lib/perl-5.8.0/lib/5.8.0/perl5db.pl:17] line 2, near "lock()"
DB<2>
which is failing inside the debugging module. Apparently, DB::lock()
is imported even if you aren't running the debugger, and even if you
don't want it!!!!
I have never been stung like this before. Silently imported functions
that override your own (later) defined functions, lions and tigers and
bears, oh my.
Best regards,
The Reverend Dharma Roadkill
------------------------------
Date: Wed, 21 May 2003 22:44:54 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Hilarious locking bug in 5.8.0
Message-Id: <GjTya.24385$4_1.5221662@twister.nyc.rr.com>
the_rev_dharma_roadkill <doug.hendricks@tnzi.com> wrote:
>
> # this sub ALWAYS grabs the lock, even when it should not!
> sub lock { *FH = shift;
> flock FH, (LOCK_EX|LOCK_NB) or print "flock lock1 $!\n"; }
> The answer is that unless you define sub lock before you use it,
> perl 5.8.0 uses a different silently defined lock() that is
> silently imported.
Not exactly (but the truth isn't much prettier).
$ perldoc -f lock
lock THING
This function places an advisory lock on a shared variable, or
referenced object contained in THING until the lock goes out of
scope.
lock() is a "weak keyword" : this means that if you've defined
a function by this name (before any calls to it), that function
will be called instead. (However, if you've said "use threads",
lock() is always a keyword.) See threads.
--
Steve
------------------------------
Date: Thu, 22 May 2003 03:44:16 +0200
From: "Sten Malmlund" <sten.malmlund@pp.htv.fi>
Subject: html2txt
Message-Id: <bah6a9$ehl$1@nyytiset.pp.htv.fi>
Hello,
This might be an obvious thing, but I'm a beginner in regular expressions.
I'm trying to make a regular expression tom get rid of all html tags to get
a plain txt file from all texts beteweeb the tags.
the following expression doesn't seem to work:
$htmlfile = $ARGV[0];
open(HTML, $htmlfile);
while ($line = <HTML>) {
# remove the trailing newline
chop($line);
$line =~ s/\<.*\>//gi; # remove tags
}
Regards,
sten
------------------------------
Date: Thu, 22 May 2003 00:59:37 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: html2txt
Message-Id: <3ECC1F6D.8090500@rochester.rr.com>
Sten Malmlund wrote:
...
> I'm trying to make a regular expression tom get rid of all html tags to get
> a plain txt file from all texts beteweeb the tags.
>
> the following expression doesn't seem to work:
...
> sten
This is a FAQ. Please see:
perldoc -q HTML
If you have questions after reading the first entry from that, post again.
--
Bob Walton
------------------------------
Date: 21 May 2003 14:32:39 -0700
From: botfood@yahoo.com (dan baker)
Subject: is flock() needed when reading a DB ?
Message-Id: <13685ef8.0305211332.4680d7a3@posting.google.com>
I have a DB to manage some member addresses and such... most writes
will be really quick and either creating or updating a single record.
I understand the need to lock the file prior to write.... but I am
wondering if locking is required prior to a read? There are report
generators that will spend a couple seconds reading, and I would like
to know if I need to lock the DB during these processes to prevent
corruption if a write comes in from another user while I am generating
reports.
I am using tie() with DB_File
Related to this seems to be the relative difficulty in locking a
tie()ed hash filesince flock() typically works on open filehandles. It
looks like most people create a separate lockfile, and use it rather
than locking the tie()ed hash directly. I am wondering if there any
other really simple examples of creating or locking a flag file, doing
my DB write, and then unlocking or unlinking the flag file in whatever
manner will protect the DB during writes....
thanks,
d
------------------------------
Date: Wed, 21 May 2003 23:08:53 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: is flock() needed when reading a DB ?
Message-Id: <9GTya.115$oB3.4933683@newssvr14.news.prodigy.com>
dan baker <botfood@yahoo.com> wrote:
> I have a DB to manage some member addresses and such... most writes
> will be really quick and either creating or updating a single record.
> I understand the need to lock the file prior to write.... but I am
> wondering if locking is required prior to a read? There are report
> generators that will spend a couple seconds reading, and I would like
> to know if I need to lock the DB during these processes to prevent
> corruption if a write comes in from another user while I am generating
> reports.
Locking is usually required on reading when updates can cause
inconsistencies. In other words, you may need to acquire a read lock
just to be certain that there's not a write lock at the moment.
Different databases handle this differently. Some may do updates in
such a way that reads are guaranteed to give a correct answer even if
updates occur.
> I am using tie() with DB_File
I don't know how it would react specifically.
> Related to this seems to be the relative difficulty in locking a
> tie()ed hash filesince flock() typically works on open filehandles. It
> looks like most people create a separate lockfile, and use it rather
> than locking the tie()ed hash directly. I am wondering if there any
> other really simple examples of creating or locking a flag file, doing
> my DB write, and then unlocking or unlinking the flag file in whatever
> manner will protect the DB during writes....
That's the exact way I'd do it. Unless the program aquires a sentinel
lock, don't open/tie/read/write the DB file.
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: Wed, 21 May 2003 18:22:28 GMT
From: "Lars Olsson" <lasseolsson@myrealbox.com>
Subject: Minimal Linux Perl setup
Message-Id: <EtPya.7609$mU6.13590@newsb.telia.net>
Hi all
I need to prepare a small linux distro to use for
pxe booting and performing some tasks with the help of Perl.
So I need a minimal Perl installation so that my initrd root file system
doesn't become to big.
If anyone has any hints regarding perhaps a small ready made Perl package
or how to trim down the standards package, I would be thankful.
TIA
Lasse
------------------------------
Date: Wed, 21 May 2003 22:10:25 GMT
From: "Alan Watson" <waty@powerup.com.au>
Subject: o conf urllist
Message-Id: <lPSya.672$iv4.7156@news-server.bigpond.net.au>
I can't seem to reset the default ftp site in CPAN. Can anyone tell me how?
I think the command is something like:
o conf urllist
Thanks,
Alan
------------------------------
Date: Wed, 21 May 2003 13:42:47 -0500
From: Joe Creaney <mail@annuna.com>
Subject: Perl game site.
Message-Id: <3ECBC8A7.1070004@annuna.com>
I have been writing a simple perl role-playing game. It has been a
learning project so that I can learn programming. I have gotten pretty
far in my pursuit. I invite others who are interested in writing games
to check out my game.
The game simple rpg is posted at www.annuna.com/perl5
------------------------------
Date: 21 May 2003 16:14:36 -0700
From: jollyrogerinstitute@hotmail.com (new2redhat)
Subject: ppm3 not working on Redhat 9
Message-Id: <40938569.0305211514.fa239b0@posting.google.com>
When I type ppm3 at the shell prompt I get:
bash: ppm3: command not found
I installed PERL 5.8 with Redhat 9. Typing 'perl' at the prompt works.
ppm3 does not. I want to install TK from an Activestate module
download.
Thanks,
------------------------------
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 5021
***************************************