Being completely new to the CGI field, my school had hired me (for free) to write a block rotation script for out school webpage, for the coming semester. I've written some code to make this work. My problem lies in having my code print out from the server it is on.
With command prompt, I can easily and effectively run my program, and it shows up as if nothin was wrong with it.
The problem arises when I try to get it to print out on my webpage.
I have a hash called
%blocks and i call upon it by printing out
$block{$day} $day being the day of the year it is (between 0..364).
Same goes for my array
@event. Is the reason these variable are not producing anything the fact that they:
- They are defined in the subroutine?
- or is there something special with Hashes and Arrays in CGI?
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
my (%blocks, $date, $timeholder, $block, @timeholder, @event);
get_block();
print header(), start_html("Block Order Script"), h1("The Next Block O
+rder is: ");
my @timer = localtime(time);
my $day = $timer[7];
my $hour=$timer[2];
my $minute= $timer[1];
my $dotw =$timer[6];
if (($hour >= "14") && ($minute > "11") && ($dotw != "1") && ($dotw !=
+ "7"))
{
$day++;
}elsif ($dotw == "1"){
$day++;
} elsif (($hour >= "14") && ($minute >"11") && ($dotw == "6")){
$day+=3;
} elsif($dotw == "7") {
$day+=2;
}
print p($blocks{$day});
print p($event[$day]);
print end_html;
sub get_block {
open (BLOCK, "/home/signguy/public_html/DB_Files/block.db") or die "$!
+";
my $r = 0;
while ($date = <BLOCK>) {
chomp ($date);
$block = <BLOCK>;
chomp ($block);
$event[$r] = <BLOCK>;
chomp ($event[$r]);
$blocks{$date} = ($block);
$r++;
}
close (BLOCK); }
----------------------------
Wiz, The VooDoo Doll
Head Master of 12:30 Productions
----------------------------
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.