Hi Perl Monks, the code below generates the following warning and error: 1) Name main::count used only once; and 2) Can’t use an undefined value as a symbol reference (references the line for output, which is the print $FH_OUT statement. A Google search turns up some internal Perl issues, but the issues seem to be internet related (which is not part of this code). The goal of the program is to read the first 30 or so lines of a file, saving certain information when a match occurs, then after reading the last line of the file, obtain the file size, then output the file's data. I am grateful for any thoughts anyone may have. Thank you!

#!/usr/bin/perl -w #use strict; use warnings; use File::stat; use lib "c:/strawberry/perl/site/lib"; #This program will extract the header information in 10K and 10Q filin +gs #as well as file sizes. #Specify the directory containing the files that you want to read; my $files_dir = 'C:\Test'; #Specify the directory containing the results/output; my $write_dir = 'C:\Test Output'; #Open the directory containing the files you plan to read; opendir(my $dir_handle, $files_dir) or die "Can't open directory $!"; #Initialize file counter variable; my $file_count = 0; #Loop for reading each file in the input directory; while (my $filename = readdir($dir_handle)) { next unless -f $files_dir.'/'.$filename; print "Processing $filename\n"; #Initialize the variable names. my $line_count=0; my $cik=-99; my $form_type=""; my $report_date=-99; my $file_date=-99; my $name=""; my $sic=-99; my $sic1=-99; my $HTML=0; #Open the input file; open my $FH_IN, '<',$files_dir.'/'.$filename or die "Can't open $filen +ame"; #Within the file loop, read each line of the current file; while (my $line = <$FH_IN>) { next unless -f $files_dir.'/'.$filename; #Open the ouput file; open my $FH_OUT, '>',$write_dir.'/'.$filename or die "Can't open file +$filename"; #The following steps obtain basic data from various lines in the file; if($line=~m/^\s*CENTRAL\s*INDEX\s*KEY:\s*(\d*)/m){$cik=$1;} if($line=~m/^\s*FORM\s*TYPE:\s*(.*$)/m){$form_type=$1;} if($line=~m/^\s*CONFORMED\s*PERIOD\s*OF\s*REPORT:\s*(\d*)/m){$report +_date=$1;} if($line=~m/^\s*FILED\s*AS\s*OF\s*DATE:\s*(\d*)/m){$file_date=$1;} if($line=~m/^\s*COMPANY\s*CONFORMED\s*NAME:\s*(.*$)/m){$name=$1;} if($line=~m/^\s*STANDARD\s*INDUSTRIAL\s*CLASSIFICATION:\s*(\d*)/m){$ +sic=$1;} if($line=~m/^\s*STANDARD\s*INDUSTRIAL\s*CLASSIFICATION:.*?\[(\d{4})/ +m){$sic1=$1;} #Update line counter; ++$line_count; } #Now that we have reached EOF< grab file size, and save the results; my $filesize = -s $files_dir . '/' . $filename; my $sb = stat($files_dir . '/' . $filename)->size; print $FH_OUT "$cik,$form_type,$report_date,$file_date,$name,$sic,$sic +1,$filesize,$sb\n"; #close $FH_IN or die "unable to close $filename"; #Update file_counter; #Update file counter; ++$file_count; #Save/write results/output; print "$count lines read from $filename\n"; closedir($dir_handle); close($FH_OUT); }

In reply to Can't use undefined variable as a symbol reference 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.