Just to recap my main point thru out this subthread: (many points here is not directly against the original post, but against the whole subthread. Many of those things I disagree with is even not part of
shotgunefx's original purpose, but
MarkM's extension. I disagree with
MarkM's points, but not him as a fellow monk ;-)
$hash{key} is the valid syntax to name a hash element, which happened to be a scalar (which could be array ref, hash ref ...), does not mean $hash{key} is a valid variable name for a scalar.
There is something subtle here, and we are looking at two different perspectives.
maybe a better way to explain this subtle difference is to look at some other computer language, for example c:
You can define a collective
int a[200];, and ref to its 100th element by saying
a[99], but
a[99] is not a valid variable name. Otherwise, how can you recognize whether
a[99] is a single variable or an element of a collective data structure?
One may say that this is Perl, not c. Well, when you look at the foundation, they have more similarities than differences. Whatever language it is, it requires the syntax can be consistently parsed/recognized.
Some people may argue that there are lots of "bad" syntax in Perl, what a big deal to have one more? Again, here is something subtle. Perl might have many "bad" syntax from a conventional language point of view, but all those "bad" syntax can be consistently parsed according to context. I bet nobody dare to have "bad" syntax that cannot be consistently parsed.
(the original content of this original reply is based on misunderstanding of what
shotgunefx means. He actually means something much more subtle.)
I don't call that a limitation ;-). To iterate thru a hash, you would do something like:
%hash = (a=>1, b=> 2, c=>3);
foreach (keys %hash) {
print "\$hash{$_} = $hash{$_}\n";
}
What makes this conventional approach not work for you?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.