Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

RE: Stripping characters from strings

by Adam (Vicar)
on Oct 30, 2000 at 00:02 UTC ( [id://39008]=note: print w/replies, xml ) Need Help??


in reply to Stripping characters from strings

AgentM had pretty much the complete list (except chop). Your question, however, is not really specific enough to do more then point you at these documents. But I suspect, rather... HOPE, that you looked at the library before posting your question and have therefor seen these documents (chop,chomp,tr,s) so you probably wanted an example. Lets see:
use strict; #Always! my $string = "This is a test string. 123\n"; chomp($string); # removes the "\n" from the end of $string. chomp($string); # no-op. chomp only removes white-space: \t, ' ', \n, +etc... chop($string); # removes the '3' from the end of $string. chop($string); # removes the '2'... get the idea? print $string, $/; # print the string, and a new-line. $string =~ s/a //; # replaces an appearance of 'a ' with '' print $string, $/; # print the string, and a new-line. # should read: "This is test string. 1" $string =~ tr/.//d; # remove all periods. print $string, $/; $string =~ s/.$//; # removes the last char. slower then chop. $string =~ s/..$//; # removes the last two characters. my $n = 6; $string =~ s/.{$n}$//; # removes the last $n characters. print $string, $/;

Log In?
Username:
Password:

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

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

    No recent polls found