Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Search for abcNUMBERdef, make it a variable, then do math?

by Jesse Smith (Novice)
on Jan 22, 2011 at 19:35 UTC ( #883708=note: print w/ replies, xml ) Need Help??


in reply to Re: Search for abcNUMBERdef, make it a variable, then do math?
in thread Search for abcNUMBERdef, make it a variable, then do math?

#!/usr/bin/perl use warnings; use strict; if (length ($ENV{'QUERY_STRING'}) > 0){ my($buffer) = $ENV{'QUERY_STRING'}; my(@pairs) = split(/&/, $buffer); foreach my($pair) (@pairs){ ($name, $value) = split(/=/, $pair); my($value) =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1) +)/eg; $in{$name} = $value; } } my($id) = param('id'); use LWP::Simple; $id2 = get ("http://www.domain.info/stats.php?id=$id"); $id2 =~ s*\[Yesterday\] *Yesterday: *g; while(<DATA>) { if(/([\w\s]+:)\s([a-z]+)(\d+)\2/) { print "$1 ", sprintf("%5.2f\n",$3*0.4/100); } } spits out Missing $ on loop variable at stats.cgi line 9. on SSH.


Comment on Re^2: Search for abcNUMBERdef, make it a variable, then do math?
Download Code
Re^3: Search for abcNUMBERdef, make it a variable, then do math?
by Anonymous Monk on Jan 22, 2011 at 19:38 UTC
    Its because you keep including that ENV{'QUERY_STRING'} garbage, get rid of it
Re^3: Search for abcNUMBERdef, make it a variable, then do math?
by Corion (Pope) on Jan 22, 2011 at 19:49 UTC

    I would assume that Perl is right when it points you to line 9.

    ... foreach my($pair) (@pairs){ ...

    This is not valid Perl code. The valid Perl code would be (note the lack of parentheses)

    foreach my $pair (@pairs){

    But in all seriousness, why are you trying to do what is CGI.pm's job? Just use CGI; and then query $q->Vars to get a hash of parameters passed to your script. Don't parse query strings yourself.

      #!/usr/bin/perl use warnings; use strict; use LWP::Simple qw(!head); use CGI qw(:standard); # then only CGI.pm defines a head() my($id) = param('id'); my($id2) = get ("http://www.domain.com/stats.php?id=$id"); $id2 =~ s*\[Yesterday\] *Yesterday: *g; **LOTS more search and replaces go right here** while(<DATA>) { if(/([\w\s]+:)\s([a-z]+)(\d+)\2/) { print "$1 ", sprintf("%5.2f\n",$3*0.4/100); } } Name "main::DATA" used only once: possible typo at stats.cgi line 15. Use of uninitialized value in concatenation (.) or string at stats.cgi + line 11. (Line geting the URL) readline() on unopened filehandle DATA at stats.cgi line 15.

        What are you trying to tell me with this reply?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://883708]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-10-24 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (132 votes), past polls