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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |