Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: avoid writing 'use utf8' in every script

by kcott (Archbishop)
on Feb 02, 2014 at 01:52 UTC ( [id://1073013]=note: print w/replies, xml ) Need Help??


in reply to avoid writing 'use utf8' in every script

G'day reqnode,

What you really want may be possible; however, what you describe is illegal syntax.

Consider this example script (see Note below):

#!/usr/bin/env perl

use utf8;

sub smiley {
    print "Smiley\n";
}

sub ☺ {
    print "Smiley\n";
}

Here's what happens when you run this:

$ pm_script_with_utf8.pl Illegal declaration of anonymous subroutine at ./pm_script_with_utf8.p +l line 9.

The documentation for the utf8 pragma even tells you this:

"One can have Unicode in identifier names, but not in package/class or subroutine names."

If you provide a short code example, that might serve to illustrate exactly what you're trying to achieve.

[Note: I've used <pre>, instead of <code>, tags for the code containing Unicode characters. This is to allow the actual characters, instead of character entity references, to be displayed. Please do the same with any such code you post.]

-- Ken

Replies are listed 'Best First'.
Re^2: avoid writing 'use utf8' in every script
by Jim (Curate) on Feb 02, 2014 at 02:30 UTC

    Q. In your UTF-8 Perl script, which characters in the subroutine name "smiley" aren't Unicode characters?

    A. None of them. In fact, every character in your Perl script is a Unicode character.

    (The Perl documentation is inaccurate. It uses the word "Unicode" incorrectly in the sentence you quoted.)

    Jim

      Update: I replied to the wrong post. It should've been to Re^2: avoid writing 'use utf8' in every script, making this lame joke even lamer. If anyone with "movenodeability" wants to transplant this reply, it would be appreciated!

      tobyink:

      Odd, I always thought

      resembled the Kanji for Simiru, as in Simiru, Mirikuru gaaru!

      </end_of_lame_joke>

      ...roboticus

      Unicode: Making a job hard to do correctly (like i18n) nearly freakin' impossible.

Re^2: avoid writing 'use utf8' in every script
by tobyink (Canon) on Feb 02, 2014 at 11:01 UTC

    I took Japanese lessons in primary school. That was a long time ago, and I've forgotten much of it. However, I'm pretty sure that "☺" is not a Japanese word.

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re^2: avoid writing 'use utf8' in every script
by reqnode (Novice) on Feb 02, 2014 at 02:12 UTC
    Lets say i have 2 scripts:
    main.pl code:
    #!perl
    use utf8;
    do 'main_include.pl';
    sub über
    {
    return shift;
    }
    main_include.pl code:
    use utf8;
    über('hi');
    

    So let's say i have a lot of files like main_include.pl and every is using über() function.
    I am trying to find a way tell perl that all inside scripts will use utf8-named functions and there is no need to indicate it every time i call them

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1073013]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found