On Thu, Apr 15, 2010 at 11:59 AM, raphael() <raphael.j...@gmail.com> wrote:
> Hello People,
> I am stuck on a minor problem. How can I create a hash?
>
> Data is as follow
>
> ---------- DATA ----------
>
> # abc      <-- this_should_be_hash_name
>
> {space} "random_name_or_number"  "date"  "other_things_1" "other_things_2"
> {space} "random_name_or_number"  "date"  "other_things_1" "other_things_2"
>
> # xyz      <-- this_should_be_a_new_hash_name (second_hash)
>
> {space} "random_name_or_number"  "date"  "other_things_1" "other_things_2"
>
> ---------- END ----------
>
> How can I create a hash by the name that matches
>
> m/^#(?:\s+)?(\S+)$/
>
> The hash should be created by the name of "$1" i.e (\S+)$
> like if "$1" is 'abc' the hash should be %abc which will later be filled by
> keys & values
> that are matched in the next line. Thus hash should be created beforehand.
>
> Am I making this clear?
>

You can use symbolic references for this purpose:
http://perldoc.perl.org/perlref.html#Symbolic-references
But this is a highly-unrecommended way, because if you'll get symbolic
names from external souce (e.g. a file) they may interfere with other
variables or built-ins.
It's much better to create a hash of hashrefs in you case.

Alexey

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to