Jak se spravne vklada promenna do retezce? ("${::x}y")

Pavel Smerk xsmerk na fi.muni.cz
Čtvrtek Červen 2 13:27:43 CEST 2011


	Ahoj,

perlmod rika, ze "You can refer to variables and filehandles in other
packages by prefixing the identifier with the package name and a double
colon: $Package::Variable. If the package name is null, the main package is
assumed. That is, $::sail is equivalent to $main::sail."

Jenomze, pokud se takove $::sail pokusim vlozit do retezce, mam problem:

C:\>perl -v

This is perl, v5.10.1 built for MSWin32-x86-multi-thread

C:\>perl -w -Mstrict -e "$::x = 1; print qq[${::x}2]"
Bareword "::x" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.

Lze to obejit napriklad nasledujicimi zpusoby

C:\>perl -w -Mstrict -e "$::x = 1; print qq[${main::x}2]"
12
C:\>perl -w -Mstrict -e "$::x = 1; print qq[${\($::x)}2]"
12
C:\>perl -w -Mstrict -e "$::x = 1; print qq[${$::{x}}2]"
Name "main::x" used only once: possible typo at -e line 1.
12

ale rikam si, jestli nedelam neco spatne a nejde to nejak zcela jednoduse a
pruhledne, jako kdybych treba $x vkladal jen jako qq[${x}2].

					Diky za pripadna nakopnuti,	P.


Další informace o konferenci Perl