[28442] in Perl-Users-Digest
Perl-Users Digest, Issue: 9806 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 5 09:06:00 2006
Date: Thu, 5 Oct 2006 06: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 Thu, 5 Oct 2006 Volume: 10 Number: 9806
Today's topics:
Re: $test <> ${test} <bol@adv.magwien.gv.at>
Re: $test <> ${test} anno4000@radom.zrz.tu-berlin.de
Re: Archive::Zip - end up with empty file ... <lev.weissman@creo.com>
Re: Archive::Zip - end up with empty file ... <mritty@gmail.com>
Re: Archive::Zip - end up with empty file ... <tadmc@augustmail.com>
Artificial Mind - Part One - Basic Architecture and Cog <tomwingmak@yahoo.com>
Re: Artificial Mind - Part One - Basic Architecture and <ajonospam@andrew.cmu.edu>
Re: Artificial Mind - Part One - Basic Architecture and <tadmc@augustmail.com>
Re: FAQ 5.2 (Was: inserting lines) <rvtol+news@isolution.nl>
Re: FAQ 5.2 (Was: inserting lines) <brian.d.foy@gmail.com>
new CPAN modules on Thu Oct 5 2006 (Randal Schwartz)
Re: One-Liner Help with -e + ksh heredoc anno4000@radom.zrz.tu-berlin.de
Re: Problem with string comparison <mkazmierski@gmail.com>
Re: question on File::Tail <someone@example.com>
Re: Spliting values and reversing a hash <ced@blv-sam-01.ca.boeing.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 5 Oct 2006 08:58:47 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: $test <> ${test}
Message-Id: <1160031528.152393@proxy.dienste.wien.at>
Curtis M. West:
> can anyone tell me, what the difference between $test and ${test} is?
The braces are required in 2 cases:
1) If you use a variable name in an otherwise ambiguous context:
$name = 'Config';
print "$name_Startup"; # prints nothing, looks for a variable
$name_Startup
print "${name}_Startup"; # prints "Config"
because '_' is a valid character in variable names, the braces tell
the parse that the name of the scalar is delimited by them and the
rest is part of the string literal.
2) When you build variable names at run-time (symbolic references):
$foobar = 'FooBar';
$x = 'foo';
$y = 'bar';
print ${$x . $y}; # prints "FooBar"
This is often used in modules when handling packages and building
full-qualified variable and function names. In the case of "${test}",
the braces are redundant are removed by the parser, so the
compiled code for "$test" and "${test}" is actually the same.
Greetings, Ferry
--
Ing Ferry Bolhar
Magistrat der Stadt Wien - MA 14
A-1010 Wien
E-Mail: bol@adv.magwien.gv.at
------------------------------
Date: 5 Oct 2006 07:22:56 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: $test <> ${test}
Message-Id: <4ojq6gFeqp1iU1@news.dfncis.de>
Ferry Bolhar <bol@adv.magwien.gv.at> wrote in comp.lang.perl.misc:
> Curtis M. West:
>
> > can anyone tell me, what the difference between $test and ${test} is?
>
> The braces are required in 2 cases:
>
> 1) If you use a variable name in an otherwise ambiguous context:
>
> $name = 'Config';
> print "$name_Startup"; # prints nothing, looks for a variable
> $name_Startup
> print "${name}_Startup"; # prints "Config"
>
> because '_' is a valid character in variable names, the braces tell
> the parse that the name of the scalar is delimited by them and the
> rest is part of the string literal.
>
> 2) When you build variable names at run-time (symbolic references):
Ah, but that is a different case.
> $foobar = 'FooBar';
> $x = 'foo';
> $y = 'bar';
> print ${$x . $y}; # prints "FooBar"
This is general de-reference syntax with a symbolic reference. Here
the braces form a block whose return value (the last statement) is
taken as a reference.
That is not the case in the first example. If it were, "${name}" would
be a symref through a bareword. It wouldn't be applicable to lexical
variables.
Anno
------------------------------
Date: 4 Oct 2006 23:29:48 -0700
From: "MoshiachNow" <lev.weissman@creo.com>
Subject: Re: Archive::Zip - end up with empty file ...
Message-Id: <1160029788.389394.204160@m7g2000cwm.googlegroups.com>
> Where did $zip come from?
> Where did $NAME, $NAME1, $NAME2 come from?
> What are the return values of all the addFileOrDirectory calls?
>
> Please post a SHORT but COMPLETE script that demonstrates your errors.
>
> Paul Lalli
Ok,The script on my Windows looks as following. I chdir to the
directory where all my files and folders to be zipped exist.Then I'm
calling a procedire ZIP as following :
&ZIP("Marksets ");
&ZIP("PrintConsole.reg");
. . .
sub ZIP {
$NAME=shift;
$NEWNAME=shift;
warn "error zipping $NAME !!! $!" unless
$zip->addFileOrDirectory("$NAME") == AZ_OK;
}
The warning I get look like:
error zipping Marksets !!! at script/rehost.pl line 2159.
error zipping PrintConsole.reg !!! Bad file descriptor at
script/rehost.pl line 2159.
error zipping KDI-PGY2500_SysInfo.nfo !!! Bad file descriptor at
script/rehost.pl line 2159.
error zipping OS_PRINTERS !!! Bad file descriptor at script/rehost.pl
line 2159.
error zipping D:\Documents and
Settings\Administrator\Desktop\KDI-PGY2500_20061005_P3102_rehostsave.txt
!!! Bad file descriptor at script/rehost.pl line 2159.
(line 2159 is the one with the $zip->addFileOrDirectory("$NAME") ).
The zip file holds all files and folders,however all folders are empty.
Thanks
------------------------------
Date: 5 Oct 2006 04:01:00 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Archive::Zip - end up with empty file ...
Message-Id: <1160046059.933128.86410@k70g2000cwa.googlegroups.com>
MoshiachNow wrote:
> > Please post a SHORT but COMPLETE script that demonstrates your errors.
^^^^^^^^
> warn "error zipping $NAME !!! $!" unless
> $zip->addFileOrDirectory("$NAME") == AZ_OK;
I see nothing in the docs for Archive::Zip that indicates $! is set on
a failure. Print out the return value of the method, and compare it to
the values listed in the documentation. That will tell you what the
problem is.
Paul Lalli
------------------------------
Date: Thu, 5 Oct 2006 06:28:46 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Archive::Zip - end up with empty file ...
Message-Id: <slrnei9r3e.7it.tadmc@magna.augustmail.com>
MoshiachNow <lev.weissman@creo.com> wrote:
> &ZIP("Marksets ");
^
^
> warn "error zipping $NAME !!! $!" unless
^
^
> error zipping Marksets !!! at script/rehost.pl line 2159.
^^^
How come there is not 2 spaces there?
Either this is not your actual code, or that is not the actual message...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 4 Oct 2006 22:12:49 -0700
From: "tommak" <tomwingmak@yahoo.com>
Subject: Artificial Mind - Part One - Basic Architecture and Cognitive Structure is now available
Message-Id: <1160025169.661358.213830@i42g2000cwa.googlegroups.com>
It's a dream of human beings to build machines that can think and
behave like human beings. The most important part of of such a machine
is an artificial mind that can emulate the cognitive processing of
human mind.
This book, "Next Generation Artificial Intelligence, Artificial Mind -
Part One - Basic Architecture and Cognitive Structure" introduces a
basic artificial mind architecture and computational model for
cognitive processing. Inside the book, three important cognitive
process modeling components, mental objects network (MON),
associative-learning mechanisms and a concept formation principle are
introduced. Based on the architecture and the computational model, one
can develop his own model of artificial mind according to his own
specific requirements.
The first edition of Artificial Mind - Part One is now available for
purchase from the author's personal web site. The price of the e-book
is USD7.00 (seven US dollars). An evaluation edition of this e-book is
also available for download from the web site.
The author's personal web site:
http://www.geocities.com/tomwingmak/
------------------------------
Date: Thu, 5 Oct 2006 02:22:21 -0400 (EDT)
From: "Arthur J. O'Dwyer" <ajonospam@andrew.cmu.edu>
Subject: Re: Artificial Mind - Part One - Basic Architecture and Cognitive Structure is now available
Message-Id: <Pine.LNX.4.61-042.0610050210550.31779@unix36.andrew.cmu.edu>
On Thu, 4 Oct 2006, tommak wrote:
>
> It's a dream of human beings to build machines that can think and
> behave like human beings. The most important part of of such a machine
> is an artificial mind [...]
> This book, "Next Generation Artificial Intelligence, Artificial Mind -
> Part One - Basic Architecture and Cognitive Structure" introduces a
> basic artificial mind architecture and computational model for
> cognitive processing.
[...]
> The first edition of Artificial Mind - Part One is now available for
> purchase from the author's personal web site. The price of the e-book
> is USD7.00 (seven US dollars). An evaluation edition of this e-book is
> also available for download from the web site.
FYI: The "e-book" (read: Adobe PDF) is a very badly edited, very /very/
long thesis on something Mak calls "Buddhist Cognitive Theory". It
contains no tangible implementation of his ideas, mainly because those
ideas aren't really well thought out in the first place. The thesis
consists mostly of bulleted lists of things: categorizing objects,
types of ideas, and so on.
On the one hand, I suppose interesting results in AI have usually been
based on crackpot psychological[1] theories (Eliza and (especially) Parry
come to mind), but on the other hand this looks like a /particularly/
crackpot theory, /particularly/ poorly expressed, and with no interesting
and shiny result to show to the audience at the end.
If it's not worth the three-second download for the "trial version",
it's certainly not worth spending real money on a licensed (or whatever)
copy.
-Arthur
[1] - Is this redundant? :)
------------------------------
Date: Thu, 5 Oct 2006 06:39:43 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Artificial Mind - Part One - Basic Architecture and Cognitive Structure is now available
Message-Id: <slrnei9rnv.7it.tadmc@magna.augustmail.com>
[ Followups set ]
tommak <tomwingmak@yahoo.com> wrote:
> It's a dream of human beings to build machines that can think and
> behave like human beings. The most important part of of such a machine
> is an artificial mind that can emulate the cognitive processing of
> human mind.
How is your article related to Perl (or to Sybase)?
You have destroyed your credibility with the Newsgroups header.
People can easily recognize your spam for what it is without
even following any of the links you provide...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 5 Oct 2006 09:01:11 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: FAQ 5.2 (Was: inserting lines)
Message-Id: <eg2hv2.1fg.1@news.isolution.nl>
brian d foy schreef:
> [...]
> To prepend lines to the beginning, print those lines before you enter
> the loop that prints the existing lines.
>
> open my $in, '<', $file or die "Can't read old file: $!";
> open my $out, '>', "$file.new" or die "Can't write new file: $!";
>
> print "# Add this line to the top\n"; # <--- HERE'S THE MAGIC
print $out ...
> [...]
> To change existing lines, insert the code to modify the lines inside
> the C<while> loop. In this case, the code finds all lowercased
> versions of "perl" and uppercases them. The happens for every line, so
> be sure that you're supposed to do that on every line!
>
> open my $in, '<', $file or die "Can't read old file: $!";
> open my $out, '>', "$file.new" or die "Can't write new file: $!";
>
> print "# Add this line to the top\n";
Idem.
> my @lines = do { local $/; <$in> }; # slurp!
my @lines; { local $/ ; my @lines = <$in> } # slurp!
;)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 05 Oct 2006 04:46:45 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 5.2 (Was: inserting lines)
Message-Id: <051020060446450600%brian.d.foy@gmail.com>
In article <yvnhcyjy3yv.fsf@famous02.dal.design.ti.com>,
<jgraber@ti.com> wrote:
> brian d foy <brian.d.foy@gmail.com> writes:
>
> > In article <031020061558043174%jgibson@mail.arc.nasa.gov>, Jim Gibson
> > <jgibson@mail.arc.nasa.gov> wrote:
>
> > The basic idea of inserting, changing, or deleting a line from a text
> > file involves reading and printing the file to the point you want to
> > make the change, making the change, then reading and printing the rest
> > of the file. Perl doesn't provide random access to lines (especially
> > since the record input separator, C<$/>, is mutable), although modules
> > such as C<Tie::File> can fake it.
> But Perl does provide random access to characters (bytes?)
> a collection of them make up a line.
You can't move to a particular line, though. You have to count the
number of record separators between you and the beginning of the file
to figure out where you are, then adjust your position until you get to
get to where you want to be. Random access means you can move directly
to where you want to be. You can't do that with lines in Perl not only
because lines don't have a set length, but you don't even know what the
record separator is, necessarily, between reads, since $/ is mutable,
so the "line" number can be path dependent.
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Thu, 5 Oct 2006 04:42:09 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Oct 5 2006
Message-Id: <J6nBq9.16B7@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Acme-Valid-1.00
http://search.cpan.org/~memowe/Acme-Valid-1.00/
your script will be valid Perl
----
Bigtop-0.18
http://search.cpan.org/~philcrow/Bigtop-0.18/
A web application data language processor
----
CPAN-Reporter-0.25
http://search.cpan.org/~dagolden/CPAN-Reporter-0.25/
Provides Test::Reporter support for CPAN.pm
----
CPAN-Reporter-0.26
http://search.cpan.org/~dagolden/CPAN-Reporter-0.26/
Provides Test::Reporter support for CPAN.pm
----
CPAN-Reporter-0.27
http://search.cpan.org/~dagolden/CPAN-Reporter-0.27/
Provides Test::Reporter support for CPAN.pm
----
CPAN-Test-Dummy-Perl5-Build-1.03
http://search.cpan.org/~andk/CPAN-Test-Dummy-Perl5-Build-1.03/
CPAN Test Dummy
----
Chemistry-File-QChemOut-0.10
http://search.cpan.org/~itub/Chemistry-File-QChemOut-0.10/
Q-Chem ouput molecule format reader
----
Daizu-0.2
http://search.cpan.org/~geoffr/Daizu-0.2/
class for accessing Daizu CMS from Perl
----
Devel-EvalContext-0.06
http://search.cpan.org/~bsmith/Devel-EvalContext-0.06/
----
Devel-EvalContext-0.07
http://search.cpan.org/~bsmith/Devel-EvalContext-0.07/
Save lexicals and hints between calls to eval
----
Devel-Hide-0.0003
http://search.cpan.org/~ferreira/Devel-Hide-0.0003/
Forces the unavailability of specified Perl modules (for testing)
----
File-BOM-0.14
http://search.cpan.org/~mattlaw/File-BOM-0.14/
Utilities for handling Byte Order Marks
----
Finance-Bank-AllianceAndLeicester-1.01
http://search.cpan.org/~bisscuitt/Finance-Bank-AllianceAndLeicester-1.01/
Check your Alliance & Leicester bank accounts from Perl
----
Finance-TW-TSEQuote-0.26
http://search.cpan.org/~clkao/Finance-TW-TSEQuote-0.26/
Check stock quotes from Taiwan Security Exchange
----
Gantry-3.41
http://search.cpan.org/~philcrow/Gantry-3.41/
Web application framework for mod_perl, cgi, etc.
----
HTML-Template-Compiled-0.78
http://search.cpan.org/~tinita/HTML-Template-Compiled-0.78/
Template System Compiles HTML::Template files to Perl code
----
LEGO-NXT-1.42
http://search.cpan.org/~collins/LEGO-NXT-1.42/
LEGO NXT Direct Commands API.
----
MapReduce-0.01
http://search.cpan.org/~iwoodhead/MapReduce-0.01/
Perl version of Google's distributed data processing
----
Media-DateTime-0.40
http://search.cpan.org/~mgrimes/Media-DateTime-0.40/
An highly extensible module to extract the creation date and time from a file.
----
Module-Mask-Deps-0.05
http://search.cpan.org/~mattlaw/Module-Mask-Deps-0.05/
Mask modules not listed as dependencies
----
Net-Appliance-Phrasebook-0.06
http://search.cpan.org/~oliver/Net-Appliance-Phrasebook-0.06/
Network appliance command-line phrasebook
----
Net-Packet-3.00_02
http://search.cpan.org/~gomor/Net-Packet-3.00_02/
a framework to easily send and receive frames from layer 2 to layer 7
----
PAR-Dist-FromCPAN-0.04
http://search.cpan.org/~smueller/PAR-Dist-FromCPAN-0.04/
Create PAR distributions from CPAN
----
PathTools-3.21
http://search.cpan.org/~kwilliams/PathTools-3.21/
----
Perlbal-1.51
http://search.cpan.org/~bradfitz/Perlbal-1.51/
Reverse-proxy load balancer and webserver
----
RPC-Object-0.00_01
http://search.cpan.org/~jwu/RPC-Object-0.00_01/
A lightweight implementation for remote procedure calls
----
RPC-Object-0.01
http://search.cpan.org/~jwu/RPC-Object-0.01/
A lightweight implementation for remote procedure calls
----
SWISH-API-More-0.01
http://search.cpan.org/~karman/SWISH-API-More-0.01/
do more with the SWISH::API
----
SWISH-API-Object-0.01
http://search.cpan.org/~karman/SWISH-API-Object-0.01/
return SWISH::API results as objects
----
SWISH-API-Stat-0.01
http://search.cpan.org/~karman/SWISH-API-Stat-0.01/
automatically reconnect to a SWISH::API handle if index file changes
----
THD7-1.1
http://search.cpan.org/~kwittmer/THD7-1.1/
Perl module providing control to a Kenwood TH-D7 radio via serial port
----
Template-Plugin-ByDate-0.03
http://search.cpan.org/~dmcbride/Template-Plugin-ByDate-0.03/
Keeps/removes included text based on whether the current date is within range.
----
Template-Plugin-Lingua-Conjunction-0.01
http://search.cpan.org/~brentdax/Template-Plugin-Lingua-Conjunction-0.01/
Template Toolkit plugin for human-readable lists
----
Test-Class-0.15
http://search.cpan.org/~adie/Test-Class-0.15/
Easily create test classes in an xUnit/JUnit style
----
Test-POE-Stopping-0.01
http://search.cpan.org/~adamk/Test-POE-Stopping-0.01/
----
Test-WWW-Jaunt-0.01_04
http://search.cpan.org/~rkrimen/Test-WWW-Jaunt-0.01_04/
A CGI-based testing platform.
----
Text-FixedLength-Extra-1.1
http://search.cpan.org/~tkeefer/Text-FixedLength-Extra-1.1/
various niceties for Text::FixedLength lovers.
----
Text-Lorem-More-0.12
http://search.cpan.org/~rkrimen/Text-Lorem-More-0.12/
Generate formatted nonsense using random Latin words.
----
WWW-Mechanize-1.21_02
http://search.cpan.org/~petdance/WWW-Mechanize-1.21_02/
Handy web browsing in a Perl object
----
WWW-Scraper-Delicious-0.10
http://search.cpan.org/~agf/WWW-Scraper-Delicious-0.10/
Retrieve links from del.icio.us
----
warnings-compat-0.01
http://search.cpan.org/~saper/warnings-compat-0.01/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 5 Oct 2006 05:58:24 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: One-Liner Help with -e + ksh heredoc
Message-Id: <4ojl80Fet9odU1@news.dfncis.de>
Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> anno4000@radom.zrz.tu-berlin.de <anno4000@radom.zrz.tu-berlin.de> wrote:
> > Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> >> anno4000@radom.zrz.tu-berlin.de <anno4000@radom.zrz.tu-berlin.de> wrote:
> >> > s/war/peace/g; <smalder73@gmail.com> wrote in comp.lang.perl.misc:
> >> >> I'm in the midst of writing a ksh script. I've got a file of junk I
> >> >> need to manipulate with some hash magic in perl, but I'm trying to keep
> >> >> the perl code encapsulated in my ksh script. I'm trying to do
> >> >> something like this...
> >> >>
> >> >> perl -e 'magic' -i file
> >> >>
> >> >> But I want the magic to look more like...
> >> >>
> >> >> perl -e <<EOF
> >> >> magic
> >> >> EOF
> >> >> -i file
> >> >>
> >> >> This way the code is not cryptic. So far I can not seem to make this
> >> >> work... am I on crack for thinking I should be able to do something
> >> >> like this? Any suggestions?
> >> >
> >> > You are misunderstanding ksh here documents. They don't return
> >> > a string, they supply the given text via standard input.
> >>
> >>
> >> they supply the given text right "here" (where the here-doc appears),
> >> hence the name "here document".
> >
> > Yes, that's where the text comes from. It goes to stdin of the command
> > it (i.e. the leading <<EOF) is part of.
>
>
> I can now see that _I_ am also misunderstanding ksh here documents.
So was I before I answered the question.
Anno
------------------------------
Date: 5 Oct 2006 01:36:15 -0700
From: "mark" <mkazmierski@gmail.com>
Subject: Re: Problem with string comparison
Message-Id: <1160037374.996209.25750@i42g2000cwa.googlegroups.com>
Hello,
Thank you - chomp was the thing I needed :) .
Regards, mark
------------------------------
Date: Thu, 05 Oct 2006 05:36:47 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: question on File::Tail
Message-Id: <PR0Vg.12202$N4.6132@clgrps12>
golden wrote:
>
> I have program that tails a file using file::tail and also periodically
>
> logs to a log file.
> The name of the file that I tail changes frequently the format of which
>
> is <file_yyyymmdd_pid.log>.
> I would like to put a small "heartbeat message" to my log file. In
> that file I wish to also include the current file name that is being
> tailed.
>
>
> I found that file::tail has an input method that simply displays the
> logfile name. I have a function that determines the appropriate log
> file. and use the "name_change" method to deal with that.
>
>
> My question is can somebody help me determine how to write to my log
> file periodically ( if the read is blocking waiting for data on the
> file taile object.
I was going to suggest using alarm() but File::Tail uses sleep() and those two
functions may not be compatible so you might want to fork() off a child
process that has a timer and either: sends a SIGUSR1 back to the parent which
catches it and writes to the log file or; have the child write to the log file.
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Thu, 5 Oct 2006 05:53:09 GMT
From: Charles DeRykus <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Spliting values and reversing a hash
Message-Id: <J6nF0L.Ap7@news.boeing.com>
anno4000@radom.zrz.tu-berlin.de wrote:
> Charles DeRykus <ced@blv-sam-01.ca.boeing.com> wrote in comp.lang.perl.misc:
>> John W. Krahn wrote:
>>> attn.steven.kuo@gmail.com wrote:
>>>> John W. Krahn wrote:
>>>>> for my $key ( keys %hash ) {
>>>>> for my $flavour ( @{ delete $hash{ $key } } ) {
>>>>> push @{ $hash{ $flavour } }, $key;
>>>>> }
>>>>> }
>>>> If I recall correctly, it isn't a good idea to delete
>>>> and add keys to a hash while iterating over it.
>>> "for my $key ( keys %hash )" creates a list of the hash keys in memory and any
>>> modifications to %hash inside the loop won't affect the contents of that list.
>>>
>>> perldoc -f delete
>> ^^^^^^
>> ITYM perldoc -f keys:
>>
>> The returned values are copies of the original keys
>> in the hash, so modifying them will not affect the
>> original hash. Compare "values".
>
> If I read that right, it is about the keys not being lvalues the
> way values are. That is one thing, changing the hash while looping
> over its keys is another.
>
> I believe it is safe to change the hash in
>
> for my $key ( keys %hash ) {
> # changes to %hash here
> }
>
> but the behavior of
>
> for my $i ( 1 .. 100_000_000 ) {
>
> can make a programmer wonder. If the loop over keys %hash were
> transformed to use an implicit iterator like the second one
> changing the hash might be unsafe.
>
That sounds right. I notice that 5.8.x (in contrast to earlier
versions) now clarifies that the most recently returned `each'
item can be safely deleted.
--
Charles DeRykus
------------------------------
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 9806
***************************************