Strange behavior after reading big file

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Strange behavior after reading big file




    I have a piece of code that looks something like this:

    my %hash;
    my $i = 0;
    open HUGE, 'Huge_File' or die '>*choke*<';
    $| = 1; print "\n";
    for my $x (<HUGE>) {
    chomp $x;
    $hash{$x} = $i++ if some_test($x);
    print "\rProcessed up to line $i " unless $i % 10000;
    }
    close HUGE;
    print "Done reading Huge_File\n";

    # ... do something with %hash

    When I run this code, it dutifully reports processing the total
    number of lines (to the nearest 10000), but it never prints "Done
    reading ... ". As far as I can tell it just hangs. The code works
    fine if the input file is of a "normal" size (1000 lines, say),
    but I need to run it on a file that is 25 million lines long, and
    it is in this case that I observe the hanging behavior I've just
    described.

    Any suggestions would be most welcome. FWIW the OS is Linux, and
    I'm running Perl 5.6.1, and have 0.5G of RAM.

    Thanks!

    -Jill

    Huge_File has about 25 million lines. The reporter statement

    J Krugman Guest

  2. Similar Questions and Discussions

    1. strange behavior in File::Basename
      I'm using Perl 5.6.1 on Debian Linux 3.0 I noticed the module File::Basename doesn't behave like the shell commands basename/dirname in a special...
    2. Strange behavior when saving a file
      I'm using Illustrator 10.0.3, Mac OS 10.2.8. When I make changes to one of my Illustrator files and save it, it makes a copy of that file to the...
    3. Strange behavior
      The problem seems to be in c code calling ruby calling c code. ======== start test.rb puts "about to require curses" require "curses" puts...
    4. Very strange file upload behavior
      I tried to search for this issue on the group, but don't even know where to start, so here's my problem. We have a very simple form which has a...
    5. Strange behavior of $.
      Apparently $. is not always set correct (see second ruby 1liner). Is this a bug? 12:12:42 : cat -n n 1 2 3 BAR="hello" 4 12:12:47 : ruby...
  3. #2

    Default Displaying Excel from my CGI

    I have created a table from my CGI program with data coming from Postgres
    and I want to now display this table as an Excel file. How can this be done?
    Thanks!

    Kevin


    Guest

  4. #3

    Default Re: Strange behavior after reading big file

    J Krugman <jill_krugman@yahoo.com> wrote:
    > for my $x (<HUGE>) {
    > but I need to run it on a file that is 25 million lines long,

    Then don't read the entire thing into memory:

    while ( my $x = <HUGE> ) {


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  5. #4

    Default Re: Displaying Excel from my CGI

    [email]kbass@midsouth.rr.com[/email] wrote:
    > I have created a table from my CGI program with data coming from Postgres
    > and I want to now display this table as an Excel file. How can this be done?
    > Thanks!
    Turn it into csv or tsv (tab separated values) which can be imported
    into Excel.

    --
    Kind regards, feel free to mail: mail(at)johnbokma.com (or reply)
    virtual home: [url]http://johnbokma.com/[/url] ICQ: 218175426
    John web site hints: [url]http://johnbokma.com/websitedesign/[/url]

    John Bokma Guest

  6. #5

    Default Re: Strange behavior after reading big file

    In <slrnblkmrq.76h.tadmc@magna.augustmail.com> [email]tadmc@augustmail.com[/email] (Tad McClellan) writes:
    >J Krugman <jill_krugman@yahoo.com> wrote:
    >> for my $x (<HUGE>) {
    >> but I need to run it on a file that is 25 million lines long,
    >Then don't read the entire thing into memory:
    > while ( my $x = <HUGE> ) {
    Yikes. What a whopper.

    Thank you so much!

    -Jill
    J Krugman Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139