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

Is it possible to use regular expressions as a way to fill in option fields when using WWW::Mechanize's set_visible method? For example, $mech->set_visible([ option => /.+/ ]); I have tried the aforementioned code and it returns the error:

Use of uninitialized value in pattern match (m//) at name.pl line 72. The 'B3200L' field can't be unchecked at /usr/local/share/perl/5.8.8/W +WW/Mechanize.pm line 1429

Making me think something is going wrong... ;)

Either that, or is there a way to select an option by it's number on the option list? Knowing how to would prove just as helpful.

EDIT: It should be noted that there are multiple option inputs each on a seperate page. Also, thanks pc88mxer for the elaboration.

Replies are listed 'Best First'.
Re: Using regex to select an option with WWW::Mechanize
by pc88mxer (Vicar) on Jul 06, 2008 at 06:00 UTC
    Update: After further discussions on the CB, it turns out that the OP wants to set the first option to the first alphanumeric value.

    What follows is an explanation of what the original code is doing.

    You probably want:

    $mech->set_visible([ option => qr/.+/ ]); # ^^
    What you have is the same as:
    $mech->set_visible([ option => ($_ =~ m/.+/) ]);
    In other words, you are passing the result of matching qr/.+/ against $_ (and this likely is where the Use of uninitialized value warning is coming from), not the regular expression itself.