anthony wrote:
Hi,
I have a question, what i do is if i have $string = "a,b,c,d,e,f,g,"
I just do chop $string;
there is no while loop with this Would this be as good??
Careful, chop removes the last character no matter what. It is advisable to use chomp in this scenario. chomp removes any trailing string that is the same as $/ (perldoc perlvar). The chomp version for this can be written as
sub remove_last_comma { local $/ = ','; chomp ($_[0]); }
my $string = "a,b,c,d,e,f,g,"; remove_last_comma ($string); print "string is $string\n";
$string = "a,b"; remove_last_comma ($string); print "string is $string\n";
This will print a,b,c,d,e,f,g a,b
If it were chop, the output would be a,b,c,d,e,f,g a,
Anthony
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]