Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

print a backspace in nph-"HTML"?

by rsiedl (Friar)
on Dec 04, 2004 at 10:04 UTC ( [id://412377]=perlquestion: print w/replies, xml ) Need Help??

rsiedl has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I've got the following little test, but i cant seem to get it to print a backspace in the textarea field.
Does anyone know if this is possible?

#!/usr/bin/perl $| = 1; use strict; use warnings; print "Content-type: text/html\n\n"; print "Starting Test<br>\n"; print "<textarea rows=1 style=\"border:1px #FFFFFF solid; overflow:hid +den;\">"; my $count = 0; for (my $i = 1; $i <= 16; $i++) { print "."; $count++; print "\b\b\b\b" if ($count == 4); $count = 0 if ($count == 4); sleep(1); } # end-for print "</textarea><br>"; print "Completed Test!\n"; exit(0);
Also, on a side note, could someone tell me how to combine these two lines into one :) ;
print "\b\b\b\b" if ($count == 4); $count = 0 if ($count == 4);
I guess i could do:
if ($count == 4) { $count = 0; print "\b\b\b\b"; }
but it seems somewhat inelegant.

Cheers,
Reagen

Replies are listed 'Best First'.
Re: print a backspace in nph-"HTML"?
by BUU (Prior) on Dec 04, 2004 at 11:36 UTC
    Uh, no, you can't print a "backspace" to an html text area. The best you could do is some form of javascript, which I won't get in to here.

    As for your second question, the if BLOCK form is the canoical and the best way to write that, but if it really offends your eyes you could try something like:  print "foo" and $count = 0 if ( cond ) or something similar. Of course, that won't set $count to 0 if the print fails, which might be a feature.
Re: print a backspace in nph-"HTML"?
by VSarkiss (Monsignor) on Dec 04, 2004 at 15:14 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.")

Re: print a backspace in nph-"HTML"?
by Zed_Lopez (Chaplain) on Dec 04, 2004 at 20:31 UTC

    Now that brother VSarkiss called my attention to the intent of the code, it could be simplified like this:

    for (0..3) { print "....\b\b\b\b"; sleep 1; }

    or, for the uberterse version:

    print "....\b\b\b\b" and sleep 1 for (0..3);

    with brother BUU's caveat that if the print doesn't succeed, the sleep statement won't execute.

    Updated: er, actually, that's wrong. There needs to be a sleep after each period.

    for (0..3) { print "." and sleep 1 for (0..3); print "\b\b\b\b" and sleep 1; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://412377]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-23 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found