Solved

1 while()

Posted on 1998-07-12
8
245 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

749 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