Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic screen display with CGI script 4

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hello peeps,

Is there a way of making a perl script display info to the screen as it is running. It seems the code below only displays the output once the script finishes, I want it to display info as it loops the record set giving a running progress message to the screen.

here is what I have
Code:
# Print header to screen
print "Content-type: text/html\n\n";

# Grab AR ID's
my @rs = getSQL("AR_Dets","ARID,CName","1=1");
                    
# Loop AR's & Publish Website
for(my $x=1; $x<=$#rs; $x++){
   # Print current AR progress message
   print "Publishing [ $rs[$x]{'CName'} ] website, please wait...<br><br>";

   # Publish Website
   &Publish_Web($rs[$x]{'ARID'});
}

print "Websites Published!";

exit();

but it only shows the screen when it has finished?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
There is the nph-push, but that's been deprecated in CGI AFAIK

What's the time involved from start to finish? Is it really necessary

You could have refreshes while the process continues on it's merry way

Code:
if process isn't finished {
  print meta refresh (delay) (content)
} else {
  print finished
}

This would require some form of global semaphore the script can check before running

cigless ...
 
it takes between 10-20 seconds to publish each website and there could be 50 websites to publish.


so thats @ 15-16 minutes to wait.

how do i use nph-push , is it deprecated but still works?





"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
A friend of mine uses inline frames in I.E. on Windoze and this does work - a bit-by-bit update. This sounds like it may be perfect for what you need. But it doesn't on my Mac (Safari or I.E. as far as i remember)...


Kind Regards
Duncan
 
how would i use an iframe to do this ?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
This is a bit hackish but I seem to remember it working before. You can turn on autoflushing on your output by setting the $| variable, which will cause each line to be sent to the browser immediately as it's printed, rather than storing all the output in a buffer and sending it once it's finished.

This example works fine in Firefox - I don't have a copy of IE handy to test:
Code:
#!/usr/bin/perl -w
use strict;
use CGI qw( :standard );

local $| = 1;

print header;

print start_html;
for ( 0 .. 5 ) {
   print div( 'Finished '. $_ );
   sleep 1;
}

print end_html;

I have a vague recollection that IE will print output as soon as it receives the end of the block-level element containing it but will wait otherwise. That's why I'm printing everything in a <div> tag.

It's worth a try - mileage may vary.
 
Damn - sorry, i forgot about this post!

