Solved

1 while()

Posted on 1998-07-12
8
253 Views
Last Modified: 2010-03-05
I found this '1 while()' construct in a Perl book.  I understand the regx part but could someone
elaborate on the 'repeat' part.  Thanks.
 1 while ($loValc =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/);
0
Comment
Question by:hank1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 1

Author Comment

by:hank1
ID: 1208386
Edited text of question
0
 
LVL 84

Expert Comment

by:ozo
ID: 1208387
perldoc perlsyn
                 Any  simple  statement  may  optionally  be  followed by a
                 SINGLE modifier, just before the terminating semicolon (or
                 block ending).  The possible modifiers are:

                     if EXPR
                     unless EXPR
                     while EXPR
                     until EXPR
so
1 while ($loValc =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/);
means the same as
while( $loValc =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/ ){ 1 }
But are you sure you don't want
1 while s/^(-?\d+)(\d{3})/$1,$2/;



0
 
LVL 1

Author Comment

by:hank1
ID: 1208388
Thanks.
Don't they both insert comma's?  The difference seems to be; yours is anchored
and so must accomodate the '-'.  I, the book, used a lookahead.  Which is
a better way to do this if it's a line of text.
Collect your points!
Thanks again.  Always happy to see an OZO.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:ozo
ID: 1208389
Well, if you have $loValc = 1234.6789, you might insert some commas you didn't intend,
but it depends what your needs are.
perlfaq5 also mentions:
    # from Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
    sub commify {
       my $input = shift;
        $input = reverse $input;
        $input =~ s<(\d\d\d)(?=\d)(?!\d*\.)><$1,>g;
        return reverse $input;
    }

0
 
LVL 1

Author Comment

by:hank1
ID: 1208390
Come get your points.
Thanks.
0
 
LVL 1

Author Comment

by:hank1
ID: 1208391
By-the-way.  Do you access the documentation supplied with the activeWare
port?  I don't see and toc or tree or (whatever) html that links it all together.
Something better out there?
0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 1208392
Didn't they port the
perldoc
utility with the rest of Perl?
If your perl port was incomplete, you can go to
http://language.perl.com/info/documentation.html

(I'll answer if you wish, but your last Last 10 Grades Given seem a little low,
I don't mean to be greedy, but I'd prefer that you reject my answer rather than lower my grade average...)
0
 
LVL 1

Author Comment

by:hank1
ID: 1208393
I had no idea that grades had any importance.  Here, have an A.  You did
have a good answer.  In the past I reserved As and Bs for experts that
really did more than was necessary.  I don't think
though I have the expertise to impact negativily on one's "review" and shall
henceforth award only As.  I see that an A or D has no impact onl my available points
either.  Strange system.  Painless for all involved.  Sure wish it worked that way in
real life!  So feel free to answer any of my questions!  Thanks again.


0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question