Bizarre copy of ARRAY

Discussion in 'Perl Misc' started by Joachim Fabini, Oct 7, 2003.

  1. Hi,

    Being a complete newbie in Perl, before submitting the bug to
    ActiveState I'd like to cross-check if the following error message is
    caused by a coding error or by a bug in the debugging part of Perl.

    When running the code from the command line everything works as
    expected (ActiveState Perl, v. 508, build 806, W32). When invoking the
    script using perl -d BugTest.pl, the debugger stops and displays the
    following message:

    > Bizarre copy of ARRAY in leave at BugTest.pl line 16.
    > Debugged program terminated. Use q to quit or R to restart,
    > use O inhibit_exit to avoid stopping after program termination,
    > h q, h R or h O to get additional info.


    Below the script:
    -------------------------------------------------------------------------
    #!/usr/bin/perl

    use strict;

    my %Tests =
    (
    "HTTP" => ["a","b","1K","10K"],
    "SMTP" => ["c","d","1K","10K","100K"]
    );


    for my $CurrentTest (keys %Tests)
    {
    # Execute test
    my ($LocalPath,$RemotePath,@FileSizes) = @{$Tests{$CurrentTest} };
    for my $i (0 .. $#{@FileSizes} )
    {
    print "Test: $CurrentTest, Iteration: $i, FileSize:
    @FileSizes[$i]\n";
    }
    }

    -------------------------------------------------------------------------

    Thanks in advance for any reply,

    Best regards
    --Joachim
     
    Joachim Fabini, Oct 7, 2003
    #1
    1. Advertising

  2. Joachim Fabini

    Greg Bacon Guest

    In article <>,
    Joachim Fabini <> wrote:

    : When running the code from the command line everything works as
    : expected (ActiveState Perl, v. 508, build 806, W32). When invoking the
    : script using perl -d BugTest.pl, the debugger stops and displays the
    : following message:
    :
    : > Bizarre copy of ARRAY in leave at BugTest.pl line 16.
    : > Debugged program terminated. Use q to quit or R to restart,
    : > use O inhibit_exit to avoid stopping after program termination,
    : > h q, h R or h O to get additional info.

    You're abusing syntax. $#{...} expects a reference inside the block,
    and to pluck a scalar from an array, say $array[$index]:

    #!/usr/bin/perl

    use strict;

    my %Tests =
    (
    "HTTP" => ["a","b","1K","10K"],
    "SMTP" => ["c","d","1K","10K","100K"]
    );

    for my $CurrentTest (keys %Tests)
    {
    # Execute test
    my ($LocalPath,$RemotePath,@FileSizes) = @{$Tests{$CurrentTest}};
    for my $i (0 .. $#FileSizes )
    {
    print "Test: $CurrentTest, Iteration: $i, FileSize:\n",
    $FileSizes[$i], "\n";
    }
    }

    Hope this helps,
    Greg
    --
    The moral is obvious. You can't trust code that you did not totally create
    yourself. (Especially code from companies that employ people like me.)
    -- Ken Thompson
     
    Greg Bacon, Oct 7, 2003
    #2
    1. Advertising

  3. Joachim Fabini

    AlV Guest

    Joachim Fabini wrote:
    > Hi,
    >
    > Being a complete newbie in Perl, before submitting the bug to
    > ActiveState I'd like to cross-check if the following error message is
    > caused by a coding error or by a bug in the debugging part of Perl.
    >
    > When running the code from the command line everything works as
    > expected (ActiveState Perl, v. 508, build 806, W32). When invoking the
    > script using perl -d BugTest.pl, the debugger stops and displays the
    > following message:


    Try the slight modification below.

    > Below the script:
    > -------------------------------------------------------------------------
    > #!/usr/bin/perl
    >
    > use strict;
    >
    > my %Tests =
    > (
    > "HTTP" => ["a","b","1K","10K"],
    > "SMTP" => ["c","d","1K","10K","100K"]
    > );
    >
    >
    > for my $CurrentTest (keys %Tests)
    > {
    > # Execute test
    > my ($LocalPath,$RemotePath,@FileSizes) = @{$Tests{$CurrentTest} };
    > ### for my $i (0 .. $#{@FileSizes} ) #### Bizarre, indeed! :eek:)


    for my $i (0 .. $#FileSizes )

    > {
    > print "Test: $CurrentTest, Iteration: $i, FileSize:
    > @FileSizes[$i]\n";
    > }
    > }
     
    AlV, Oct 7, 2003
    #3
  4. On Tue, 07 Oct 2003 14:03:53 +0200, Joachim Fabini
    <> wrote:

    Thanks to all who replied - replacing $#{@FileSizes} by $#FileSizes
    does the job.

    Best regards
    --Joachim
     
    Joachim Fabini, Oct 7, 2003
    #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. Alex
    Replies:
    2
    Views:
    1,257
  2. Replies:
    26
    Views:
    2,143
    Roland Pibinger
    Sep 1, 2006
  3. John
    Replies:
    0
    Views:
    100
  4. Replies:
    12
    Views:
    206
    Anno Siegel
    Oct 6, 2005
  5. kj
    Replies:
    2
    Views:
    143
Loading...

Share This Page