Solved

1 while()

Posted on 1998-07-12
8
233 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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