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, $/;
| [reply] [d/l] |
| [reply] |
Also checkout substr. Setting the second argument to a negative number (-1) and the fourth (optional) argument to '' can achieve the same thing, or you can use it like an lvalue and assign a value to it.
my $foo="foo";
my $bar=substr($foo, -1, 1, '');
print "Foo: $foo\tBar: $bar\n";
# or
substr($foo,-1)='';
print "Foo: $foo\n";
Results:
Foo: fo Bar: o
Foo: f
| [reply] [d/l] |
You could do something like
s/.$//g;
This means:
substitute(s/)
any one character(.)
counting from the end ($)
with nothing (//)
and at all possible matches(g).
| [reply] [d/l] |
Is the g needed in this case? Wouldn't this only match
the end of line once?
| [reply] |
| [reply] |
#Split a string into characters
$_ = "Ashok kumar";
@chars = split(//,$_);
@chars = reverse @chars;#@chars will have "ramuk kohsA"
| [reply] |
#Split a string into characters
$_ = "Ashok kumar";
@chars = split(//,$_);
@chars = reverse @chars;#@chars will have "ramuk kohsA"
| [reply] [d/l] |