Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 30th, 2000, 09:33 PM
tucats tucats is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Posts: 18 tucats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
my question is how do i pass variable information to this script using a query...

the script:


#!/usr/local/bin/perl



$data_dir = "/home/kidz4day/kidz4dayz-www/cgi-bin/counter/";

$show_date = "1";

$show_link = "0";

$auto_create = "1";

$lock_sec = "3";

$pad_size = "1";


print "Content-type: text/htmlnn";

$count_page = "$ENV{'DOCUMENT_URI'}";


if ($count_page =~ //$/) {
chop($count_page);
}

$count_page =~ s/[^w]/_/g;
$lock_file = "$count_page.lock";

&check_lock($lock_sec);

if (-e "$data_dir$count_page") {
open(COUNT,"$data_dir$count_page");
$line = <COUNT>;
chop($line) if $line =~ /n$/;
close(COUNT);
($date,$count) = split(/||/,$line);
}
elsif ($auto_create == 1) {
&create;
}
else {
&error('page_not_found');
}

$count++;
$print_count = $count;

$count_length = length($count);

for ($i = $pad_size;$i > $count_length;$i--) {
$print_count = "0$print_count";
}


if ($show_date == 1) {
if ($show_link =~ /http:///) {
print "<a href="$show_link">$print_count</a> visitors since $date";
}
else {
print "$print_count visitors since $date";
}
}
else {
if ($show_link =~ /http:///) {
print "<a href="$show_link">$print_count</a>";
}
else {
print "$print_count";
}
}

open(COUNT,">$data_dir$count_page") | | &error('could_not_increment');
print COUNT "$date||$count";
close(COUNT);

&clean_up;


sub create {
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
@months = ("January","February","March","April","May","June","July",
"August","September","October","November","December");
$year += 1900;
$date = "$months[$mon] $mday, $year";
$count = "0";
open(COUNT,">$data_dir$count_page") | | &error('count_not_created');
print COUNT "$date||$count";
close(COUNT);
}

sub error {
$error = shift(@_);

if ($error eq 'page_not_found') {
print "[TextCounter Fatal Error: This Page Not Found; Auto-Create Option Disabled]";
}
elsif ($error eq 'bad_uri') {
print "[TextCounter Fatal Error: This Page Not In Valid URI]";
}
elsif ($error eq 'count_not_created') {
print "[TextCounter Fatal Error: Could Not Write to File $datadir$count_page]";
}
elsif ($error eq 'could_not_increment') {
print "[TextCounter Fatal Error: Could Not Increment Counter]";
}
exit;
}

sub check_lock {
$time = $_[0];

for ($i = 1;$i <= $time; $i++) {
if (-e "$data_dir$lock_file") {
sleep 1;
}
else {
open(LOCK,">$data_dir$lock_file");
print LOCK "0";
close(LOCK);
last;
}
}
}

sub clean_up {
unlink("$data_dir$lock_file");
}

##### ok, now i need to be able to send values for the variables...:

$show_date = "1";

$show_link = "0";

$auto_create = "1";

$lock_sec = "3";

$pad_size = "1";

from a query... i was shown this subrouting...:

sub parseInput()
{

if ($ENV{'REQUEST_METHOD'} eq "POST")
{
read(STDIN, $temp, $ENV{'CONTENT_LENGTH'});
}

elsif ($ENV{'REQUEST_METHOD'} eq "GET" )
{
$temp = $ENV{'QUERY_STRING'};
}

@pairs=split(/&/,$temp);

foreach $item(@pairs)
{
($key,$content)=split (/=/,$item,2);
$content=~tr/+/ /;
$content=~ s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}

}


and calling the script by:

&parseInput;

he said to put this before i tried to get at any of the variables...

I have tried all kinds of things... can you show me how to pass variable values through a query...

example...:

<!--#exec cgi="/cgi-bin/counter.cgi?show_date=1&pad_size=5"-->

thank you so much for your time...

Reply With Quote
  #2  
Old January 31st, 2000, 06:50 PM
tucats tucats is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Posts: 18 tucats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
don't answer...

i already figured it out...

Reply With Quote
  #3  
Old March 21st, 2000, 05:34 AM
mmccue mmccue is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2000
Posts: 43 mmccue User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via ICQ to mmccue
I'm telling ya... happens every time.. You post a question thats been like a bug up your butt for the last week, and 5 minutes (or in your case 21 hours) you've got it figured out.

Totally autonomous help system!!!!

Mike

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > parseinput()


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT