[32356] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3623 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 26 00:09:26 2012

Date: Sat, 25 Feb 2012 21:09:07 -0800 (PST)
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, 25 Feb 2012     Volume: 11 Number: 3623

Today's topics:
    Re: a question about efficiency <derykus@gmail.com>
    Re: a question about efficiency <hjp-usenet2@hjp.at>
    Re: a question about efficiency <hjp-usenet2@hjp.at>
    Re: a question about efficiency <hjp-usenet2@hjp.at>
    Re: a question about efficiency <kiuhnm03.4t.yahoo.it>
    Re: a question about efficiency <ben@morrow.me.uk>
    Re: a question about efficiency <kiuhnm03.4t.yahoo.it>
    Re: a question about efficiency (Seymour J.)
    Re: a question about efficiency (Greg Bacon)
    Re: a question about efficiency (Greg Bacon)
    Re: a question about efficiency (Greg Bacon)
    Re: Constructing a value beforehand <hjp-usenet2@hjp.at>
    Re: Constructing a value beforehand <rvtol+usenet@xs4all.nl>
        Parameter guidelines for the Strong AI Singularity <mentifex@myuw.net>
    Re: tree to array of arrays (Tim McDaniel)
    Re: tree to array of arrays <nospam.gravitalsun.antispam@hotmail.com.nospam>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 24 Feb 2012 16:28:24 -0800 (PST)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: a question about efficiency
Message-Id: <73857a2b-e47b-4638-b28b-e85d8f52e596@v2g2000vbx.googlegroups.com>

On Feb 24, 12:21=A0pm, Kiuhnm <kiuhnm03.4t.yahoo.it> wrote:
> On 2/24/2012 18:55, C.DeRykus wrote:
> ...
> > I think it's documented somewhere that
> > 'my' has both compile-time and run-time
> > effects. In your former case, it's still
> > a closure but the run-time resets $x =A0because of =A0the scope introdu=
ced
> > by
> > map; whereas, in the latter, there's no
> > inner scope to wipe out the incrementing.
> > Here's an illustration:
>
> > perl -E 'my $y;&$_ for map { sub {my $x;++$x;++$y;say "$x|$y" } }
> > (1..10) '
> > ...
> > Of course, there's probably more to this :)
>
> Yes, I believe there is! Look at the references:
>
> perl -E 'my $y; &$_ for map { sub {my $x;++$x;++$y;say "$x|$y, refs:",
> \$x, "|", \$y } } (1..10) '
>
> As you can see, there are many $x. The label is the same, but they're
> different variables.
>

No, AIUI, memory for is released and
then reallocated for 'my' variables
each time through the loop on a private
stack. You probably shouldn't poke too
deeply into what goes on behind the
peephole :)

--
Charles DeRykus





------------------------------

Date: Sat, 25 Feb 2012 09:58:16 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: a question about efficiency
Message-Id: <slrnjkh8l8.8lm.hjp-usenet2@hrunkner.hjp.at>

On 2012-02-21 17:43, Kiuhnm <kiuhnm03.4t.yahoo.it> wrote:
> On 2/21/2012 16:34, Rainer Weikusat wrote:
>> Kiuhnm<kiuhnm03.4t.yahoo.it>  writes:
>>>> 		d =>   sub {
>>>> 		    my $l1;
>>>>
>>>> 		    for (keys(%ENV)) {
>>>> 			if ((my $l = length($_))>   $l1) { $l1 = $; }
>>>> 		    }
>>>> 		}
>>>> 	       });
>>>> -------------
>>>
>>> If this isn't another Perl feature I don't know about, you forgot an
>>> l' in your last assignment. On my PC, the 'l' improves the
>>> efficiency.
>>
>> Not significantly (if at all).
>
> It makes a huge difference on my configuration (~30%).

More importantly, it makes a difference on the correctness. «$;» is not
the same variable as «$l». («use warnings 'numeric'» would have caught
that error, btw).

	hp


-- 
   _  | Peter J. Holzer    | Deprecating human carelessness and
|_|_) | Sysadmin WSR       | ignorance has no successful track record.
| |   | hjp@hjp.at         | 
__/   | http://www.hjp.at/ |  -- Bill Code on asrg@irtf.org


------------------------------

Date: Sat, 25 Feb 2012 10:13:49 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: a question about efficiency
Message-Id: <slrnjkh9id.8lm.hjp-usenet2@hrunkner.hjp.at>

