On 4/20/05, Keith Worthington wrote:
> Hi All,
> 
> Here is my code so far.  I am really getting frustrated with my inability to
> get this right.
> 
> I didn't understand Chris' earlier suggestion about using defined but I tried
> using it anyway.
> 
> I cannot seem to get the pattern match to properly handle a dimension that is
> just feet or just inches.
> 
> I would really appreciate some pointers on this problem.
> 

Hi Keith,
I assumed from your question that your main problem now is in handling
the size part ( what you called $v_size_str) and splitting it up into
4 parts - a first dimension feet and inches and a second dimension
feet and inches.
So here is some code to help you out. It doesn't break any of the
parts into sub-parts (e.g. 28-3/8 into the 3 numbers) but I assume you
can do that yourself. It also assumes you already have a variable
holding just the size part. For convenience (mine :-)), the code reads
from __DATA__ and assigns to $_ instead of $v_size_str, but you
shouldn't have any trouble modifing it. Here's the code:
############# begin code
use strict;
use warnings;
while (<DATA>) {
   chomp;
   my ($dim1,$dim2) = split /\s*x\s*/i;
   print "==$dim1== ==$dim2==\n";
   my ($dim1_feet, $dim1_inches) = get_sub_dims($dim1);
   my ($dim2_feet, $dim2_inches) = get_sub_dims($dim2);
   print "The sub-dims are: $dim1_feet, $dim1_inches, $dim2_feet,
$dim2_inches\n";
}
sub get_sub_dims {
   my $dim = shift;
   my ($feet, $inches) = (0,0);
   if ($dim =~ m/^\s*(.+?)'/) {
      $feet = $1;
      $dim =~ s/^\s*(.+?)'\s*//;
   }
   if ($dim =~ m/^\s*(.+?)"/) {
      $inches = $1;
   }
   return ($feet, $inches);
}

__DATA__
9' x 25'
7'6" x 12'7"
7'10" x 16'
83' X 40"
17' x 50'
5' X 90'6"
39" X 100"
30" x 12'
28-3/8" x 14'4"
16'  6-3/4" x 43"
21'3 1/2" x 24'
14'8.5" x 16'7"
############# end code

If anything in the code isn't clear, please don't hesitate to ask.
HTH,
-- 
Offer Kaye

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to