Well, without indentation your code is difficult to read. Try wrapping it in <c></c> tags and format it to be readable by those unfamiliar with it. From a quick glance there are many errors (such as putting a \n after the semi-colon. Using warnings will catch that.)

That being said, try (actually, don't try it -- just get inspiration from it :P)

#!/usr/bin/perl use warnings; use strict; my @final; # Joined lines will be in here open(URLS, '<', 'urls.txt') or die $!; # I can never remember if < is +read chomp(my @urls = <URLS>); # Every line of URLS is a different element +in @urls close URLS; open(CODES, '<', 'data.txt') or die $!; chomp(my @codes = <CODES>); close CODES; foreach my $url (@urls) { # For every element (line) in @urls, foreach my $code (@codes) { # and for every element in @codes, push @final, $url$code; # append the two and push it into @fin +al } }

The first three lines should be in all your Perl programs. Using warnings will catch a lot of stupid mistakes you will make and using strictures will keep you from making a lot of stupid mistakes. I think the rest of the code is self explanatory.

Updated with more comments.

Update 2: Ikegami reminded me (thanks ikegami :D) that you must chomp() each element of the arrays before you push it into @final to remove the newline at the end. I'll update my code to show this soon. Done (with inspiration from kyle :P).

And you didn't even know bears could type.


In reply to Re: Joining Arrays? by Lawliet
in thread 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":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.