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

any incarnation of: (...) fails!
"Fails" in which way? Any errors on screen or in the webserver's logs? Do you use CGI (or similar) to parse the inputs?

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
  • Comment on Re: How to convert an @ARGV to form based input?

Replies are listed 'Best First'.
Re^2: How to convert an @ARGV to form based input?
by taint (Chaplain) on Aug 21, 2012 at 06:17 UTC
    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;
      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;
      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;