As ish states - this is exactly the method we used (but with inner html rather than div's) - but it all boils down to the same thing

I.E. certainly does seem to spurt out more and more output - as and when it can... but only I.E.!


Kind Regards
Duncan
 
ishnid , you are a genius!

as well as a SOB, now can you tell me what these errors are moaning about please :p

[Wed Aug 17 17:21:45 2005] AR_WEB_PUB.cgi: Use of uninitialized value in string ne at d:/inetpub/vhosts/homeloanpartnership.co.uk/cgi-bin/members/ARWebglobs.pm line 173. [Wed Aug 17 17:21:49 2005] AR_WEB_PUB.cgi: Use of uninitialized value in string ne at d:/inetpub/vhosts/homeloanpartnership.co.uk/cgi-bin/members/ARWebglobs.pm line 173. [Wed Aug 17 17:22:02 2005] AR_WEB_PUB.cgi: Use of uninitialized value in string ne at d:/inetpub/vhosts/homeloanpartnership.co.uk/cgi-bin/members/ARWebglobs.pm line 173. [Wed Aug 17 17:22:02 2005] AR_WEB_PUB.cgi: Use of uninitialized value in concatenation (.) or string at d:/inetpub/vhosts/homeloanpartnership.co.uk/cgi-bin/members/ARWebglobs.pm line 279. [Wed Aug 17 17:22:02 2005] AR_WEB_PUB.cgi: Use of uninitialized value in concatenation (.) or string at d:/inetpub/vhosts/homeloanpartnership.co.uk/cgi-bin/members/ARWebglobs.pm line 279. [Wed Aug 17 17:22:02 2005] AR_WEB_PUB.cgi: Use of uninitialized value in concatenation (.) or string at d:/inetpub/vhosts/homeloanpartnership.co.uk/cgi-bin/members/ARWebglobs.pm line 279. [Wed Aug 17 17:22:05 2005] AR_WEB_PUB.cgi: Use of uninitialized value in string ne at d:/inetpub/vhosts/homeloanpartnership.co.uk/cgi-bin/members/ARWebglobs.pm line 173. [Wed Aug 17 17:22:12 2005] AR_WEB_PUB.cgi: Use of uninitialized value in string ne at d:/inetpub/vhosts/homeloanpartnership.co.uk/cgi-bin/members/ARWebglobs.pm line 173. [Wed Aug 17 17:22:16 2005] AR_WEB_PUB.cgi: Use of uninitialized value in string ne at d:/inetpub/vhosts/homeloanpartnership.co.uk/cgi-bin/members/ARWebglobs.pm line 173. [Wed Aug 17 17:22:19 2005] AR_WEB_PUB.cgi: Use of uninitialized value in string ne at d:/inetpub/vhosts/homeloanpartnership.co.uk/cgi-bin/members/ARWebglobs.pm line 173.

whats wrong with this code (line 173) is the if statement

Code:
# If Logo else use text
if($dets[1]{'Logo'} ne ""){$html .= "
		<img src=\"" . AR_URL_TO_WEB . "/$_[0]/$dets[1]{'Logo'}\"></td>";
}

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
That warning will trigger if $dets[1]{Logo} is undefined. You're currently checking if it's defined and set to an empty string. Perl will convert undef to an empty string and then perform the comparison, triggering that warning in the first place. If your intention is just to check if it has a value, you can just do:
Code:
if ( defined $dets[1]{Logo} ) {
   # whatever
}
 
what's the point in PERL converting to "" (which i thought it did for NULL) and then warning me, I though it was PERLs functionality, i'd rather the program not work like other systems with (Invalid use of null), why work fine and do exactly what I want but give me a warning about.

That's doesn't make any sense to me.

which leaves me another problem, what about those for line 279...
Code:
$html .= "      
<!--- Right Hand Heading Text Image--->

$html is not empty so why is the concatenation (.) an error, i can understand the cause of the other error but not this one.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I'ts ok I worked it out it was not the $html with the problem but another variable that was null/empty.

I still don't understand the point in this warnings module, sounds like a women to me, does what you want, but constantly bitches about it!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Nice analogy!

The problem is that perl doesn't know exactly what you want. In this case, you want the default behaviour to happen, which is fine (that's why it's only a warning and not an error). However, consider somebody who has made an error in filling their data structure and tries this:
Code:
if ( $variable[0]{something} eq 'my_name' ) {
   # do something
}
Perl still converts undef to an empty string for the string comparison. However, that if() statement is never going to be true, because $variable wasn't filled correctly. Without a warning, that's going to be very hard to debug.
 
do you mean because the single quotes around 'something' are missing, or because the 'hash key' does not exist because it might be entered correctly syntax wise but the hash key was spelt wrong and there would never be a hash key of the name used.

I would assume this is picked up by not getting the desired result, either in display or data saved to DB for example.

This is normally how I find these errors, because it was only the command you shared on this post for printing direct to the browser which showed up these errors.

Although I use warnings because you guys taught me it was good practice, I never normally get to see the warnings as I only ever test via a browser as I do not host the webserver or PERL install.

at least I now know how I can force warnings to the browser and will probably have alot of code fixing to do in many scripts, why thank you ishnid, so kind of you to find more errors in my coding, why I had nothing to do until now - NOT!

lol - hey ishnid , you'll make a programmer of me yet, you really are a gentleman and a scholar, much respect too you all the guys & gals who help me.

Regards,
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Oh and the print direct to browser, works great in FireFox but not I.E.

Well I don't have enough records to loop properly to test, but when I do i'll post an update.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
IE doesn't work as well as FF for this , but if you are looping a few records and keep printing a status message, it eventually trickles through.

Thanks, Isnid.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top