I am not sure exactly what your end goal is.

In Perl regex'es the \s stands for any whitespace character (space,\n,\r,\f,\t). \s* would mean zero or more of these and \s+ would mean at least one of these and possibly more of them. \s is an easy "short hand" for any of these "non-printable" space characters.

It could very well be that as other posters have suggested that the problem lies with 16 bit vs 8 bit chars. But then again, perhaps not if the issue is just "blank space" characters vs some other character.

Consider the following code. Common function names are: isprint() or isprintable() for a yes/no value. Below my sub get_printable() always returns something.

#!/usr/bin/perl -w use strict; my $var = "Some random text.\n\tMore\n\tEven More.\n\r\t And yet More +."; print "VAR is:$var\n"; print "Output of loop:\n"; foreach my $char (split//,$var) { print get_printable($char); } print "\n"; sub get_printable { my $char = shift; return $char if ($char =~ tr/A-Za-z0-9. //); return sprintf ("[hex%.2X]",ord($char)); } __END__ Prints: VAR is:Some random text. More Even More. And yet More. Output of loop: Some random text.[hex0A][hex09]More[hex0A][hex09]Even More.[hex0A][hex +0D][hex09] And yet More.

In reply to Re: What is the function that does the following..? by Marshall
in thread What is the function that does the following..? by ttlgreen

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.