Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It sounds like you are processing a Windows text file on Linux, in which case you want to open the file with the <code>:crlf</code> layer, which will convert all CRLF line-endings to the standard Perl <code>\n</code> ending.</p> <p><em>If you are reading Windows files on a Windows platform then the conversion is already done for you, and you won't find CRLF sequences in the data you have read.</em> If you are reading a Linux file then there are no CR characters in there anyway.</p> <p>It also sounds like your records are separated by a blank line. Setting the built-in input record separator variable <code>$/</code> to a null string will cause Perl to read a whole record at a time.</p> <p>I believe this version of your subroutine is what you need. Note that people familiar with Perl will thank you for using lower-case letters and underscore for variables and subroutine names. Mixed case is conventionally reserved for package names.</p> <p>You don't show <code>create_hash_table</code> so I can't tell what data it needs. I have chomped and split the record into lines, and passed a list of the lines in the record with the newlines removed. It would probably be better to pass the entire record as a single string and leave <code>create_hash_table</code> to process it as required.</p> <pre><code>sub read_input_file { my ($input_file) = @_; open my $fh, '&lt;:crlf', $input_file or die $!; local $/ = ''; my $record_counter = 0; while (my $record = &lt;$fh&gt;) { chomp; ++$record_counter; create_hash_table(split /\n/, $record); } close $fh; print "Total records : $record_counter\n"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload