Re: Entities.pm - How does decode_entities work?
- From: "Dave Saville" <dave@xxxxxxxxxxxxxxx>
- Date: Fri, 17 Dec 2010 10:31:36 +0000 (UTC)
On Thu, 16 Dec 2010 23:40:01 UTC, "Uri Guttman" <uri@xxxxxxxxxxxxxxx>
"DS" == Dave Saville <dave@xxxxxxxxxxxxxxx> writes:
DS> On Thu, 16 Dec 2010 17:44:02 UTC, "Uri Guttman" <uri@xxxxxxxxxxxxxxx>
>> >>>>> "DS" == Dave Saville <dave@xxxxxxxxxxxxxxx> writes:
DS> I needed to massage some text to put in a web page. I started out with
DS> some s/!/!;/g; type lines and then twigged that perl would most
DS> likely have a module to do it. HTML::Entities.pm. This works fine, but
DS> I then wanted to see *how* it did it.
DS> Having found the module, Entities.pm, I copied it to a tmp directory
DS> and modified the start of my test script from
DS> use HTML::Entities;
DS> use lib '.';
DS> use Entities;
>> what happened to the HTTP:: part? why did you think you could drop it?
DS> Er, what HTTP part? Did you mean the HTML part? I dropped it because
DS> my test version was not in an HTML directory. It was in the same
DS> directory as the test code.
DS> I then started sticking in print statements and eventually worked out
DS> how the encode worked. I then tried to do the same with the decode
DS> only to get an error:
DS> Undefined subroutine &Entities::decode_entities called at try.pl line
>> you broke its exporting.
DS> How? It can find encode_entities fine. Why didn't that break? The
DS> EXPORT lines don't mention the higher HTML layer except in the package
DS> header and I removed that portion of it.
because you used only Entities. rtfm on how use works. it first finds
and loads the module you requested (that worked). but then it calls the
import method on the class name passed to use. the module's class is
HTML::Entities but you used only Entities so it called
Entities->import() which doesn't exist and so nothing got exported.
you must use the proper class name when using a module to get
Please read what I wrote. :-)
Calling script has use "Entities;"
Entities.pm has "package Entities;"
HTML:: is not mentioned anywhere else.