Hi Joe,
just hab the same Problems with your Script as with cgi::param,...
Ok, I just played around a little bit, checked some books and came to this solution:
our %values;
sub parse_form {
my ($ENV,$daten,@fields,$name,$value);
if ($ENV{'REQUEST_METHOD'} eq 'GET')
{$daten = $ENV{'QUERY_STRING'}
}
else
{read(STDIN,$daten,$ENV{'CONTENT_LENGTH'});
}
@fields = split (/&/,$daten);
foreach (@fields){
($name, $value) = split(/=/, $_);
$values {$name} = $value;
}
} # End sub parse_form
Only thing I want to change now is the access to the Values. Seems to be nice like you
do it, but I still couldn�t follow...
So I have to recall it like print $values{seriennummer};
Working on it... :-)
Greets Johannes
> -----Urspr�ngliche Nachricht-----
> Von: David vd Geer Inhuur tbv IPlib [SMTP:[EMAIL PROTECTED]]
> Gesendet am: Dienstag, 25. Juni 2002 17:47
> An: [EMAIL PROTECTED]
> Betreff: param problem
>
>
> Johan,
>
> Somethings are going wrong here.
> Indeed the "our" should make the var global.
>
> Looking at your header it's obvious you use : name=value&name2=value2
>
> When you print $header, you will see that the first "?" is not shown.
> What I did in my script was building my header like this :
>
> name1=value1?name2=value2? .......
>
> So what you have got to do right now is :
>
> @pairs = split(/\&/, $head); # split vars using & as delimitor
>
> You see, change the question mark into a ampensant(&). Now you will get you scalars
> just like you used to.
>
> our ${$name} = $value;
>
> Does nothing else then :
>
> our $serien = "10/rd30";
>
> It's just that it does it automated, so you can use : print "Serienumber: $serien";
> To print it. give it a try within the sub-routine and outside. Just to make sure the
> our works.
>
>
> Regs David
> >
> > Our?! Never heard this bevore,... as you probably can think now i�am new to
>perl,.. :-)
> >
> > So I guess our is the opposite to my? My is available only in the routine it is
>defined in (and the called subroutines) and our is also available for the main script
>or any other colling part even if it is defined in a subroutine?
> >
> > Still it�s not clear to me how to access my values,... :-)
> >
> > If i pass the parameters ?parameter1=value1¶meter2=value2, i have to access
>the parametervalues like $$parameter1 and $$parameter2 alright?
> >
> > Johannes
> >
> > > -----Urspr�ngliche Nachricht-----
> > > Von: David vd Geer Inhuur tbv IPlib [SMTP:[EMAIL PROTECTED]]
> > > Gesendet am: Dienstag, 25. Juni 2002 17:26
> > > An: [EMAIL PROTECTED]
> > > Betreff: Re: AW: AW: AW: AW: param problem
> > >
> > >
> > > Make Sure you do the "our ${$name} = $value;"
> > >
> > > this will make the $name available throught the script.
> > > The rest I would pre-define in the sub-routine :
> > >
> > > sub parse_form {
> > >
> > > my ($buffer, $value, $name, .. ... .);
> > > ...
> > > ..
> > > our ${$name} = $value;
> > >
> > > }
> > >
> > > Good Luck.
> > >
> > > Regs David
> > > ---------------------
> > > > Ok, got some problems using strict but thats OK.one last Thing for today:
>where do i have to call the sub
> > > > and how do I access the parameters later in the script?
> > > >
> > > > greetings Johannes usually one named me Joe to,...
> > > > > -----Urspr> �ngliche Nachricht-----
> > > > > Von: David vd Geer Inhuur tbv IPlib [SMTP:[EMAIL PROTECTED]]
> > > > > Gesendet am: Dienstag, 25. Juni 2002 17:03
> > > > > An: [EMAIL PROTECTED]
> > > > > Betreff: Re: AW: AW: AW: param problem
> > > > >
> > > > >
> > > > > Yep, you'dd better do.
> > > > > This is always the first routine I load before I start to do anything.
> > > > >
> > > > > Regs David
> > > > > >
> > > > > > OK, I�m going to try it then,...
> > > > > > Just thought one should know what to put in a script,... :-) But aren> �t
>we all just Zombies,... :-)
> > > > > > Guess i have to do that in the beginning of the script?
> > > > > >
> > > > > > Johannes
> > > > > > > -----Urspr�ngliche Nachricht-----
> > > > > > > Von: David vd Geer Inhuur tbv IPlib
>[SMTP:[EMAIL PROTECTED]]
> > > > > > > Gesendet am: Dienstag, 25. Juni 2002 16:30
> > > > > > > An: [EMAIL PROTECTED];
>[EMAIL PROTECTED]
> > > > > > > Cc: [EMAIL PROTECTED]
> > > > > > > Betreff: Re: AW: AW: param problem
> > > > > > >
> > > > > > >
> > > > > > > Hi Johan,
> > > > > > >
> > > > > > > Let's tell you a secret.
> > > > > > > I don't know what it means as well :)
> > > > > > > Well some part then. This is just typicaly something I always re-use and
> > > > > > > actualy never had the time to re-look at it.
> > > > > > >
> > > > > > > Don't worry about the length by the way. Just give it a try, it never
>failed for
> > > > > > > me. And maybe you might become one of the zombies (just like me), that
>now and
> > > > > > > than just steals code and re-uses it without understanding what it does
>:)
> > > > > > >
> > > > > > > Now let's at least give some info :
> > > > > > >
> > > > > > > my $head = $ENV{QUERY_STRING}; ## Just read 1 of the Enironment vars
>and put it
> > > > > > > into $head. In this case you request the
>query string.
> > > > > > > You might want to use google.com, look at :
> > > > > > > http://hoohoo.ncsa.uiuc.edu/cgi/env.html
> > > > > > >
> > > > > > > $value =~ tr/+/ /;
> > > > > > > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> > > > > > >
> > > > > > > Well This is where we have this mailinglist for. Regex is not my best
>part.
> > > > > > > But as we all have to learn :)
> > > > > > >
> > > > > > >
> > > > > > > my ${$name} = $value;
> > > > > > >
> > > > > > > Just a way of craeting a scalar. We just found out for example : $name =
>"serie";
> > > > > > > $value = 10;
> > > > > > >
> > > > > > > So what we do is : ${serie} = 10;
> > > > > > > or $serie= 10;
> > > > > > >
> > > > > > >
> > > > > > > Hhhm, relooking at the length($buffer). Could be taken out from what I
>can see.
> > > > > > > Don't know what it does out there.>
> > > > > > >
> > > > > > >
> > > > > > > Regs David
> > > > > > > ----------------------------------
> > > > > > >
> > > > > > > >
> > > > > > > > Puh thats tought! So i have to go the hard way for it? What a pity!
> > > > > > > > Lets see if i understand the code... Is there any source where I can
>read about passing parameters to a perl script via the browser?
> > > > > > > >
> > > > > > > > > One solution, when not using $value = param('value');
> > > > > > > > >
> > > > > > > > > sub parse_form {
> > > > > > > > >
> > > > > > > > > read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> > > > > > > > >
> > > > > > > > [Theuerkorn Johannes] so i have to give the length of the
>variable name and value? And what if i don�t know it before?
> > > > > > > > > if (length($buffer) < 5) {
> > > > > > > > > $head = $ENV{QUERY_STRING};
> > > > > > > > > }
> > > > > > > > [Theuerkorn Johannes] No, i don�t understand the reading part
>at all ... :-(
> > > > > > > >
> > > > > > > > > @pairs = split(/\?/, $head); # split vars using ? as delimitor
> > > > > > > > > foreach $pair(@pairs) {
> > > > > > > > > ($name, $value) = split(/=/, $pair); # split var and value
>using = as delim.
> > > > > > > > >
> > > > > > > > [Theuerkorn Johannes] Ok, so i got the name and values
>somehow into the pairs array and now i put it into two variables $name and $value for
>further use, right? But again i don�t know how the values got into $head...
> > > > > > > >
> > > > > > > > > $value =~ tr/+/ /;
> > > > > > > > > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;>
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > > [Theuerkorn Johannes] Ok, have to learn a lot a> s it
>seems, i definetely have no clue what happens here,... OK, lets try: in the first
>line you change every + to a blank, don�t you? And as far as I know from RegExp, in
>the second line you change EVERYTHING to something. But to what?
> > > > > > > > >
> > > > > > > > > ${$name} = $value;
> > > > > > > > >
> > > > > > > > [Theuerkorn Johannes] Hey thats cool, i definetely understand
>that! ;-)
> > > > > > > > > }
> > > > > > > > > } # End sub parse_form
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Regs David
> > > > > > > > > ---------------------
> > > > > > > > > > From
>[EMAIL PROTECTED] Tue Jun 25 15:32:57
>MET 2002
> > > > > > > > > > Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
> > > > > > > > > > Precedence: bulk
> > > > > > > > > > List-Post: <mailto:[EMAIL PROTECTED]>
> > > > > > > > > > List-Help: <mailto:[EMAIL PROTECTED]>
> > > > > > > > > > List-Unsubscribe: <mailto:[EMAIL PROTECTED]>>
> > > > > > > > > > List-Subscribe: <mailto:[EMAIL PROTECTED]>
> > > > > > > > > > Delivered-To: mailing list [EMAIL PROTECTED]
> > > > > > > > > > Message-ID: <AEEEEE93AFA5D411AF8500D0B75E4A16058EE1B5@BSL203E>
> > > > > > > > > > To: "'MECKLIN, JOE (ASI)'" <[EMAIL PROTECTED]>
> > > > > > > > > > Cc: [EMAIL PROTECTED]
> > > > > > > > > > Subject: AW: param problem
> > > > > > > > > > Date: Tue, 25 Jun 2002 15:10:05 +0200
> > > > > > > > > > MIME-Version: 1.0
> > > > > > > > > > X-Mailer: Internet Mail Service (5.5.2653.19)
> > > > > > > > > > Content-Type: text/plain;
> > > > > > > > > charset="ISO-8859-1"
> > > > > > > > > > Content-Transfer-Encoding: quoted-printable
> > > > > > > > > > Content-Length: 1671
> > > > > > > > > > Status: RO
> > > > > > > > > >
> > > > > > > > > > Thanks, but this doesn�t work either, the problem with the + is
>that the cgi:param method takes everything after the & sign as the next variable. As
>the syntax for the param method is:
>http://server/script.pl?variable1=value&variable2=value...etc
> > > > > > > > > >
> > > > > > > > > > > -----Urspr�ngliche Nachricht-----
> > > > > > > > > > > Von: MECKLIN, JOE (ASI) [SMTP:[EMAIL PROTECTED]]
> > > > > > > > > > > Gesendet am: Dienstag, 25. Juni 2002 15:05
> > > > > > > > > > > An: 'Theuerkorn Johannes'
> > > > > > > > > > > Betreff: RE: param problem>
> > > > > > > > > > >
> > > > > > > > > > > In place of the plus sign (+), try sending the html enco> ding
>+
> > > > > > > > > > > The html on the receiving end should translate that to a plus
>sign.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -----Original Message-----
> > > > > > > > > > > From: Theuerkorn Johannes
>[mailto:[EMAIL PROTECTED]]
> > > > > > > > > > > Sent: Tuesday, June 25, 2002 7:59 AM
> > > > > > > > > > > To: [EMAIL PROTECTED]
> > > > > > > > > > > Subject: cgi:param problem
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Hi there,
> > > > > > > > > > >
> > > > > > > > > > > i�ve got to pass a serial number to a perl.cgi. Doing it via the
>cgi:param
> > > > > > > > > > > funktion seems not to work.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > >use strict;
> > > > > > > > > > > >use CGI;
> > > > > > > > > > > >use DBI;
> > > > > > > > > > > >my $cgi_obj = new CGI;
> > > > > > > > > > > >my $seriennummer = $cgi_obj->param("seriennummer");
> > > > > > > > > > >
> > > > > > > > > > > Passing http://server/script4.pl?seriennummer=CN+/P4226666
> > > > > > > > > > >
> > > > > > > > > > > results in a variable seriennummer=CN/P4226666
> > > > > > > > > > >
> > > > > > > > > > > As i want to use the variable seriennummer for an SQL Query
>later, this>
> > > > > > > > > > > doesn�t work.>
> > > > > > > > > > >
> > > > > > > > > > > Any possibility passing the + to my cgi Script? (\+ doesn�> t w>
>ork, either '+'
> > > > > > > > > > > or "+")
> > > > > > > > > > >
> > > > > > > > > > > Johannes
> > > > > > > > > > >
> > > > > > > > > > > --
> > > > > > > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > > > > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > > > > > > >
> > > > > > > > > > --
> > > > > > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > > > > > > For additional commands, e-mail: [EMAIL PROTECTED]>
> > > > > > > > > >
> > > > > > > > > >
> > > > > >
> > > >
> >
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]