[25866] in Perl-Users-Digest
Perl-Users Digest, Issue: 8099 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 20 21:05:36 2005
Date: Fri, 20 May 2005 18: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 Fri, 20 May 2005 Volume: 10 Number: 8099
Today's topics:
Re: local, END, and $? xhoster@gmail.com
Re: local, END, and $? <henry.townsend@not.here>
Re: local, END, and $? (Anno Siegel)
Modyfying loop? <spam@noreply.org>
Re: Modyfying loop? (Anno Siegel)
Re: Modyfying loop? <noreply@gunnar.cc>
Re: Modyfying loop? <pilkowsk@informatik.uni-marburg.de>
Re: semi-opacity with GD <richard.bennett@nospam.skynet.be>
Re: semi-opacity with GD <sisyphus1@nomail.afraid.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 May 2005 15:48:35 GMT
From: xhoster@gmail.com
Subject: Re: local, END, and $?
Message-Id: <20050520114835.548$Cg@newsreader.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> >
> > I don't understand where the problem is:
> >
> > $ perl -e 'exit 3; END { local $?; system("NON_COMMAND"); \
> > print "status:$?\n"; }'; echo $?
> > status:-1
> > 3
>
> Apparently the OP wasn't aware that local( $x) assigns an undefined
> value to $x. If you want a localized variable to keep its previous
> value (at least for a while, otherwise local() wouldn't make sense),
> write
>
> local $x = $x;
But that does not work in this case. I don't know if it is because
$? is special, or because END blocks are special, or a combination of
both.
perl -e 'exit 3; END{{print "status=$?\n";local $?=$?;\
print "status=$?\n";}}' ; echo $?
status=3
status=0
0
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Fri, 20 May 2005 12:14:50 -0400
From: Henry Townsend <henry.townsend@not.here>
Subject: Re: local, END, and $?
Message-Id: <taadnfZmctVlkRPfRVn-sg@comcast.com>
Anno Siegel wrote:
> ko <kuujinbo@hotmail.com> wrote in comp.lang.perl.misc:
>
>>Henry Townsend wrote:
>>>So it loses $? within the block. If I change it to say "local $? = $?;"
>>>then $? becomes 0 both in and out of the block...
>
> Apparently the OP wasn't aware that local( $x) assigns an undefined
> value to $x. If you want a localized variable to keep its previous
> value (at least for a while, otherwise local() wouldn't make sense),
> write
>
> local $x = $x;
Actually I did mention that I'd tried assigning explicitly but it wasn't
in the test case I sent. As another poster has pointed out,
local $? = $?;
doesn't work, even in Perl 5.8.6. Of course grabbing its value in a
lexical before localizing it is a safe workaround but there's still a
mystery here, at least to me.
--
Henry Townsend
------------------------------
Date: 20 May 2005 18:04:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: local, END, and $?
Message-Id: <d6l8qv$fve$1@mamenchi.zrz.TU-Berlin.DE>
<xhoster@gmail.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> > >
> > > I don't understand where the problem is:
> > >
> > > $ perl -e 'exit 3; END { local $?; system("NON_COMMAND"); \
> > > print "status:$?\n"; }'; echo $?
> > > status:-1
> > > 3
> >
> > Apparently the OP wasn't aware that local( $x) assigns an undefined
> > value to $x. If you want a localized variable to keep its previous
> > value (at least for a while, otherwise local() wouldn't make sense),
> > write
> >
> > local $x = $x;
>
> But that does not work in this case. I don't know if it is because
> $? is special, or because END blocks are special, or a combination of
> both.
>
> perl -e 'exit 3; END{{print "status=$?\n";local $?=$?;\
> print "status=$?\n";}}' ; echo $?
>
> status=3
> status=0
> 0
Weird but true. I don't think END has much to do with it. Also,
"local $?" without assignment doesn't set it to undef, but to 0.
That's understandable, because it is really a two-byte integer in
the run-time system. The behavior with local is still strange.
An intermediate variable can make it behave more normal:
perl -e 'exit 3; END{{print "status=$?\n"; $x = $?; local $?=$x;\
print "status=$?\n";}}' ; echo $?
status=3
status=3
3
Anno
------------------------------
Date: Fri, 20 May 2005 22:38:26 +0000
From: michael <spam@noreply.org>
Subject: Modyfying loop?
Message-Id: <d6li07$kov$01$1@news.t-online.com>
I'm trying to print hash array's by using a loop, whereby each loop
iteration except the first, should become part of a nested <UL>.
Firstly, this prints just one <UL> group of <LI>'s of 2 hash arrays:
use Tie::IxHash;
tie %flora_and_fauna, "Tie::IxHash";
tie %aquatic_creatures, "Tie::IxHash";
%flora_and_fauna = ('Flora & Fauna' => 'z0.html',
'Pretty Flowers' => 'z1.html',
'Deadly Vines' => 'z2.html');
%aquatic_creatures = ('Aquatic Creatures' => 'z3.html',
'Pretty Fish' => 'z4.html',
'Don\'t Eat' => 'z5.html');
print "<ul id=menu><!-- opened holding UL -->\n";
foreach $key ( keys %flora_and_fauna) {
$value = $flora_and_fauna{$key};
print "<li>";
print "<a href=$value>$key</a>";
print "</li>\n";
}
foreach $key ( keys %aquatic_creatures) {
$value = $aquatic_creatures{$key};
print "<li>";
print "<a href=$value>$key</a>";
print "</li>\n";
}
print "</ul><!-- closed holding UL -->\n";
Resulting html is then:
<ul id=menu><!-- opened holding UL -->
<li><a href=z0.html>Flora & Fauna</a></li>
<li><a href=z1.html>Pretty Flowers</a></li>
<li><a href=z2.html>Deadly Vines</a></li>
<li><a href=z3.html>Aquatic Creatures</a></li>
<li><a href=z4.html>Pretty Fish</a></li>
<li><a href=z5.html>Don't Eat</a></li>
</ul><!-- closed holding UL -->
Whilst what I would like is the following and slightly different structure:
<ul id=menu><!-- opened holding UL -->
<li><a href=z0.html>Flora & Fauna</a><!-- CUT -->
<UL><!-- open UL here -->
<li><a href=z1.html>Pretty Flowers</a></li>
<li><a href=z2.html>Deadly Vines</a></li>
</UL><!-- close UL here -->
</LI><!-- close LI here -->
<li><a href=z3.html>Aquatic Creatures</a><!-- CUT -->
<UL><!-- open UL here -->
<li><a href=z4.html>Pretty Fish</a></li>
<li><a href=z5.html>Don't Eat</a></li>
</UL><!-- close UL here -->
</LI><!-- close LI here -->
</ul><!-- closed holding UL -->
So basically I'd like to:
1) Cut the closing </LI> out of the first iteration of each of the loops,
being the last five characters.
2) Print an opening <UL> between first and second iteration only or at the
beginning of the second.
3) Close the </UL> after the last </li> of each hash array (as done below).
4) Insert a closing a </LI> after each hash array (as also done below).
So the following takes care of step 3 and 4 but not 1 and 2 ...
print "<ul id=menu><!-- opened holding UL -->\n";
foreach $key ( keys %flora_and_fauna) {
$value = $flora_and_fauna{$key};
print "<li>";
print "<a href=$value>$key</a>";
print "</li>\n";
}
print "</UL><!-- close UL here -->\n";
print "</LI><!-- close LI here -->\n";
foreach $key ( keys %aquatic_creatures) {
$value = $aquatic_creatures{$key};
print "<li>";
print "<a href=$value>$key</a>";
print "</li>\n";
}
print "</UL><!-- close UL here -->\n";
print "</LI><!-- close LI here -->\n";
print "</ul><!-- closed holding UL -->\n";
... and that of course prints a wrong html syntax, as below:
<ul id=menu><!-- opened holding UL -->
<li><a href=z0.html>Flora & Fauna</a></li>
<li><a href=z1.html>Pretty Flowers</a></li>
<li><a href=z2.html>Deadly Vines</a></li>
</UL><!-- close UL here -->
</LI><!-- close LI here -->
<li><a href=z3.html>Aquatic Creatures</a></li>
<li><a href=z4.html>Pretty Fish</a></li>
<li><a href=z5.html>Don't Eat</a></li>
</UL><!-- close UL here -->
</LI><!-- close LI here -->
</ul><!-- closed holding UL -->
In other words, I'd simple like to cut one closing </li> and add an opening
<ul> to the above, which may sound easy enough, but it probably isn't...
Could it perhaps be done by modifying the foreach loop, or by copying
values to something else and change with regex or insert/remove by some
other method, or by using a different loop method altogether, not foreach?
Many thanks,
Michael
--
A classic is something that everyone wants to have read
and nobody wants to read.
-- Mark Twain, "The Disappearance of Literature"
------------------------------
Date: 20 May 2005 21:30:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Modyfying loop?
Message-Id: <d6lkud$mjf$1@mamenchi.zrz.TU-Berlin.DE>
michael <spam@noreply.org> wrote in comp.lang.perl.misc:
> I'm trying to print hash array's by using a loop, whereby each loop
> iteration except the first, should become part of a nested <UL>.
The word "nested" is a keyword in programming. It often means that
a recursive approach is in order.
Suppose you know what to do (what string to return) when there are
no nested parts. To find the string for a structure that has nested
parts, find (recursively) the strings for the parts and glue them
together with (usually fixed) other strings.
It may be hard to fix the looping approach (which I snipped), though
with an explicit stack it should be possible. I'm not for recursion
at any cost, but here it may be worth a try.
Anno
------------------------------
Date: Fri, 20 May 2005 23:59:49 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Modyfying loop?
Message-Id: <3f751nF6cet8U1@individual.net>
michael wrote:
> I'm trying to print hash array's by using a loop, whereby each loop
> iteration except the first, should become part of a nested <UL>.
I would consider a different data structure, to begin with. Instead of a
bunch of hashes, an AoAoA might be suitable:
my @AoAoA = (
[
[ 'Flora & Fauna' => 'z0.html' ],
[ 'Pretty Flowers' => 'z1.html' ],
[ 'Deadly Vines' => 'z2.html' ],
],
[
[ 'Aquatic Creatures' => 'z3.html' ],
[ 'Pretty Fish' => 'z4.html' ],
[ 'Don\'t Eat' => 'z5.html' ],
],
);
That would let you keep the order without using Tie::IxHash. The AoAoA
can be printed using nested foreach loops:
print qq(<ul id="menu">\n);
for (@AoAoA) {
my ($label, $url) = @{ shift @$_ };
print qq( <li><a href="$url">$label</a>\n <ul>\n);
for my $pair (@$_) {
my ($label, $url) = @$pair;
print qq( <li><a href="$url">$label</a></li>\n);
}
print " </ul>\n </li>\n";
}
print "</ul>\n";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 21 May 2005 00:40:11 +0200
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Modyfying loop?
Message-Id: <3f777jF6d8j7U1@individual.net>
* michael schrieb:
>
> I'm trying to print hash array's by using a loop, whereby each loop
> iteration except the first, should become part of a nested <UL>.
> Firstly, this prints just one <UL> group of <LI>'s of 2 hash arrays:
>
> use Tie::IxHash;
>
> tie %flora_and_fauna, "Tie::IxHash";
> tie %aquatic_creatures, "Tie::IxHash";
Always, you should use "strict" and "warnings", do you? Please declare
your vars with my(), e.g.
tie my %flora_and_fauna, "Tie::IxHash";
tie my %aquatic_creatures, "Tie::IxHash";
>
> %flora_and_fauna = ('Flora & Fauna' => 'z0.html',
> 'Pretty Flowers' => 'z1.html',
> 'Deadly Vines' => 'z2.html');
>
> %aquatic_creatures = ('Aquatic Creatures' => 'z3.html',
> 'Pretty Fish' => 'z4.html',
> 'Don\'t Eat' => 'z5.html');
[...]
> Whilst what I would like is the following and slightly different structure:
>
> <ul id=menu><!-- opened holding UL -->
> <li><a href=z0.html>Flora & Fauna</a><!-- CUT -->
> <UL><!-- open UL here -->
> <li><a href=z1.html>Pretty Flowers</a></li>
> <li><a href=z2.html>Deadly Vines</a></li>
> </UL><!-- close UL here -->
> </LI><!-- close LI here -->
> <li><a href=z3.html>Aquatic Creatures</a><!-- CUT -->
> <UL><!-- open UL here -->
> <li><a href=z4.html>Pretty Fish</a></li>
> <li><a href=z5.html>Don't Eat</a></li>
> </UL><!-- close UL here -->
> </LI><!-- close LI here -->
> </ul><!-- closed holding UL -->
Please indent your lines somehow. No one could read this without effort.
Afterwards, you want to read `perldoc -f each` and try something like
print "<ul id='menu'>\n";
for ( \%flora_and_fauna, \%aquatic_creatures ) {
my $firstkey = each %$_;
print " <li>$firstkey\n";
print " <ul>\n";
print " <li>$_</li>\n" while local $_ = each %$_;
print " </ul>\n";
print " </li>\n";
}
print "</ul>\n";
to get something like
<ul id='menu'>
<li>Flora & Fauna
<ul>
<li>Pretty Flowers</li>
<li>Deadly Vines</li>
</ul>
</li>
<li>Aquatic Creatures
<ul>
<li>Pretty Fish</li>
<li>Don't Eat</li>
</ul>
</li>
</ul>
>
> Could it perhaps be done by modifying the foreach loop, or by copying
> values to something else and change with regex or insert/remove by some
> other method, or by using a different loop method altogether, not foreach?
Right, just use a "different loop method". I suggest to use *while and
each* instead of *foreach and keys*.
regards,
fabian
------------------------------
Date: Fri, 20 May 2005 13:54:01 +0200
From: Richard Bennett <richard.bennett@nospam.skynet.be>
Subject: Re: semi-opacity with GD
Message-Id: <428dcfd6$0$21652$ba620e4c@news.skynet.be>
Sisyphus wrote:
>
> "Richard Bennett" <richard.bennett@nospam.skynet.be> wrote
>> hi,
>> Yep, it works. In fact, you can also output to file - that works too.
>
> Heh .... I eventually got round to starting Apache and writing a cgi
> script so that I could view these images that were created on the fly. I
> ran the first of the 2 scripts that you posted, and I can see that the
> image gets paler as $alpha is increased, but there's definitely no
> translucence there for me. It is definitely opaque.
You are testing with a browser like Firefox? IE doesn't support this effect.
Also, you have to layer the generated image over another one, to see it
showing through.
here's an example of the output of the last version of the script;
http://212.23.52.148/cgi-bin/img4.pl
of course it just looks pale, but if you display it over something else the
background shows through.
Thanks again,
richard.
------------------------------
Date: Sat, 21 May 2005 10:21:43 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: semi-opacity with GD
Message-Id: <428e7f16$0$4656$afc38c87@news.optusnet.com.au>
"Richard Bennett" <richard.bennett@nospam.skynet.be> wrote in message
news:428dcfd6$0$21652$ba620e4c@news.skynet.be...
> Sisyphus wrote:
> > Heh .... I eventually got round to starting Apache and writing a cgi
> > script so that I could view these images that were created on the fly. I
> > ran the first of the 2 scripts that you posted, and I can see that the
> > image gets paler as $alpha is increased, but there's definitely no
> > translucence there for me. It is definitely opaque.
> You are testing with a browser like Firefox? IE doesn't support this
effect.
> Also, you have to layer the generated image over another one, to see it
> showing through.
>
Aaah - I was layering the generated image over another one ... but looking
at it with IE :-)
Cheers,
Rob
------------------------------
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 8099
***************************************