an UN-deprecated way to cvt aryRef to size?

Discussion in 'Perl Misc' started by David Combs, Apr 10, 2006.

  1. David Combs

    David Combs Guest

    Subject: an UN-deprecated way to cvt aryRef to size?

    The line at 792 gives me a deprecated-error:

    my $ary1Size = scalar(@{$ary1Ref});

    <line 792>: @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT ONCE!

    gives me the warning (I guess it's a warning):

    1457 ==/dkcjunk==> perl -wc Dkclib.pm_02
    Using an array as a reference is deprecated at Dkclib.pm_02 line 792.
    Dkclib.pm_02 syntax OK

    DOC-ERROR: The msg is backwards: actually, I'm using a ref as an array.

    When I change it to this:

    my $ary1Size = scalar(@{$ary1Ref});

    # @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT ONCE!
    $ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT ONCE!

    I get no such message:

    1458 ==/dkcjunk==> perl -wc Dkclib.pm
    Dkclib.pm syntax OK
    1459 ==/dkcjunk==>


    Please, just what *is* the ("new" (as of 5.8.6?)) rule?


    And, maybe that rule should be ADDED to the "error msg".


    Thanks!

    David
     
    David Combs, Apr 10, 2006
    #1
    1. Advertising

  2. David Combs

    Matt Garrish Guest

    "David Combs" <> wrote in message
    news:e1em87$du9$...
    >
    > Subject: an UN-deprecated way to cvt aryRef to size?
    >
    > The line at 792 gives me a deprecated-error:
    >
    > my $ary1Size = scalar(@{$ary1Ref});
    >
    > <line 792>: @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT
    > ONCE!
    >
    > gives me the warning (I guess it's a warning):
    >
    > 1457 ==/dkcjunk==> perl -wc Dkclib.pm_02
    > Using an array as a reference is deprecated at Dkclib.pm_02 line 792.
    > Dkclib.pm_02 syntax OK
    >
    > DOC-ERROR: The msg is backwards: actually, I'm using a ref as an array.
    >


    No, you're using an array as reference. Change it to:

    @{$ary2Ref->[$ary1Ref]} = undef;

    The way you wrote it above is equivalent to @{$ary2Ref}->[$ary1Ref].

    Matt
     
    Matt Garrish, Apr 10, 2006
    #2
    1. Advertising

  3. David Combs

    Matt Garrish Guest

    "Matt Garrish" <> wrote in message
    news:pfB_f.2545$...
    >
    > "David Combs" <> wrote in message
    > news:e1em87$du9$...
    >>
    >> Subject: an UN-deprecated way to cvt aryRef to size?
    >>
    >> The line at 792 gives me a deprecated-error:
    >>
    >> my $ary1Size = scalar(@{$ary1Ref});
    >>
    >> <line 792>: @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT
    >> ONCE!
    >>
    >> gives me the warning (I guess it's a warning):
    >>
    >> 1457 ==/dkcjunk==> perl -wc Dkclib.pm_02
    >> Using an array as a reference is deprecated at Dkclib.pm_02 line 792.
    >> Dkclib.pm_02 syntax OK
    >>
    >> DOC-ERROR: The msg is backwards: actually, I'm using a ref as an array.
    >>

    >
    > No, you're using an array as reference. Change it to:
    >
    > @{$ary2Ref->[$ary1Ref]} = undef;
    >


    Bad typing on my part, that obviously should have been
    @{$ary2Ref->[$ary1Size-1]}

    Matt
     
    Matt Garrish, Apr 10, 2006
    #3
  4. David Combs wrote:
    > Subject: an UN-deprecated way to cvt aryRef to size?
    >
    > The line at 792 gives me a deprecated-error:
    >
    > my $ary1Size = scalar(@{$ary1Ref});


    Why are you using the scalar() function?

    my $ary1Size = @{ $ary1Ref };

    > <line 792>: @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT ONCE!
    >
    > gives me the warning (I guess it's a warning):
    >
    > 1457 ==/dkcjunk==> perl -wc Dkclib.pm_02
    > Using an array as a reference is deprecated at Dkclib.pm_02 line 792.
    > Dkclib.pm_02 syntax OK


    So, it's not the conversion to size that rises the warning?

    > DOC-ERROR: The msg is backwards: actually, I'm using a ref as an array.


    How is that?

    > When I change it to this:
    >
    > my $ary1Size = scalar(@{$ary1Ref});
    >
    > # @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT ONCE!
    > $ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT ONCE!
    >
    > I get no such message:
    >
    > 1458 ==/dkcjunk==> perl -wc Dkclib.pm
    > Dkclib.pm syntax OK
    > 1459 ==/dkcjunk==>


    So you found a solution. What's the problem, then?

    Want an alternative solution?

    ${ $ary2Ref }[$ary1Size-1] = undef;

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Apr 11, 2006
    #4
  5. David Combs

    Matt Garrish Guest

    "Matt Garrish" <> wrote in message
    news:pfB_f.2545$...
    >
    > "David Combs" <> wrote in message
    > news:e1em87$du9$...
    >>
    >> Subject: an UN-deprecated way to cvt aryRef to size?
    >>
    >> The line at 792 gives me a deprecated-error:
    >>
    >> my $ary1Size = scalar(@{$ary1Ref});
    >>
    >> <line 792>: @$ary2Ref->[$ary1Size-1] = undef; # PRE-ALLOCATE IT, ALL AT
    >> ONCE!
    >>
    >> gives me the warning (I guess it's a warning):
    >>
    >> 1457 ==/dkcjunk==> perl -wc Dkclib.pm_02
    >> Using an array as a reference is deprecated at Dkclib.pm_02 line 792.
    >> Dkclib.pm_02 syntax OK
    >>
    >> DOC-ERROR: The msg is backwards: actually, I'm using a ref as an array.
    >>

    >
    > No, you're using an array as reference. Change it to:
    >
    > @{$ary2Ref->[$ary1Ref]} = undef;
    >


    I shouldn't post before eating. I thought you were trying to get at the
    array. Change that to:

    @{$ary2Ref}[$ary1Size-1] = undef;

    Matt
     
    Matt Garrish, Apr 11, 2006
    #5
    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. Barney Barumba
    Replies:
    0
    Views:
    578
    Barney Barumba
    Jul 23, 2003
  2. david
    Replies:
    4
    Views:
    6,436
    david
    Oct 9, 2003
  3. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,732
    Michael Jung
    May 25, 2008
  4. tesis
    Replies:
    2
    Views:
    1,200
    Mark Fitzpatrick
    Oct 12, 2008
  5. P. mark Anderson
    Replies:
    1
    Views:
    125
    Eric Hodel
    Feb 28, 2008
Loading...

Share This Page