in reply to Another Unicode/emoji question

How do you generate and encode the string from the template?

Replies are listed 'Best First'.
Re^2: Another Unicode/emoji question
by Bod (Parson) on Dec 22, 2023 at 15:22 UTC

    A bit like this...

    #!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); use strict; use warnings; use lib "$ENV{'DOCUMENT_ROOT'}/../lib"; use Site::Utils; use utf8; use Pawsies; my $pawsies = Pawsies->new; my $template = Template->new(INCLUDE_PATH => $Site::Variables::temp +late_path); ################### # Control Variables # # write to file each time Google calls API my $debug = 1; # # number of days in the past to sync calendar my $sync = 28; # ################### $data{'format'} = 'calendar' unless $data{'format'} eq 'plain'; print "Content-type: text/$data{'fomat'}; charset=utf-8\n\n"; my @day; my $query = $dbh->prepare("SELECT *, DATE_FORMAT(start, '%Y%m%dT%H%i%s +') AS dtstart ...."); $query->execute($sync); while (my $row = $query->fetchrow_hashref) { $row->{'dog'} = dogName($row->{'idBooking'}); push @day, $row; } my $vars = { 'day' => \@day, }; $template->process("admin/google/ian.tt", $vars)or die $template->erro +r;

      You forgot to encode.

      Simple way to fix:

      use open ":std", ":encoding(UTF-8)";
        You forgot to encode

        I didn't forget...I didn't know I needed to...

        Simple way to fix

        The open pragma is new to me...thanks for bringing it to my attention.

        I've been reading the documentation and an ikegami answer on SO and I am unsure what use open ":std", ":encoding(UTF-8)"; is doing that isn't already there from use utf8; and Content-type: text/calendar; charset=utf-8;

        ":std" apply the layer to the global filehandles STDIN, STDOUt and STDERR - is that right?

        But what is the difference between ":encoding(UTF-8)" and ":utf8"? I gather utf8 is a Perl specific implementation of UTF-8 but how does this difference manifest in practical terms?

        UPDATE:
        Somehow I missed use open in kcott's excellent answer here Re: Another Unicode/emoji question