Only working with parameters

2003-10-31 Thread J. Alejandro Ceballos Z.
I created a CGI that returns an txt code (to display a banner), but what 
it looks strange to me is that if I call it with only one parameter 
(type  of code to return, and associated variable) it works fine, but if 
I use an other parameter, it sends me an error message.

This works fine:
http://www.go4new.biz/cgi-bin/horiz.cgi?js=1
Those do not work:
http://www.go4new.biz/cgi-bin/horiz.cgi?js=1&query=information
http://www.go4new.biz/cgi-bin/horiz.cgi?query=display&js=1
Any idea about where may be the error?



TIA,

Joal



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Only working with parameters

2003-10-31 Thread Wiggins d Anconia


> 
> I created a CGI that returns an txt code (to display a banner), but what 
> it looks strange to me is that if I call it with only one parameter 
> (type  of code to return, and associated variable) it works fine, but if 
> I use an other parameter, it sends me an error message.
> 
> This works fine:
> http://www.go4new.biz/cgi-bin/horiz.cgi?js=1
> 
> Those do not work:
> http://www.go4new.biz/cgi-bin/horiz.cgi?js=1&query=information
> http://www.go4new.biz/cgi-bin/horiz.cgi?query=display&js=1
> 
> Any idea about where may be the error?
> 
>

What is the error that is sent?  I am assuming the above links are real,
which displays an Internal Server Error, what does the error log say?

There is not a lot of help that can be provided based on what you have
told us. Are you using the CGI.pm module?  

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



flock() semantics?

2003-10-31 Thread Shaun Fryer
Hi all,

I'm writing an app which uses a flat file to store a
*short* list of simple key/value pairs. However having
read the flock() man page, I'm unsure about whether I
need to seek() in cases where I'm not merely appending
to the file (such as when deleting a record).

sub Delete_Record {
my ($file, $key, $value, @array) = @_;
open(OUT, ">$file");
flock(OUT, LOCK_EX);

seek(OUT, 0, 0); # Should I do this?

foreach (@array) { # FYI: $/ = "\n"

seek(OUT, 0, 2); # Or perhaps this?

print OUT $_ unless ( m/^$key\s+$value$/ );
}
flock(OUT, LOCK_UN);
close(OUT);
}

Btw, the above code is just to illustrate the question,
thus no error checking and so forth.

-- 
=
 Shaun Fryer
=
 http://sourcery.ca/
 ph: 905-529-0591
=

Science is like sex: occasionally something useful
comes out of it, but that's not why we do it.
-: Richard Feynmann


pgp0.pgp
Description: PGP signature


Re: Only working with parameters

2003-10-31 Thread J. Alejandro Ceballos Z.
The links are real, and the message sent is "Premature end of scripts 
headers",
like if I tryied to print something before sending the header, but I 
reviewed my
code and only at last I send a print message, validated for any kind of 
call:

It looks something like:

   if ($bExternal) { print "Location:$Response\n\n"; }
   elsif (defined($cInput{js})) { print
   "Content-type:text/plain\n\n$cResponse"; }
   elsif defined($cInput{txt})) { print
   "Content-type:text/plain\n\n$cResponse"; }
   elsif defined($cInput{html})) { print
   "Content-type:text/html\n\n$cResponse"; }
   else { print "Content-type:text/plain\n\n$cResponse"; }
Where $cResponse has the external uri, or the code to response.

