Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie Perl script question

Status
Not open for further replies.

ephi144

MIS
Joined
May 10, 2008
Messages
3
Location
US
I need to run the following perl sctipt. the following lines are giving me an error

<code>
#!/usr/bin/perl
#!/usr/bin/perl
use strict;
use warnings;

my $Folder ="C:/";
opendir FOLDER,"$Folder";
my @InFiles =grep !/^\.\.?$/, "C:/SECFiles/".+readdir FOLDER;
closedir FOLDER;

foreach my $listitem ( @InFiles )
{
print "$listitem\n";
}


my $outFile = "C:/SECFiles/holdingsout.txt";

open (OUTFILE,">>$outFile");



</code>

C:\>perl PerlScript.pl
C:/SECFiles/.metadata
could not open C:/SECFiles/.metadata: No such file or directory

C:\>


why am i getting that error and of course what does that mean?





 
the error message seems very clear:

could not open C:/SECFiles/.metadata: No such file or directory

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
First, there is nothing in the above code that will cause an attempt to open that file. So you obviously aren't showing us the whole picture.

Secondly, you set $folder to 'C:/', list all the files in this directory, then prefix them with 'C:/SECfiles/'. Why would you expect them to exist?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
thank you to both of you! i can post my script. i did not write it. i do not know perl and am trying to learn. this was given to me to get it working.

stevexff your reply is what i was looking for. it gives me a starting point.
though here is a script! as matter of fact if one you can get it working for me i will gladly donate $ to you via pay pal.

#!/usr/bin/perl
use strict;
use warnings;

my $Folder ="C:/";
opendir FOLDER,"$Folder";
my @InFiles =grep !/^\.\.?$/, "C:/SECFiles/".+readdir FOLDER;
closedir FOLDER;

foreach my $listitem ( @InFiles )
{
print "$listitem\n";
}


my $outFile = "C:/SECFiles/holdingsout.txt";

open (OUTFILE,">>$outFile");


foreach (@InFiles) {
# Read data
my $Data;
unless(open (FILE,"<$_")){
print STDERR "could not open $_: $!\n";
next;
}
local $/;
$Data=<FILE>;

#Get info from data at top

my($CompanyConformedName) = $Data =~ /FILER:\s+COMPANY DATA:\s+COMPANY CONFORMED NAME:\s+(.+?)$/sm;
my($CompanyStreet1) = $Data =~ /\s+BUSINESS ADDRESS:\s+STREET 1:\s+(.+?)$/sm;
my($CompanyStreet2) = $Data =~ /\s+BUSINESS ADDRESS:\s+STREET 1:\s+$CompanyStreet1\s+STREET 2:\s+(.+?)$/sm;
my($CompanyCity) = $Data =~ /\s+BUSINESS ADDRESS:\s+STREET 1:\s+$CompanyStreet1\s+STREET 2:\s+$CompanyStreet2\s+CITY:\s+(.+?)$/sm;
my($CompanyState) = $Data =~ /\s+BUSINESS ADDRESS:\s+STREET 1:\s+$CompanyStreet1\s+STREET 2:\s+$CompanyStreet2\s+CITY:\s+$CompanyCity\s+STATE:\s+(.+?)$/sm;
my($CompanyZip) = $Data =~ /\s+BUSINESS ADDRESS:\s+STREET 1:\s+$CompanyStreet1\s+STREET 2:\s+$CompanyStreet2\s+CITY:\s+$CompanyCity\s+STATE:\s+$CompanyState\s+ZIP:\s+(.+?)$/sm;
my($CompanyPhone) = $Data =~ /\s+BUSINESS ADDRESS:\s+STREET 1:\s+$CompanyStreet1\s+STREET 2:\s+$CompanyStreet2\s+CITY:\s+$CompanyCity\s+STATE:\s+$CompanyState\s+ZIP:\s+$CompanyZip\s+BUSINESS PHONE:\s+(.+?)$/sm;
my($DateFiled) = $Data =~ /FILED AS OF DATE:\s+(.+?)$/sm;
my($PeriodEnded) = $Data =~ /CONFORMED PERIOD OF REPORT:\s+(.+?)$/sm;
my($SEC) = $Data =~ /SEC FILE NUMBER:\s+(.+?)$/sm;
my($Principal) = $Data =~ /Person Signing this Report on Behalf of Reporting Manager:\s+Name:\s+(.+?)$/sm;
my($PrinTit) = $Data =~ /Title:\s+(.+?)$/sm;
my($PrinPhone) = $Data =~ /Phone:\s+(.+?)$/sm;





#Remove data at top
$Data =~ s/\A(.*^[-\s]{100,}$)//sm;

#Seperate into lines

my @Lines = split(/\n/,$Data);
shift @Lines;
shift @Lines;

#print data to outfile

while(my $Line = shift @Lines){
next if $Line =~ /^\s/;
my @f=split(/\s{2,}/, $Line);
print OUTFILE "OWNER=$CompanyConformedName\t";
print OUTFILE "Street1=$CompanyStreet1\t";
print OUTFILE "Street2=$CompanyStreet2\t";
print OUTFILE "City=$CompanyCity\t";
print OUTFILE "State=$CompanyState\t";
print OUTFILE "Zip=$CompanyZip\t";
print OUTFILE "CompanyPhone=$CompanyPhone\t";
print OUTFILE "DateFiled=$DateFiled\t";
print OUTFILE "PeriodEnded=$PeriodEnded\t";
print OUTFILE "SEC=$SEC\t";
print OUTFILE "Principal=$Principal\t";
print OUTFILE "PrTitle=$PrinTit\t";
print OUTFILE "PrinPhone=$PrinPhone\t";
print OUTFILE "Stock=$f[0]\t";
print OUTFILE "cusip=$f[2]\t";
print OUTFILE "value=$f[3]\t";
print OUTFILE "prn=$f[4]\n";
}
}



other info:

i can put script in my c:/ or c:/SECFiles
the file names are going to have .txt extension
but name can have any alphanumeric characters.

thanks
 
Exmample text files name

0001145839-08-000048.txt
 
OK. Your script reads a bunch of reports, and strips out the pertinent details. These get written to an output file as one line records of name-value pairs separated by tabs.

While there are numerous things wrong with it from a coding style perspective, it probably mostly works, so we won't fix it too much. Near the top, change
Code:
my $Folder ="C:/";
opendir FOLDER,"$Folder";
 my @InFiles =grep !/^\.\.?$/, "C:/SECFiles/".+readdir FOLDER;
closedir FOLDER;
to
Code:
my $Folder = [red]"C:/SECFiles/"[/red];
opendir FOLDER,"$Folder";
 my @InFiles =grep !/^\.\.?$/, [red]$Folder[/red].+readdir FOLDER;
closedir FOLDER;
and
Code:
my $outFile = "C:/SECFiles/holdingsout.txt";
to
Code:
my $outFile = [red]$Folder . [/red]"holdingsout.txt";
This should at least stop the "file not found" messages. Once this is done, you can put it in whichever directory you want.




Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top