wrkrbeee has asked for the wisdom of the Perl Monks concerning the following question:
Hi Perl Monks, I have a program below that crashes as it attempts to perform an OPEN command. Specifically, the program crashes at: open(INPUT, "$inddirect/company$qtr$yr.idx") || die "file for company$qtr$yr.idx: $!"; Although a novice, it seems obvious that PERL is unable to find this file in the specified location. However, I can see the file in this location. Is there something else that I am overlooking? I am grateful for any insight here. BTW, I inherited the program, and I recognize that it is terribly inefficient. Thank you for your time and patience!
use Tie::File; use Fcntl; #First year you want downloaded files for for: my $startyear=2014; #Last year you want files for: my $endyear=2014; #First qtr you want files for (usually 1): my $startqtr=1; #Last year you want files for (usually 4): my $endqtr=4; #The directory you want your index files to be stored in. my $inddirect="/Volumes/EDGAR1/Edgar/full-index"; #The directory you are going to download filings to my $direct="/Volumes/EDGAR1/Edgar/Edgar2/10K_10Q"; #The file that will contain the filings you want to download. my $outfile="/Volumes/EDGAR1/Edgar/sizefiles1.txt"; my $formget1='(10-K )'; my $formget2='(10-K405 )'; my $formget3='(10KSB )'; my $formget4='(10-KSB )'; my $formget5='(10KSB40 )'; my $formget6='(10-KT )'; my $formget7='(10KT405 )'; my $formgetq1='(10-Q )'; my $formgetq2='(10QSB )'; my $formgetq3='(10-QSB )'; my $formgetq4='(10-QT )'; #if using windows, set to "\\" - if mac (or unix), set to "/"; my $slash='/'; #loop through all the index years you specfied for($yr=$startyear;$yr<=$endyear;$yr++) { #loop through all the index quarters you specified if($yr<$endyear){$eqtr=4}else{$eqtr=$endqtr} for($qtr=$startqtr;$qtr<=$eqtr;$qtr++) { #Open the index file open(INPUT, "$inddirect/company$qtr$yr.idx") || die "file for company$ +qtr$yr.idx: $!"; #Open the file you want to write to. The first time through #the file is opened to "replace" the existing file. #After that, it is opened to append ">>". if ($yr==$startyear && $qtr==$startqtr) {$outfiler=">$outfile";} else{$outfiler=">>$outfile";} open(OUTPUT, "$outfiler") || die "file for 2006 1: $!"; $count=1; while ($line=<INPUT>) { #ignore the first 10 lines because they only contain header informatio +n if ($.<11) {next}; $form_type=substr($line,62,12); my $cik=substr($line,74,10); $file_date=substr($line,86,10); $file_date=~s/\-//g; my $fullfilename=trim(substr($line,98,43)); if ($form_type=~/^$formget1(?!\/)/) { print OUTPUT "$fullfilename\n" ; $count++; } elsif ($form_type=~/^$formget2(?!\/)/) { print OUTPUT "$fullfilename\n" ; $count++; } elsif ($form_type=~/^$formget3(?!\/)/) { print OUTPUT "$fullfilename\n" ; $count++; } elsif ($form_type=~/^$formget4(?!\/)/) { print OUTPUT "$fullfilename\n" ; $count++; } elsif ($form_type=~/^$formget5(?!\/)/) { print OUTPUT "$fullfilename\n" ; $count++; } elsif ($form_type=~/^$formget6(?!\/)/) { print OUTPUT "$fullfilename\n" ; $count++; } elsif ($form_type=~/^$formget7(?!\/)/) { print OUTPUT "$fullfilename\n" ; $count++; } elsif ($form_type=~/^$formgetq1(?!\/)/) { print OUTPUT "$fullfilename\n" ; $count++; } elsif ($form_type=~/^$formgetq2(?!\/)/) { print OUTPUT "$fullfilename\n" ; $count++; } elsif ($form_type=~/^$formgetq3(?!\/)/) { print OUTPUT "$fullfilename\n" ; $count++; } elsif ($form_type=~/^$formgetq4(?!\/)/) { print OUTPUT "$fullfilename\n" ; $count++; } #if ($count>10){last;} #end of the while loop <INPUT> } close(INPUT); close(OUTPUT); # check to see if directory exists. If not, create it. unless(-d "$direct$slash$yr"){ mkdir("$direct$slash$yr") or die; } #Open the directory and get put the names of all files into the array +@old opendir(DIR,"$direct$slash$yr")||die "Can't open directory"; @Old=readdir(DIR); tie(@New1,Tie::File,"$outfile", mode=> O_RDWR) or die "Cannot tie file BOO: $!n"; %seen=(); #defines an array called @aonly. @aonly=(); foreach $item(@Old){$seen{$item}=1} foreach $item(@New1){ $item=~/(edgar\/data\/.*\/)(.*\.txt)/; unless($seen{$item}){ push(@aonly,$item); } } ftpsignin(); foreach $filetoget(@aonly) { # $filetoget=trim($filetoget); $fullfile="/$filetoget"; $fonly=$filetoget; #Don't forget to put your directory in here. $fonly=~s/.*\/(.*)/$direct$slash$yr$slash$1/; #$ftp->get("$fullfile", "$fonly") #or warn "can't get file",ftpsignin(),next; # "cannot get file",$ +ftp->message, next; } $ftp->quit; #end of qtr loop } #end of year loop } sub ftpsignin { use Net::FTP; $ftp = Net::FTP->new("ftp.sec.gov", Debug => 0, Passive => 1) or die "Cannot connect to some.host.name: $@"; $ftp->login("anonymous",'-anonymous@') or next; #die "Cannot login ", $ftp->message; $ftp->binary(); # set binary mode } sub trim { my $new_phrase; my $phrase = shift(@_); $phrase =~ s/^\s+//; $phrase =~ s/\s+$//; $new_phrase = "$phrase"; return "$new_phrase"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: file not found with OPEN
by choroba (Cardinal) on Jan 06, 2015 at 17:53 UTC | |
by wrkrbeee (Scribe) on Jan 06, 2015 at 17:56 UTC | |
|
Re: file not found with OPEN
by Laurent_R (Canon) on Jan 06, 2015 at 18:09 UTC | |
by wrkrbeee (Scribe) on Jan 06, 2015 at 18:19 UTC | |
by wrkrbeee (Scribe) on Jan 06, 2015 at 18:35 UTC | |
by Laurent_R (Canon) on Jan 06, 2015 at 18:49 UTC | |
by wrkrbeee (Scribe) on Jan 06, 2015 at 21:06 UTC | |
by Laurent_R (Canon) on Jan 06, 2015 at 21:53 UTC | |
|
Re: file not found with OPEN
by nlwhittle (Beadle) on Jan 06, 2015 at 18:13 UTC | |
by wrkrbeee (Scribe) on Jan 06, 2015 at 18:18 UTC | |
by nlwhittle (Beadle) on Jan 06, 2015 at 18:39 UTC | |
by wrkrbeee (Scribe) on Jan 06, 2015 at 18:44 UTC | |
by Laurent_R (Canon) on Jan 06, 2015 at 18:53 UTC | |
by wrkrbeee (Scribe) on Jan 06, 2015 at 18:52 UTC | |
by nlwhittle (Beadle) on Jan 06, 2015 at 18:26 UTC | |
by wrkrbeee (Scribe) on Jan 06, 2015 at 18:28 UTC | |
by nlwhittle (Beadle) on Jan 06, 2015 at 18:56 UTC | |
by wrkrbeee (Scribe) on Jan 06, 2015 at 18:58 UTC | |
by wrkrbeee (Scribe) on Jan 06, 2015 at 19:00 UTC | |
by Laurent_R (Canon) on Jan 06, 2015 at 19:51 UTC | |
| |
|
Re: file not found with OPEN (reafactor)
by Anonymous Monk on Jan 06, 2015 at 20:57 UTC | |
by Anonymous Monk on Jan 06, 2015 at 20:59 UTC | |
by wrkrbeee (Scribe) on Jan 06, 2015 at 21:02 UTC | |
by Laurent_R (Canon) on Jan 06, 2015 at 21:45 UTC | |
by Anonymous Monk on Jan 06, 2015 at 21:13 UTC | |
by Anonymous Monk on Jan 06, 2015 at 21:31 UTC | |
by Anonymous Monk on Jan 06, 2015 at 21:24 UTC | |
|
Re: file not found with OPEN
by locked_user sundialsvc4 (Abbot) on Jan 06, 2015 at 18:58 UTC | |
by wrkrbeee (Scribe) on Jan 06, 2015 at 19:08 UTC |