[28149] in Perl-Users-Digest
Perl-Users Digest, Issue: 9513 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 22 18:05:51 2006
Date: Sat, 22 Jul 2006 15:05:07 -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 Sat, 22 Jul 2006 Volume: 10 Number: 9513
Today's topics:
Re: Can anybody help me get a job or work mgarrish@gmail.com
Re: Idiot Q: How to find index number of HASH match? <franzl.wisseworst@mailinator.net>
Re: Idiot Q: How to find index number of HASH match? <franzl.wisseworst@mailinator.net>
Re: Idiot Q: How to find index number of HASH match? <franzl.wisseworst@mailinator.net>
Re: Idiot Q: How to find index number of HASH match? <franzl.wisseworst@mailinator.net>
Re: Idiot Q: How to find index number of HASH match? <tadmc@augustmail.com>
Re: Lingua::Han::PinYin and utf8 problem <hjp-usenet2@hjp.at>
my VAR = EXPR if COND grin.k1tt3n@gmail.com
Re: my VAR = EXPR if COND <rafalk@comcast.net>
Re: my VAR = EXPR if COND <klaus03@gmail.com>
Re: my VAR = EXPR if COND <DJStunks@gmail.com>
Re: my VAR = EXPR if COND <mi@univie.ac.at>
Re: my VAR = EXPR if COND <benmorrow@tiscali.co.uk>
Re: my VAR = EXPR if COND <DJStunks@gmail.com>
Re: my VAR = EXPR if COND <David.Squire@no.spam.from.here.au>
Re: perl + regex bug? nitroamos@gmail.com
Re: perl + regex bug? <tadmc@augustmail.com>
Re: Problem with function "crypt" mgarrish@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 22 Jul 2006 12:33:45 -0700
From: mgarrish@gmail.com
Subject: Re: Can anybody help me get a job or work
Message-Id: <1153596825.757643.307380@s13g2000cwa.googlegroups.com>
robic0 wrote:
> I'm almost on skid row now. I have a gun and I'm thinking of ending it all.
> My family is almost starving and I have no prospects for work.
>
What happened? RXParse didn't take the world by storm? The king is
dead. Long live the king!
Matt
------------------------------
Date: Sat, 22 Jul 2006 17:23:57 +0200
From: Franzl Wisseworst <franzl.wisseworst@mailinator.net>
Subject: Re: Idiot Q: How to find index number of HASH match?
Message-Id: <e9tgq6$stl$00$1@news.t-online.com>
Thank you for the various comments above which sheds much light as well as
more confusion on the situation....
The multi-level hash is probably the method I need.
------------------------------
Date: Sat, 22 Jul 2006 19:31:10 +0200
From: Franzl Wisseworst <franzl.wisseworst@mailinator.net>
Subject: Re: Idiot Q: How to find index number of HASH match?
Message-Id: <e9toae$7el$01$1@news.t-online.com>
While I'm still pondering about how to best solve the above question by the
various solutions posted in response, I have now a different question,
although ultimately for the one and same purpose.
The below script is a bare-bone version, without the language multi-arrays
attempt. It simply generates groups of unordered html-lists which form the
basis of a navigation system.
The navigation will have a bunch of UL's and LI's glued together in
css drop menu fashion, but I've cut that css out from this post.
Each group of links will have several LI's nested within the first-level UL
and LI entry, like this:
<ul>
<li class=yellow>page one
<ul>
<li>DING</li>
<li>Something</li>
</ul>
The current page is identified through an $ENV{"DOCUMENT_NAME"} call. The
whole thing is generated via SSI and the script resides in a dot-pl file.
In case the current page exists in one of the hash arrays, the resulting
css-class is set to "yellow" and subsequently the background of the
list items contained in its css-block all become yellow. For example, the
background of the first <li> and nested <ul><li>'s will be yellow when the
page DING is viewed.
For user-friendliness sake I'd like the current page (e.g. DING) not to be
a link to itself when it is viewed.
My question is therefore, how would one normally omit the enclosing <a
href=$_> and </a> html-code output based on a particular condition, in this
case if and where the current page name ($current::page) match exists?
for (\%activities) {
my $firstkey = each %$_;
print "<li class=$class::value><a
href=$firstkey>$activities{$firstkey}</a>\n";
print "<ul>\n";
print "<li><a href=$_>$activities{$_}</a></li> \n" while local $_ = each
%$_;
print "</ul>\n";
print "</li>\n";
}
The complete script is included below:
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
# bg css-color to visually indicate which group of
# links/ul current page exists in
######## css bits #########
print "<head>\n";
print "<style>\n";
print ".green {background:green;}\n";
print ".yellow {background:yellow;\n";
print "</style>\n";
print "</head>\n\n";
######## some pre-procedures ########
use Tie::IxHash;
use strict;
use warnings;
tie my %location, "Tie::IxHash";
tie my %activities, "Tie::IxHash";
# Place CGI environment variable in
# $current::page global
# needed later to identify if page is in group
if ($ENV{"DOCUMENT_NAME"}){
$current::page = $ENV{"DOCUMENT_NAME"};
}
else {
$current::page = "undefined";
}
print $current::page;
######### the hashes with links ##########
%location = ('page1.html' => 'page one',
'ding.html' => 'DING',
'something.html' => 'Something');
%activities = ('fishing.html' => 'Fishing',
'diving.html' => 'Diving',
'drinking.html', => 'Beer');
##### display first group of links with a loop ####
if (exists($location{$current::page})){
$class::value = "yellow";
}
else {
$class::value = "green";
}
print "<ul>\n";
for (\%location) {
my $firstkey = each %$_;
print "<li class=$class::value><a
href=$firstkey>$location{$firstkey}</a>\n";
print "<ul>\n";
print "<li><a href=$_>$location{$_}</a></li> \n" while local $_ = each %$_;
print "</ul>\n";
print "</li>\n";
}
print "</ul>";
#### display second group of links with loop ####
if (exists($activities{$current::page})){
$class::value = "yellow";
}
else {
$class::value = "green";
}
print "<ul>";
for (\%activities) {
my $firstkey = each %$_;
print "<li class=$class::value><a
href=$firstkey>$activities{$firstkey}</a>\n";
print "<ul>\n";
print "<li><a href=$_>$activities{$_}</a></li> \n" while local $_ = each
%$_;
print "</ul>\n";
print "</li>\n";
}
print "</ul>";
# etc...
No doubt there exists more compact methods for the whole procedure,
especially when there are many more groups of links. But code-bloat is not
a problem here, as the script simply generate static pages once in a while
which are later sent up on a server via automated ftp procedures. Instead
configurability and exception to rules may be more important in the future.
The purpose of the perl script is simply to remove tedious and error prone
cross page html coding, while still retaining that old tailor made quality.
------------------------------
Date: Sat, 22 Jul 2006 19:59:19 +0200
From: Franzl Wisseworst <franzl.wisseworst@mailinator.net>
Subject: Re: Idiot Q: How to find index number of HASH match?
Message-Id: <e9tptg$agq$01$2@news.t-online.com>
While I'm still pondering about how to best solve the above question by the
various solutions posted in response, I have now a different question,
although ultimately for the one and same purpose.
The below script is a bare-bone version, without the language multi-arrays
attempt. It simply generates groups of unordered html-lists which form the
basis of a navigation system.
The navigation will have a bunch of UL's and LI's glued together in
css drop menu fashion, but I've cut that css out from this post.
Each group of links will have several LI's nested within the first-level UL
and LI entry, like this:
<ul>
<li class=yellow>page one
<ul>
<li>DING</li>
<li>Something</li>
</ul>
</li>
</ul>
The current page is identified through an $ENV{"DOCUMENT_NAME"} call. The
whole thing is generated via SSI and the script resides in a dot-pl file.
In case the current page exists in one of the hash arrays, the resulting
css-class is set to "yellow" and subsequently the background of the
list items contained in its css-block all become yellow. For example, the
background of the first <li> and nested <ul><li>'s will be yellow when the
page DING is viewed.
For user-friendliness sake I'd like the current page (e.g. DING) not to be
a link to itself when it is viewed.
My question is therefore, how would one normally omit the enclosing <a
href=$_> and </a> html-code output based on a particular condition, in this
case if and where the current page name ($current::page) match exists?
for (\%activities) {
my $firstkey = each %$_;
print "<li class=$class::value><a
href=$firstkey>$activities{$firstkey}</a>\n";
print "<ul>\n";
print "<li><a href=$_>$activities{$_}</a></li> \n" while local $_ = each
%$_;
print "</ul>\n";
print "</li>\n";
}
The complete script is included below:
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
# bg css-color to visually indicate which group of
# links/ul current page exists in
######## css bits #########
print "<head>\n";
print "<style>\n";
print ".green {background:green;}\n";
print ".yellow {background:yellow;\n";
print "</style>\n";
print "</head>\n\n";
######## some pre-procedures ########
use Tie::IxHash;
use strict;
use warnings;
tie my %location, "Tie::IxHash";
tie my %activities, "Tie::IxHash";
# Place CGI environment variable in
# $current::page global
# needed later to identify if page is in group
if ($ENV{"DOCUMENT_NAME"}){
$current::page = $ENV{"DOCUMENT_NAME"};
}
else {
$current::page = "undefined";
}
print $current::page;
######### the hashes with links ##########
%location = ('page1.html' => 'page one',
'ding.html' => 'DING',
'something.html' => 'Something');
%activities = ('fishing.html' => 'Fishing',
'diving.html' => 'Diving',
'drinking.html', => 'Beer');
##### display first group of links with a loop ####
if (exists($location{$current::page})){
$class::value = "yellow";
}
else {
$class::value = "green";
}
print "<ul>\n";
for (\%location) {
my $firstkey = each %$_;
print "<li class=$class::value><a
href=$firstkey>$location{$firstkey}</a>\n";
print "<ul>\n";
print "<li><a href=$_>$location{$_}</a></li> \n" while local $_ = each %$_;
print "</ul>\n";
print "</li>\n";
}
print "</ul>";
#### display second group of links with loop ####
if (exists($activities{$current::page})){
$class::value = "yellow";
}
else {
$class::value = "green";
}
print "<ul>";
for (\%activities) {
my $firstkey = each %$_;
print "<li class=$class::value><a
href=$firstkey>$activities{$firstkey}</a>\n";
print "<ul>\n";
print "<li><a href=$_>$activities{$_}</a></li> \n" while local $_ = each
%$_;
print "</ul>\n";
print "</li>\n";
}
print "</ul>";
# etc...
No doubt there exists more compact methods for the whole procedure,
especially when there are many more groups of links. But code-bloat is not
a problem here, as the script simply generate static pages once in a while
which are later sent up on a server via automated ftp procedures. Instead
configurability and exception to rules may be more important in the future.
The purpose of the perl script is simply to remove tedious and error prone
cross page html coding, while still retaining that old tailor made quality.
------------------------------
Date: Sat, 22 Jul 2006 21:34:54 +0200
From: Franzl Wisseworst <franzl.wisseworst@mailinator.net>
Subject: Re: Idiot Q: How to find index number of HASH match?
Message-Id: <e9tvig$lnb$01$1@news.t-online.com>
> For user-friendliness sake I'd like the current page (e.g. DING) not to be
> a link to itself when it is viewed.
I can get the first level UL/LI to display conditionally as in below code.
The first UL ($firstkey) always contains only one LI entry however.
What I can't figure is how to do the same in the while part for the nested
UL/LI's below, if at all possible with the hash as currently set-up?
print "<ul>\n";
for (\%location) {
my $firstkey = each %$_;
if ($current::page eq $firstkey){
print "<li class=$class::value>$location{$firstkey}"; # <-- no-link OK !
}
else {
print "<li class=$class::value><a href=$firstkey>$location{$firstkey}</a>";
}
print "<ul>\n";
print "<li><a href=$_>$location{$_}</a></li> \n"while local $_ = each %$_;
# how on earth can I do the same in the above line?!?
print "</ul>\n";
print "</li>\n";
}
print "</ul>";
------------------------------
Date: Sat, 22 Jul 2006 15:55:51 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Idiot Q: How to find index number of HASH match?
Message-Id: <slrnec546n.a20.tadmc@magna.augustmail.com>
Franzl Wisseworst <franzl.wisseworst@mailinator.net> wrote:
> My question is therefore, how would one normally omit the enclosing <a
> href=$_> and </a> html-code output based on a particular condition, in this
> case if and where the current page name ($current::page) match exists?
>
> for (\%activities) {
> my $firstkey = each %$_;
> print "<li class=$class::value><a
> href=$firstkey>$activities{$firstkey}</a>\n";
> print "<ul>\n";
> print "<li><a href=$_>$activities{$_}</a></li> \n" while local $_ = each
> %$_;
while ( local $_ = each %$_ ) {
if ( exists $activities{$_} )
{ print "<li>$activities{$_}</li> \n" }
else
{ print "<li><a href=$_>$activities{$_}</a></li> \n" }
}
> print "</ul>\n";
> print "</li>\n";
> }
[snip]
> if ($ENV{"DOCUMENT_NAME"}){
> $current::page = $ENV{"DOCUMENT_NAME"};
> }
> else {
> $current::page = "undefined";
> }
You could replace all of that with:
$current::page = $ENV{DOCUMENT_NAME} || 'undefined';
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 22 Jul 2006 22:57:13 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Lingua::Han::PinYin and utf8 problem
Message-Id: <pan.2006.07.22.20.57.09.530894@hjp.at>
On Sat, 22 Jul 2006 09:26:19 +0000, corff wrote:
> Hi all,
>
> I have a minimal script:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> # use utf8;
> binmode STDOUT,":utf8";
> use Lingua::Han::PinYin;
>
> my $h2p = new Lingua::Han::PinYin(format => 'utf8');
There doesn't seem to be any format parameter for
Lingua::Han::PinYin->new().
> my $name=chr(0x4e00); # utf CJK, first character, "yi"
>
> print "$name, long: ",length $name,"\n"; # Diagnostics
>
> #print $h2p->han2pinyin("�"),"\n";
> #print $h2p->han2pinyin(chr(0x4e00)),"\n";
> #print $h2p->han2pinyin("$name"),"\n";
>
> Uncomment the first print statement, and it prints "yi" as last line,
> as expected.
Note that the String "�" is 3 characters long, not 1 (you have 'use
utf8' commented out).
> Uncommenting any of the other lines produces this error message:
> Cannot decode string with wide characters at /usr/lib/perl5/5.8.5/i386-linux-thread-multi/Encode.pm line 164.
>
> How can I treat han2pinyin() my stuff in a scalar instead of as a literal?
That doesn't seem to have anything to do with scalars and literals.
Instead, han2pinyin seems to expect an utf-8-encoded string.
use Encode;
print $h2p->han2pinyin(encode('utf-8', $name)),"\n";
works.
hp
--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
------------------------------
Date: 22 Jul 2006 10:39:45 -0700
From: grin.k1tt3n@gmail.com
Subject: my VAR = EXPR if COND
Message-Id: <1153589985.864124.59890@s13g2000cwa.googlegroups.com>
I just discovered the bug/feature of having a static variable if it
initialized as:
my $var = expr() if condition();
That is, if condifition is not true, then var is initialized with
whatever was last there.
It seems like this issue is over 7 years old, but I see no mention of
it in "man perlsub".
(It cost me two hours this morning wrangling with mod_perl).
Are there any plans to document/correct this soon?
This was running on perl 5.8.8.
Thanks,
Rob
------------------------------
Date: Sat, 22 Jul 2006 13:57:10 -0400
From: Rafal Konopka <rafalk@comcast.net>
Subject: Re: my VAR = EXPR if COND
Message-Id: <kip4c2dtgl3jumuq18ha7rq7eiq2786mlt@4ax.com>
On 22 Jul 2006 10:39:45 -0700, grin.k1tt3n@gmail.com wrote:
>I just discovered the bug/feature of having a static variable if it
>initialized as:
>
>my $var = expr() if condition();
>
>That is, if condifition is not true, then var is initialized with
>whatever was last there.
>
I think it's always safer to declare the variable first (particularly
inside loops) and then set it to some value:
my $var;
$var = expr() if condition();
Rafal
>Thanks,
>Rob
------------------------------
Date: 22 Jul 2006 10:58:50 -0700
From: "Klaus" <klaus03@gmail.com>
Subject: Re: my VAR = EXPR if COND
Message-Id: <1153591130.298252.244360@b28g2000cwb.googlegroups.com>
grin.k1tt3n@gmail.com wrote:
> I just discovered the bug/feature of having a static variable if it
> initialized as:
>
> my $var = expr() if condition();
>
> That is, if condifition is not true, then var is initialized with
> whatever was last there.
>
> It seems like this issue is over 7 years old, but I see no mention of
> it in "man perlsub".
I found something in "perlsyn", sub-paragraph "statement modifiers":
=================================================
"The behaviour of a my statement modified with a statement modifier
conditional or loop construct (e.g. my $x if ...) is undefined. The
value of the my variable may be undef, any previously assigned value,
or possibly anything else. Don't rely on it. Future versions of perl
might do something different from the version of perl you try it out
on. Here be dragons."
------------------------------
Date: 22 Jul 2006 11:18:41 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: my VAR = EXPR if COND
Message-Id: <1153592321.692304.201800@i42g2000cwa.googlegroups.com>
grin.k1tt3n@gmail.com wrote:
> I just discovered the bug/feature of having a static variable if it
> initialized as:
>
> my $var = expr() if condition();
>
> That is, if condifition is not true, then var is initialized with
> whatever was last there.
>
> It seems like this issue is over 7 years old, but I see no mention of
> it in "man perlsub".
> (It cost me two hours this morning wrangling with mod_perl).
>
> Are there any plans to document/correct this soon?
>
> This was running on perl 5.8.8.
I don't think I understand what you're getting at. Either that or I
don't see it:
C:\>perl -Mstrict -e "for (1,0) {my $var = 'defined' if $_; \
print qq[$_: \$var = $var\n]}"
1: $var = defined
0: $var =
??
This is perl, v5.8.7 built for MSWin32-x86-multi-thread
-jp
------------------------------
Date: Sat, 22 Jul 2006 21:47:37 +0200
From: Heinrich Mislik <mi@univie.ac.at>
Subject: Re: my VAR = EXPR if COND
Message-Id: <Pine.A41.4.63.0607222145470.44910@login.univie.ac.at>
On Sat, 22 Jul 2006, grin.k1tt3n@gmail.com wrote:
> I just discovered the bug/feature of having a static variable if it
> initialized as:
>
> my $var = expr() if condition();
>
> That is, if condifition is not true, then var is initialized with
> whatever was last there.
>
> It seems like this issue is over 7 years old, but I see no mention of
> it in "man perlsub".
> (It cost me two hours this morning wrangling with mod_perl).
>
> Are there any plans to document/correct this soon?
It is in perdoc perlsyn:
NOTE: The behaviour of a "my" statement modified with a statement modi-
fier conditional or loop construct (e.g. "my $x if ...") is undefined.
The value of the "my" variable may be "undef", any previously assigned
value, or possibly anything else. Don't rely on it. Future versions
of perl might do something different from the version of perl you try
it out on. Here be dragons.
cheers
heinrich
-------------------------------------------------------------------------------
Heinrich Mislik Tel:+43 1 4277 14056
eMail Heinrich.Mislik@univie.ac.at
-------------------------------------------------------------------------------
------------------------------
Date: Sat, 22 Jul 2006 20:39:28 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: my VAR = EXPR if COND
Message-Id: <ggbap3-fn5.ln1@osiris.mauzo.dyndns.org>
Quoth "DJ Stunks" <DJStunks@gmail.com>:
> grin.k1tt3n@gmail.com wrote:
> > I just discovered the bug/feature of having a static variable if it
> > initialized as:
> >
> > my $var = expr() if condition();
> >
> > That is, if condifition is not true, then var is initialized with
> > whatever was last there.
> >
> > It seems like this issue is over 7 years old, but I see no mention of
> > it in "man perlsub".
> > (It cost me two hours this morning wrangling with mod_perl).
> >
> > Are there any plans to document/correct this soon?
> >
> > This was running on perl 5.8.8.
>
> I don't think I understand what you're getting at. Either that or I
> don't see it:
>
> C:\>perl -Mstrict -e "for (1,0) {my $var = 'defined' if $_; \
> print qq[$_: \$var = $var\n]}"
> 1: $var = defined
> 0: $var =
>
> ??
>
> This is perl, v5.8.7 built for MSWin32-x86-multi-thread
I believe the OP is referring to this behaviour:
~% perl -le'sub foo { my $x if 0; print $x++ } foo; foo;'
0
1
~%
which is a way of faking 'static' variables (note that without the C<if
0> you get 0 both times). This has always been undocumented (technically
it's a bug), and in bleadperl (the dev track for 5.10) it has been
replaced with proper static vars declared with the C<state> keyword. I'm
not sure what will happen to this construct then: I wouldn't be
surprised if it was fixed... so don't rely on it.
Ben
--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* benmorrow@tiscali.co.uk *
------------------------------
Date: 22 Jul 2006 13:44:47 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: my VAR = EXPR if COND
Message-Id: <1153601087.681080.252860@m79g2000cwm.googlegroups.com>
Ben Morrow wrote:
> Quoth "DJ Stunks" <DJStunks@gmail.com>:
> > grin.k1tt3n@gmail.com wrote:
> > > I just discovered the bug/feature of having a static variable if it
> > > initialized as:
> > >
> > > my $var = expr() if condition();
> > >
> > > That is, if condifition is not true, then var is initialized with
> > > whatever was last there.
> >
> > I don't think I understand what you're getting at.
>
> I believe the OP is referring to this behaviour:
>
> ~% perl -le'sub foo { my $x if 0; print $x++ } foo; foo;'
> 0
> 1
> ~%
>
> which is a way of faking 'static' variables (note that without the C<if
> 0> you get 0 both times). This has always been undocumented (technically
> it's a bug), and in bleadperl (the dev track for 5.10) it has been
> replaced with proper static vars declared with the C<state> keyword. I'm
> not sure what will happen to this construct then: I wouldn't be
> surprised if it was fixed... so don't rely on it.
so "static variable" would be synonymous with "private variable" as
through a closure?
C:\>perl -Mstrict -le "{my $x; sub foo {print $x++}} foo; foo;"
0
1
?
-jp
------------------------------
Date: Sat, 22 Jul 2006 21:50:48 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: my VAR = EXPR if COND
Message-Id: <e9u338$87a$1@gemini.csx.cam.ac.uk>
DJ Stunks wrote:
> Ben Morrow wrote:
>> Quoth "DJ Stunks" <DJStunks@gmail.com>:
>>> grin.k1tt3n@gmail.com wrote:
>>>> I just discovered the bug/feature of having a static variable if it
>>>> initialized as:
>>>>
>>>> my $var = expr() if condition();
>>>>
>>>> That is, if condifition is not true, then var is initialized with
>>>> whatever was last there.
>>> I don't think I understand what you're getting at.
>> I believe the OP is referring to this behaviour:
>>
>> ~% perl -le'sub foo { my $x if 0; print $x++ } foo; foo;'
>> 0
>> 1
>> ~%
>>
>> which is a way of faking 'static' variables (note that without the C<if
>> 0> you get 0 both times). This has always been undocumented (technically
>> it's a bug), and in bleadperl (the dev track for 5.10) it has been
>> replaced with proper static vars declared with the C<state> keyword. I'm
>> not sure what will happen to this construct then: I wouldn't be
>> surprised if it was fixed... so don't rely on it.
>
> so "static variable" would be synonymous with "private variable" as
> through a closure?
ITIM "static" as in one of the many uses of that keyword in C/C++: a
variable that is static to a function retains its value between function
calls. They are declared, for example, as "static int ever_called = 0;".
This functionality is similar to a variable declared outside a
subroutine in a closure, though I suspect that there is more to closures
than that (at least in other languages) - and in Perl you can have
multiple subs in the same closure.
DS
------------------------------
Date: 22 Jul 2006 09:54:17 -0700
From: nitroamos@gmail.com
Subject: Re: perl + regex bug?
Message-Id: <1153587257.368334.98690@m79g2000cwm.googlegroups.com>
Hello -- I totally agree that it is unlikely that there is a bug in
perl itself, and so that's why I'm posting -- because I'm relatively
inexperienced with perl and I think there is something important to
learn here. On the other hand, I have enough experience with cross
platform development that I know that in general compiler bugs can't be
ruled out. Further, my perl debugging skills are a bit weak... I don't
even know what kinds of problems to look for. Also, I almost never post
online because I'm almost always able to figure out the problems on my
own or with google's help, so I'm sorry if my protocol is wrong.
However, this one has eluded me.
Also, sorry for not providing enough information. I had hoped that the
sample output would be enough, but since it's not, I went ahead and put
my whole program online (see line 106). I debated whether I should try
to extract a new program; I hope this is ok:
http://www.wag.caltech.edu/QMcBeaver/jag_recorr_all
which requires this input file:
http://www.wag.caltech.edu/QMcBeaver/ne_pw91.01.in
(I won't keep those files up there forever...)
A short description about what has happened by the time line 106 is
reached: Basically the point of the program is to read in some of those
orbitals and then spit some of them back out combinatorially into new
files. By line 106, the first 5 orbitals (for example the 20 lines of
numbers including a header line from the sample input) are stored in
$orbitals[$i], so this pattern:
$orbitals[$i] =~ /\s+(\d+)\s+Orbital Energy/;
should grab the first integer from this part of that string (i've
replaced the other 19 lines of numbers with "..."):
1 Orbital Energy -32.554095 Occupation 1.000000
...
And then because I want to preserve that integer, I save it $index =
$1; so that I can use it in later pattern matches. I have a set of
combinatorially produced strings that look like "_1_3_4_5" and I want
to find out if the integer that I matched from the orbital string above
is contained in the combinatorial strings. The combinatorial strings
are a sequence of "_Integer", so once I have an integer from an
orbital, i have to check for "_Integer_" and "_Integer$" since I don't
want orbital "2" to match both "_1_2_3" and "_1_3_24". Now I realize
that I could change the pattern in my combinatorial string, but I've
already invested enough time in this particular bug (in my code) that I
want to know what the problem is.
I would be happy to run any recommended test with my code. I fixed the
integer vs single digit bug that Paul Lalli pointed out (thanks!), but
that was not the source of the problem. Also, regarding my
understanding of regex and regarding those couple of lines, I have
played around extensively with printing out different combinations of
$i, $index, $1, etc and all of them are printing exactly as I would
expect. The only deviation from what I expect is that anchored pattern
matching.
Here is what Klaus recommended I try:
>
> print "before: \$index = x'", unpack('H*', $index), "'\n";
> $index--; $index++;
> print "after : \$index = x'", unpack('H*', $index), "'\n";
I very slightly modified it to save space, and I've only pasted a
sample of the output at the bottom. As you can see, by commenting out
that one line, I'm getting different matching results even though
unpacking shows the same thing before and after. Regarding locale
settings, I don't know how to check... but I don't think there are any
strange characters in my strings because I tried looking for them using
pattern matching. Also, if I add print out this: length "$index", I get
length of 1 in all cases -- before and after.
I think the most telling piece of evidence is that both this pattern:
if($element =~ m/^_$index$/){
and this pattern:
if($element =~ m/^_$index/){
correctly produce these kinds of matches:
_1 matches _1 with index = 1
_2 matches _2 with index = 2
_3 matches _3 with index = 3
printed with this:
print "$element matches $& with index = $index\n";
whereas this pattern:
if($element =~ m/_$index$/){
will not produce those matches.
Thanks!
Amos.
****** Results from Klaus' test ******
Here are partial results from:
print "index=$index before: \$index = x'", unpack('H*',
$index), "' ";
$index--; $index++;
print "after : \$index = x'", unpack('H*', $index), "'\n";
index=1 before: $index = x'31' after : $index = x'31'
index=2 before: $index = x'32' after : $index = x'32'
_2_3_4_5 matches _2_ with index = 2
index=3 before: $index = x'33' after : $index = x'33'
_2_3_4_5 matches _3_ with index = 3
index=4 before: $index = x'34' after : $index = x'34'
_2_3_4_5 matches _4_ with index = 4
index=5 before: $index = x'35' after : $index = x'35'
_2_3_4_5 matches _5 with index = 5
index=1 before: $index = x'31' after : $index = x'31'
_1_2_3_4_5 matches _1_ with index = 1
index=2 before: $index = x'32' after : $index = x'32'
_1_2_3_4_5 matches _2_ with index = 2
index=3 before: $index = x'33' after : $index = x'33'
_1_2_3_4_5 matches _3_ with index = 3
index=4 before: $index = x'34' after : $index = x'34'
_1_2_3_4_5 matches _4_ with index = 4
index=5 before: $index = x'35' after : $index = x'35'
_1_2_3_4_5 matches _5 with index = 5
and with the idiocy line commented out:
print "index=$index before: \$index = x'", unpack('H*',
$index), "' ";
#$index--; $index++;
print "after : \$index = x'", unpack('H*', $index), "'\n";
I get (note that none of the $& printed have the form "_Integer"):
index=1 before: $index = x'31' after : $index = x'31'
index=2 before: $index = x'32' after : $index = x'32'
_2_3_4_5 matches _2_ with index = 2
index=3 before: $index = x'33' after : $index = x'33'
_2_3_4_5 matches _3_ with index = 3
index=4 before: $index = x'34' after : $index = x'34'
_2_3_4_5 matches _4_ with index = 4
index=5 before: $index = x'35' after : $index = x'35'
index=1 before: $index = x'31' after : $index = x'31'
_1_2_3_4_5 matches _1_ with index = 1
index=2 before: $index = x'32' after : $index = x'32'
_1_2_3_4_5 matches _2_ with index = 2
index=3 before: $index = x'33' after : $index = x'33'
_1_2_3_4_5 matches _3_ with index = 3
index=4 before: $index = x'34' after : $index = x'34'
_1_2_3_4_5 matches _4_ with index = 4
index=5 before: $index = x'35' after : $index = x'35'
------------------------------
Date: Sat, 22 Jul 2006 13:45:46 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl + regex bug?
Message-Id: <slrnec4siq.943.tadmc@magna.augustmail.com>
nitroamos@gmail.com <nitroamos@gmail.com> wrote:
> And then because I want to preserve that integer, I save it $index =
> $1; so that I can use it in later pattern matches. I have a set of
> combinatorially produced strings that look like "_1_3_4_5" and I want
> to find out if the integer that I matched from the orbital string above
> is contained in the combinatorial strings.
print "$index is contained in $orbital\n"
if grep $_ == $index, split /_/, $orbital;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 22 Jul 2006 10:45:18 -0700
From: mgarrish@gmail.com
Subject: Re: Problem with function "crypt"
Message-Id: <1153590318.338146.313460@75g2000cwc.googlegroups.com>
Dr.Ruud wrote:
> mgarrish@gmail.com schreef:
> > madan:
>
> >> use strict;
> >
> > use warnings;
> > use CGI::Carp qw/fatalsToBrowser/;
>
> Maybe news:J2s31s.M4E@news.boeing.com applies here too:
>
> <quote>
> Often overlooked, the warningsToBrowser call must be invoked too or
> the buffer won't be flushed, eg,
>
> use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
> print header();
> warningsToBrowser(1);
> </quote>
>
Yes, and a particularly bad oversight on my part since he'd already put
the fatalsToBrowser call in and that's what I was responding to... : (
Matt
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 9513
***************************************