Home > Archive > PERL Beginners > June 2005 > why die; produce an error?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
why die; produce an error?
|
|
| Ing. Branislav Gerzo 2005-06-05, 8:55 pm |
| Hi all,
I noticed strange behavior with die;
Here is snippet:
use strict;
use warnings;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->agent_alias('Windows IE 6');
$mech->get( 'http://www.zoznam.sk' );
for my $link ( $mech->links() ) {
print $link->url_abs, "\n";
}
This works quite OK, but when I put die; at the end of script it
throws me an error:
Can't locate URI/javascript.pm in @INC (@INC contains: c:/Perl/lib c:/Perl/site/
lib .) at (eval 19) line 3.
...propagated at myscript.pl line 10.
at line 10 is die;
Whats going here ?
Also exist a way how to get normal URL via javascript?
Lets say I have:
<a href="javascript:nWindow=window.open('/test.html','test',
'toolbar=no,width=600,height=500'); void('');">test</a>
I'd like to get abs_url of this one.
Thanks.
| |
| Offer Kaye 2005-06-06, 8:55 am |
| On 6/5/05, Ing. Branislav Gerzo wrote:
> Hi all,
>=20
> I noticed strange behavior with die;
> Here is snippet:
>=20
> use strict;
> use warnings;
> use WWW::Mechanize;
>=20
> my $mech =3D WWW::Mechanize->new();
> $mech->agent_alias('Windows IE 6');
> $mech->get( 'http://www.zoznam.sk' );
> for my $link ( $mech->links() ) {
> print $link->url_abs, "\n";
> }
>=20
>=20
> This works quite OK, but when I put die; at the end of script it
> throws me an error:
> Can't locate URI/javascript.pm in @INC (@INC contains: c:/Perl/lib c:/Per=
l/site/
> lib .) at (eval 19) line 3.
> ...propagated at myscript.pl line 10.
>=20
> at line 10 is die;
>=20
> Whats going here ?
>=20
I can't reproduce your problem, using perl 5.8.6 on Linux,
WWW::Mechanize version 1.12 . The script I'm using (test.pl):
########### begin code
use strict;
use warnings;
use WWW::Mechanize;
my $mech =3D WWW::Mechanize->new();
$mech->agent_alias('Windows IE 6');
$mech->get( 'http://www.google.com/' );
for my $link ( $mech->links() ) {
print $link->url_abs, "\n";
}
die;
########### end code
I'm running it using "perl test.pl". The output from this is:
########### begin output
http://www.google.co.il/imghp?hl=3Diw&tab=3Dwi
http://www.google.co.il/grphp?hl=3Diw&tab=3Dwg
http://www.google.co.il/dirhp?hl=3Diw&tab=3Dwd
http://www.google.co.il/advanced_search?hl=3Diw
http://www.google.co.il/preferences?hl=3Diw
http://www.google.co.il/language_tools?hl=3Diw
http://www.google.co.il/intl/iw/about.html
http://www.google.com/ncr
Died at aaa.pl line 10.
########### end output
(the die statement is on line 10).
So the problem is:
1. In some other code you didn't show
2. Specific to your OS, Perl version of W::M version
I suspect reason 1 is the culprit :)
HTH,
--=20
Offer Kaye
| |
| Ing. Branislav Gerzo 2005-06-06, 8:55 am |
| Offer Kaye [OK], on Monday, June 6, 2005 at 10:31 (+0300) contributed
this to our collective wisdom:
$mech->get( 'http://www.google.com/' );
OK> So the problem is:
OK> 1. In some other code you didn't show
OK> 2. Specific to your OS, Perl version of W::M version
OK> I suspect reason 1 is the culprit :)
you should try that with www.zoznam.sk, or some page where is
JavaScript link. On Google AFAIK is not, so I think that's why
your script is OK. Just change the page and you will see.
I am on windows, Perl v5.8.6 built, W::M 1.12
--
How do you protect mail on web? I use http://www.2pu.net
[My parents were liberal. They LEFT me whenever possible.]
| |
| Thomas Bätzler 2005-06-06, 8:55 am |
| Ing. Branislav Gerzo <konfera@2ge.us> wrote:
> you should try that with www.zoznam.sk, or some page where is
> JavaScript link. On Google AFAIK is not, so I think that's
> why your script is OK. Just change the page and you will see.
Doesn't that kind-of answer your question?
If you call die without an argument, it'll use the message in
$@ instead. That's set by the last eval() in your code. I would
expect that failing eval() happens in the module you're calling.
HTH,
Thomas
| |
| Ing. Branislav Gerzo 2005-06-06, 8:55 am |
| Thomas Bätzler [TB], on Monday, June 6, 2005 at 11:01 (+0200 ) wrote
the following:
TB> Doesn't that kind-of answer your question?
TB> If you call die without an argument, it'll use the message in
TB> $@ instead. That's set by the last eval() in your code. I would
TB> expect that failing eval() happens in the module you're calling.
hm question is, why die; produces error, and when is no die; in that
snippet everything is OK? (I hope:)
--
How do you protect mail on web? I use http://www.2pu.net
[Master debaters often argue with themselves.]
| |
| Thomas Bätzler 2005-06-06, 8:55 am |
| Ing. Branislav Gerzo <konfera@2ge.us> asked:
> hm question is, why die; produces error, and when is no die;
> in that snippet everything is OK? (I hope:)
Read my lips: die without argument list (as used in your code)
will show the error that occured during the last eval() that was
executed by your code. See the section on die in the perlfunc
manpage.
Off the top of my head I'd say that when parsing the links on
the page you requested, WWW::Mechanize creates an URI object for
each link that is found. The URI class is subclassed by the URI
request scheme (i.e. URI::http, URI::nttp, ... ) and the needed
subclass is loaded dynamically by URI.pm:
# scheme not yet known, look for internal or
# preloaded (with 'use') implementation
$ic = "URI::$scheme"; # default location
# turn scheme into a valid perl identifier by a simple tranformation...
$ic =~ s/\+/_P/g;
$ic =~ s/\./_O/g;
$ic =~ s/\-/_/g;
no strict 'refs';
# check we actually have one for the scheme:
unless (@{"${ic}::ISA"}) {
# Try to load it
eval "require $ic";
die $@ if $@ && $@ !~ /Can't locate.*in \@INC/;
return unless @{"${ic}::ISA"};
}
What happens is that your page has java script: links embedded.
URI.pm tries to load URI::javascript, but it's not there. Since
URI.pm considers this a non-fatal error, it does not die. However,
the $@ variable remains set. When you die() later in your code,
you are shown that message.
So, is this a bug in WWW::Mechanize? Well, the WWW::Mechanize
FAQ has the following to say on java script:
"JavaScript is entirely client-based, and WWW::Mechanize is a client
that doesn't understand JavaScript."
HTH,
Thomas
| |
| Ing. Branislav Gerzo 2005-06-06, 8:55 am |
| Thomas Bätzler [TB], on Monday, June 6, 2005 at 12:07 (+0200 )
contributed this to our collective wisdom:
TB> What happens is that your page has java script: links embedded.
TB> URI.pm tries to load URI::javascript, but it's not there. Since
TB> URI.pm considers this a non-fatal error, it does not die. However,
TB> the $@ variable remains set. When you die() later in your code,
TB> you are shown that message.
TB> So, is this a bug in WWW::Mechanize? Well, the WWW::Mechanize
TB> FAQ has the following to say on java script:
TB> "JavaScript is entirely client-based, and WWW::Mechanize is a client
TB> that doesn't understand JavaScript."
thanks a lot for nice explanation, this is exactly how reply should
looks for begginers like me, I give you ++ :)
I didn't know about non-fatal errors <-> die;
Thanks a lot again.
--
How do you protect mail on web? I use http://www.2pu.net
[OFFLINE 1.50 "Mary had a little RAM - about a MEG or so.]
| |
| Offer Kaye 2005-06-06, 3:56 pm |
| On 6/6/05, Thomas B=E4tzler wrote:
>=20
> Off the top of my head I'd say that when parsing the links on
> the page you requested, WWW::Mechanize creates an URI object for
> each link that is found. The URI class is subclassed by the URI
> request scheme (i.e. URI::http, URI::nttp, ... ) and the needed
> subclass is loaded dynamically by URI.pm:
>=20
Cool, I didn't know that :)
Thanks for the great explanation Thomas, I was wondering why W::M was
looking for something called URI::javascript, you answered that
perfectly.
As a side issue, I tried running the failing script using Devel::ebug
and could not quite reproduce this issue. I'm using the latest
Devel::ebug version (0.43). Has anyone had any success using this
module for debugging work?
Cheers,
--=20
Offer Kaye
|
|
|
|
|