![]() |
|
Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Joining Arrays?by Jaganath (Initiate) |
on Dec 20, 2008 at 21:07 UTC ( #731808=perlquestion: print w/replies, xml ) | Need Help?? |
Jaganath has asked for the wisdom of the Perl Monks concerning the following question:
Hi folks - I'm a perl FNG and I have a question about joining and outputing arrays.
I have two arrays (lines read in from txt files and split on \n).
What I need to do is join them, but in itterations. i.e., the first array contains urls, say http://www.something.com/blah.aspx?code= and http://www.somethingelse.com/stuff.aspx?thing= The second array contains product codes, say 375035304 564564774 346464646 I need to end up with an array containing an entry for each url/code combination -i.e http://www.something.com/blah.aspx?code=375035304 http://www.something.com/blah.aspx?code=564564774 http://www.something.com/blah.aspx?code=346464646 http://www.somethingelse.com/stuff.aspx?thing=375035304 http://www.somethingelse.com/stuff.aspx?thing=564564774 http://www.somethingelse.com/stuff.aspx?thing=346464646 So far nothing I've tried works (I'm only about 12 hours into my perl voyage so please forgive my ignorance :0) Any help would be very welcome - here's my code so far: #!/usr/bin/perl #open and assign urls file open (URLS, "urls.txt") || die("Couldn't open file!"); @raw_urls=<URLS>; close(URLS); #open and assign isbn/prod code file open (CODES, "data.txt") || die("Couldn't open file!"); @raw_codes=<CODES>; close(CODES); # loop through urls, split out and dump in array foreach $urls (@raw_urls) { (@url)=split(\n, $urls); print @url; \n #test output } # loop through codes, split out and dump in array foreach $codes (@raw_codes) { (@code)=split(\n, $codes); print @code; \n #test output }
Back to
Seekers of Perl Wisdom
|
|