Can you explain it?

Discussion in 'Perl Misc' started by Oliver Block, Jul 26, 2005.

  1. Oliver Block

    Oliver Block Guest

    Hi,

    do you have any idea, why the following construct increases the number
    of element of my array of arrays @myArray with one?

    if ( @#{ $myArray[$myElements] } < 0) { ...

    bye,

    Oliver
     
    Oliver Block, Jul 26, 2005
    #1
    1. Advertising

  2. Oliver Block

    Guest

    "Oliver Block" <> wrote:
    > Hi,
    >
    > do you have any idea, why the following construct increases the number
    > of element of my array of arrays @myArray with one?
    >
    > if ( @#{ $myArray[$myElements] } < 0) { ...


    I don't know that it does do that (I couldn't replicate it), but I wonder
    why you messing with a slice of the semi-special hash '%#'?

    Did you perhaps mean $# rather than @#?

    Are you using warnings?

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Jul 26, 2005
    #2
    1. Advertising

  3. Oliver Block <> wrote:


    > Subject: Can you explain it?



    Please put the subject of your article in the Subject of your article.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jul 27, 2005
    #3
  4. Oliver Block

    Anno Siegel Guest

    Oliver Block <> wrote in comp.lang.perl.misc:
    > Hi,
    >
    > do you have any idea, why the following construct increases the number
    > of element of my array of arrays @myArray with one?
    >
    > if ( @#{ $myArray[$myElements] } < 0) { ...


    What a mess. Your subject tells us nothing about your question, your
    code is messed up, and your question makes an unjustified assumption.

    In truth, what you do doesn't increase the number of array elements by
    one, it creates a new array element in position $myElements unless
    there already is one. The reason for this happening is called
    "autovivification". Read about it in perlref.

    Anno
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
     
    Anno Siegel, Jul 27, 2005
    #4
    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.
Similar Threads
  1. Shapper
    Replies:
    3
    Views:
    421
    willow
    Jun 10, 2005
  2. John Laco

    Can you explain this?

    John Laco, Sep 26, 2003, in forum: ASP General
    Replies:
    7
    Views:
    150
    _Netah X
    Sep 26, 2003
  3. anne001
    Replies:
    4
    Views:
    136
    James Edward Gray II
    Aug 2, 2006
  4. Aashish Kiran

    can you explain code

    Aashish Kiran, Jan 8, 2010, in forum: Ruby
    Replies:
    3
    Views:
    169
    Aldric Giacomoni
    Jan 8, 2010
  5. Picker Leon
    Replies:
    13
    Views:
    192
    Brian McCauley
    Dec 11, 2003
Loading...

Share This Page