Re: Question about scoping



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 transfer
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)
You don't need to run the same regular expression twice, nor do you really
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
.