Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: How to convert an @ARGV to form based input?

by taint (Chaplain)
on Aug 21, 2012 at 06:17 UTC ( #988589=note: print w/ replies, xml ) Need Help??


in reply to Re: How to convert an @ARGV to form based input?
in thread How to convert an @ARGV to form based input?

Greetings @CountZero, and thank you for your prompt reply! Yes, there are errors. In the case above, perl complains about:
Global symbol "$domain" requires explicit package name at dnsdig.cgi line 8.
Mind you, I've tried MANY different incarnations today. But I think that was the output perl emitted in the web log, when I used the example above.
Thanks again for taking the time to respond.
--Chris

#!/usr/bin/perl -Tw
use perl::always;
my $perl_version = "5.12.4";
print $perl_version;


Comment on Re^2: How to convert an @ARGV to form based input?
Download Code
Re^3: How to convert an @ARGV to form based input?
by CountZero (Bishop) on Aug 21, 2012 at 06:40 UTC
    Mmmm, obviously you have not shown us the whole of your program and that makes it difficult to help you. It seems the code to stuff the content of the form fields into $domain is entirely missing.

    I suggest you make a small and simple cgi-script using CGI::Simple or such and see you can get some data in and out of it. Don't yet bother yourself with coupling the cgi-script with your DNS-routines. You can add those later.

    Or even better, start using some web-frameworks (Dancer springs to mind) to make life more easy for you.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
      Greetings, and thanks for your reply. That is a fully working piece of code:
      #!/usr/bin/perl -w use strict; use Net::DNS; my $dns = new Net::DNS::Resolver; for my $domain( @ARGV ) { my $mx = $dns->query( $domain, 'MX' ); print "content-type:text/html; charset=utf-8\n\n"; print "$domain:\n\n"; foreach my $rr ($mx->answer) { print "<br />", $rr->exchange, ' [<b>', $rr->preference, "</b> +]\n"; } }
      Go ahead, stuff it into a cgi script, and put it into a cgi enabled folder. Then enter
      http:/yourdomain.tld/path/to/your/script?google.com
      In that form, it works just fine.
      But that is not my intended final implementation. I had hoped to replace the (@ARGV) with a form input field -- hence the title of this post.
      --Chris
      #!/usr/bin/perl -Tw
      use perl::always;
      my $perl_version = "5.12.4";
      print $perl_version;
        It is of course the not working script we are interested in. :)

        So how does your error-producing script look like?

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        My blog: Imperial Deltronics
Re^3: How to convert an @ARGV to form based input?
by grizzley (Chaplain) on Aug 21, 2012 at 07:20 UTC
    That's obviously because in for my $domain(...) loop you defined $domain but when you replaced this line with if($domain ne "") this variable was not defined anymore. Put my $domain; before if and it will work.
      Greetings @grizzley, and thank you for your reply. Sadly, following your advice DOES define $domain, but doing so only nullifies the if loop. So the form fields never show up. FWIW, the perl output in the web log reveals:
      Use of uninitialized value $domain in string ne at dnsdig.cgi line 9. Use of uninitialized value $domain in concatenation (.) or string at d +nsdig.cgi line 18. Can't call method "answer" on an undefined value at dnsdig.cgi line 19 +.

      If I understood you correctly, the code I used was:
      #!/usr/bin/perl -w use strict; use Net::DNS; my $dns = new Net::DNS::Resolver; my $domain; if($domain ne "") { print "<form action=\"dnsdig.cgi\" method=\"post\"> <input name=\"domain\" type=\"text\" value=\"\" /> <input type=\"submit\" value=\"Get MX\" /> </form>"; } else { my $mx = $dns->query( $domain, 'MX' ); print "content-type:text/html; charset=utf-8\n\n"; print "$domain:\n\n"; foreach my $rr ($mx->answer) { print "<br />", $rr->exchange, ' [<b>', $rr->preference, "</b> +]\n"; } }

      Thanks again for taking the time to respond.
      --Chris
      #!/usr/bin/perl -Tw
      use perl::always;
      my $perl_version = "5.12.4";
      print $perl_version;
        D'OH!
        That should have read:
        if($domain eq "") {
        not
        if($domain ne "") {
        Sorry.
        It still doesn't work.
        --Chris
        #!/usr/bin/perl -Tw
        use perl::always;
        my $perl_version = "5.12.4";
        print $perl_version;

        Ok, now the error message looks differently, don't you agree? :)

        $domain is already defined, but uninitialized. Please replace my $domain; with my $domain = 'google.com'; and check the result.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988589]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2014-09-22 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (176 votes), past polls