?
Solved

need urgent help regarding arrays

Posted on 2003-02-28
5
Medium Priority
?
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

777 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