> -----Original Message----- > From: Bret Goodfellow [mailto:[EMAIL PROTECTED] > Sent: Wednesday, August 01, 2007 14:25 > To: beginners@perl.org > Subject: How do I truncate or remove a trailing character > > Okay, I know this has to be simple, but because I am trying > to truncate > or remove a special character I've run into a roadblock. > Here's what I > want to do. > > $value = "12345)" ; > > How do I change $value so that the trailing ")" is removed. In > otherwords with the given example, how do I manipulate $value so that > its value is "12345"? Please keep in mind that $value may be variable > in length, so I can't use substr($value, 0, 5). Can split be > used to do > this? Stumped. > Will there always be non decimal number or it could be easier to pull all the numbers: if ( $value =~ /^(\d+)/ ) { $value = $1 } else { printf "Expecting a numeric field, but got<%s>\n", $value; # now either back to the top of a loop or whatever
} or if always want last character removed: chop($value); # removes last character Or $value = substr($value,0,length($value)-1); You have to decide what edits or the data looks like, but something to think about. Wags ;) ********************************************************************** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. ********************************************************************** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/