Re: Question about scoping
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Tue, 27 Feb 2007 21:18:02 GMT
Bob Dubery wrote:
sub validateFile
{
# get the value passed to this subroutine
my $dataString = shift;
# remove the newline character and all other formatting characters
chomp $dataString;
$dataString =~ s/\t//g;
$dataString =~ s/\n//g;
$dataString =~ s/\r//g;
$dataString =~ s/\f//g;
OMG! Replace the previous five lines with:
$dataString =~ tr/\t\n\r\f//d;
# check for and remove the starting charater for the data transferYou don't need to run the same regular expression twice, nor do you really
if ($dataString =~ /^/) # character (0x02)
{
$dataString =~ s/^//; # character (0x02)
# check for and remove the ending charater for the data transfer
if ($dataString =~ /$/) # character (0x03)
{
$dataString =~ s/$//; # character (0x03)
need the comment:
# check for and remove the starting charater for the data transfer
if ($dataString =~ s/^\x02//)
{
# check for and remove the ending charater for the data transfer
if ($dataString =~ s/\x03$//)
{
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.
- References:
- Question about scoping
- From: Bob Dubery
- Question about scoping
- Prev by Date: Re: Choosing the path based on the system "uname" command
- Next by Date: Re: Choosing the path based on the system "uname" command
- Previous by thread: Question about scoping
- Next by thread: Re: Extracting Message body from email using POP3Client
- Index(es):