Gossamer Forum
Home : General : Perl Programming :

can any one help me?

Quote Reply
can any one help me?
i have this piece of code which i want to chage a little

instead of having a cam on 'my $url' i want this to be Variable to which i make the variation when i call up the script
for e.g. http://reviews.numerique-photo.com/clipper.cgi?cam=<font color=red>221</font>
I hope you understand sorry hard to explain


#!/usr/local/bin/perl

use strict;
use CGI;
use LWP::Simple;

my $domain = $ENV{'QUERY_STRING'};
my $ssaveas = "f:/inter-markets/gallery/db/cgi-bin/pixer/top.txt";
my $url = "http://reviews.numerique-photo.com/cameraDetail.php3?cam=<font color=red>244</font>";
my $results = get ($url);
my $output = '';
my ($thisweek, $lastweek, $title, $topimg, $imgalt);
my $n = 0;
$results or &error ("No Updates Available");
$results =~ s/\r//g;
$results =~ s/\n//g;

# USE ([^<]*)
while ($results =~ m#<td width="300"><font size="-1" face="Verdana,Arial,Helvetica">([^<]*)</font></td>#sog) {
$n = $n + 1;
print "GOT OUTPUT!";

if ($n <= 24) {
($thisweek, $lastweek, $title) = ($1, $2, $3);


if ($lastweek eq "*") {
$topimg = "";
$imgalt = "";
}
else {
$topimg = "";
$imgalt = "";
}

$output .= qq~|$thisweek~;
}
}


