$dirtoget = "/tmp/invs";
opendir(FILEDIR, $dirtoget) || die ("Cannot open $dirtoget");
@thefiles = grep -T, <$dirtoget/*>; #Store the filenames into an array
closedir(FILEDIR);
#Calling another perl script that takes each filename as argument
#and splits the file into multiple files for further processing
foreach $file (@thefiles) {
@split_files = `perl split_invs.pl $file`) || next;
chomp(@split_files);
$temp = join(" ", @split_files);
`/tmp/get_acct_info.sh $temp`; #This script takes each split file and reads some information &
#outputs the info to the file output_acct_list.out
#Load the main accounts file into a hash to compare against another file
#and output accounts only in output_accts_list
$origaccts = "/tmp/main_accounts.txt";
open(FILEHANDLE, $origaccts) || die ("Cannot open $origaccts");
%lookup = map {chomp; $_ => undef} ;
close(FILEHANDLE);
$acctlist = "/tmp/output_acct_list.out"; #Open the file output_acct_list for reading
open(ACCTLISTFILE, $banlist) || die ("Cannot open $acctlist");
#Output file that will contain filename of the bills that should be loaded into our system
open($output, '>', '/tmp/invs_load.txt') ||
die ("Cannot open output file /tmp/invs_load.txt");
while ($line = ){
chomp $line;
($filename, undef, undef, undef, $account) = split /\t/, $line;
next if exists $lookup{$account};
print $output "$filename\n"; #Print the filename of bills to be loaded to invs_load.txt
}
}
A one-liner
perl -ne"print qx[perl -pe1 $_]" test.lst > test.all
Where test.lst contains the list of files 1 per line and their contents is concatenated into test.all
Update: This is a better one that avoids using large amounts of memory for large files:
perl -ne"system 'perl.exe', '-pe1', $_;" test.lst >test.all
#accts_to_load.txt contains the filenames of al the files I want to append together
$acctstoload = "/apps/tmp/invs/accts_to_load.txt";
open(ACCTLOAD, $acctstoload) || die("cannot open $acctstoload");
#Here, I want to give a specific name to the file all the split files are being merged into
$batchfile = "mergedfile.txt";
while() {
`cat $_ >> $batchfile`;
}
I'm not sure what i'm doing wrong. Any suggestions would be appreciated. Thanks.
Unfortunately, I didn't fully understand Smokemachine's script was doing.
Did you write the script you are attempting to modify or extend?
Which is more important to you in the short term?
#!/usr/bin/perl -n
BEGIN{die "file please" unless $ARGV[0];}
push @a,$_;
END{
open(FILE, ">>".shift @a);
foreach(@a){
open(FILE2, "<$_");
while(){
print FILE $_;
}close FILE2}
}
perlmonks.org content © perlmonks.org and Anonymous Monk, BrowserUk, smokemachine
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03