Re: @a[0] vs $a[0]

Discussion in 'Perl' started by John Bokma, Sep 8, 2003.

  1. John Bokma

    John Bokma Guest

    dw wrote:

    > "John Bokma" <> wrote in message
    > news:...
    >
    >>ixtahdoom wrote:
    >>
    >>
    >>>What are the subtle differences surrounding these two notations? It
    >>>seems odd that @a[0] and $a[0] yeild the same thing, but $a{foo} and
    >>>%a{foo} is an error. What exactly is the difference? Why don't I
    >>>have to cast $a[0] as @{$a[0]}?
    >>>
    >>>Thanks, this little seeming inconsistency has puzzled me for some
    >>>time.
    >>>itd

    >>
    >>@a[0] is a slice
    >>$a[0] is a scalar
    >>
    >>just remember the following things:
    >>
    >>$ a thing
    >>@ means thingies you can get by using numbers
    >>% thingies you can get by keys (which kan be numbers, strings etc)
    >>
    >>So if you want a thing out of a thingies you use $ and not @ (thingies)
    >>nor % (thingies)
    >>

    >
    >
    > however, as a comparison for the %a{foo}, similarly to doing @a[0,5,9] to
    > get an array slice, you can do @a{item1, item5, item9} to get a slice from a
    > hash.


    Indeed, @a{ .... } gives a thingies you can get by using numbers, hence
    the @.

    --
    Kind regards, feel free to mail: mail(at)johnbokma.com (or reply)
    virtual home: http://johnbokma.com/ ICQ: 218175426
    John web site hints: http://johnbokma.com/websitedesign/
     
    John Bokma, Sep 8, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page