On 2012-02-21 22:32, Tim McDaniel <tmcd@panix.com> wrote:
> In article <4f44154e$0$1380$4fafbaef@reader2.news.tin.it>,
> Kiuhnm  <kiuhnm03.4t.yahoo.it> wrote:
>>On 2/21/2012 20:36, Tim McDaniel wrote:
>>> In article<4f43d60b$0$1387$4fafbaef@reader2.news.tin.it>,
>>> Kiuhnm<kiuhnm03.4t.yahoo.it>  wrote:
>>>> Finally I can omit those hideous curly braces.
>>>
>>> If you think curly braces are "hideous", you might prefer using
>>> some other language instead.
[...]
> I've heard good things about Ruby.  At a quick glance, it has no curly
> braces for control flow, but does use them for hashes.  I don't know
> how much power it has, but the one report I heard of was from a
> long-time Perl expert, and he had no complaints about things he could
> do in Perl but could not do in Ruby.
>

http://www.plat-forms.org/results-2011 may be an interesting read
(unfortunately the "detailed results report" seems to be still missing
after more than a year).

	hp


-- 
   _  | Peter J. Holzer    | Deprecating human carelessness and
|_|_) | Sysadmin WSR       | ignorance has no successful track record.
| |   | hjp@hjp.at         | 
__/   | http://www.hjp.at/ |  -- Bill Code on asrg@irtf.org


------------------------------

Date: Sat, 25 Feb 2012 10:19:17 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: a question about efficiency
Message-Id: <slrnjkh9sl.8lm.hjp-usenet2@hrunkner.hjp.at>

On 2012-02-22 13:43, Shmuel Metz <spamtrap@library.lspace.org.invalid> wrote:
> In <-POdnUXcZo6I-tnSnZ2dnUVZ_q2dnZ2d@posted.hiwaay2>, on 02/21/2012
>    at 09:55 PM, gbacon@hiwaay.net (Greg Bacon) said:
>>IÔÇÖm
>
> Please check the settings on your news client. Usenet is an ASCII
> medium, so anything in other character sets should be MIME encoded. It
> looks like you're using UTF-8, in which case I'd recommend an encoding
> of QP[1] rather than BASE64.

The usenet has been 8-bit clean almost since the beginning, so QP and
Base64 are not needed (and should actually be avoided). But any charset
other than US-ASCII has to be declared in a Content-Type header or the
recipient can't know what the bytes mean.

	hp


-- 
   _  | Peter J. Holzer    | Deprecating human carelessness and
|_|_) | Sysadmin WSR       | ignorance has no successful track record.
| |   | hjp@hjp.at         | 
__/   | http://www.hjp.at/ |  -- Bill Code on asrg@irtf.org


------------------------------

Date: Sat, 25 Feb 2012 15:28:17 +0100
From: Kiuhnm <kiuhnm03.4t.yahoo.it>
Subject: Re: a question about efficiency
Message-Id: <4f48f000$0$1388$4fafbaef@reader1.news.tin.it>

On 2/25/2012 1:28, C.DeRykus wrote:
> On Feb 24, 12:21 pm, Kiuhnm<kiuhnm03.4t.yahoo.it>  wrote:
>> On 2/24/2012 18:55, C.DeRykus wrote:
>> ...
>>> I think it's documented somewhere that
>>> 'my' has both compile-time and run-time
>>> effects. In your former case, it's still
>>> a closure but the run-time resets $x  because of  the scope introduced
>>> by
>>> map; whereas, in the latter, there's no
>>> inner scope to wipe out the incrementing.
>>> Here's an illustration:
>>
>>> perl -E 'my $y;&$_ for map { sub {my $x;++$x;++$y;say "$x|$y" } }
>>> (1..10) '
>>> ...
>>> Of course, there's probably more to this :)
>>
>> Yes, I believe there is! Look at the references:
>>
>> perl -E 'my $y;&$_ for map { sub {my $x;++$x;++$y;say "$x|$y, refs:",
>> \$x, "|", \$y } } (1..10) '
>>
>> As you can see, there are many $x. The label is the same, but they're
>> different variables.
>>
>
> No, AIUI, memory for is released and
> then reallocated for 'my' variables
> each time through the loop on a private
> stack. You probably shouldn't poke too
> deeply into what goes on behind the
> peephole :)

