Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: frac12 to decimal

by karoshi (Novice)
on Feb 09, 2009 at 03:52 UTC ( [id://742342]=note: print w/replies, xml ) Need Help??


in reply to frac12 to decimal

Behold, the hash holding those is declared with "use vars":

use vars qw(%entity2char %char2entity);

So, after that package has been loaded and compiled, you could reach into that package and change just the values of them keys:

# switch package package HTML::Entities; $entity2char{frac14} = '.25'; $entity2char{frac12} = '.5'; $entity2char{frac34} = '.75'; # switch back to your package package main; # go on with your code

Replies are listed 'Best First'.
Re^2: frac12 to decimal
by CColin (Scribe) on Feb 09, 2009 at 18:19 UTC
    Hi Thanks - I guess that answers the question on changing the behaviour of the module without changing the module, but having said that this particular code did not bring about the desired behaviour. That's still the piece I can't figure out what's happening? The hash in the module:
    %entity2char
    Contains the following key value pairs that seem to govern this behaviour.
    frac14 => chr(188), frac12 => chr(189), frac34 => chr(190),
    Presumably chr(188) and its brethren are taken straight from the HTML, then fracNN to which it is mapped is somehow translated to display as the tiny one character wide fraction symbol. But stating:
    # switch package package HTML::Entities; $entity2char{frac14} = '.25'; $entity2char{frac12} = '.5'; $entity2char{frac34} = '.75'; # switch back to your package package main; # go on with your code
    Does not seem to change that behaviour?
      ½ is a HTML entity, it maps directly to chr(188)/U+00BC, which in ISO88591 is vulgar fraction one quarter , and all computer programs which know how to display ISO88591 will draw on the screen ½

      from HTML/Entity.pm:

      # Make the opposite mapping while (my($entity, $char) = each(%entity2char)) { $entity =~ s/;\z//; $char2entity{$char} = "&$entity;"; }

      so try: change %char2entity as well

      package HTML::Entities; $char2entity{'.25'} = '¼'; $char2entity{'.5'} = '½'; $char2entity{'.75'} = '¾'; package main; ...

      or post some code to look at.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://742342]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-24 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found