<div dir="ltr"><div class="gmail_default" style="font-size:small">Hello fellow mongers!</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">    Today I opened and read a file.  Advanced stuff, right?  :-)</div><div class="gmail_default" style="font-size:small"><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_default" style="font-size:small"><font face="monospace" color="#0000ff">open my $fh, '<', 'file.dat';</font></div><div class="gmail_default" style="font-size:small"><font face="monospace" color="#0000ff">$line = <$fh>;</font></div><div class="gmail_default" style="font-size:small"><font color="#0000ff" style="font-family:monospace">if ($line =~ /^Your data:/) </font><font face="arial, sans-serif">....</font></div></blockquote><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">    The problem is that the input file has a Unicode BOM (byte-order mark), so the first three bytes of the string are in fact 0xEF, 0xBB, and 0xBF.  So the match fails, even though if you look at the file in an editor, it looks like it begins with "<font face="monospace">Your data</font>".  It took me a fair amount of time to figure this out.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">    I am shocked that I have never encountered this before.  But I'm even more shocked that Perl doesn't automagically handle this internally.  What the heck, Perl??  This has me re-thinking how I open all text files!  If I am opening text files of unknown encoding, am I expected to read the BOM (if present) and then change the PerlIO encoding via '<font face="monospace" color="#0000ff">binmode</font>' myself?  For each and every input text file I open and read?  That's BS.  I've gotta be missing some obvious step.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">    Any wisdom from the hive mind would be appreciated.  Thanks!</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">-- Eric Roode</div><div class="gmail_default" style="font-size:small"><br></div></div>