Re: 2 off in array count and index

2010-03-22 Thread Rene Schickbauer

jbl wrote:

I am reading a directory and creating an array of .png file names. I
know for a fact that there are 1025 png files in the folder
With $count = @files I get 1027
With $last = $#files I get 1026
$files [0] = .
$files[1] = ..


. is the current directory, .. is the parent directory.

These are always inserted by the filesystem in any directory for 
navigation purposes. These are (in principle) dynamically generated 
abbreviations for directory names.


Simply put
.. is needed when you need to go up one level higher in the file 
hierachie without parsing the current path, like cd ..


. is mostly needed on the command line, when you want to execute a 
program from the current directory if its not in the search path, like 
./myapp.


You might want to take a look at
http://www.washington.edu/computing/unix/startdoc/directories.html

LG
Rene

--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re: ERROR: malformed header

2009-12-02 Thread Rene Schickbauer

Raheel Hassan wrote:

HI,

I have an error in opening one of my perl script, could any one tell me
where i look for resolving this problem. This error i looked in the apache
error logs. Thanks in advance.

* malformed header from script. Bad header=\tPUBLIC -//W3C//DTD XHTML 1.0:
dashboard.pl, referer: http://localhost/index.pl*;


Hard to say exactly without the actual code. Looks like you're printing 
something in the wrong order (maybe a warning).


Can you give us the relevant code snippet?

LG
Rene

--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re: Saving param after new recall of a cgi script

2009-12-01 Thread Rene Schickbauer

Marek wrote:

Hi!


How do I save the parameters from the first input? I tried everything,
but there is nothing kept in my array. Do I have to save these
parameters into an external file?


You could also use Storable  Base64 to encode your data structure into 
a Base64 string. Put this string into a hidden text field. When the 
second form is submitted, you can decode your original data structure 
from that hidden field.


That way, you don't have to store ANYTHING on your server until the user 
hits the final SUBMIT.


Something like this could do the trick:
http://search.cpan.org/~cavac/Maplat-0.9/lib/Maplat/Helpers/DBSerialize.pm

I originally wrote it to store perl data structures into a database text 
field, should work in a hidden HTML form, too. Something like this:


input type=hidden name=foo value=YourEncodedString


LG
Rene

--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re: Loading results (via ajax) from a CGI

2009-12-01 Thread Rene Schickbauer

bu...@alejandro.ceballos.info wrote:
I have a CGI (made with cgi.pm) that receive a parameters, check against 
a DB and returns a text with not found or OK found message. Pretty 
simple.


In other site, i have an ajax routine that sends the parameters (via 
get) and is expected to capture the resulting page, but is not working. 
If I try with a static page, there is not problem, only when calling 
that CGI.


The may be a problem with your headers. What i mean is, is the browser 
(wrongly) caching the page you request?


Try setting the correct headers. Also, you might add an ever-changing 
dummy value to your request to trick the browser into thinking this is a 
new, non-cached page.


You have
var myurl = 'http://server/script.cgi?value='+int_value;

change to:

var myurl = 'http://server/script.cgi?value='+int_value + 'dummyvalue=' 
+ now.getTime();


LG
Rene

--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re: cgi and perl database interaction

2009-12-01 Thread Rene Schickbauer

Hi!

Now, the thing is that the PHP scripts also connect to the database and, 
presumably, uphold the connection over the duration of the session so as 
not to disconnect and reconnect continually when the user browses the 
website.


My question is - is it possible to do the same thing with those CGI 
scripts?


CGI scripts are basically scripts executed at the commandline with a few 
parameters and environment variables set (each call normally starts a new 
instance).


You could look into the various web frameworks if and how they solved the 
problem. If you can't install anything on the server besides CGI scripts, 
you're probably out of luck, though.


If you CAN install additional software on the server, mod_perl could be the way 
to go. Or run your own small perl-based server for those pages on another port, 
HTTP::Server::Simple::CGI (or my Maplat-Framework) might fit your profile - you 
may even run them as backend only on localhost and use a PHP script as simple 
proxy 8-)


It really depends on what you're planing in the long run.

LG
Rene

--
#!/usr/bin/perl #99BoB (C)2004 cavac:prg count drink vessel place act1 act2
@a...@argv;$c=$a[0]||99;$b= .($a[2]||bottles). of .($a[1]||beer);$w= .
($a[3]||on the wall).,;do{print$c$b$w\n$c$b,\n.($a[4]||take one down).
, .($a[5]||pass it around).,\n.--$c.$b$w\n\n;}while($c);printEND!\n;

--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/