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

Hi again, I took your advice and managed to get together a script for my request. here is what I have so far sorry, i don't really know how to configure this post..so it's kind of messy
#!/usr/bin/perl -w use LWP::UserAgent; my $digits; open( FILE, "< /tmp/blah.txt" ) or die "Can't open $filename : $!"; while( <FILE> ) { $digits = $_; print "Attempting line: " . $digits; k_go_now($digits); # Sleep to keep us slightly more hidden and load off their servers sleep(1); } # k go now sub; grabs input from file ($username, $password) tries to +login sub k_go_now { my ($digits) = @_; $ua = LWP::UserAgent->new; $ua->agent("MyApp/0.1 "); # Create a request my $req = HTTP::Request->new(POST => 'https://xxx'); $req->content_type('application/x-www-form-urlencoded'); $req->content('query=libwww-perl&mode=dist'); # Pass request to the user agent and get a response back my $res = $ua->request($req); # Check the outcome of the response if ($res->is_success) { check_output ($res->content); } else { print $res->status_line, "\n"; } } # suib check_output checks the response from the website and if it's a +ny good sub check_output { my ($output) = @_; if ($output =~ /Login Failed/) { print "Nope, failed login\n"; } elsif ($output =~ /Login Successful/) { print "got'em with login details\n"; } else { print "unknown response !!!\n$output\n\n"; } }
I'm pretty sure it's all good but I cant help but think that I screwed up somewhere with the syntax, could you guys point me in the right direction please? When I run it, it says Line 7 is a possible typo. Thanks -sjlo

Replies are listed 'Best First'.
Re: Where did I go wrong?
by ikegami (Patriarch) on Nov 13, 2007 at 22:26 UTC

    You are hiding errors by not using use strict;. One is that $filename is neither declared nor initialized.

    open( FILE, "< /tmp/blah.txt" ) or die "Can't open $filename : $!";

    should be

    my $filename = '/tmp/blah.txt'; open( FILE, '<', $filename ) or die "Can't open $filename: $!\n";

    By the way, you might want to use HTTP::Request::Common instead of building the query manually.

      ok..here are the errors... unmatched right curly bracket at c:\users\xxx\perl\script.pl line 17, at end of line syntax error at line 17, near "}" execution aborted due to compilation errors
        That error does not exist in the code you gave us.
Re: Where did I go wrong?
by holli (Abbot) on Nov 13, 2007 at 22:34 UTC
    i don't really know how to configure this post.
    As this site is best viewed with OpenEyes™, it's all there, right under the preview: Writeup Formatting Tips


    holli, /regexed monk/
      getting the error.. Name 'main::FILE" used only once: possible typo at line 9 Use of uniniitalized value in concatenation <.> or string and Attemping line: 302 Moved Temporarily not sure what that means
        You probably want something like
        use strict; use warnings; my $FILE = undef; my $filename = 'C:\tmp\blah.txt'; open( $FILE, '<', $filename ) or die "Can't open $filename: $!"; while(<$FILE>) { ... } close $FILE or die "Close failed";
        See perlopentut for more.

        Also, it looks like you are running Win32. /tmp/blah.txt is not a proper Win32 filename.

        Update: Thanks to cdarke for pointing out Win32 filename subtleties, where /tmp/blah.txt indeed is a possibly filename.

        --
        Andreas
Re: Where did I go wrong?
by Fletch (Bishop) on Nov 13, 2007 at 22:21 UTC

    Well the first thing I see is that you neglected to use <code></code> tags around your code so it's a big honking unformatted mess where it's impossible to see what "line 7" is.

    Update: And it's been janitored into readability. Fweee.

Re: Where did I go wrong?
by toolic (Bishop) on Nov 13, 2007 at 22:24 UTC
    i don't really know how to configure this post..so it's kind of messy
    Use code tags around your code, as described in Writeup Formatting Tips
    When I run it, it says Line 7 is a possible typo
    Please show the exact error message you get when you run it.
      i fixed it now...I didn't know about the /code tags..heres the error message.. Name "main::filename" used only once: possible typo at C:\users\xxx\desktop\perl\script.pl line 7 use of uninitalized value in concatenation <.> or string at C:\users\xxx\desktop\perl\script.pl can't open : no such file or directory at c:\users\xxx\desktop\perl\script.pl
        /tmp/blah.txt doesn't exist.