Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

}

In reply to Joining Arrays? by Jaganath

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-25 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found