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:


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


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