mr_p has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I would like to add string variables and arrays in hash, can someone help me how to do this? My Code will be going though multiple url and storing its links in newLinks.

Thanks.

@Hash ( url = "http://www.perl.org", @newArray = [], @lastArray = [] );

How Do I do this in perl and access it.

Replies are listed 'Best First'.
Re: Hashes and String Variables
by ikegami (Patriarch) on Jun 13, 2010 at 22:14 UTC

    Hashes associate strings with scalars. References to arrays are scalars, so that's no problem.

    my %hash = ( url => 'http://www.example.org/', newArray => [], lastArray => [], );

    Mind you, newArray and lastArray are awful names for variable.

      Thanks for your help. I won't use newArray and lastArray...lol..curLinks and prevLinks.

        I tried the following. Can you tell me what I am doing wrong here? Thank You.

        my @files = qw( http://use.perl.org/ http://search.cpan.org/ http://jobs.perl.org/ ); my @hash = ( url => '', curArray => [], prevArray => [], ); foreach my $url2 ( @files ) { #push (@hash{url}, $url2); $hash{url} = $url2; }
      Hello again,

      Can anyone help me with my original question. I am trying everything I can think of but not working.

      Thanks.
Re: Hashes and String Variables
by ww (Archbishop) on Jun 13, 2010 at 22:18 UTC
    Obtaining help here is really quite easy...

    Once you show you've made some effort at resolving your problem How do I post a question effectively? ...
      which includes writing a problem definition that's clear and complete I know what I mean. Why don't you?

    Congratulations on following the guidance re posting of code using code tags; I look forward to your clarification/satisfaction of the other prereqs for our assistance.

Re: Arrays and Strings in Hashes
by toolic (Bishop) on Jun 13, 2010 at 23:04 UTC