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

Hello Monks!
I have a question and it may be quite elaborate. I've spent a day in this problem and maybe there isn't a straight forward solution or I may just be stupid!
So here I go: I've ActiveState Perl v5.8. I'm using WxPerl to create a GUI.
Lets say I have two text fields (WxTextCtrl) from which I take inputs. I then use WWW::Mechanize to fill in a web form with these two inputs and submit the form (consider the code below).

Now the problem is that it doesn't work! Its not a problem with HTTP or any other network related stuffs. When I just pass simple string value as follows for example "$title = "whatever"; and $commentfile = "file.htm"", the program works but when I take content of text box and fill in the form, it doesn't work.
The only explanation that I can think of is because WxTextCtrl->GetValue() returns WxString. Since WxString is derived from std::string I don't think this should happen!
Has anyone faced similar sort of problem?
I tried $title = sprintf("%s",$title) in attempt to convert $title from WxString to std::string, but to no avail (or was this stupid attempt :P).
sub __mechanize_http { $win = @_; $title = $win->{titleTxt}->GetValue(); #$win is the main window and +titleTxt is the name of one of the text field. GetValue() will return + the content of text field in WxString fromat. $commentfile = $win->{fileNameTxt}->GetValue(); #Wx::TextCtrl->GetValue() returns WxString. print "\nTitle: ",$title; print "\nOutput: ", $commentfile; my $url = "http://www.example.com/"; my $mech = WWW::Mechanize->new(autocheck => 1); $mech->agent_alias ( "Windows IE 6" ); $mech->get($url) or die "Can't even get $url: " . $mech->response->status_line unless ($mech->success); $mech->form_name('AddForm'); $mech->field(title => $title); $mech->field(commentfile => $commentfile); $mech->submit(); }

Replies are listed 'Best First'.
Re: Question on WxString (WxPerl) and WWW::Mechanize
by b4swine (Pilgrim) on Sep 11, 2007 at 01:16 UTC
    I have used WxPerl a lot, and there is no difference between WxString and an ordinary perl string. So that is not the issue.

    If you want to make sure of this, put a check: right after getvalue, add

    die unless $title eq 'whatever'; die unless $comentfile eq 'file.htm';
      Thanks for replying!
      Your snippet was useful. I did add the line and the program doesn't terminate but it still don't work. Would you happen to know any quirks of WWW::Mechanize module, like whether its subroutines cannot be passed with certain kind of string??
      This is weird, when I add  die unless $title eq 'whatever'; the processing doesn't terminate and the program doesn't work, but when I make explicit assignment after your line as:
      die unless $title eq 'whatever'; $title = 'whatever';
      It works. So... o_0
      I even added following lines:
      if ((defined($title))&&($title ne "")) { print "\nTitle filled with ... $title"; $mech->field(title => $title); }

      The output says: Title filled with ... whatever
      and then.. LWP::UserAgent::request: Simple response: Internal Server Error
Re: Question on WxString (WxPerl) and WWW::Mechanize
by Anonymous Monk on Sep 11, 2007 at 07:49 UTC
    Don't you get any warnings? $win should be an object, not a number
    $win = @_;
    should be
    ($win) = @_;
      Thank you! I didn't know that. But I do put brackets and now I know why.
        I'm working around this problem.
        I'm writing the WxString from textfield into a text file and then reading from the text file when I have to assign the value to form fields in WWW::Mechanize module! This way I avoid any direct contact with WxString during assignment.