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
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.