more useful options PerlMonks

### Re: print a backspace in nph-"HTML"?

by VSarkiss (Monsignor)
 on Dec 04, 2004 at 15:14 UTC Need Help??

in reply to print a backspace in nph-"HTML"?

I don't know enough about textareas to answer your main question, but the canonical way to do the \$count thing is with modulo arithmetic:

```print "\b\b\b\b" if ++\$count % 4 == 0;
Or you may want to use == 1 or == 3, depending on what effect you want to achieve. You can read about %, the modulus operator, in perlop.

Replies are listed 'Best First'.
Re^2: print a backspace in nph-"HTML"?
by Zed_Lopez (Chaplain) on Dec 04, 2004 at 16:50 UTC

But that doesn't make count 0 if count was 4 as the OP's code had it.

```print "\b\b\b\b" unless \$count %= 4

is closer but also executes the print statement for \$count = 0, 8, 12, etc., and assigns 0 to \$count for 8, 12, etc.

This works:

```\$count = 0, print "\b\b\b\b" if \$count == 4;

but I'd use a block here.

It doesn't matter whether \$count is zero -- that's the point I was making. The only use the OP's code is making of \$count is whether or not to print the four backspaces. Basically, he wants \$count to go:
0, 1, 2, 3, (emit "\b\b\b\b"), 0, 1, 2, 3 , emit, 0, ...
And you've fallen into the same trap of caring what the values are.

All you care about is the sequence:
loop, loop, loop, loop (emit "\b\b\b\b"), loop, loop, ...
Which is exactly what modulo arithmetic gains you.

You can adjust whether you want the backspaces emitted after the first, second, third, or fourth iteration by changing what value you want to look for (which is what I was trying to get at when I wrote "you should look for == 1 or == 3 depending on what effect you want to achieve.")

You're right; I was only looking at the if clause in isolation, not in context.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://412412]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-08-07 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?
 • erzuuli ‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.