Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Currency symbols in variable names

by davido (Cardinal)
on Aug 26, 2019 at 05:48 UTC ( [id://11105036]=note: print w/replies, xml ) Need Help??


in reply to Currency symbols in variable names

A simplistic view of what constitutes a legitimate identifier is any name that matches the following regexp:

m/\A\[_\p{ID_Start}]\p{XID_Continue}*\z/

But this has many shortcomings, some of which are described in a StackOverflow article from tchrist (When I read his articles dealing with Unicode I mostly just feel small). It doesn't allow for most punctuation variables described in perlvar, for example... but even discounting those, it's just a start.

I mention this because the symbols you are using in your identifier will not match that regular expression, despite ID_Start and XID_Continue matching well over a hundred thousand characters. And these aren't punctuation characters described in perlvar either. So for typical use you can probably disqualify them outright.

One thing of note is that when wielding symbolic refs, nearly any set of characters is legal, including your currency symbols. Case in point:

use utf8; binmode STDOUT, ':utf8'; no strict 'refs'; my $symbol = '£1%^@"¥'; $$symbol = 42; print "\$$symbol = $$symbol\n"; print "$symbol is found in package ", *{__PACKAGE__ . '::£1%^@"¥'}{PAC +KAGE}, "\n"; print "\$main::${symbol} has a value of ", ${'main::£1%^@"¥'}, "\n";

Spoiler alert, it works. And notice we're using the £ and ¥ characters.

Symbol manipulation is something Perl is good at, but that we try to avoid for our own sanity. A language that more fully embraces it is Scheme. And since symbol manipulation is the name of the game for Scheme, naturally that language is fine with ¥ as a function identifier:

(define ¥ (lambda (x y) (+ x y))) ;Value: |â¥| 1 ]=> (¥ 3 5) ;Value: 8


Dave

Replies are listed 'Best First'.
Re^2: Currency symbols in variable names
by pme (Monsignor) on Aug 28, 2019 at 07:01 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-25 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found