When you set $/ to something unrecognized or even just something that isn't found in the input file it works the same way as if you had set it to undef. It causes the whole file, or as much as will fit into memory, to be slurped on the first pass of the while loop. Then inside the while loop, since you split on something it does find, that part splits $_ into your array. As long as the file is small enough to be slurped on the first pass it seems to work.

The problem with your approach is you shouldn't try to read multi-line records and then split each record into the same record. If it works it is already split by the read with $/.

To fix this is set $/ to "Query=" and then trim any extra spaces at the beginning of $_ within your while loop. Inside the while loop split each record into whatever form you need.

#!/usr/bin/perl use strict; use warnings; $/ = "Query="; my $count = 0; while (<DATA>) { chomp; s/^\s+//; my @record = split(/[:\n]/, $_); $count++; print join(' : ', @record), "<count=$count>\n"; } __DATA__ Query= M01133:26:000000000-A6UCG:1:1101:22656:1128 1:N:0:1+@M01133:26:000000000-A6UCG:1:1101:22656:1128 2:N:0:1 Length=501 Query= M01133:26:000000000-A6UCG:1:1101:22656:1129 1:N:0:1+@M01133:26:000000000-A6UCG:1:1101:22656:1129 2:N:0:1 Length=501 Query= M01133:26:000000000-A6UCG:1:1101:22656:1130 1:N:0:1+@M01133:26:000000000-A6UCG:1:1101:22656:1130 2:N:0:1 Length=501 Query= M01133:26:000000000-A6UCG:1:1101:22656:1131 1:N:0:1+@M01133:26:000000000-A6UCG:1:1101:22656:1131 2:N:0:1 Length=501

Output:

<count=1> M01133 : 26 : 000000000-A6UCG : 1 : 1101 : 22656 : 1128 : 1 : N : 0 : +1+@M01133 : 26 : 000000000-A6UCG : 1 : 1101 : 22656 : 1128 2 : N : 0 +: 1 : : Length=501<count=2> M01133 : 26 : 000000000-A6UCG : 1 : 1101 : 22656 : 1129 : 1 : N : 0 : +1+@M01133 : 26 : 000000000-A6UCG : 1 : 1101 : 22656 : 1129 2 : N : 0 +: 1 : : Length=501<count=3> M01133 : 26 : 000000000-A6UCG : 1 : 1101 : 22656 : 1130 : 1 : N : 0 : +1+@M01133 : 26 : 000000000-A6UCG : 1 : 1101 : 22656 : 1130 2 : N : 0 +: 1 : : Length=501<count=4> M01133 : 26 : 000000000-A6UCG : 1 : 1101 : 22656 : 1131 : 1 : N : 0 : +1+@M01133 : 26 : 000000000-A6UCG : 1 : 1101 : 22656 : 1131 2 : N : 0 +: 1 : : Length=501<count=5>

In reply to Re: input record separator and split by Lotus1
in thread input record separator and split by frednc_2014

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.