open (ID, ">$ssaveas") or print ("error. unable to open file.
");
print ID $output; # update counter.

print ID $output; # update counter.
print ID "";
close ID;

print "Content-type: text/plain\n\n";
print "Top Games Update Complete";

exit();

Quote Reply
Re: can any one help me? In reply to
I think this is wrong.....

$output .= qq~|$thisweek~;

..should be......

$output .= qq~$thisweek~;

or....

$output .= qq|$thisweek|;

Do you mean something like:

my $url = param('cam');



Paul Wilson.
http://www.wiredon.net
Quote Reply
Re: can any one help me? In reply to
you are the man

thanks alot you just saved my life thanks mate

Quote Reply
Re: can any one help me? In reply to
ok, so it don't work any more

i think i must of not used you mod properly
please could you read what i've done
####----------------------------
#!/usr/local/bin/perl

use strict;
use CGI;
use LWP::Simple;
my $url2 = param('cam');
my $url = 'http://www.reviews.numrerique-photo.com/cameraDetail.php3?cam=$url2';
my $ssaveas = "f:/inter-markets/gallery/db/cgi-bin/pixer/top.txt";

my $results = get ($url);
my $output = '';
my ($thisweek, $lastweek, $title, $topimg, $imgalt);
my $n = 0;
$results or &error ("No Updates Available");
$results =~ s/\r//g;
$results =~ s/\n//g;

# USE ([^<]*)
while ($results =~ m#<td width="300"><font size="-1" face="Verdana,Arial,Helvetica">([^<]*)</font></td>#sog) {
$n = $n + 1;
print "GOT OUTPUT!";

if ($n <= 24) {
($thisweek, $lastweek, $title) = ($1, $2, $3);


if ($lastweek eq "*") {
$topimg = "";
$imgalt = "";
}
else {
$topimg = "";
$imgalt = "";
}

$output .= qq~|$thisweek~;
}
}


open (ID, ">$ssaveas") or print ("error. unable to open file.
");
print ID $output; # update counter.

print ID $output; # update counter.
print ID "";
close ID;

print "Content-type: text/plain\n\n";
print "Top Games Update Complete";

#####--------------------------------------------

all i get is this error

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


Undefined subroutine &main::param called at f:\inter-markets\gallery\db\cgi-bin\pixer\topgames.pl line 6.

when i call it from cams.pl?cam=262

Quote Reply
Re: can any one help me? In reply to
The code I gave was wrong.....

Could you explain more clearly what you want and I will try to help. I didn't really understand what you wanted so just guessed at something.

Paul Wilson.
http://www.wiredon.net
Quote Reply
Re: can any one help me? In reply to
sorry mate

ok it was pretty much what you said

what i have is my url=http://example.com/eg.html?cam=5

but what i want is to define cam=5 in the address bar
so if cam=3 then i don't need to cange it in the cgi file just when i call up script i can wright http://myserver.com/script.pl?cam=3

so to do this so far
i've written
my $url2 = param('cam');
my $url = 'http://www.reviews.numrerique-photo.com/cameraDetail.php3?cam=$url2';

Quote Reply
Re: can any one help me? In reply to
You will need to define what you want each url to do - like cam=1 cam=2 cam=3 etc.......

if ($url2 == "1") {
dosomething
}
elsif ($url2 == "2") {
bla
}

Paul Wilson.
http://www.wiredon.net
Quote Reply
Re: can any one help me? In reply to
i must be the worst explainer in the world
i will try again

i'm calling my scripts from http://eg.com/eg.pl?cam=31
what i want is it to grab the number 31
and put it in to
my url=http://content.com/content.html?cam=<u>here</u>

sorry mate

Quote Reply
Re: can any one help me? In reply to
Possibly:

$buffer = $ENV{'QUERY_STRING'};
@pairs = split(/&/, $buffer);

($name, $value) = split(/=/, $pair);
my $url= "http://content.com/content.html?cam=$value";




Paul Wilson.
http://www.wiredon.net
Quote Reply
Re: can any one help me? In reply to
you are using single quotes in the your var init which doesn't allow interpolation.
Code:
my $url2 = param('cam');
my $url = 'http://www.reviews.numrerique-photo.com/cameraDetail.php3?cam=$url2';
try:
Code:
my $url2 = param('cam');
my $url = qq~http://www.reviews.numrerique-photo.com/cameraDetail.php3?cam=$url2~;
stick with using the CGI.pm method rather than parsing the environmental variable, it's much more secure.
you can just do
use CGI qw(:standard);
to keep from loading the entire module in every time when you only need standard features.

-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: can any one help me? In reply to
can you please help me?
here is my full source code
and my url (all i keep getting is this error)

http://reviews.numerique-photo.com/cgi-bin/pixer/topgames.pl?cam=555

#!/usr/local/bin/perl

use strict;
use CGI;
use LWP::Simple;



my $url2 = param('cam');
my $url = qq~http://www.reviews.numrerique-photo.com/cameraDetail.php3?cam=$url2~;
my $ssaveas = "f:/inter-markets/gallery/db/cgi-bin/pixer/top.txt";

my $results = get ($url);
my $output = '';
my ($thisweek, $lastweek, $title, $topimg, $imgalt);
my $n = 0;
$results or &error ("No Updates Available");
$results =~ s/\r//g;
$results =~ s/\n//g;

# USE ([^<]*)
while ($results =~ m#<td width="300"><font size="-1" face="Verdana,Arial,Helvetica">([^<]*)</font></td>#sog) {
$n = $n + 1;
print "GOT OUTPUT!";

if ($n <= 24) {
($thisweek, $lastweek, $title) = ($1, $2, $3);


if ($lastweek eq "*") {
$topimg = "";
$imgalt = "";
}
else {
$topimg = "";
$imgalt = "";
}

$output .= qq~|$thisweek~;
}
}


open (ID, ">>$ssaveas") or print ("error. unable to open file.
");
print ID $output; # update counter.

print ID $output; # update counter.
print ID "";
close ID;

print "Content-type: text/plain\n\n";
print "Top Games Update Complete";

exit();

Quote Reply
Re: can any one help me? In reply to
Since you are using CGI.pm, you can use the following param codes:

Code:

my $url2 = $in->param('cam');


Regards,

Eliot Lee
Quote Reply
Re: can any one help me? In reply to
you wouldn't use $in unless you created a blessed CGI object with $in. the error that that url gives is being caused by invalid http headers.
add the line
print "Content-Type: text/html\n\n";
above any previous print statements in your script to specify the content type.

-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: can any one help me? In reply to
any one else got any ideas? i've tried everything on this forum and nothing seems to work
what i want it the enviorment strigs pulled from the address bar and and put in to my url
like this
my $url2 = [code for pulling down];
my $url = qq~http://exmaple.com/eg.pl?cam=$url2~;

Quote Reply
just to say Thanks In reply to
i am writing just to say thank you to everyone who helped me on this script

i finally got it working

yep that's right it works i restarted the script and
used some ofthe ideas on this board

so thanks to everyone

Dave