symbolic-references

How can I use the value of a variable as a variable name in Perl?

南楼画角 提交于 2019-12-31 04:32:08
问题 If I have a variable, $bar , which is equal to string "foo" and $foo is equal to 0xdead , how can I get $foo 's value while I only have the the string for the variable name? Essentially, I want to do a kind of pointer indirection on the global namespace or a hash lookup on the global namespace. The following didn't work: perl -e 'my $foo=0xdead; my $bar ="foo"; print ${$bar}."\n";' It only prints the newline. 回答1: This trick works only with global variables (symbolic references seek the

Why does Perl evaluate code in ${…} during string interpolation?

强颜欢笑 提交于 2019-12-19 02:54:09
问题 Why does the following snippet work at all? And what evil might be possible using this? But seriously, is there any reason, the code in ${} gets evaluated at all and then used as scalar reference? use strict; no strict 'refs'; our $message = "Hello world!"; print "${ lc 'MESSAGE' }\n"; 回答1: It's ok, unless you use symbolic references. Suppose the following code: my %messages = (hello => "Hello world!", bye => "Bye-bye, world!"); sub get_message_ref { return \$messages{$_[0]} }; # returns

How can I use the value of a variable as a variable name in Perl?

雨燕双飞 提交于 2019-12-02 07:16:32
If I have a variable, $bar , which is equal to string "foo" and $foo is equal to 0xdead , how can I get $foo 's value while I only have the the string for the variable name? Essentially, I want to do a kind of pointer indirection on the global namespace or a hash lookup on the global namespace. The following didn't work: perl -e 'my $foo=0xdead; my $bar ="foo"; print ${$bar}."\n";' It only prints the newline. This trick works only with global variables (symbolic references seek the symbol table of the current package), i. e. perl -e '$foo=0xdead; my $bar ="foo"; print ${$bar}."\n";' If you

Why does Perl evaluate code in ${…} during string interpolation?

孤者浪人 提交于 2019-11-30 20:43:02
Why does the following snippet work at all? And what evil might be possible using this? But seriously, is there any reason, the code in ${} gets evaluated at all and then used as scalar reference? use strict; no strict 'refs'; our $message = "Hello world!"; print "${ lc 'MESSAGE' }\n"; codeholic It's ok, unless you use symbolic references . Suppose the following code: my %messages = (hello => "Hello world!", bye => "Bye-bye, world!"); sub get_message_ref { return \$messages{$_[0]} }; # returns scalarref print "${ get_message_ref('bye') }\n"; Agree, its usefulness is not obvious with scalarrefs

What's the recommended usage of a Git symbolic reference?

谁都会走 提交于 2019-11-30 11:03:38
The following shell code correctly creates a chain of symbolic references git symbolic-ref "first" "refs/heads/master" git symbolic-ref "second" "first" git symbolic-ref "nested/third" "second" git symbolic-ref "refs/heads/fourth" "nested/third" And the following shell code correctly resolves the latest created symbolic reference to the tip of master. git show-ref "refs/heads/fourth" None of these use cases are described in the official documentation ( git-symbolic-ref doc , git-show-ref doc ). However, the following doesn't work git check-ref-format --print "first" So, my questions are: Is it

Symbolic references in Java

左心房为你撑大大i 提交于 2019-11-30 08:37:52
In these days I have been playing with Java reflection and .class format. I'm currently studying ldc instruction. In JVM Specification I found term I don't understand: symbolic reference , and I have the following questions. What does it mean? Where is it used? In which cases does the ldc instruction load a symbolic reference? Is there any code in Java corresponding to that action? It would be helpful if you would quote the exact piece of the documentation that's giving you trouble. Since you haven't, I'm going to take a guess at what you might have quoted, from the doc for ldc : Otherwise, if

What's the recommended usage of a Git symbolic reference?

笑着哭i 提交于 2019-11-29 16:37:16
问题 The following shell code correctly creates a chain of symbolic references git symbolic-ref "first" "refs/heads/master" git symbolic-ref "second" "first" git symbolic-ref "nested/third" "second" git symbolic-ref "refs/heads/fourth" "nested/third" And the following shell code correctly resolves the latest created symbolic reference to the tip of master. git show-ref "refs/heads/fourth" None of these use cases are described in the official documentation (git-symbolic-ref doc, git-show-ref doc).

Symbolic references in Java

99封情书 提交于 2019-11-29 12:17:17
问题 In these days I have been playing with Java reflection and .class format. I'm currently studying ldc instruction. In JVM Specification I found term I don't understand: symbolic reference , and I have the following questions. What does it mean? Where is it used? In which cases does the ldc instruction load a symbolic reference? Is there any code in Java corresponding to that action? 回答1: It would be helpful if you would quote the exact piece of the documentation that's giving you trouble.

How can I use a variable as a variable name in Perl?

坚强是说给别人听的谎言 提交于 2019-11-25 23:37:55
问题 I need to achieve the following in perl printmsg(@val1, $msg1) if @val1; printmsg(@val2, $msg2) if @val2; printmsg(@val3, $msg3) if @val3; printmsg(@val4, $msg4) if @val4; printmsg(@val5, $msg5) if @val5; printmsg(@val6, $msg6) if @val6; So i wrote the following snippet for(my $i=1; $i < 6; $i++ ) { printmsg(@val$i, $msg$i) if @val$i; } It doesn\'t work and breaks out with errors. 回答1: Whenever you find yourself postfixing variable names with an integer index, realize that you should have