WWW :: Mechanize Field Methods

What's the difference between

$mech -> field($name, $value)

      

and

$mech -> set_fields($name => $value)

      

and why do they both exist? It seems they each set a field named $name

on $value

.

+3


source to share


1 answer


$mech -> field($name, $value)

      

Field

() allows you to set one name at a time. But

$mech -> set_fields($name => $value, $name2 => $value2,... $nameN => $valueN)

      

... set_fields () allows you to set multiple names at the same time.



It doesn't really matter, because you can always use the first one in a loop:

my @data = (
    first => 'A',
    last  => 'B',
    age   => 22,
    #possibly 100,000 other name/value pairs
);

my($name, $value);

while(@data) {
   ($name, $value) = splice(@data, 0, 2);
   $mech->field($name, $value); 
}

      

... but it's more convenient to write:

$mech->set_fields(@data);

      

+4


source







All Articles