1 #!/usr/bin/perl -w
 2 # File: appendfiles.pl
 3 # Author: Tom Large - tlarge@thelug.org
 4 # Location: http://www.thelug.org/docs/
 5 # Description: Takes two files, for every line in the second
 6 # file, a copy of each line in the first file is inserted
 7 # before it.  This script itself will generally be useless.
 8 # It does however example a simple looping technique.
 9 
10 open(2NDFILE ,"./file2.txt" );
11 @2ndfile = <2NDFILE>;
12 close( 2NDFILE );
13 
14 open(1STFILE ,"./file1.txt" );
15 @1stfile = <1STFILE>;
16 close( 1STFILE );
17 
18 open ( OUTPUT, ">./output" );
19 
20 foreach $1stfile (sort @1stfile)
21 {	
22 	chomp $1stfile;
23 	foreach $2ndfile (sort @2ndfile)
24 	{
25 	  chomp $2ndfile;
26 	  print OUTPUT "$1stfile$2ndfile;\n" if $1stfile =~ /\w+/;
27 	}
28 }
29 close( OUTPUT );


syntax highlighted by Code2HTML, v. 0.9.1