Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Strange character beginning text files

by beable (Friar)
on Jul 20, 2004 at 02:49 UTC ( [id://375771]=note: print w/replies, xml ) Need Help??


in reply to Strange character beginning text files

You should try using the ord($ch) function to find out what the character is. It looks like it might be ASCII character number 1, but it's hard to tell on a webpage. If it is an unprintable ASCII character, you could use the tr operator to delete it:
#!/usr/bin/perl use strict; use warnings; my $string = "\001hello\002world\003lookit\004these\005weird\006charac +ters"; my $string2 = $string; # replace ASCII chars from 0 to 8 with spaces $string =~ tr[\000-\010][ ]; # or delete weird chars: $string2 =~ tr[\000-\010][]d; print "string is $string\n"; print "string2 is $string2\n"; __END__

Replies are listed 'Best First'.
Re^2: Strange character beginning text files
by tachyon (Chancellor) on Jul 20, 2004 at 05:08 UTC

    To limit data to the ASCII printable set you can just do tr/\011\012\015\040-\176//cd You may want to lose or change one of the CR LF chars as well.

    Opps, forgot tab, thanks beable

    cheers

    tachyon

      Tut tut, sirrah. \011 is printable. From "man ascii":
      Oct Dec Hex Char 011 9 09 HT '\t'
      </nitpick>

        Ooops, forgot that! That's what happens if you code off the top of your head with no unit tests :-)

        cheers

        tachyon

Log In?
Username:
Password:

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

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

    No recent polls found