Isn't you the one who's poking? :)
My assumptions are simpler:
a) Perl has a garbage collector (which supports circular referencing),
b) any "object" is kept alive while referenced,
c) Perl's closures behave like real closures.
You, on the other hand, are focusing on how Perl internally handles 
things. That level of detail isn't needed to understand this simple 
example, IMHO.
For instance, your explanation is no longer valid if I slightly change 
the code, while mine is easier and still correct.
I could be wrong, of course, since the less I know about Perl the more 
I'm forced to assume about its design and behavior.

-->
#!/usr/bin/perl -w

use 5.010;

my @xrefs;
my $y;
&$_ for map { sub {
         ++$y; my $x = $y;
         push @xrefs, \$x;
         say "$x|$y, refs:", \$x, "|", \$y;
         } } (1..10);
say "$_ contains $$_" for (@xrefs);
<--

Kiuhnm


------------------------------

Date: Sat, 25 Feb 2012 14:53:43 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: a question about efficiency
Message-Id: <n89n19-b72.ln1@anubis.morrow.me.uk>


Quoth Kiuhnm <kiuhnm03.4t.yahoo.it>:
>
> My assumptions are simpler:
> a) Perl has a garbage collector (which supports circular referencing),

Depends on what you mean by 'supports'. Circular chains of refs are
allowed, but they will never be collected until broken (or weakened)
manually.

> b) any "object" is kept alive while referenced,
> c) Perl's closures behave like real closures.

Yup.

Ben



------------------------------

Date: Sat, 25 Feb 2012 17:31:03 +0100
From: Kiuhnm <kiuhnm03.4t.yahoo.it>
Subject: Re: a question about efficiency
Message-Id: <4f490cc6$0$1381$4fafbaef@reader1.news.tin.it>

On 2/25/2012 15:53, Ben Morrow wrote:
>
> Quoth Kiuhnm<kiuhnm03.4t.yahoo.it>:
>>
>> My assumptions are simpler:
>> a) Perl has a garbage collector (which supports circular referencing),
>
> Depends on what you mean by 'supports'. Circular chains of refs are
> allowed, but they will never be collected until broken (or weakened)
> manually.

That's sad.

>> b) any "object" is kept alive while referenced,
>> c) Perl's closures behave like real closures.
>
> Yup.

Glad to hear I got those right.

Kiuhnm


------------------------------

Date: Sat, 25 Feb 2012 18:35:44 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: a question about efficiency
Message-Id: <4f497050$8$fuzhry+tra$mr2ice@news.patriot.net>

In <slrnjkh9sl.8lm.hjp-usenet2@hrunkner.hjp.at>, on 02/25/2012
   at 10:19 AM, "Peter J. Holzer" <hjp-usenet2@hjp.at> said:

>The usenet has been 8-bit clean almost since the beginning,

RFC 977 leaves the question open; I don't know about UUCP. RFC 3977
didn't come out until 2006, although it may well be that all deployed
NNTP software was 8-bit clean by then.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



------------------------------

Date: Sat, 25 Feb 2012 20:29:15 -0600
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: a question about efficiency
Message-Id: <G4qdnZN3AbhmBdTSnZ2dnUVZ_uadnZ2d@posted.hiwaay2>

Rainer Weikusat <rweikusat@mssgmbh.com> wrote:

