- 论坛徽章:
- 0
|
mlists.j@gmail.com 是哪位呢?
该不会是 ChinaUnix 上的朋友吧?
我今天从 maillist 上收到这份会话,看了一下时间是 12.5 号的,难道 mlists.j@gmail.com 是哪位 ChinaUnix 上的朋友?
仙子是你吗?
- A Strange Syntax
- 7 封邮件
- --------------------------------------------------------------------------------
- Jennifer Garner <mlists.j@gmail.com> 2005年12月5日 下午9:52
- 收件人: beginners@perl.org
- Hi,lists,
- Seeing this code please:
- our %sym = (
- name => 'flower',
- age => 23,
- );
- print ${*{$::{sym}}{HASH}}{name};
- The result of printing is : flower.
- How to analyse the last sentence of that code?Thanks.
-
-
- --------------------------------------------------------------------------------
- Adriano Ferreira <a.r.ferreira@gmail.com> 2005年12月5日 下午10:53
- 收件人: Jennifer Garner <mlists.j@gmail.com>, beginners@perl.org
- On 12/5/05, Jennifer Garner <mlists.j@gmail.com> wrote:
- > print ${*{$::{sym}}{HASH}}{name};
- > How to analyse the last sentence of that code?Thanks.
- From "perldoc perlref"
- 7. A reference can be created by using a special syntax, lovingly
- known as the *foo{THING} syntax. *foo{THING} returns a reference
- to the THING slot in *foo (which is the symbol table entry which
- holds everything known as foo).
- $scalarref = *foo{SCALAR};
- $arrayref = *ARGV{ARRAY};
- $hashref = *ENV{HASH};
- $coderef = *handler{CODE};
- $ioref = *STDIN{IO};
- $globref = *foo{GLOB};
- So $::{sym} returns the glob symbol "sym" on the main package ($main::
- or $::), takes a reference to its HASH part, and returns what it got
- in the key "name". Piece of cake, ain't it?
- Regards,
- Adriano.
- --
- To unsubscribe, e-mail: beginners-unsubscribe@perl.org
- For additional commands, e-mail: beginners-help@perl.org
- <http://learn.perl.org/> <http://learn.perl.org/first-response>
-
-
- --------------------------------------------------------------------------------
- Wiggins d'Anconia <wiggins@danconia.org> 2005年12月6日 上午2:33
- 收件人: Adriano Ferreira <a.r.ferreira@gmail.com>
- 抄送: Jennifer Garner <mlists.j@gmail.com>, beginners@perl.org
- Adriano Ferreira wrote:
- > On 12/5/05, Jennifer Garner <mlists.j@gmail.com> wrote:
- >
- >>print ${*{$::{sym}}{HASH}}{name};
- >
- >
- >>How to analyse the last sentence of that code?Thanks.
- >
- >
- >>From "perldoc perlref"
- >
- > 7. A reference can be created by using a special syntax, lovingly
- > known as the *foo{THING} syntax. *foo{THING} returns a reference
- > to the THING slot in *foo (which is the symbol table entry which
- > holds everything known as foo).
- >
- > $scalarref = *foo{SCALAR};
- > $arrayref = *ARGV{ARRAY};
- > $hashref = *ENV{HASH};
- > $coderef = *handler{CODE};
- > $ioref = *STDIN{IO};
- > $globref = *foo{GLOB};
- >
- > So $::{sym} returns the glob symbol "sym" on the main package ($main::
- > or $::), takes a reference to its HASH part, and returns what it got
- > in the key "name". Piece of cake, ain't it?
- >
- > Regards,
- > Adriano.
- >
- Now that you understand it, replace it with $sym->{name} so the next
- person doesn't have to ask. Unless you are using a really old Perl.
- http://danconia.org
- [引用文字已隐藏]
-
- --------------------------------------------------------------------------------
- Flemming Greve Skovengaard <dsl58893@vip.cybercity.dk> 2005年12月6日 上午3:05
- 收件人: "beginners@perl.org" <beginners@perl.org>
- 抄送: Wiggins d'Anconia <wiggins@danconia.org>
- Wiggins d'Anconia wrote:
- >
- > Now that you understand it, replace it with $sym->{name} so the next
- > person doesn't have to ask. Unless you are using a really old Perl.
- >
- Actually that should be *sym->{name} instead of $sym->{name} ( or %sym->{name}
- but that's deprecated ).
- Else you get "Variable "$sym" is not imported at ..." when using 'use strict;'
- ( as you should ).
- --
- Flemming Greve Skovengaard The prophecy of the holy Norns
- a.k.a Greven, TuxPower The world is doomed to die
- <dsl58893@vip.cybercity.dk> Fire in the sky
- 4112.38 BogoMIPS The end is coming soon
- [引用文字已隐藏]
-
- --------------------------------------------------------------------------------
- Jennifer Garner <mlists.j@gmail.com> 2005年12月6日 上午9:10
- 收件人: Flemming Greve Skovengaard <dsl58893@vip.cybercity.dk>
- 抄送: "beginners@perl.org" <beginners@perl.org>, Wiggins d'Anconia <wiggins@danconia.org>
- ${*{$::{sym}}{HASH}}{name};
- As we know, $::{sym} == *main::sym, it's a typeglob.
- but what is **main::sym? and the same,what is *{$glob}?thanks.
- [引用文字已隐藏]
-
- --------------------------------------------------------------------------------
- Adriano Ferreira <a.r.ferreira@gmail.com> 2005年12月7日 上午12:26
- 收件人: Jennifer Garner <mlists.j@gmail.com>, beginners@perl.org
- On 12/5/05, Jennifer Garner <mlists.j@gmail.com> wrote:
- > As we know, $::{sym} == *main::sym, it's a typeglob.
- > but what is **main::sym? and the same,what is *{$glob}?thanks.
- **main::sym is a syntax error, but *{*main::sym}==*main::sym.
- But don't be fooled by the equality $::{sym} == *main::sym. It just
- means they numerically compare the same. Taking references you get
- that $::{sym} returns a scalar and *main::sym a glob.
- $ perl -e 'print \($::sym, *main::sym)'
- SCALAR(0x1002f094)GLOB(0x10010fa8)
- So *{$glob} is the way to tell Perl to go from the scalar to the glob,
- when we'll be able to access its HASH part.
- That's why
- $ perl -e 'our %sym = (name => "flower"); print ${*{$::{sym}}{HASH}}{name};"
- prints "flower", but
- $ perl -e 'our %sym = (name => "flower"); print ${$::{sym}{HASH}}{name};"
- prints nothing ($::{sym}{HASH} returns undef). As Wiggins wisely said,
- $sym->{name} is more sane.
- --
- [引用文字已隐藏]
-
- --------------------------------------------------------------------------------
- Jennifer Garner <mlists.j@gmail.com> 2005年12月7日 上午9:16
- 收件人: "beginners@perl.org" <beginners@perl.org>
- Thanks for Adriano Ferreira.Your explaination is good for me.I have known
- that.
- [引用文字已隐藏]
复制代码
[ 本帖最后由 思平 于 2005-12-7 11:07 编辑 ] |
|