title: Website log-in with Perl and Mechanize
body: <p>So this is driving me crazy. Basically, when I hard-code my user name and password, I can log-in no problem.  But I want to prompt the user to enter the username and password, as I would like to share this program with others.  (the program is supposed to log into our courses site and download all of our course work info - lectures, hw, etc)</p>
  
  <p>This code works:</p>
  
  <pre><code>use WWW::Mechanize;
  use LWP;
  
  my $username = 'user'; 
  my $password = 'pass';
  
  my $mech = WWW::Mechanize-&gt;new();
  $mech -&gt; cookie_jar(HTTP::Cookies-&gt;new());
  $mech -&gt; get('log-in url');
  $mech -&gt; form_name('theform');
  $mech -&gt; field ('username' =&gt; $username);
  $mech -&gt; field ('password' =&gt; $password);
  $mech -&gt; click ('log in');
  print $mech-&gt; content();
  </code></pre>
  
  <p>however, when I try and prompt the user to enter log-in info, it does now work.  printing content returns the html of the log-in page, not the following page (courses page for said user)</p>
  
  <pre><code>use LWP;
  use WWW::Mechanize;
  
  my $login_url = 'log-in url';
  print "\nUser name: ";
  my $username = &lt;&gt;;
  print "Password: ";
  my $password = &lt;&gt;;
  
  my $mech = WWW::Mechanize-&gt;new();
  $mech -&gt; cookie_jar(HTTP::Cookies-&gt;new());
  $mech -&gt; get($login_url);
  $mech -&gt; form_name('theform');
  $mech -&gt; field ('username' =&gt; $username);
  $mech -&gt; field ('password' =&gt; $password);
  $mech -&gt; click ('log in');
  print $mech-&gt; content();
  </code></pre>
  
  <p>this really makes no sense since they are essentially the same thing.  I even typed in the username/password in quotes in the prompt and still no avail..... (i realize also that it wont be very easy to check without a website and log-in info, sorry about that)</p>