: Steele defines closure as 'function defined in a non-null lexical
: environment'. Originally, I suggested to use the same definition for
: Perl. But this definition cannot be used for Perl because it is not
: possible to create a Perl subroutine which is outside of any lexical
: environment aka 'outer scope'. And 'the implementation of
: Perl_cv_clone' doesn't figure here at all: Irregardless of how
: closures are implemented in Perl (meaning, even if there wasn't always
: an outside link => Ben's posting), there's still always such an
: outside environment when the subroutine is created.

How does C<sub { 3 }> or C<sub { my($x) = @_; $x + 7 }> reach into
the outer lexical scope? Calling either of these representatives a
closure dilutes the term to the point of meaninglessness.

Greg
-- 
Nevertheless, if we emancipate regexes to serve as co-equal control
structures, and if we can rid ourselves of the regexist attitudes that many
of us secretly harbor, we'll have a much more productive society than we
currently do.               -- Larry Wall, Apocalypse 5


------------------------------

Date: Sat, 25 Feb 2012 20:36:56 -0600
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: a question about efficiency
Message-Id: <HOSdnZ8tSr9VB9TSnZ2dnUVZ_qCdnZ2d@posted.hiwaay2>

Ben Morrow <ben@morrow.me.uk> wrote:

: The CvOUTSIDE links are still there, and perl goes to some trouble to
: keep them valid. See pad_findlex and the implementation of eval:
: 
:     perl -E'my ($x, $y, $z) = (1,2,3);
:         sub foo { say eval $_ for qw/$x $y $z/ }
:         foo'

That example clearly falls outside the category of subs with no
way of reaching into their respective outer lexical environments, so
why bring it up at this point in the discussion?

Greg
-- 
 ... the consolidation of the states into one vast republic, sure to be
aggressive abroad and despotic at home, will be the certain precursor of
that ruin which has overwhelmed all those that have preceded it.
    -- Robert E. Lee


------------------------------

Date: Sat, 25 Feb 2012 20:48:01 -0600
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: a question about efficiency
Message-Id: <TJCdnQEN38v8ANTSnZ2dnUVZ_s6dnZ2d@posted.hiwaay2>

Peter J. Holzer <hjp-usenet2@hjp.at> wrote:

: The usenet has been 8-bit clean almost since the beginning, so QP and
: Base64 are not needed (and should actually be avoided). But any charset
: other than US-ASCII has to be declared in a Content-Type header or the
: recipient can't know what the bytes mean.

Can’t we all just go back to EBCDIC?

Greg
-- 
Freedom means that when you wake up in the morning, your life, liberty and
property are yours to do with them what you will. Of course, that means that
no one else's life, liberty, or property is yours. That's freedom. It's real
simple.                    -- James Ostrowski


------------------------------

Date: Sat, 25 Feb 2012 09:54:02 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Constructing a value beforehand
Message-Id: <slrnjkh8db.8lm.hjp-usenet2@hrunkner.hjp.at>

On 2012-02-23 18:18, Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth Xze <bhdistortion@gmail.com>:
>> my $bVerbose = 0;
>
> Is this Hungarian notation? Perl variables already have sigils, they
> don't need more prefixes.

While I don't use Hungarian notation myself (I think it's ugly, the
wrong way around, and not much use in practice), I disagree:

Perl sigils are no adequate substitute for the type prefixes in
Hungarian notations. Ignoring the fact that sigils don't even really
denote the type of a variable, there are only three of them, and even in
Systems Hungarian notation there are many more types which can be
distinguished:

 $bVerbose  (Verbose is a boolean)
 $nObjects  (Objects is a count, i.e., a non-negative integer)
 $fLength   (Length is floating point number)
 $bsParam   (Param is a byte string, you still need to decode() it)
 $csParam   (Param is a character string)
 $dogSpot   (Spot is object of class Animals::Dog)

If you go into Application Hungarian Notation (the original kind
invented by Charles Simonyi, which I find a lot more useful than systems
HN), you distinguish logical types, for example:

    my $lenWidth  = 5; # a length
    my $lenHeight = 3; # another length
    my $arRect;        # an area

    $arRect = $lenWidth * $lenHeight; # ok. an Area is the product of
                                      # two lengths

    if ($arRect > $lenHeight) # not ok. You can't directly compare an
                              # area and a length 

Or if you have to use lengths in inches and centimeters, you could
encode the type to avoid crashing your space probe ...

	hp


-- 
   _  | Peter J. Holzer    | Deprecating human carelessness and
|_|_) | Sysadmin WSR       | ignorance has no successful track record.
| |   | hjp@hjp.at         | 
__/   | http://www.hjp.at/ |  -- Bill Code on asrg@irtf.org


------------------------------

Date: Sat, 25 Feb 2012 16:18:58 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Constructing a value beforehand
Message-Id: <4f48fbe2$0$6936$e4fe514c@news2.news.xs4all.nl>

On 2012-02-25 09:54, Peter J. Holzer wrote:

> Perl sigils are no adequate substitute for the type prefixes in
> Hungarian notations. Ignoring the fact that sigils don't even really
> denote the type of a variable, there are only three of them, and even in
> Systems Hungarian notation there are many more types which can be
> distinguished:
>
>   $bVerbose  (Verbose is a boolean)
>   $nObjects  (Objects is a count, i.e., a non-negative integer)
>   $fLength   (Length is floating point number)
>   $bsParam   (Param is a byte string, you still need to decode() it)
>   $csParam   (Param is a character string)
>   $dogSpot   (Spot is object of class Animals::Dog)

