Hello, I have a wierd bug-like behavior that crops up when I use CGI and typed lexicals in a loop construction. Here is a bit of code that brings about the problem:
#!/usr/bin/perl use strict; use CGI; package WeirdBugObject; use fields qw{weird bug object}; sub new{ return fields::new(shift); } package main; my @params=CGI::param(); my $wbArrayRef=[WeirdBugObject->new(),WeirdBugObject->new()]; foreach my WeirdBugObject $wbo (@$wbArrayRef){print(ref($wbo),"\n"); +}
The error I get is:
CGI::read_from_cmdline: Can't declare class for non-scalar @words in + "my" at testWeirdBug.pl line 11.

This corresponds to the line where I invoke CGI::param();

I find this puzzling since the error message refers to class @words which is not a variable in my program, but rather in CGI.pm. But even weirder is the behavior with respect to the typed lexical in the loop a few lines below. The error actually goes away if I do not use a typed lexical in line 13. For example,

foreach my $wbo (@$wbArrayRef){ print(ref($wbo),"\n");}

I got perl 5.6.0 on my workstation with CGI Version 2.93. Does anyone know if this is a bug in perl 5.6.0 or in CGI? The problem doesn't seem to happen in perl 5.8.0 with CGI version 2.89. I think I need to upgrade something, but I am not sure I want to upgrade the whole perl install yet if it is not necessary to.

I generally use fields pragma and type my lexicals.

Thanks for any help you can give!

-JonathanU


In reply to Weird behavior with CGI, typed lexicals by jonathanu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.