Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: how to output special characters?

by blazar (Canon)
on Jul 18, 2008 at 19:05 UTC ( [id://698710]=note: print w/replies, xml ) Need Help??


in reply to Re^2: how to output special characters?
in thread how to output special characters?

just wondering why print() function cannot display them.

I personally believe that you're confused: as others duly explained to you, print indeed does print() them. The fact that they're control charachters makes them not visible on a plain terminal, though. The fact that some specialized tools like more or less will display them in such a way that makes them visible is totally irrelevant. Thus, to literally answer your question: "because print() is made to print stuff as opposed to especially display it." Of course, nobody prevents you from rolling your own display() sub to do so. E.g.:

sub display { map { (my $s = $) =~ s/[[:cntrl:]]/^A/g; $s; } @_; }

Here, I just made it show any control carachter like "^A" which may be or not what you want, but I don't know of any standard mapping or representation for them. If you have one, then again feel free to just refine the thing. All that perldoc perlre has to say is: 'all characters with ord() less than 32 are usually classified as control characters (assuming ASCII, the ISO Latin character sets, and Unicode), as is the character with the ord() value of 127 ("DEL")'

To be completely fair, Perl IO routines do some translations, and if you're really motivated to have print() do it for you, then you may move your display() code to a suitable layer once you're fine with it.

--
If you can't understand the incipit, then please check the IPB Campaign.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-23 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found