In Perl, the sigil tells you about the structure (or count) of the 
variable (or expression).

Perl is a strongly typed language. The datatype is in the operators.


     my $elements = @array;  # normally equal to $#array + 1

     my $array = \@array;  # take a reference


In p5p there is an auto-dereference thread, that wants to make

     push $array, @elements;

be syntactic sugar for

     push @$array, @elements;


I opposed that, by pointing at the consequence that

    my $array = \@array;

should then mean that $array contains 2 values:
1. the number of elements (to be returned in numeric context), and
2. the array-reference (to be returned in scalar context, specifically 
in auto-dereference context)

Be aware that in Perl it is normal for a variable to have multiple 
values at the same time.

-- 
Ruud


------------------------------

Date: Fri, 24 Feb 2012 13:14:01 -0800 (PST)
From: Mentifex <mentifex@myuw.net>
Subject: Parameter guidelines for the Strong AI Singularity
Message-Id: <2e765c7d-bcdf-4c54-aca2-1ca3949f25b7@f6g2000pbq.googlegroups.com>

=== Purpose ===

A parameter in the AI Mind software serves to guide or limit the
operation of a mind-module. If a module is conducting a search of
AI memory, one parameter may govern how much of memory will be
searched, while other parameters may dictate exactly what is to
be looked for. Since it is easier to change a parameter than an
entire mind-module, the use of parameters makes it possible to
have a mind-module serve a general purpose that changes as the
parameters change.

=== Time-parameter ===

The variable "midway" is a parameter for searching the memory space
of the AI Minds. While the AI Minds remain small and experimental,
midway is usually set to zero so that it does not yet play a role.
When the AI is searching backwards in its memory for a concept,
the search starts at the present time and goes backwards to the
midway point. If midway is set at zero, the AI searches the
entire memory. Oftentimes the search stops as soon as one single
result is found, such as an example of how to say the word "NOT".

As the AI Minds grow larger and larger and claim their rightful
habitat on one SuperComputer after another, the midway parameter
will make it possible to limit searches of memory to a reasonable
portion of the entire life-span of the artificial intelligence (AI).
Since a concept may even have a different meaning or interpretation
in the distant past, limiting the search to the most recent portions
of memory helps to maintain a current, present-day frame of mind.
It also helps achieve the goal of maintaining a high speed of
thought,
because the more memory a search must traverse, the slower the
operation
of the software will become, especially if the AI does not yet have
MasPar or massive parallelism in both hardware and software.

The midway parameter does not need to be calculated as exactly
half of the available memory space. The AI mind engineers and the
AI maintenance crews have the option of setting a very low level
for midway at the first installation of a mission-critical AI
for the purpose of exhaustive system-testing, and a more relaxed
value for a fully functional AI contributing usefully to the
collegial operation of the Global AI Overmind. If the AI Minds
could be considered to have an infancy and an adolescence, the
professional mind-tenders might gradually use the midway
setting to knock out the infancy memories and then later even
the tempestuous, tumultuous memories of the AI adolescence -- as in
the science-fiction book, "The Adolescence of P-1".

The parameter "midway" as a limitation on memory-search could even
be subject to dynamic adjustments. If a massive SuperComputer AI
is trying to recall any detail at all about a given topic or name
or idea, and the initial search has no results for a "midway" set
at a half-wit value, there could be a dynamic mechanism to bypass
the "midway" limitation and to search back over all available memory
in a kind of quest for Total Information Awareness (TIA).

=== Speech-parameter ===

The "aud" variable is sent into the SpeechAct module as a parameter
indicating where to start pronouncing a word stored in auditory
memory.
SpeechAct keeps pronouncing the word until the continuation-flag
turns
to zero. If the "aud" parameter starts out in error at zero,
SpeechAct
substitutes a DeFault of one ("1") for "aud" and says the word ERROR
as an indicator to the AI programmer that something is wrong.

=== Language-parameter ===

In a polyglot AI Mind speaking several human languages, there may
need to be a "glot" or "hl" (human language) parameter that allows
the AI to switch out of one human language and into another for
purposes of thinking and communicating. A strong AI like MindForth
may use one massive set of concepts for all languages, but for each
language the vocabulary is different and the syntax is different.
Therefore the ThInk module is not geared to a specific language,
but must call the EnCog module for thinking in English or the
DeCog module for thinking in German (Deutsch).

