Subject: | Cloned Mech and original Mech are not independent each other |
In following Code, I expected that $Mech and it's cloned $Mech2 should
be independent each other. However when $Mech2's inputbox 'S56' is
changed , $Mech's inputbox is set to same value!
-----------------------------------------------------------
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->get($url);
my $mech2 = $mech->clone();
my $temp = $mech->form_name('MainForm')->value('S65');
my $temp2 = $mech2->form_name('MainForm')->value('S65');
print "\$mech's S65 = $temp\n";
print "\$mech2's S65 = $temp2\n";
$mech2->set_fields( S65 => 'ABC' );
$temp = $mech->form_name('MainForm')->value('S65');
$temp2 = $mech2->form_name('MainForm')->value('S65');
print "\$mech's S65 = $temp\n";
print "\$mech2's S65 = $temp2\n";
$mech->set_fields( S65 => 'ABCd' );
$temp = $mech->form_name('MainForm')->value('S65');
$temp2 = $mech2->form_name('MainForm')->value('S65');
print "\$mech's S65 = $temp\n";
print "\$mech2's S65 = $temp2\n";
-------------------------------------------------------
The outputs are
$mech's S65 =
$mech2's S65 =
$mech's S65 = ABC
$mech2's S65 = ABC
$mech's S65 = ABCd
$mech2's S65 = ABCd
-------------------------------------------------------
Version Information
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 18 registered patches, see perl -V for more detail)
Copyright 1987-2007, Larry Wall
Binary build 822 [280952] provided by ActiveState
http://www.ActiveState.com
Built Jul 31 2007 19:34:48
WWW-Mechanize : 1.540, HTTP-Server-Simple:0.28
Os: Windows Xp Pro 2002 SP3
Why?
but Cloned object and original object points defferent address.
for example,
$mech = WWW::Mechanize=HASH(0x1cd92dc)
$mech2 = WWW::Mechanize=HASH(0x233c980)