in reply to Re^2: hang caused by read / readline?
in thread hang caused by read / readline?

Use block mode to filter out the NULs first.
perl -pe'BEGIN { $/ = \(64*1024); } s/\0+//g' infile | line_reading_sc +ript.pl

Replies are listed 'Best First'.
Re^4: hang caused by read / readline?
by grepdashv (Initiate) on Sep 04, 2009 at 07:50 UTC

    (Sorry if this is a repeat, but my last reply doesn't appear to be visible in the main node view.) How could that first part of your code be incorporated into an existing script rather than being issued from the command line? I would like to perform the s/\0+//g substitution on the input file and then save it before moving on to the rest of the script.

      my $buf = ''; local $/ = \4096; while (<>) { s/\0+//g; $buf .= $_; process_line("$1") while $buf =~ s/^(.*)\n//; } process_line($buf) if length($buf);
        Thanks! I was able to get some Chatterbox help, also. I noticed that your first example used a chunk size of 65536, but this example is using a chunk size of 4096. I used 65536 in my script, and it ran very quickly. Is there a reason to use something other than 65536 for $/ ? What are the considerations?
Re^4: hang caused by read / readline?
by grepdashv (Initiate) on Sep 04, 2009 at 07:24 UTC

    Hmmm, how could that first part be incorporated into an existing script rather than being issued from the command line?