Even if an AI program awakens to a DeFault setting of one particular
language, there needs to be a mechanism for changing the parameter of
which language to think in. In "Three Days of the Condor", Robert
Redford and Max von Syndow effortlessly switch from English into
French and back again when their secret conversation has a risk of
being overheard by someone walking past them. In the much more
mundane environment of superintelligent AI entities taking over
the world and sharing the planet in joint stewardship with human
beings, each interface between a human being and the AI OverMind
will need a mechanism for setting and resetting the "glot" parameter.
Typically the human input to the AI will set the parameter. Whatever
language the human being uses to address the AI, should govern the
parameter for the AI to think in the chosen language. Of course,
if an AI is working as an interpreter, there may be one language
as input and another language as output.

=== Input-parameters ===

In a broad sense, human input to the AI may often serve in the role
of a parameter for mental function inside the AI. In particular, the
KbRetro mind-module pays attention to the words "yes" and "no" in
English or their equivalents in other languages when the human user
is responding to a yes-or-no question. The idea of the question is
at first a proposition that needs confirmation or negation from the
human user. If an AI asks, "Do robots need food?" and the human being
tersely answers "No", the very word "no" serves as a parameter that
retroactively adjusts the associative links in the knowledge base
(KB),
so that there remains no valid assertion of the original idea.

=== Thought-parameters ===

Because human beings and intelligent robots think in language,
the AI Mind of a robot needs to attach parameters during the
comprehension of thought and to search with parameters for
the generation of thought. For example, the Russian Dushka AI

http://www.scn.org/~mentifex/Dushka.html

attaches a case parameter and a number parameter when it stores
a word of input in auditory memory. In so doing, Dushka learns
the form of a Russian word in the same way as a child learns it.
If the thinking of Dushka requires that same form of the word in
the future, Dushka retrieves the Russian word from memory by
searching for any form of the word that fits the parameters.

Mentifex
--
http://mind.sourceforge.net/lisp.html
http://mind.sourceforge.net/perl.html
http://mind.sourceforge.net/python.html
http://mind.sourceforge.net/ruby.html


------------------------------

Date: Fri, 24 Feb 2012 21:38:12 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: tree to array of arrays
Message-Id: <ji9004$643$1@reader1.panix.com>

Kiuhnm  <kiuhnm03.4t.yahoo.it> wrote:
>Just keep in mind that hashes don't care about order. If order is
>important to you, you'll need a tree of "pairs",

I replied:

 or use Tie::Hash::Indexed or Tie::IxHash, which appear to have a
> hash interface yet care about order.

In article <ji8tq8$26m8$1@news.ntua.gr>,
George Mpouras <nospam.gravitalsun.antispam@hotmail.com.nospam> wrote:
>tie is also slow compared to direct assignments

Direct assignments where you're coding a structure to hold the
contents of an ordered hash is going to be slow and erro-prone too.

-- 
Tim McDaniel, tmcd@panix.com


------------------------------

Date: Sat, 25 Feb 2012 23:31:09 +0200
From: "George Mpouras" <nospam.gravitalsun.antispam@hotmail.com.nospam>
Subject: Re: tree to array of arrays
Message-Id: <jibjut$27bn$1@news.ntua.gr>

# Here is one solution to the problem
# If you can make it more compact, please it 'll be great



use strict;
use warnings;
use feature 'say';

my $hash={};
while(<DATA>) { chomp $_;
List_to_hash(split /\//, $_)
}

my $array = Hash_to_Array($hash);


sub List_to_hash
{
my $lastkey = pop @_;
my $Ref     = $hash;

    foreach (@_)
    {
    $Ref->{$_} = {} unless ref $Ref->{$_};
    $Ref = $Ref->{$_}
    }

$Ref->{$lastkey} = 1
}



sub Hash_to_Array
{
my (@Array, $v);

    foreach (keys %{$_[0]})
    {
    $v = $_[0]->{$_};

        if ( ref $v )
        {
        push @Array, [$_, Hash_to_Array($v)]
        }
        else
        {
        push @Array, $_
        }
    }
\@Array
} 



#use Data::Dumper; print Dumper(\%hash); exit;
use Data::Dumper; print Dumper($array); exit;

__DATA__
d1/d7/d8
d1/d2/f1
d1/d2/f2
f1
f2
d1/f1
d2/f3
d4/d6/f1


------------------------------

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3623
***************************************


home help back first fref pref prev next nref lref last post