why do i get this error?

Discussion in 'Perl Misc' started by dana livni, Feb 22, 2004.

  1. dana livni

    dana livni Guest

    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();
    }
    ---------------------------------------------------------------------------
     
    dana livni, Feb 22, 2004
    #1
    1. Advertising

  2. dana livni

    gnari Guest

    "dana livni" <> wrote in message
    news:...
    > 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
     
    gnari, Feb 22, 2004
    #2
    1. Advertising

  3. dana livni <> wrote:

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


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 22, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sanjay Pais
    Replies:
    0
    Views:
    2,284
    Sanjay Pais
    Aug 8, 2005
  2. Jarod
    Replies:
    1
    Views:
    2,397
    Matt Dinovo
    Jan 26, 2006
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    909
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,994
    Smokey Grindel
    Dec 2, 2006
  5. PB
    Replies:
    10
    Views:
    6,626
    Dave Thompson
    Mar 27, 2006
Loading...

Share This Page