Skip to content

Instantly share code, notes, and snippets.

@ferki
Last active March 28, 2020 17:50
Show Gist options
  • Save ferki/cdc05ad868100ac57eb194f836edbb8a to your computer and use it in GitHub Desktop.
Save ferki/cdc05ad868100ac57eb194f836edbb8a to your computer and use it in GitHub Desktop.
file encoding issue RexOps/Rex#1274
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
open my $utf8, '>', '/tmp/use_utf8file';
print $utf8 'Daniel Böhmer';
close $utf8;
no utf8;
open my $not_utf8, '>', '/tmp/no_utf8file';
print $not_utf8 'Daniel Böhmer';
close $not_utf8;
# check results with this command:
# file --mime-encoding *_utf8file
use Rex;
task 'files', sub {
# utf8 disabled
say 'disabling utf8 pragma';
no utf8;
my $file = '/tmp/test';
file $file, content => 'Daniel Böhmer';
say 'file content:';
say cat $file;
say 'encoding:';
say run "file $file";
say '-' x 10;
# utf8 enabled
say 'enabling utf8 pragma';
use utf8;
my $file = '/tmp/test';
file $file, content => 'Daniel Böhmer';
say 'file content:';
say cat $file;
say 'encoding:';
say run "file $file";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment