How can I make my CGI script more efficient when I have to call a C programme using system?

2005-11-26 Thread He Nan
In my script there is a external C programme , I have to call it every time
when the script runs .
But the C programme needs to load big dictionary , the time consuming is
more than 5 seconds .
What should I do to make it more efficient , could I modify the C programme
so that when it runs for the first time , the dictionary is loaded into the
memory and never free until service is shutdown , or shall I try mod_perl to
write a module in c ? I'm confused , for I'm a beginner to CGI programming .


Re: How can I make my CGI script more efficient when I have to call a C programme using system?

2005-11-26 Thread Bryce Harrington
On Sat, Nov 26, 2005 at 09:47:33PM +0800, He Nan wrote:
 In my script there is a external C programme , I have to call it every time
 when the script runs .
 But the C programme needs to load big dictionary , the time consuming is
 more than 5 seconds .
 What should I do to make it more efficient , could I modify the C programme
 so that when it runs for the first time , the dictionary is loaded into the
 memory and never free until service is shutdown , or shall I try mod_perl to
 write a module in c ? I'm confused , for I'm a beginner to CGI programming .

Have you looked at CGI::Fast ?  It permits persistence like mod_perl,
but is easier to set up and configure.

I've just begun playing with it myself for caching the DB hash for a
Perl-based online game, but it's doing well so far.

For you, CGI::Fast should allow you to keep the dictionary in memory
between invocations.  

Another technique I've used is to run the C program as a daemon process,
and then connect to it through a socket from your perl program when you
need to do operations.  But that's probably overkill for your case...

Bryce

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: mode Q on File::stat

2005-11-26 Thread John W. Krahn
Abid Khwaja wrote:
 Thanks for the pointers.  Here's what I did:
 
 1. stat the file to see the mode set by the system
 
 demerzel:~/etc abid$ ls -l
 total 16
 -rw-rw   1 root  uucp  311 Nov 14 15:20 slist.conf
 demerzel:~/etc abid$ stat -s slist.conf
 st_dev=234881026 st_ino=6858828 st_mode=0100660 st_nlink=1 st_uid=0 
 st_gid=66 st_rdev=0 st_size=311 st_atime=1132939903  st_mtime=1131999637
 st_ctime=1132948249 st_blksize=4096 st_blocks=8  st_flags=0
 
 2. check for root:uucp and 660
 
 use Fcntl;
 use File::stat;
 
 my $etcgroup = /etc/group;
 my $conffile = /Users/abid/etc/slist.conf;
 my $shouldbegroup = uucp;
 my $shouldbeuid = 0;
 my $shouldbemode = 0100660; # -rw-rw perms
 
 my $shouldbegid;
 
 sysopen(GROUP, $etcgroup, O_RDONLY)
 || die can't find/open $etcgroup: $!\n;
 
 while (GROUP) {
 if (/^$shouldbegroup/  /\d+/) {
 $shouldbegid = $;
 last;
 }
 }

You could use perl's built-in getgrnam function to do that:

$ perl -le' $shouldbegid = getgrnam uucp; print $shouldbegid'
14


 close(GROUP)
 || die can't close $etcgroup: $!\n;
 
 # get config file permissions
 my $perms = stat($conffile)
 || die can't find $conffile: $!\n;
 
 # are permissions set correctly?
 unless (($perms-uid == $shouldbeuid) 
 ($perms-gid == $shouldbegid) 
 (($perms-mode  $shouldbemode) == $shouldbemode)) {

I think you may misunderstand how the  operator works.  You are telling it to
turn off bits in $perms-mode that are not turned on in both $perms-mode and
$shouldbemode.  For example:

$ perl -e' $x = 0777; $y = 0660; printf %#o\n, $x  $y'
0660
$ perl -e' $x = 0; $y = 0660; printf %#o\n, $x  $y'
0


 print Aborting!  Incorrect config file perms!\n;
 exit 1
 }


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: mode Q on File::stat

2005-11-26 Thread Mohammed Shameer
From perldoc, 
stat function returns a 13 element list
I think
my $perms = stat($conffile)
will not work as you expect.


On Saturday 26 November 2005 04:03, Abid Khwaja wrote:
 Thanks for the pointers.  Here's what I did:

 1. stat the file to see the mode set by the system

 demerzel:~/etc abid$ ls -l
 total 16
 -rw-rw   1 root  uucp  311 Nov 14 15:20 slist.conf
 demerzel:~/etc abid$ stat -s slist.conf
 st_dev=234881026 st_ino=6858828 st_mode=0100660 st_nlink=1 st_uid=0
 st_gid=66 st_rdev=0 st_size=311 st_atime=1132939903
 st_mtime=1131999637 st_ctime=1132948249 st_blksize=4096 st_blocks=8
 st_flags=0

 2. check for root:uucp and 660

 use Fcntl;
 use File::stat;

 my $etcgroup = /etc/group;
 my $conffile = /Users/abid/etc/slist.conf;
 my $shouldbegroup = uucp;
 my $shouldbeuid = 0;
 my $shouldbemode = 0100660; # -rw-rw perms

 my $shouldbegid;

 sysopen(GROUP, $etcgroup, O_RDONLY)

  || die can't find/open $etcgroup: $!\n;

 while (GROUP) {
  if (/^$shouldbegroup/  /\d+/) {
  $shouldbegid = $;
  last;
  }
 }

 close(GROUP)

  || die can't close $etcgroup: $!\n;

 # get config file permissions
 my $perms = stat($conffile)

  || die can't find $conffile: $!\n;

 # are permissions set correctly?
 unless (($perms-uid == $shouldbeuid) 
  ($perms-gid == $shouldbegid) 
  (($perms-mode  $shouldbemode) == $shouldbemode)) {
  print Aborting!  Incorrect config file perms!\n;
  exit 1
  }

 On Nov 24, 2005, at 9:37 PM, John W. Krahn wrote:
  Abid Khwaja wrote:
  I've been trying to figure out how to use File::stat to check file
  modes but haven't had much luck understanding how it works from the
  documentation.  My goal is to check if a file is owned by a specific
  user, group owned by a specific group and has mode 660.  I have the
  uid and gid checks down but need help with with the mode check.
 
  The documentation for the stat function explains how to do that:
 
  perldoc -f stat
  [snip]
  You can import symbolic mode constants (S_IF*) and functions
  (S_IS*) from the Fcntl module:
 
  use Fcntl ’:mode’;
 
  $mode = (stat($filename))[2];
 
  $user_rwx  = ($mode  S_IRWXU)  6;
  $group_read= ($mode  S_IRGRP)  3;
  $other_execute =  $mode  S_IXOTH;
 
  printf Permissions are %04o\n, S_IMODE($mode), \n;
 
  $is_setuid =  $mode  S_ISUID;
  $is_setgid =  S_ISDIR($mode);
 
 
  Also the STAT(2) man page may help.
 
  So I'm doing the following test:
 
  use File::stat;
  my $conffile = /etc/slist.conf;
  my $perms = stat($conffile)
 
 || die can't find $conffile: $!\n;
 
  my $mode = $perms-mode;
  print $mode\n;
 
  against the following file:
 
  --   1 joe  uucp  311 Nov 14 15:20 slist.conf
 
  When I run the code, here's what I get:
 
  32768
 
  The output varies as I change the file mode but I don't see the
  relation
  between the code output and the mode.  If someone can explain to
  me  how
  this works, it would be greatly appreciated.  I'm running this on
  a MacOS
  X box but the code needs to run cross-unix-platform.
 
  That is because most discussions about the mode assume an octal
  representation
  where the three least significant bits are the world permissions
  and the next
  three bits are the group permissions and the next three bits are
  the owner
  permissions.  Of those three bits the least significant bit is execute
  permission and the next bit is write permission and the next bit is
  read
  permission.  For example:
 
  $ touch TEST
  $ chmod 0752 TEST
   ^^^
   ogw
 
  $ ls -l TEST
  -rwxr-x-w-  1 john users 0 2005-11-24 18:20 TEST
   ^
   ooogggwww
 
  $ perl -le'
  use File::stat;
  my $st = stat TEST or die stat: $!;
  printf %o\n,  $st-[2];
  '
  100752
 ^^^
 ogw
 
 
 
  John
  --
  use Perl;
  program
  fulfillment
 
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  http://learn.perl.org/ http://learn.perl.org/first-response

-- 
If you can't convince them, confuse them.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: mode Q on File::stat

2005-11-26 Thread John W. Krahn
Mohammed Shameer wrote:
 From perldoc, 
 stat function returns a 13 element list
 I think
 my $perms = stat($conffile)
 will not work as you expect.

Please read the documentation for the File::stat module to see why this does
indeed work.

perldoc File::stat


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




ASCII - ASCII printable

2005-11-26 Thread Brano Gerzo
Hi all,

