<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Perl on Jasmon blogi</title><link>https://www.qkaasu.com/tags/perl/</link><description>Recent content in Perl on Jasmon blogi</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Fri, 09 Apr 2010 08:26:16 +0000</lastBuildDate><atom:link href="https://www.qkaasu.com/tags/perl/index.xml" rel="self" type="application/rss+xml"/><item><title>JB datailee: How to remove UTF8 BOM</title><link>https://www.qkaasu.com/2010/04/09/jb-datailee-how-to-remove-utf8-bom/</link><pubDate>Fri, 09 Apr 2010 08:26:16 +0000</pubDate><guid>https://www.qkaasu.com/2010/04/09/jb-datailee-how-to-remove-utf8-bom/</guid><description>&lt;p>Huomaatko miten oikein ulkomaankieltä otsikossa! Suoraan itse asiaan. Jos on jollain kökkökikkareella, kuten Windowsin Notepadillä muokannut utf(8/16..) tiedostoja, joita pitäis sitten käyttää weppiskripteissä, niin huomaatkin, että siellä onkin tiedoston alussa Byte Order Mark, joka ryssii koko homman.&lt;/p>
&lt;p>Onneksi Perlikuningas &lt;a title="Perl King Richard Ishida" href="http://people.w3.org/rishida/blog/?p=102" target="_blank">Richard Ishida&lt;/a> on koodannut meille tähän poistoskriptin.&lt;/p>
&lt;pre>#!/usr/local/bin/perl
# program to remove a leading UTF-8 BOM from a file
# works both STDIN -&amp;gt; STDOUT and on the spot (with filename as argument)
if ($#ARGV &amp;gt; 0) {
print STDERR "Too many arguments!\n";
exit;
}
my @file; # file content
my $lineno = 0;
my $filename = @ARGV[0];
if ($filename) {
open( BOMFILE, $filename ) || die "Could not open source file for reading.";
while (&amp;lt;BOMFILE&amp;gt;) {
if ($lineno++ == 0) {
if ( index( $_, '﻿' ) == 0 ) {
s/^\xEF\xBB\xBF//;
print "BOM found and removed.\n";
}
else { print "No BOM found.\n"; }
}
push @file, $_ ;
}
close (BOMFILE) || die "Can't close source file after reading.";
open (NOBOMFILE, "&amp;gt;$filename") || die "Could not open source file for writing.";
foreach $line (@file) {
print NOBOMFILE $line;
}
close (NOBOMFILE) || die "Can't close source file after writing.";
}
else { # STDIN -&amp;gt; STDOUT
while (&amp;lt;&amp;gt;) {
if (!$lineno++) {
s/^\xEF\xBB\xBF//;
}
push @file, $_ ;
}
foreach $line (@file) {
print $line;
}
}
 
&lt;/pre>
&lt;p>Sisennykset voi vähän bugata, mut siinähän bugaa. Sitten vielä usage notes:&lt;/p>
&lt;pre> for f in `ls`; do ~/rbom.pl $f; done
# loops over a directory and removes BOM from every file
&lt;/pre>
&lt;p>Ei muuta :)&lt;/p></description></item></channel></rss>