Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

need urgent help regarding arrays

Posted on 2003-02-28
5
Medium Priority
?
210 Views
Last Modified: 2010-03-05
hi all,
I have got 2 arrays @urls and @desp.  What I really wanna do is to combine these 2 arrays so that it give me urls and its own description like the first element of the combine array shud be http://www.city.surrey.bc.ac and second element shud be "city university website".



Similarly the third element of the combine array shud be surreycc.gov.uk and the 4th "surrey some description".

then i want to store the combined array in a hash array so that i get keys as website address and desp as value for it.

i have also tried using @combine=(@urls,@desp)
but iam not getting desired output.

@urls=("http://www.city.surrey.bc.ac",
 "http://www.surreycc.gov.uk/",
 "http://www.surreyweb.org.uk",
 "http://www.surreyad.co.uk/");
@desp=("city university website", "surrey some decsription", "surrey some description", "surrey");
@combine=();

foreach $item(@urls)
{
foreach $item2(@desp)
{
push(@combine,$item.$item2);
}
}


can anybody plz help as soon as possible.


thanks,
tie
0
Comment
Question by:ironlady
5 Comments
 

Accepted Solution

by:
sykkn earned 80 total points
ID: 8046098
How about something like this.

===========================================================

@urls=("http://www.city.surrey.bc.ac",
       "http://www.surreycc.gov.uk/",
       "http://www.surreyweb.org.uk",
       "http://www.surreyad.co.uk/");
@desp=("city university website", "surrey some decsription",
        "surrey some description", "surrey");

%urlHash = ();
for($i=0;$i<$#urls;$i++) {
  $urlHash{$urls[$i]} = $desp[$i];
}

===========================================================
0
 
LVL 5

Expert Comment

by:PC_User321
ID: 8046138
for ($i =0; $i <= $#urls; $i++) {
   $combine[$i * 2] = $urls[$i];
   $combine[$i * 2 +1] = $desp[$i];
}
0
 

Author Comment

by:ironlady
ID: 8047591
hi,

it seems both the codes are working thanks to pcuser and sykkn.

i wnat to split points between them so that they get 10 points each.

is that possible.

many thanks again for replying
tie
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 8048034
Of course you could be *really* nice for all their hard work, and give the full points to one of them, and then create another question - points for otherperson with the same number of points:)
0
 

Author Comment

by:ironlady
ID: 8048119
thank u very much for ur help

kind regards
tie
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question