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.

In reply to Re^3: how to output special characters? by blazar
in thread how to output special characters? by perlfan99

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.