in reply to Viewing metasymbols in output?
This is a nice way to map it out and preserve the spatial relationships of the text. Tabs are changed to ' -> ' and spaces to dots '·' (chr 183 ASCII). This is how my editor displays them when I select the display all chars option. chr 182 ASCII is that funny backwards P symbol ¶ used for newlines. We use the octal naming convention for these chars for convenience. chr 0266 = '¶' and chr 0267 = '·'
In the unlikely event these special chars are included in the text to be processed we hex encode them using the standard URL encoding convention of a % followed by two hex digits. We can then remove the URL encoding to regenerate our original text.
sub show { my @data = @_; for (@data) { s/(\266|\267)/sprintf"%%%02X",ord $1/egm; s/ /chr(0267)/egm; s/\t/ -> /gm; s/\n/chr(0266)."\n"/egm; } return wantarray ? @data : join'',@data; } sub hide { my @data = @_; for (@data) { s/ -> /\t/gm; s/\266//gm; s/\267/ /gm; s/%([0-9a-f][0-9a-f])/chr hex $1/eigm; } return wantarray ? @data : join'',@data; } @data = (<DATA>)[0..7]; print "Original data, including specials\n\n"; print @data; print "\n\nShow invisible chars in data\n\n"; print show(@data); print "\n\nHide and show data - should not change\n\n"; print hide(show(@data)); __DATA__ tab 4 spaces, trailing tab tab and 4 spaces ····4·spaces,·trailing·tab -> ¶ -> ····tab·and·4·spaces¶ -> -> ¶ ¶
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|