Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Balance Change

by MCS (Monk)
on Feb 08, 2006 at 18:02 UTC ( #528880=note: print w/ replies, xml ) Need Help??


in reply to Re: Balance Change
in thread Balance Change

Ok, I understand all of this except for the 'x while.' I understand that x is a repetition operator but I've always seen it written like: '"a" x 80.' However here, there is nothing on the left hand side. Could you explain what it does? I'm guessing it repeats the substitution so that it can find the nested cases but I'd be interested in knowing how it works.


Comment on Re^2: Balance Change
Re^3: Balance Change
by Roy Johnson (Monsignor) on Feb 08, 2006 at 18:34 UTC
    It's not the (lower-case) x operator, it's an (upper-case) unquoted string. Its purpose is to do nothing, but allow there to be a while loop. All the action of the while loop takes place inside its condition.

    Caution: Contents may have been coded under pressure.
Re^3: Balance Change
by Mago (Parson) on Feb 08, 2006 at 18:38 UTC
    Condition for while, another form would be:

    '1 while' or 'A while' or ...

    ;)

    Mago
    mago@rio.pm.org


Re^3: Balance Change
by MCS (Monk) on Feb 08, 2006 at 19:30 UTC

    Thanks for the help everyone, I've also found you can write it like this as well:

    while ( <code goes here> ) {}

    The important but being that there's nothing in the {}. This gives us the original one-liner broken up to this:

    #!/usr/bin/perl my $string = 'abc abc abc \textit{abc abc} abc \textit{abc abc \textbf +{abc \textbf{abc abc} abc} abc} abc.'; while ($string =~ s/\\text(i|b)[tf]\{([^{}]*)\}/<$1>$2<\/$1>/g) {} print $string;

    Or you could take out the {} and add a 0, X, or whatever in front of the while (...)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://528880]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2014-08-29 01:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls