develooper Front page | perl.perl5.porters | Postings from May 2003

Re: docpatch concerning multidim emulation

Thread Previous | Thread Next
From:
Ronald J Kimball
Date:
May 24, 2003 09:09
Subject:
Re: docpatch concerning multidim emulation
Message ID:
20030520135648.GA1637392@linguist.thayer.dartmouth.edu
On Tue, May 20, 2003 at 02:40:34AM -0500, david nicol wrote:
> 
> too chatty?  Aside from adding a mess of verbiage about the
> intended topic, I parenthesized the reference to awk like the
> historical note it is, and in the bit complaining about
> the semicolon providing an insufficiently robust line noise
> variable I changed "I" to "Larry."

> --- perlvar.old	Mon May 19 23:54:33 2003
> +++ perlvar.new	Tue May 20 02:39:13 2003
> @@ -362,18 +362,48 @@
>  
>  which means
>  
>      ($foo{$a},$foo{$b},$foo{$c})
>  
> -Default is "\034", the same as SUBSEP in B<awk>.  If your
> -keys contain binary data there might not be any safe value for C<$;>.
> -(Mnemonic: comma (the syntactic subscript separator) is a
> -semi-semicolon.  Yeah, I know, it's pretty lame, but C<$,> is already
> -taken for something more important.)
> +Also, 
> +
> +    @subscripts=($a,$b,$c);
> +    ...
> +    $foo{@subscripts}
> +
> +won't work how you want because the tuple will scalarize into an integer: to
> +syntactly force an array of subsripts into the list required to trigger
> +multidimensional emulation, include an empty list into your list, like
> +
> +    @subscripts=($a,$b,$c);
> +    ...
> +    $foo{(),@subscripts}
> +

I don't think this paragraph works as written.  In particular, "tuple" and
"scalarize" are questionable terms.


Note that this code:

  @subscripts = ($a, $b, $c);
  $hash{@subscripts} = $str;

won't do what you want, because the array will be evaluated in scalar
context.  To force an array of subscripts to be evaluated in list context
for multidimensional array emulation, include an empty list in the hash
subscript:

  @subscripts = ($a, $b, $c);
  $foo{@subscripts,()} = $str;


> +
> +The default value of C<$;> is "\034" (the same as SUBSEP in B<awk>.)

The period should be outside the parenthesis.


> +If your keys contain binary data there might not be any safe value for
> +C<$;>, especially if you plan on recovering the subscript list by splitting
> +the keys:
> +
> +    for (keys %foo){
> +        my @subscripts = split /$;/o;
> +        ...
> +


> +After analyzing the actual data your program will be working
> +with, you might decide
> +that multidimensional emulation is safe and convenient for your purposes.
> +Keys generated by joining lists with the default C<$;> store well
> +in tied hashes, and there exist ready-made tools 
> +such as CPAN's L<Tie::Scalar::Escaped>
> +module, which was hastily contrived for mention here.

I don't understand the value in adding this paragraph to the documentation
for $;.  "Hastily contrived" does not sound like a good recommendation for
a module.


>  
> -Consider using "real" multidimensional arrays as described
> -in L<perllol>.
> +TMTOWTDI: Consider using "real" multidimensional arrays and hashes as described
> +in L<perlref> and L<perllol>.

The acronym will just confuse people who aren't familiar with it.  Leave it
off.


> +(Mnemonic: comma (the syntactic subscript separator) is a
> +semi-semicolon.  Larry found this lame, but C<$,> had already
> +been deployed.)

I think the original wording for the mnemonic was better.  How about:

(Mnemonic: comma (the syntactic subscript separator) is a
semi-semicolon.  Yes, this is lame, but C<$,> is already taken for
something more important.)


Ronald

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About