Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

data cleaning - removing text from variables

by ecuguru (Monk)
on May 21, 2004 at 07:05 UTC ( [id://355198]=perlquestion: print w/replies, xml ) Need Help??

ecuguru has asked for the wisdom of the Perl Monks concerning the following question:

Hey dave,

that worked great.. thanks!
For more of an explanation.. I have a serial A/D Converter and am getting some line noise while transmitting the data.. Like in hundreds of thousands of lines of data, I get some extraneous line noise represeted by characters. The perl script is parsing and analyzing the collection of data. It's just line noise, so I'm trying to identify the noisy values.
Thanks Again!
  • Comment on data cleaning - removing text from variables

Replies are listed 'Best First'.
Re: data cleaning - removing text from variables
by davido (Cardinal) on May 21, 2004 at 08:12 UTC
    the letters are hex.

    Huh?

    So if you have the hex number 7A, you want to retain the 7 and discard the A? That will cause the number 7A, which is 122 in decimal, to become 7 in decimal. Is this really what you want? What you're doing is simply discarding all digits of value greater than nine. ...doesn't make sense to me.

    Nevertheless, here's another way to do it..:

    $string =~ tr/0-9.//cd;

    The /c flag means to complement the characters enumerated on the left side of the tr/// operator. And /d means to delete any character from the target string that is found in the list. /cd means delete any character not found in the list on the lefthand side.


    Dave

Re: data cleaning - removing text from variables
by Ryszard (Priest) on May 21, 2004 at 07:11 UTC
    Regex's are your friend.
    #perl -e '$_="1aa23.4a";$_=~s/[a-f]//gi;print "$_\n"' 123.4 #

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-23 23:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found