in reply to Array indices
I realize your example is just an example, and that it probably represents a much more complicated real-world coding situation. But the point is, when related items are indexed the same way, why not let them share the same space in an array using a hash ref?my @names = ( { first => 'john', last => 'brown' }, { first => 'jacob', last => 'black' }, # you get the point ); my @fullnames; for (@names) { push @fullnames, $_->{first} . ' ' . $_->{last}; }
However, this is just how *I* would have solved this particular problem. If I were you, I wouldn't get too scared of using array indices. I for one won't look down upon you for it ;) There is nothing *wrong* with using them, and there are certainly times when their use is merited -- while filling a complex structure in this node, using indices seemed to be the optimal solution. Sometimes having related data in the same structure is more intuitive, and at other times it might make more sense (usually for efficiency) to split them into separate arrays and use an index to iterate them both.
As for your second question, I know there will be a new operator that will allow you to check for inclusion of a scalar in an array. I believe it's called ~= (someone please correct me if I'm off here):
Or maybe the syntax is the other way around. I don't know if the return value of that operator will be the item's index in the array, or just a true/false. Other monks here will certainly know the answer better than I.print "found heimer\n" if ("heimer" ~= @firstnames); # Perl 6 (or app +roximation)
blokhead
|
|---|