why do i get this error?

D

dana livni

i wort this script:

and when i try to run it. it start to work even inserts the rigth
information into the DataBase, but after 10-12 time the main loop
runs, i get this kind of error:


perl.exe application error
"the instruction at "0x7800ffe7" referenced memory at "0x04281228".
the memory could not be "read".

why? please help me.
---------------------------------------------------------------------------
#----------main program----------
use LWP::Simple;
use strict;
use Win32::ODBC;

open(INPUT, 'params.txt');
#my $company_symbol = <INPUT>;
#$company_symbol =~ m/Company Symbol\: (.+)/i;
#$company_symbol = $1;
my $dir = <INPUT>;
$dir =~ m/Dir to Save in\: (.+)/i;
$dir = $1;
my $dsn = <INPUT>;
$dsn =~ m/DataBase Nane\: (.+)/i;
$dsn = $1;
close INPUT;

#my $db = new Win32::ODBC($dsn);
my @company_symbols;
select_all();
for my $company_symbol(@company_symbols){
#-------get params--------

my $company_code = select_from($company_symbol);


#-------DownLoad the Major Holders URL--------
my $d_url1 = "http://finance.yahoo.com/q/mh?s=$company_symbol";
my $d_file1 = "$dir\\$company_symbol 1.txt";
my $dana = getstore($d_url1,$d_file1);
my $d_data1 = file_to_data($d_file1);

my $shareholder_name;
my $share_num;
my $share_percentage;
my $share_value;
my $time_reported;


#-------Parse and Insert the TOP INSIDER & RULE 144 HOLDERS
Data--------
$d_data1 =~ m/\<tr\>\<td\>\<small\>\<b\>TOP INSIDER \&amp\; RULE 144
HOLDERS\<\/b\>\<\/small\>\<\/td\>\<\/tr\>(.+?)\<\/table\>\<\/td\>\<\/tr\>\<\/table\>/ig;
my $temp_text = $1;
my @shareholder_detailes = ($temp_text =~ m/\<tr\>\<td
class\=\"yfnc\_tabledata1\"\>\<a
href\=\".+?"\>(.+?)\<\/a\>\<\/td\>\<td class\=\"yfnc\_tabledata1\"
align\=\"center\"\>(.+?)\<\/td\>\<td class\=\"yfnc\_tabledata1\"
align\=\"center\"\>(.+?)\<\/td\>\<\/tr\>/ig);
my $len = scalar(@shareholder_detailes);
for (my $j = 0;$j < $len;$j += 3)
{
$shareholder_name = $shareholder_detailes[$j];
$shareholder_name =~ s/\'/\"/ig;
$share_num = $shareholder_detailes[$j+1] ;
$time_reported = $shareholder_detailes[$j+2];
insert_data($shareholder_name,'inside
holder',$company_code,$share_num,' - ',' - ',$time_reported);
}


#-------Parse and Insert the TOP INSTITUTIONAL HOLDERS Data--------
$d_data1 =~ m/\<tr\>\<td\>\<small\>\<b\>TOP INSTITUTIONAL
HOLDERS\<\/b\>\<\/small\>\<\/td\>\<\/tr\>\<\/table\>(.+?)\<\/table\>\<\/td\>\<\/tr\>\<\/table\>/ig;
my $temp_text = $1;
my @shareholder_detailes = ($temp_text =~ m/\<tr\>\<td
class\=\"yfnc\_tabledata1\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\" align\=\"right\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\" align\=\"right\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\" align\=\"right\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\"
align\=\"right\"\>(.+?)\<\/td\>\<\/tr\>/ig);
my $len = scalar(@shareholder_detailes);
for (my $j = 0;$j < $len;$j += 5)
{
$shareholder_name = $shareholder_detailes[$j];
$shareholder_name =~ s/\'/\"/ig;
$shareholder_name =~ s/\&amp\;/\&/ig;
$share_num = $shareholder_detailes[$j+1] ;
$share_percentage = $shareholder_detailes[$j+2] ;
$share_value = $shareholder_detailes[$j+3] ;
$time_reported = $shareholder_detailes[$j+4];
insert_data($shareholder_name,'institution
holder',$company_code,$share_num,$share_percentage,$share_value,$time_reported);
}


#-------Parse and Insert the TOP MUTUAL FUND HOLDERS Data--------
$d_data1 =~ m/\<tr\>\<td\>\<small\>\<b\>TOP MUTUAL FUND
HOLDERS\<\/b\>\<\/small\>\<\/td\>\<\/tr\>\<\/table\>(.+?)\<\/table\>\<\/td\>\<\/tr\>\<\/table\>/ig;
my $temp_text = $1;
my @shareholder_detailes = ($temp_text =~ m/\<tr\>\<td
class\=\"yfnc\_tabledata1\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\" align\=\"right\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\" align\=\"right\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\" align\=\"right\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\"
align\=\"right\"\>(.+?)\<\/td\>\<\/tr\>/ig);
my $len = scalar(@shareholder_detailes);
for (my $j = 0;$j < $len;$j += 5)
{
$shareholder_name = $shareholder_detailes[$j];
$shareholder_name =~ s/\'/\"/ig;
$shareholder_name =~ s/\&amp\;/\&/ig;
$share_num = $shareholder_detailes[$j+1] ;
$share_percentage = $shareholder_detailes[$j+2] ;
$share_value = $shareholder_detailes[$j+3] ;
$time_reported = $shareholder_detailes[$j+4];
insert_data($shareholder_name,'mutual fond
holder',$company_code,$share_num,$share_percentage,$share_value,$time_reported);
}
print "finished handeling company - $company_symbol\n";
}
#$db->Close();

#----------subrutines----------


#----------creating a variables with the file content----------
sub file_to_data
{
my $file = shift @_;
open(INPUT,$file);
my @lines = <INPUT>;
chomp(@lines);
close INPUT;
my $data = join('',@lines);
return $data;
}


#----------insert data into tabe----------
sub insert_data
{
my $sql = "INSERT INTO
company_shareholders(holder_name,holder_type,company_code,share_num,share_percentage,share_value,time_reported)
VALUES('$_[0]','$_[1]','$_[2]','$_[3]','$_[4]','$_[5]','$_[6]')";
my $db = new Win32::ODBC($dsn);
$db->Sql($sql);
$db->Close();
}


#----------select data from tabe----------
sub select_from
{
my $sql = "SELECT company_code FROM symbols WHERE (company_symbol =
'$_[0]')";
my $db = new Win32::ODBC($dsn);
$db->Sql($sql);
$db->FetchRow();
my $company_code = $db->Data("company_code");
$db->Close();
return $company_code;
}


#----------select all company symbols from tabe----------
sub select_all
{
my $sql = "SELECT company_symbol FROM symbols WHERE (company_symbol
like 'A%')";
my $db = new Win32::ODBC($dsn);
$db->Sql($sql);
my $i = 0;
while($db->FetchRow())
{
$company_symbols[$i] = $db->Data("company_symbol");
$i++;
}
$db->Close();
}
---------------------------------------------------------------------------
 
G

gnari

dana livni said:
i wort this script:

and when i try to run it. it start to work even inserts the rigth
information into the DataBase, but after 10-12 time the main loop
runs, i get this kind of error:


perl.exe application error
"the instruction at "0x7800ffe7" referenced memory at "0x04281228".
the memory could not be "read".

why? please help me.
-------------------------------------------------------------------------- -
#----------main program----------
[snipped most of way too complex program to ask to be debugged here,
specially considering it reads unknown input data from file]
open(INPUT, 'params.txt');

what happens if open fails?
$dir =~ m/Dir to Save in\: (.+)/i;
$dir = $1;

what does $1 contain if the match failed?
my $dsn = <INPUT>;
$dsn =~ m/DataBase Nane\: (.+)/i;
$dsn = $1;

ditto

[gave up, snipped rest]

what you need to do is some basic debugging

does the problem still happen if you replace all the ODBC
stuff with dummy fuctions ?

does the problem still happen if you replace the LWP
stuff with simple preset data?

in fact try to simplify the program, by taking out all the parts not
needed to exhibit the problem. then replace all the file reads with
fixed variable assignements, make sure it compiles and show us.
(if you have not ready solved it)

gnari
 
T

Tad McClellan

dana livni said:
open(INPUT, 'params.txt');


You should always, yes *always*, check the return value from open():


open(INPUT, 'params.txt') or die "could not open 'params.txt' $!";

$dir =~ m/Dir to Save in\: (.+)/i;
$dir = $1;


You should not use the dollar-digit variables unless you have
first ensured that the match _succeeded_, else they will have
stale values in them from some previous match that _did_ succeed.

The colon character is not special it does not need backslashing.

if ( $dir =~ m/Dir to Save in: (.+)/i )
{ $dir = $1 }

You don't even need to use the dollar-digits. This will
accomplish the same thing (assuming no \n in the string):

$dir =~ s/Dir to Save in: //i;

my $d_file1 = "$dir\\$company_symbol 1.txt";


You don't really need to use silly slashes you know...

my $d_file1 = "$dir/$company_symbol 1.txt";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top