Click to See Complete Forum and Search --> : stripping whitespace and \n in perl


YaRness
10-09-2000, 08:50 AM
ok, so i have a variable $hex, it contains a hex number followed by 0 or more whitespaces and an end-of-line. chomp doesn't seem to be cutting it, some whitespace or other oddities are still clinging to the variable. what i can't figure out is how to extract JUSt the hex number with no extra characters. all i can figure out is that a hex number matches [A-Fa-f\d], but i dunno what to do with that info from there.

------------------
"Assembly of Japanese bicycle require great peace of mind."
Registered Linux User #188285 http://counter.li.org/
------------------

jemfinch
10-09-2000, 10:44 AM
You can try either tr/\s//d or s/\s+//g. I would imagine the first is faster.

Jeremy

klamath
10-09-2000, 12:37 PM
Actually jemfinch, tr doesn't use \s or the other regular expression character classes. For example:

$perl -e '$str=q{\s\shello world\s\s};$str =~ tr/\s//d;print "$str\n"'
\\hello world\\

I'd do:

tr/A-Fa-f0-9//cd

I think that's correct... And jemfinch is right, tr// is always faster than s///

------------------
- Klamath
Get my GnuPG Key Here (http://klamath.dyndns.org/mykey.asc)

YaRness
10-09-2000, 01:15 PM
Originally posted by klamath:
Actually jemfinch, tr doesn't use \s or the other regular expression character classes. For example:

$perl -e '$str=q{\s\shello world\s\s};$str =~ tr/\s//d;print "$str\n"'
\\hello world\\

I'd do:

tr/A-Fa-f0-9//cd

I think that's correct... And jemfinch is right, tr// is always faster than s///


ooo ahhh ohhhh.

oh, that's exactly what i was looking for. damn, now i hafta quit surfing on the web waiting for an answer and finish what i started at 7am today http://www.linuxnewbie.org/ubb/biggrin.gif

danke.



------------------
"Assembly of Japanese bicycle require great peace of mind."
Registered Linux User #188285 http://counter.li.org/
------------------