in reply to Finally, C

Is there any way, in Perl, to create an alias to a lexical?
Yes, but it requires a trick:
my $foo = "foo"; for my $bar ($foo) {$bar = "bar"} print $foo; __END__ bar
And there's the @_ trick you already mentioned. There are also a couple of constructs that allow you to alias a variable to $_.
Lexicals seem very different to me from anything there's in C, am I wrong?
Maybe, depending on what you are asking. If you mean that variables are implemented different than in C, yes, you are right. If you are referring to what differs a (Perl) lexical variable from a (Perl) package variable, and want to know how this differs from the C equivalent, then there's no real answer. In C, all variables are lexical - there's no such thing as name spaces in C.
Perl --((8:>*

Replies are listed 'Best First'.
Re^2: Finally, C
by QM (Parson) on Dec 16, 2005 at 23:56 UTC
    This also demonstrates that the for variable is an alias, and not a copy:
    my $foo = "foo"; for my $bar ($foo) { print "foo: $foo, ", \$foo, "\n"; print "bar: $bar, ", \$bar, "\n"; $bar = "bar"; print "foo: $foo, ", \$foo, "\n"; print "bar: $bar, ", \$bar, "\n"; } print "foo: $foo, ", \$foo, "\n"; __OUTPUT__ foo: foo, SCALAR(0x18245f0) bar: foo, SCALAR(0x18245f0) foo: bar, SCALAR(0x18245f0) bar: bar, SCALAR(0x18245f0) foo: bar, SCALAR(0x18245f0) __END__

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of