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
}
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
}
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Joining Arrays?
by Lawliet (Curate) on Dec 20, 2008 at 21:40 UTC | |
by ikegami (Patriarch) on Dec 20, 2008 at 21:49 UTC | |
by Lawliet (Curate) on Dec 20, 2008 at 22:01 UTC | |
Re: Joining Arrays?
by kyle (Abbot) on Dec 20, 2008 at 21:55 UTC | |
by graff (Chancellor) on Dec 21, 2008 at 03:52 UTC | |
by kyle (Abbot) on Dec 21, 2008 at 04:45 UTC | |
by pobocks (Chaplain) on Dec 21, 2008 at 06:07 UTC | |
by pKai (Priest) on Dec 21, 2008 at 17:26 UTC | |
by gone2015 (Deacon) on Dec 21, 2008 at 13:17 UTC | |
by Lawliet (Curate) on Dec 21, 2008 at 06:48 UTC | |
by eric256 (Parson) on Dec 22, 2008 at 03:32 UTC | |
by TimToady (Parson) on Dec 23, 2008 at 02:25 UTC | |
by nagalenoj (Friar) on Dec 22, 2008 at 10:00 UTC | |
by eric256 (Parson) on Dec 22, 2008 at 16:11 UTC |
Back to
Seekers of Perl Wisdom