in reply to Re: Data structure for this...
in thread Data structure for this...

Hi,

Thanks for the suggestions re: style - I knew it wasn't very elegant, but want to get the script to run with "use strict" so just pasted in all the "my"s !

I'll go away and modify my code to use a hash as suggested.

Regarding the issue of too many variables, both n2 and C2 unpack to two items each, so there is actually the correct no. of variables. Perhaps it would be clearer to write "n n" and "C C".

Finally, WTF is auto-vivication?? !!
--
Robin Bowes | http://robinbowes.com

Replies are listed 'Best First'.
Re: Re: Re: Data structure for this...
by Limbic~Region (Chancellor) on Oct 16, 2003 at 16:39 UTC
    robinbowes,
    my ($one, $two, $three) = qw(1 2 3); # works with warnings and stric +tures
    You are of course correct about unpack returning the correct number of values. I am a novice in that regard, so I leave the style up to you.

    Auto-vivication is the action by which a hash key that didn't previously exist gets created. This may or may not be intentional. Consider:

    #!/usr/bin/perl -w use strict; my %hash; print "wow\n" if $hash{foo}{bar}; print $_, $/ for keys %hash;
    Just by testing if the second level key 'bar' was true, 'foo' was automatically created. In the example code that I gave you, the hash keys were being auto-vivified intentionally in a hash slice. Sometimes it can be unintentional.

    Cheers - L~R

Re3: Data structure for this...
by dragonchild (Archbishop) on Oct 16, 2003 at 16:40 UTC
    auto-vivification - PerlDoc is your friend.

    Essentially, it's the fact that Perl will quietly create a space for something if you refer to it. Example:

    my %x; $x{foo} = 'bar';

    In that example, the memory for $x{foo} is auto-vivified. Contrast that with C++ and you'll see the benefit.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    ... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.