About using the CGI.pm, the answer is no. I am not using due the amount 
of calls. I implemented
as an internal subroutine that is called as &ReadInput(*cInput); and the 
code is almost
like the original routine:

   sub ReadInput
{
# Capture variable pointer
local (*cFormatedData) = @_ if @_;
# Create local variables
local ($cRawData,@cData,$nParam,$cKey,$cValue);
# Get raw data
if ($ENV{'REQUEST_METHOD'} eq "GET")
  { $cRawData = $ENV{'QUERY_STRING'};}
else # if ($ENV{'REQUEST_METHOD'} eq "POST")
  { read(STDIN,$cRawData,$ENV{'CONTENT_LENGTH'});}
# Split data
@cData = split(/[&;]/,$cRawData);
foreach $nParam (0 .. $#cData)
  {
  # Re-convert spaces
  $cData[$nParam] =~ s/\+/ /g;
  # Separate key and value to later re-convert special chars
  ($cKey, $cValue) = split(/=/,$cData[$nParam],2);
  $cKey =~ s/%(..)/pack("c",hex($1))/ge;
  $cValue =~ s/%(..)/pack("c",hex($1))/ge;
  # Associate key and value in a new array
  $cFormatedData{$cKey} .= "\0" if (defined($cFormatedData{$cKey}));
  $cFormatedData{$cKey} .= $cValue;
  }
return scalar(@cFormatedData);
}
The only module I load is at the beggining of the code, at 2nd line:

use CGI::Carp qw(fatalsToBrowser);



Wiggins d Anconia wrote:

 

I created a CGI that returns an txt code (to display a banner), but what 
it looks strange to me is that if I call it with only one parameter 
(type  of code to return, and associated variable) it works fine, but if 
I use an other parameter, it sends me an error message.

This works fine:
http://www.go4new.biz/cgi-bin/horiz.cgi?js=1
Those do not work:
http://www.go4new.biz/cgi-bin/horiz.cgi?js=1&query=information
http://www.go4new.biz/cgi-bin/horiz.cgi?query=display&js=1
Any idea about where may be the error?

   

What is the error that is sent?  I am assuming the above links are real,
which displays an Internal Server Error, what does the error log say?
There is not a lot of help that can be provided based on what you have
told us. Are you using the CGI.pm module?  

http://danconia.org

 





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


interpolating a variable with a request parameter

2003-10-31 Thread radhika sambamurti
Hi, 
I am trying to do this:

for( $i = 0; $i < 5; $i++) {
$qty[$i] = $q->param('qty$i');
}
I could say $q->qty0;
$q->qty1;
|
|
|
$q->qty4;

and be done with it. That works. But I would rather do it from the loop.
Why is my variable $i not being appended to qty form variable being passed?
Any ideas?

Thxs.
Radhika

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: interpolating a variable with a request parameter

2003-10-31 Thread Wiggins d Anconia


> Hi, 
> I am trying to do this:
> 
>   for( $i = 0; $i < 5; $i++) {
>   $qty[$i] = $q->param('qty$i');
>   }
> I could say $q->qty0;
> $q->qty1;
>   |
>   |
>   |
> $q->qty4;
> 
> and be done with it. That works. But I would rather do it from the loop.
> Why is my variable $i not being appended to qty form variable being
passed?
> Any ideas?
> 

You are using single quotes in your hash key, which prevent variable
interpolation. Switch them to double quotes and it should work.

foreach my $i (0 .. 5) {
   $qty[$i] = $q->param("qty$i");
}

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: interpolating a variable with a request parameter

2003-10-31 Thread Wiggins d Anconia


> 
> 
> > Hi, 
> > I am trying to do this:
> > 
> > for( $i = 0; $i < 5; $i++) {
> > $qty[$i] = $q->param('qty$i');
> > }
> > I could say $q->qty0;
> > $q->qty1;
> > |
> > |
> > |
> > $q->qty4;
> > 
> > and be done with it. That works. But I would rather do it from the loop.
> > Why is my variable $i not being appended to qty form variable being
> passed?
> > Any ideas?
> > 
> 
> You are using single quotes in your hash key, which prevent variable
> interpolation. Switch them to double quotes and it should work.
> 
> foreach my $i (0 .. 5) {
>$qty[$i] = $q->param("qty$i");
> }
> 

Sorry, to be specific its an argument to the 'param' method, I usually
call 'params' so I was thinking hash. Regardless, the underlying
reasoning is the same

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: interpolating a variable with a request parameter

2003-10-31 Thread drieux
On Friday, Oct 31, 2003, at 10:01 US/Pacific, radhika sambamurti wrote:

Hi,
I am trying to do this:
for( $i = 0; $i < 5; $i++) {
$qty[$i] = $q->param('qty$i');
what you are probably finding is that

	$qty[0] eq 'qty$i'

since you used the single quote token.

whereas

	$qty[$i] = $q->param("qty$i");

would probably Allow the string to be interpolated as
"qty0" which is what you seem to want.
ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: interpolating a variable with a request parameter

2003-10-31 Thread Wiggins d Anconia


> 
> On Friday, Oct 31, 2003, at 10:01 US/Pacific, radhika sambamurti wrote:
> 
> > Hi,
> > I am trying to do this:
> >
> > for( $i = 0; $i < 5; $i++) {
> > $qty[$i] = $q->param('qty$i');
> 
> what you are probably finding is that
> 
>   $qty[0] eq 'qty$i'
> 
> since you used the single quote token.
> 

Yikes, I hope not... shouldn't he be getting "Use of unitialized value
at line..." yada yada yada (aka an undefined value)...

"This feature is new in 2.63.

If the parameter does not exist at all, then param() will return undef
in a scalar context, and the empty list in a list context."

I can't imagine what it would have done before 2.63, did it return the
string of the requested parameter?

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: interpolating a variable with a request parameter

2003-10-31 Thread radhika sambamurti
Thanks! That worked.

On Fri, 31 Oct 2003 11:43:52 -0700
"Wiggins d Anconia" <[EMAIL PROTECTED]> wrote:

> 
> 
> > 
> > 
> > > Hi, 
> > > I am trying to do this:
> > > 
> > >   for( $i = 0; $i < 5; $i++) {
> > >   $qty[$i] = $q->param('qty$i');
> > >   }
> > > I could say $q->qty0;
> > > $q->qty1;
> > >   |
> > >   |
> > >   |
> > > $q->qty4;
> > > 
> > > and be done with it. That works. But I would rather do it from the loop.
> > > Why is my variable $i not being appended to qty form variable being
> > passed?
> > > Any ideas?
> > > 
> > 
> > You are using single quotes in your hash key, which prevent variable
> > interpolation. Switch them to double quotes and it should work.
> > 
> > foreach my $i (0 .. 5) {
> >$qty[$i] = $q->param("qty$i");
> > }
> > 
> 
> Sorry, to be specific its an argument to the 'param' method, I usually
> call 'params' so I was thinking hash. Regardless, the underlying
> reasoning is the same
> 
> http://danconia.org
> 
> -- 
> 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]