Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

More help with split
Hi All,

I continue to work on my first perl program. :-)  I am stuck again and could
use your guidance.

Here is the code snippet that I am working on right now.  The problem that I
have is that when processing a size like 30" x 150'6" it sees the first
dimension as a number of feet.  How can I get perl to recognize that somethi
ng
like this is implicitly 0' 30"?

#     Parse up the size string.
if ($v_size_str =~ /[0-9]*['"][    ]*x[    ]*[0-9]*['"]/i){
#        It looks like a size string so continue to process.
#        Split the size string into its two parts.
($v_dim1, $v_dim2) = split(/[   ]*x[    ]*/i, $v_size_str);
#        Now split dimension one into feet and inch parts.
my ($v_feet_str, $v_inch_str) = split(/(?:'|")/, $v_dim1);
print "Feet:    $v_feet_str\n";
print "Inches:  $v_inch_str\n";
#        Check for fraction in inch string.
if ($v_inch_str =~ /\//){
#           There is a fraction to deal with.
#           Parse the fraction using whitespace or a hyphen (-)
#           and the forward slash (/) character.
my ($v_whole_in, $v_numer, $v_denom) = split(/(?: |-|\/)/,
$v_inch_str);
print "Whole inches:    $v_whole_in\n";
print "Numerator:  $v_numer\n";
print "Denominator:  $v_denom\n";
}

Kind Regards,
Keith

Report this thread to moderator Post Follow-up to this message
Old Post
Keith Worthington
04-20-05 08:56 PM


Re: More help with split
On 4/20/05, Keith Worthington <keithw@narrowpathinc.com> wrote:
> Hi All,
>=20
> I continue to work on my first perl program. :-)  I am stuck again and co=
uld
> use your guidance.
>=20
> Here is the code snippet that I am working on right now.  The problem tha=
t I
> have is that when processing a size like 30" x 150'6" it sees the first
> dimension as a number of feet.  How can I get perl to recognize that some=
thing
> like this is implicitly 0' 30"?
>=20
> #     Parse up the size string.
>       if ($v_size_str =3D~ /[0-9]*['"][    ]*x[    ]*[0-9]*['"]/i){
> #        It looks like a size string so continue to process.
> #        Split the size string into its two parts.
>          ($v_dim1, $v_dim2) =3D split(/[   ]*x[    ]*/i, $v_size_str);
> #        Now split dimension one into feet and inch parts.
>          my ($v_feet_str, $v_inch_str) =3D split(/(?:'|")/, $v_dim1);
>          print "Feet:    $v_feet_str\n";
>          print "Inches:  $v_inch_str\n";
> #        Check for fraction in inch string.
>          if ($v_inch_str =3D~ /\//){
> #           There is a fraction to deal with.
> #           Parse the fraction using whitespace or a hyphen (-)
> #           and the forward slash (/) character.
>             my ($v_whole_in, $v_numer, $v_denom) =3D split(/(?: |-|\/)/,
> $v_inch_str);
>             print "Whole inches:    $v_whole_in\n";
>             print "Numerator:  $v_numer\n";
>             print "Denominator:  $v_denom\n";
>          }
>=20
> Kind Regards,
> Keith
>=20

Keith,

In this case, you need to keep the seperator.  split will do this if
you use parentheses.  It also returns and extra "undef" delimiter in
this case, so you want to watch out for that.  take a look at the
conditional operator in perldoc perlop to fins out what all is going
on here.

my @split =3D split(/(')|("))/, $v_dim1);
my ($v_feet_str, $v_inch_str) =3D $split[1] eq "'" ? ($split[0],
$split[3]) : (0, $split[0]);

HTH,

--jay

Report this thread to moderator Post Follow-up to this message
Old Post
Jay Savage
04-20-05 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:13 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.