in reply to Joining Arrays?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Joining Arrays?
by ikegami (Patriarch) on Dec 20, 2008 at 21:49 UTC | |
by Lawliet (Curate) on Dec 20, 2008 at 22:01 UTC |