I need convert all ASCII unprintalbe to ASCII printable (if possible)
according to (http://en.wikipedia.org/wiki/ASCII), tell me please,
what should I use/look for.

Thanks a lot.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: ASCII - ASCII printable

2005-11-26 Thread Xavier Noria

On Nov 26, 2005, at 19:21, Brano Gerzo wrote:


I need convert all ASCII unprintalbe to ASCII printable (if possible)
according to (http://en.wikipedia.org/wiki/ASCII), tell me please,
what should I use/look for.


The string \033 would be converted to what?

-- fxn


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: ASCII - ASCII printable

2005-11-26 Thread Brano Gerzo
Xavier Noria [XN], on Saturday, November 26, 2005 at 20:20 (+0100)
typed the following:


 I need convert all ASCII unprintalbe to ASCII printable (if possible)
 according to (http://en.wikipedia.org/wiki/ASCII), tell me please,
 what should I use/look for.

XN The string \033 would be converted to what?

yes, on the first line I wrote (if possible), as you guess right,
this is not possible.
But for example (I write DEC numbers):
128 - c
129 - u
130 - e
and so on (http://www.lookuptables.com/)

So I guess I'm looking for some conversion table, if this is not done,
I will create one, but never do this before, don't know what to use
:( hm, maybe tr will help here...

-- 

 ...m8s, cu l8r, Brano.

[Another classic walk-across-the-livingroom scene -- Crow]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: ASCII - ASCII printable

2005-11-26 Thread Xavier Noria

On Nov 26, 2005, at 20:39, Brano Gerzo wrote:


Xavier Noria [XN], on Saturday, November 26, 2005 at 20:20 (+0100)
typed the following:


I need convert all ASCII unprintalbe to ASCII printable (if  
possible)

according to (http://en.wikipedia.org/wiki/ASCII), tell me please,
what should I use/look for.


XN The string \033 would be converted to what?

yes, on the first line I wrote (if possible), as you guess right,
this is not possible.
But for example (I write DEC numbers):
128 - c
129 - u
130 - e
and so on (http://www.lookuptables.com/)

So I guess I'm looking for some conversion table, if this is not done,
I will create one, but never do this before, don't know what to use
:( hm, maybe tr will help here...


Yeah, looks like you need some kind of conversion table, but I still  
do no understand the problem to solve. Can you be more specific? Do  
you have examples of actual inputs and their corresponding conversions?


-- fxn


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




format to scalar better solution?

2005-11-26 Thread Brano Gerzo
Hello all,

I like format function, but I miss output to scalars.
write always print to STDOUT, or filehandle, but I need access
contents to scalar. I found in docs one solution, but it is not much
nice:

use Carp;
sub swrite {
croak usage: swrite PICTURE ARGS unless @_;
my $format = shift;
$^A = ;
formline($format,@_);
return $^A;
}


$string  = swrite('END', 1, 2, 3);
Check me out
@  @|||  @
END
print  $string;


...but when I have in formating template lets say 40 variables...
I'm just curious, if there are some other possibilities.

Thanks

/brano



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: ASCII - ASCII printable

2005-11-26 Thread Brano Gerzo
Xavier Noria [XN], on Saturday, November 26, 2005 at 20:53 (+0100)
thinks about:

XN Yeah, looks like you need some kind of conversion table, but I still
XN do no understand the problem to solve. Can you be more specific? Do
XN you have examples of actual inputs and their corresponding conversions?

this is selfexplain: http://www.lookuptables.com/
when the character is possible to convert to something printable, I
can write conversion (161 - i), but for example 241 has no printable
character, so it should be space or nothing.

As I look to these codes, I found around 36 characters, which I should
convert.

And need for this? I'm sending to client some file, but name of
attachment is created from database. In DB I have iso-8859-1
characters, which looks ugly (I don't know client's encoding, I don't
know how to encode filename of attachment...), so I just want send
clear characters

-- 

 ...m8s, cu l8r, Brano.

[DISCLAIMER: I really shouldn't respond to my mail before I have my
beer.]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: ASCII - ASCII printable

2005-11-26 Thread Xavier Noria

On Nov 26, 2005, at 21:03, Brano Gerzo wrote:


Xavier Noria [XN], on Saturday, November 26, 2005 at 20:53 (+0100)
thinks about:

XN Yeah, looks like you need some kind of conversion table, but I  
still
XN do no understand the problem to solve. Can you be more  
specific? Do
XN you have examples of actual inputs and their corresponding  
conversions?


this is selfexplain: http://www.lookuptables.com/
when the character is possible to convert to something printable, I
can write conversion (161 - i), but for example 241 has no printable
character, so it should be space or nothing.


Ok, there are not enough details to provide actual code, but I think  
you'll be done with tr///, it is documented in perlop.


-- fxn


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Google API + SOAP

2005-11-26 Thread Mandar Rahurkar
Hi,
   I am using following script to access Google Api however I get the following 
error :

502 Bad Gateway at ./googly.pl line 15 . 

I think the problem is with SOAP::Lite package. Has anyone experience this 
error before ?

Thanks,
Mandar



#! /ws/ifp-22/scratch/Perl/bin/perl

use SOAP::Lite;

@ARGV == 2 or die Usage: googly query  number of results\n ;

my($q, $maxResults) = @ARGV;


$key=---;
# key, q, start, maxResults, filter, restrict, safeSearch, 
# lr, ie, oe
my @params = ($key, $q, 0, $maxResults, 0, '', 0, '', 'latin1', 'latin1');

my $result =
SOAP::Lite
- service(file:GoogleSearch.wsdl)
- doGoogleSearch(@params);

print join \n,
map( { qq{a href=$_-{URL}} . ($_-{title} || 
$_-{URL}) . qq{/a
br /} } @{$result-{resultElements}} );

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Installing Perl Modules Locally

2005-11-26 Thread Mandar Rahurkar

Hi All,
   I am trying to install perl modules locally since I dont have a 
root aceess. I installed  a local version of perl. However I 
am having problems installing modules:


ExtUtils::AutoInstall 0.49 required. Install it from CPAN? [Y/n] y
*** Installing ExtUtils::AutoInstall
Password:

It asks me for the password when I use MCPAN (perl -MCPAN -e shell) to 
install it.


this is what my male_pl_arg looks like:

makepl_arg PREFIX=/ws/ifp-22/scratch/Perl
INSTALLPRIVLIB=/ws/ifp-22/scratch/Perl/lib/perl5 
INSTALLSCRIPT=/ws/ifp-22/scratch/Perl/bin 
INSTALLSITELIB=/ws/ifp-22/scratch/Perl/lib/perl5/site_perl
INSTALLBIN= /ws/ifp-22/scratch/Perl/bin 
INSTALLMAN1DIR=/ws/ifp-22/scratch/Perl/man/man1 
INSTALLMAN3DIR=/ws/ifp-22/scratch/Perl/man/man3


Whats is going wrong ??

thanks,
Mandar


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Captcha Images

2005-11-26 Thread Mike Blezien

Hello,

we are currently implementing the Authen/Captcha validation scheme into a 
registration form. been searching Google to locate alternative images that can 
be used inplace of the default images used by the module, but without much luck 
locating them. Does any one know where these type of images maybe found, or if 
someone on the list my have create their own and my wish to share them :)


TIA,
--
Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Captcha Images

2005-11-26 Thread Chris Devers
On Sat, 26 Nov 2005, Mike Blezien wrote:

 we are currently implementing the Authen/Captcha validation scheme 
 into a registration form. been searching Google to locate alternative 
 images that can be used inplace of the default images used by the 
 module, but without much luck locating them. Does any one know where 
 these type of images maybe found, or if someone on the list my have 
 create their own and my wish to share them :)

Aren't they being generated dynamically, taking random test and applying 
distortion to the rendered bitmap of that text ?

If you just had a library of, say, a dozen or even a few dozen of these 
images, it wouldn't be that hard to automate logging in through the 
canned captcha images, once it's known that there is a small pool of 
images to identify. 

To be effective, I'd imagine they have to be made dynamically. There 
should be multiple modules to help do this sort of thing. Have you 
taken a look for 'captcha' on CPAN?


-- 
Chris Devers

~‰ENÓâ±þÜj²K
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response


Re: Captcha Images

2005-11-26 Thread Mike Blezien

Chris,

Chris Devers wrote:

On Sat, 26 Nov 2005, Mike Blezien wrote:


we are currently implementing the Authen/Captcha validation scheme 
into a registration form. been searching Google to locate alternative 
images that can be used inplace of the default images used by the 
module, but without much luck locating them. Does any one know where 
these type of images maybe found, or if someone on the list my have 
create their own and my wish to share them :)



Aren't they being generated dynamically, taking random test and applying 
distortion to the rendered bitmap of that text ?


If you just had a library of, say, a dozen or even a few dozen of these 
images, it wouldn't be that hard to automate logging in through the 
canned captcha images, once it's known that there is a small pool of 
images to identify. 

To be effective, I'd imagine they have to be made dynamically. There 
should be multiple modules to help do this sort of thing. Have you 
taken a look for 'captcha' on CPAN?


We have the Authen/Captcha module already installed. it has it own set of png 
alpha/numerical image characters(a..z  0..9) and 5 backgrounds which it does 
generates dynamically random character image display, but was wondering if there 
are other images available that can be used, as the module does allow for an 
alternative image folder to be used inplace of the default image location it 
uses. the default images are a bit plain. :)



--
Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
=-=-=-=-=-=-=-=


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response