Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: How do you tell if a sub argument is an lvalue?

by liverpole (Monsignor)
on Feb 10, 2007 at 20:57 UTC ( [id://599395]=note: print w/replies, xml ) Need Help??


in reply to How do you tell if a sub argument is an lvalue?

Hi rsmah++,

That is a very interesting question!

I don't know if this is the best answer, but my first thought was to try assigning to the variable and see what happens:

use strict; use warnings; my $a = "123"; foo($a, "456"); sub foo { for (my $i = 0; $i < @_; $i++) { my $type = eval { $_[$i] = "variable" } || "constant"; printf "Arg #%d is $type\n", $i + 1; } }

The output of this is:

Arg #1 is variable Arg #2 is constant

Since the write operation is wrapped in an eval, it returns undef if the assignment failed (constant), otherwise the result of the assignment.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (8)
As of 2024-04-19 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found