taint has asked for the wisdom of the Perl Monks concerning the following question:

Greetings monks!
I've been really looking at chromatic's Modern::Perl today. I'm finding that I'm even less a Perl hack, than I thought I was. To the point; I was working on a fairly simple script, when I came across M::P. So I added it to the use list. Well, that threw a bunch of new errors to the list I was already attempting to resolve. So, I figured I'd start small/simple. So I wrote the following as a starting template:
#!/usr/bin/perl -Tw # a stupid simple script that prints a form && echoes any input use CGI; use Modern::Perl 2011; my $head ='<!DOCTYPE html><head></head><body> <br /> <form method="post" action="/valid-form.cgi"> '; my $form =' <label for="input">Input: </label><input type="text" na +me="input" value="" /> <input type="submit" value="Post Input" /> '; my $foot =' </form></body></html>'; print "content-type:text/html; charset=utf-8\n\n"; print $head; print $form; my $query = CGI->new; $input = $query->param('input'); if (!$input) { print "<br />No input"; }else{ print "<br />$input"; } print $foot;
Simple enough --eh? NO. Seems that in the absence of M::P, everything is just Ducky. But now, with the addition of M::P, it fails.
Global symbol "$input" requires explicit package name at Global symbol "$input" requires explicit package name at Global symbol "$input" requires explicit package name at
Hmm... the $input stuff is a near Copy->Paste from the CGI pod.
I'm stumped.
Anyone care to comment?

Thank you for all your time, and consideration.

--Chris

#!/usr/bin/perl -Tw
use perl::always;
my $perl_version = (5.12.5);
print $perl_version;

Replies are listed 'Best First'.
Re: Why does Modern::Perl hate CGI.pm || my simple form?
by choroba (Cardinal) on Nov 05, 2013 at 23:20 UTC
    Modern::Perl means strict. Under strict, every variable must be declared. $input is not declared. See also my.

    Update: Try also diagnostics or splain:

    $ echo 'Global symbol "$input" requires explicit package name at -e li +ne 1.' | splain Global symbol "$input" requires explicit package name at -e line 1 (#1 +) (F) You've said "use strict" or "use strict vars", which indicates + that all variables must either be lexically scoped (using "my" or +"state"), declared beforehand using "our", or explicitly qualified to say which package the global variable is in (using "::").
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Greetings, and thank you for taking the time to respond.
      Good advise -- I'll take it!

      Thanks again.

      --Chris

      #!/usr/bin/perl -Tw
      use perl::always;
      my $perl_version = (5.12.5);
      print $perl_version;
Re: Why does Modern::Perl hate CGI.pm || my simple form?
by LanX (Saint) on Nov 05, 2013 at 23:21 UTC
      "BTW: CGI.pm must die!"
      LOL!
      I'm inclined to agree. I find the only time I use it, it to keep the code/script looking clean/tidy.
      Using it otherwise I think would just make me lazy/uninformed.
      Thanks for the informative response, Rolf!
      #!/usr/bin/perl -Tw
      use perl::always;
      my $perl_version = (5.12.5);
      print $perl_version;
        In case the solution was not obvious to other onlookers. Here's the corrected version that I should have known to do in the first place. :/
        #!/usr/bin/perl -Tw # dead simple stupid script that echoes input use CGI; use Modern::Perl 2011; my $head ='<!DOCTYPE html><head></head><body> <br /> <form method="post" action="/valid-form.cgi"> '; my $form =' <label for="input">Input: </label><input type="text" na +me="input" value="" /> <input type="submit" value="Post Input" /> '; my $foot =' </form></body></html>'; print "content-type:text/html; charset=utf-8\n\n"; print $head; print $form; my $query = CGI->new; my $input = $query->param('input'); if (!$input) { print "<br />No input"; }else{ print "<br />$input"; } print $foot;
        Take note of the additional my

        Best wishes.

        --Chris out...

        #!/usr/bin/perl -Tw
        use perl::always;
        my $perl_version = (5.12.5);
        print $perl_version;
Re: Why does Modern::Perl hate CGI.pm || my simple form?
by ww (Archbishop) on Nov 06, 2013 at 03:12 UTC
      Greetings ww!
      Indeed. I did. As noted in the thread you mentioned; I updated to the current version of M::P. So things are (should) go as expected. :)

      Best wishes.

      --Chris out...

      #!/usr/bin/perl -Tw
      use perl::always;
      my $perl_version = (5.12.5);
      print $perl_version;