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"; }

In reply to file not found with OPEN by wrkrbeee

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.