What's the point of splitting $store and $product only to join them again? | [reply] |
It's joined again with "\034" (by default)
You will be able to access this hash from other code using $h{$store,$product}. It's easier to write than $h{"$store $product"}
If, later, you decide that store can have spaces in its name, you will rewrite your first split code, but you won't have to rewrite $h{$store,$product} in other places.
Anyway, you can ask topic starter why he need split, while he just needs to
to determine if a store has a product
| [reply] |
> Anyway, you can ask topic starter why he need split, while he just needs to
> > to determine if a store has a product
With the nested approach he can also use things like keys %{$hash{$store}} to list all products.
The delimiter approach is a nice idea, but is neither shorter to write nor more efficient.
Cheers Rolf
( addicted to the Perl Programming Language)
| [reply] [d/l] |
.. Anyway, you can ask topic starter why he need split, while he just needs to
I'm sorry, but you've missed my point :) I am questioning the wisdom of your suggestion for an alternative approach.
Since OP already decided on a hash-of-hashes, why switch back to a simple hash? Or hash-of-array-?emulation?
Why throw away the benefits of easy lookup?
There has to be some benefit to doing it differently; and few drawbacks
| [reply] |
$h{$store, $product}=1;
This is flaky to say the least. I assume you meant
$h{"$store,$product"}=1;
so atleast it'd be possible to pick them apart later on.
Even so, it will only be a matter of time until a store pops up with a comma in its name and you'll have to start rethinking the whole thing. Maybe try two or three different delimiters before rewriting to use a better suited data structure.
Like, say, a hash of hashes ;-)
--
Time flies when you don't know what you're doing
| [reply] [d/l] [select] |
I assume you meant
$h{"$store,$product"}=1;
No. Re-read my posting. Also, click the link in my posting and read perldoc article.
| [reply] |