[ back to toc ]

Perl - removing characters in Scalars

Date: 2002/05/02 10:26

Q:
Hi Peter,

Just a quick question - I'm new to Perl but think it's fantastic, I use it
on my FreeBSD box.

I would like to know how to remove certain characters within scalars, for
example the scalar $box contains "hello", how can I remove the "l"s to
produce the scalar $box containing "heo"?

The same for white spaces, if a scalar contains " I'm Phil" or "
000.00" - how can I get it to only contain "I'mPhil" or "000.00"
respectively?

Many thnaks for taking the time to read this email - I look forward to
your reply.

Phil
A:
Here is some screen copy from my Linux box demonstrating the commands:

verhas@verhaslinux:~$ perl
$a = "hello";
$a =~ s/l//g;
print "$a\n";
$b = "I'm Phil";
$b =~ s/\s//g;
print "$b\n";
$c = " 000.00";
$c =~ s/\s//g;
print "$c\n";
__END__
heo
I'mPhil
000.00
verhas@verhaslinux:~$

Visit my on-line audio tutorials on Perl, at

http://www.peter.verhas.com/tutorials/

Regards,
Peter

[ back to toc ]