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
Solved

1 while()

Posted on 1998-07-12
8
240 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.…
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…

856 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