Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

$'name

by mkmcconn (Chaplain)
on Mar 01, 2001 at 00:32 UTC ( [id://61423]=perlquestion: print w/replies, xml ) Need Help??

mkmcconn has asked for the wisdom of the Perl Monks concerning the following question:

If the $' in $'var is not at all related to $', how does Perl keep them straight?
ex:
#!/usr/bin/perl -wl use strict; $main::var = "a rose by "; #$main::var $main'var = $'var."another name"; #$main::var again use vars q($var); $var =~ s/(\b\w)/uc($1)/ge; #$main::var $var =~ /N/; print $'var; #print $main::var print 'G'.$'." With $'var"; #games with $' use English; print "s$' and s$POSTMATCH";

mkmcconn

Replies are listed 'Best First'.
(tye)Re: $'name
by tye (Sage) on Mar 01, 2001 at 01:43 UTC

    See line 5811 of toke.c (for Perl5.6.0):

    else if (*s == '\'' && isIDFIRST_lazy_if(s+1,UTF)) {
    So, in effect, /\$'[a-zA-Z_]/ is treated differently than /\$'[^a-zA-Z_]/ [note the caret (^)].

            - tye (but my friends call me "Tye")
The $'name G'ame.
by tadman (Prior) on Mar 01, 2001 at 01:18 UTC
    I would suppose that the lexer in the perl parser is intelligent enough to recognize the pattern for variables of that sort. It could loosely be described as:      \$'([a-zA-Z_][a-zA-Z0-9_]*)? Which could define a valid variable name.

    Otherwise, how would you distinguish between $x and $xy? Or, $_ and $_x for that matter.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-26 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found