Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Reading lines beginning with pound # ignored

by BillKSmith (Monsignor)
on Jun 23, 2023 at 15:52 UTC ( [id://11153099] : note . print w/replies, xml ) Need Help??


in reply to Reading lines beginning with pound # ignored

I know that I am a week late and slightly off topic. You probably want to read your file line-by-line rather than slurping the whole thing. Use $INPUT_RECORD_SEPARAROR.
use strict; use warnings; use autodie; use English; my $mac_file = '#EXTM3U' . "\N{CARRIAGE RETURN}" . '#EXTINF:547,Excerpt from the Binti' . "\N{CARRIAGE RETURN}" . 'Excerpt from the Binti novella series by Nnedi Okorafor.mp3'. "\N{CARRIAGE RETURN}" ; open my $MAC_FH, '<', \$mac_file; my @lines; while (my $line = do{local $INPUT_RECORD_SEPARATOR = "\r";<$MAC_FH>}) +{ #$line =~ tr/\r/\n/; push @lines, $line; } close $MAC_FH; print "Line0: ", $lines[0], "\n"; print "Line1: ", $lines[1], "\n"; print "Line2: ", $lines[2], "\n";
Bill