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

Confusion reigns, for me at least, in the land of perl data structures. After hours of frustrated fiddling (ooh matron!) I must again humbly beg for the monks assitance.
Why oh why is this the case:
my $reqs = [ HTTP::Request->new('GET', "http://www.sun.com"), HTTP::Request->new('GET', "http://www.perlmonks.org") ]; #the above list of requests is not equivalent to: @urls = ("www.sun.com","www.perlmonks.org"); my $reqs = [ HTTP::Request->new('GET', $urls[0]), HTTP::Request->new('GET', $urls[1]) ];
I've tried what seem like all the obvious syntactic booboos, can someone please explain whats going on?
Thanks,
Ntav

NAPH (not another perl hacker)
P.S. prolog has it's own "programming blues". does such a thing exist for perl?

Replies are listed 'Best First'.
Re: more string / list confusion
by wog (Curate) on Sep 13, 2001 at 03:53 UTC
    I think they are not equivilent because www.sun.com is not equivilent to http://www.sun.com, etc. Your code looks fine otherwise. (Though, personally, I'd reccommend using map instead of typing out each $urls[0], $urls[1], etc.)
Re: more string / list confusion
by suaveant (Parson) on Sep 13, 2001 at 05:23 UTC
    wog is very right, I believe... you could do...
    my $reqs = [map { HTTP::Request->new('GET', "http://$_") } @urls];
    if you do not want to type the http at the front

                    - Ant
                    - Some of my best work - Fish Dinner