Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Currency symbols in variable names

by davido (Cardinal)
on Aug 26, 2019 at 05:48 UTC ( #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 (Prior) on Aug 28, 2019 at 07:01 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2020-01-24 14:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?