Solved

1 while()

Posted on 1998-07-12
8
212 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
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 remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now