release 0.2
Sunday, 8 October 1995
The first thing you need to do is figure out how you want to access (such
as via an assignment) just one individual element of your data
structure just using lists and hashes. Use an @ARRAY
if you're
thinking of an array or linked list or stack or queue or deque, but use a
%HASH
if you're thinking of a record or a structure or a lookup
table.
Here are some further tips of general interest:
push @{ $a[3] }, @new_list
push $a[3], @new_list
- foreach $k (keys %{ $h{"key"} }) { ... }
- foreach $k (keys $h{"key"}) { ... }
while ( <> ) { @fields = split; push @a, [ @fields ]; }This generally means never using the backslash to take a reference, but rather using the [] or {} constructors. This, for examples, is wrong!
while ( <> ) { @fields = split; push @a, \@fields; }It's the same problem as this in C:
char a[100], *p[10], *somefunc(); for (i = 0; i < 10; i++) { strcpy(a, somefunc(i)); p[i] = a; }
An exception to this rule would be when you're writing a recursive data structure or are creating multiple key indices for the same set of records.
use strict
will help here.
- @ { $a[$i] } = @list
- $a[$i] = [ @list ]