[19384] in Perl-Users-Digest
Perl-Users Digest, Issue: 1579 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 21 14:10:33 2001
Date: Tue, 21 Aug 2001 11:10: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: <998417411-v10-i1579@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 21 Aug 2001 Volume: 10 Number: 1579
Today's topics:
Newbie question, Dynamic Allocation <rose@cs.queensu.ca>
Re: Newbie question, Dynamic Allocation <Tassilo.Parseval@post.rwth-aachen.de>
Re: Newbie question, Dynamic Allocation (Tad McClellan)
Re: Newbie question, Dynamic Allocation <ren@tivoli.com>
Re: Perl PGP routines <fty@mediapulse.com>
Re: perl versus java <fty@mediapulse.com>
Re: permuting extremely large string <joe+usenet@sunstarsys.com>
Re: Prevent module SNMP_Session to generate a die by wh (Anno Siegel)
Re: Prevent module SNMP_Session to generate a die by wh <ilya@martynov.org>
Re: Prevent module SNMP_Session to generate a die by wh (Anno Siegel)
Re: Prevent module SNMP_Session to generate a die by wh <ilya@martynov.org>
String extraction (shaz)
Re: subroutines in @INC ? <gisle@ActiveState.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 21 Aug 2001 11:08:10 -0400
From: Arlis rose <rose@cs.queensu.ca>
Subject: Newbie question, Dynamic Allocation
Message-Id: <3B82795A.159A8A35@cs.queensu.ca>
Hey everyone, just wondering if someone could help me to fix a little
problem I've been having with perl lately dealing with Dynamic
variables. I want to be able to create "x" number of variable in a for
loop where each variable ends with the number'd iteration of the loop
.... ie
for ($i=0; $i < 6; $i++) {
my $name$i = blah; #this is the line I can't get to work... want
to create varibale name0, name1, name2, etc...
}
Does anyone know how to do this (or even if I can do it)? (I have
thought about using an array, but would like to now if it is possible to
make this sort of dynamic invocation using simple variables/scalers
instead). I know that TCL/TK supports this sort of naming scheme, but
am not sure if many other languages do....
ThanX,
Daemon_Legend -> Arlis Rose | Research Assistant at Queen's University
------------------------------
Date: Tue, 21 Aug 2001 17:19:51 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Newbie question, Dynamic Allocation
Message-Id: <3B827C17.4030907@post.rwth-aachen.de>
Arlis rose wrote:
> Hey everyone, just wondering if someone could help me to fix a little
> problem I've been having with perl lately dealing with Dynamic
> variables. I want to be able to create "x" number of variable in a for
> loop where each variable ends with the number'd iteration of the loop
> .... ie
> for ($i=0; $i < 6; $i++) {
> my $name$i = blah; #this is the line I can't get to work... want
> to create varibale name0, name1, name2, etc...
> }
>
> Does anyone know how to do this (or even if I can do it)? (I have
> thought about using an array, but would like to now if it is possible to
> make this sort of dynamic invocation using simple variables/scalers
> instead). I know that TCL/TK supports this sort of naming scheme, but
> am not sure if many other languages do....
Don't do it! Perl could, of course, also create dynamically named
variables. But this stuff (symbolic references) is usually not
considered a good thing and would require you to soften the
stricture-pragma ('no strict "refs"'...by the way, did you 'use
strict;'?). Use something more generically Perlish: a hash:
my $name = "key";
my %hash;
for my $suffix (0 .. 6) {
$hash{$name$suffix} = 'blah';
}
Will create:
%hash =
( 'key0' => 'blah' ,
'key1' => 'blah' ,
...
'key6' => 'blah' ,
)
$hash{key0} is the way to get the stored value back.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Tue, 21 Aug 2001 10:32:44 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie question, Dynamic Allocation
Message-Id: <slrn9o4s8c.v1t.tadmc@tadmc26.august.net>
Arlis rose <rose@cs.queensu.ca> wrote:
>Hey everyone, just wondering if someone could help me to fix a little
>problem I've been having with perl lately dealing with Dynamic
>variables. I want to be able to create "x" number of variable in a for
^^^^^^
No you don't...
>loop where each variable ends with the number'd iteration of the loop
>.... ie
>for ($i=0; $i < 6; $i++) {
> my $name$i = blah; #this is the line I can't get to work... want
>to create varibale name0, name1, name2, etc...
>}
>
>Does anyone know how to do this
Yes, but "Symbolic references" are evil. Use a hash instead.
my %h;
$h{"$name$i"} = 'blah';
This is a Frequently Asked Question. Please check the Perl FAQs
*before* posting to the Perl newsgroup.
"How can I use a variable as a variable name?"
>(or even if I can do it)?
You can, but it can lead to very hard to find bugs:
http://www.plover.com/~mjd/perl/varvarname.html
http://www.plover.com/~mjd/perl/varvarname2.html
http://www.plover.com/~mjd/perl/varvarname3.html
>(I have
>thought about using an array,
That seems the best approach.
>but would like to now if it is possible to
Yes it is possible. But don't ever do it :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 21 Aug 2001 11:54:03 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Newbie question, Dynamic Allocation
Message-Id: <m3zo8tuzf8.fsf@dhcp9-161.support.tivoli.com>
On Tue, 21 Aug 2001, rose@cs.queensu.ca wrote:
> Hey everyone, just wondering if someone could help me to fix a little
> problem I've been having with perl lately dealing with Dynamic
> variables. I want to be able to create "x" number of variable in a for
> loop where each variable ends with the number'd iteration of the loop
> .... ie
> for ($i=0; $i < 6; $i++) {
> my $name$i = blah; #this is the line I can't get to work... want
> to create varibale name0, name1, name2, etc...
> }
While Perl does allow you to do this (it's called symbolic
references), it really isn't a good idea. Instead, use an array or
hash. For example:
my @name;
for (my $i=0; $i < 6; $i++) {
$name[$i] = "blah";
}
> Does anyone know how to do this (or even if I can do it)? (I have
> thought about using an array, but would like to now if it is possible to
> make this sort of dynamic invocation using simple variables/scalers
> instead). I know that TCL/TK supports this sort of naming scheme, but
> am not sure if many other languages do....
You're looking for ${"name$i"}, but again, don't do that.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 21 Aug 2001 17:31:28 GMT
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: Perl PGP routines
Message-Id: <QVwg7.72163$VV1.4944526@bin1.nnrp.aus1.giganews.com>
"Tom Leitch" <tom@leitchy.com> wrote in message
news:8sac7.875$tq.136858@news6-win.server.ntlworld.com...
> > Anyone know where I can get hold of a perl.cgi PGP encryption routine so
I
> > can encrypt emails to myself from my ISP's server?
>
>
> http://search.cpan.org/doc/BTROTT/Crypt-OpenPGP-0.13/lib/Crypt/OpenPGP.pm
>
> ...that should do what you are looking for. It's a pure Perl
implementation
> of PGP.
Wrong. Crypt::OpenPGP is a pure-Perl implementation of the OpenPGP standard
(RFC2440). You still need the PGP software to encrypt/decrypt files.
------------------------------
Date: Tue, 21 Aug 2001 17:46:56 GMT
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: perl versus java
Message-Id: <k8xg7.72386$VV1.4951523@bin1.nnrp.aus1.giganews.com>
"Thomas Porschberg" <mail@porschberg.de> wrote in message
news:m3elqr5vvf.fsf@redrat.quark.de without thinking for himself...
> I search some URL's about the discussion "perl versus java".
> I'am espacially interested in differences in runtime behaviour
> and the possibility to work with Oracle databases.
http://search.dogpile.com/texis/search?q=perl+vs+java&geo=no&fs=web
http://search.metacrawler.com/crawler?general=perl+vs+java
http://www.mamma.com/Mamma?query=perl+vs+java&qtype=0&x=50&y=14
http://groups.google.com/groups?q=perl+vs+java&meta=site%3Dgroups
As the scarecrow sings "If I only had a brain"
Jay
------------------------------
Date: 21 Aug 2001 11:16:40 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: permuting extremely large string
Message-Id: <m3zo8tcujr.fsf@mumonkan.sunstarsys.com>
Ilmari Karonen <iltzu@sci.invalid> writes:
> In article <3B8145D4.DEFB44BF@yahoo.com>, John Porter wrote:
> >Ilmari Karonen wrote:
> >> use Tie::CharArray;
> >> tie my @chars, 'Tie::CharArray', $string;
> >> # now permute @chars with the standard Fisher-Yates shuffle
> >
> >Yes; but wouldn't it be significantly more efficient to
> >modify the F-Y shuffle to swap characters in the string
> >directly?
>
> Yes -- about 6 times faster according to my benchmark. But the code
> looks a lot uglier. :-)
Then beautify it with Inline::C. Strings *are* character arrays there.
--
Joe Schaefer "Experience is one thing you can't get for nothing."
-- Oscar Wilde
------------------------------
Date: 21 Aug 2001 15:06:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Prevent module SNMP_Session to generate a die by which my CGI script stops running
Message-Id: <9lttco$e4v$3@mamenchi.zrz.TU-Berlin.DE>
According to Ilya Martynov <ilya@martynov.org>:
>
> KvdV> Hello All,
>
> KvdV> I wrote an application which collects snmp data from a bunch of
> KvdV> systems. I'm using the SNMP_Session package. This application is
> KvdV> supposed to run all the time. The problem is that apparently
> KvdV> SNMP_Session executes a Perl die when there's an SNMP problem
> KvdV> (e.g. no response received). This, in turn, terminates the whole
> KvdV> application (cgi script). How can I prevent this module to
> KvdV> terminate my program?
>
> eval {
> .... code that can call die ...
> };
>
> if($@) {
> .... check why we have died ...
> }
>
> See 'perldoc -tf eval'
That is one way. Another could involve a $SIG{ __DIE__} handler to
register the error (you can't recover from a fatal) and an END{} block
that restarts the program.
Anno
------------------------------
Date: 21 Aug 2001 19:29:11 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Prevent module SNMP_Session to generate a die by which my CGI script stops running
Message-Id: <878zgdph2w.fsf@abra.ru>
AS> That is one way. Another could involve a $SIG{ __DIE__} handler to
AS> register the error (you can't recover from a fatal) and an END{} block
AS> that restarts the program.
I've always been under impression that it is quite bade idea to use
$SIG{ __DIE__} for error handler because you can have only one error
handler why evals can be stacked. It is very unfriendly for
modularized code. Also SIG handlers look like an 'action at the
distance' while eval provides errors hanling in context.
And BTW what do you mean saying 'you can't recover from a fatal'? Is
there anything that cannot be handled in eval but can be handled in
$SIG{__DIE__}?
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 21 Aug 2001 16:13:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Prevent module SNMP_Session to generate a die by which my CGI script stops running
Message-Id: <9lu1bn$jj8$1@mamenchi.zrz.TU-Berlin.DE>
According to Ilya Martynov <ilya@martynov.org>:
>
> AS> That is one way. Another could involve a $SIG{ __DIE__} handler to
> AS> register the error (you can't recover from a fatal) and an END{} block
> AS> that restarts the program.
>
> I've always been under impression that it is quite bade idea to use
> $SIG{ __DIE__} for error handler because you can have only one error
> handler why evals can be stacked.
You can also chain handlers, though that's a pain to do.
> It is very unfriendly for
> modularized code.
Quite, a module should avoid them (there are exceptions). In the
main program, __WARN__ and __DIE__ handlers are fine.
> Also SIG handlers look like an 'action at the
> distance' while eval provides errors hanling in context.
Yes, but that's the point. Sometimes you can't, or won't, wrap eval
around every call that might die, so a handler is an alternative.
> And BTW what do you mean saying 'you can't recover from a fatal'? Is
> there anything that cannot be handled in eval but can be handled in
> $SIG{__DIE__}?
Sorry, "can't recover from a fatal" is a red herring at this point.
I was mixing in compile-time behavior where I shouldn't have.
Anno
------------------------------
Date: 21 Aug 2001 20:37:54 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Prevent module SNMP_Session to generate a die by which my CGI script stops running
Message-Id: <874rr1pdwd.fsf@abra.ru>
AS> Quite, a module should avoid them (there are exceptions). In the
AS> main program, __WARN__ and __DIE__ handlers are fine.
Suppose your main program uses a module which uses exceptions
(i.e. die and eval) a lot. SIG{__DIE__} can easily break such module.
And BTW - just noticed this in perlvar in perl 5.6.1:
BUGS
... "$SIG{__DIE__}" as currently implemented invites grievous
and difficult to track down errors. Avoid it and use an
"END{}" or CORE::GLOBAL::die override instead.
To be fair I'm not sure what does it means.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 21 Aug 2001 09:11:31 -0700
From: ssa1701@yahoo.co.uk (shaz)
Subject: String extraction
Message-Id: <23e71812.0108210811.1bbd822b@posting.google.com>
You once explained how to write a script which found the keyword in a
text file.
I was wondering if it would be possible if you could give me little
more help.
The code below is what you said I should use.
#!/usr/bin/perl -w
use strict;
my @tags = ('<NN>', '<VBZ>', '<DET>');
my $search = join('|',@tags);
my %taglist;
while (<DATA>) {
while (/(\w+)\s($search)/og) {
# print "$1 -> $2\n";
$taglist{$2}{$1}++;
}
}
This finds a SINGLE keyword. I have tried to modify it to find words
that appear next to each other based on their tags.
I tried this using
while (/(\w+)\s($search)\s(\w+)\s($search)/og)
instead of while (/(\w+)\s($search)/og)
but it does not work.
An example text file is
My <NN> Perl <NN> is <CD> not <VBZ> very <ADJ> good <ADJ>, so <NN>
please <NN> help <CD> me<NN>.
The new code should find My Perl
Any help would be grately appriciated.
Thanks
------------------------------
Date: Tue, 21 Aug 2001 16:23:30 GMT
From: Gisle Aas <gisle@ActiveState.com>
Subject: Re: subroutines in @INC ?
Message-Id: <m3ofp95qh5.fsf@ActiveState.com>
Bart Lateur <bart.lateur@skynet.be> writes:
> This sounds like a feature to make tools like perl2exe and perlapp, that
> include module source into the same file.
We tried to use this to simplify perlapp. It did not work because
some modules like to play tricks with the *INC stuff. Some of the
issues I remember were:
- DBI.pm chomps all entries in @INC. This end up stringifying
any code references that you put in. (Bleadperl has been fixed
so this problem might go away).
- Some module (Tk) construct absolute file names based on the
values in %INC. It then loads *.al by passing absolute file
names to require. Since the file name is absolute require
does not look in @INC and your code does never get a chance
of serving it.
--
Gisle Aas
ActiveState
------------------------------
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 1579
***************************************