RE: SQL question // date_format

2003-09-29 Thread Bob Showalter
David Gilden wrote:
 Good evening,
 
 The following mySQL query works fine, but the server is in
 California. I would like add 2 hours to %l,
 because the client is in Texas. I could just go to time in GMT and
 forget about it :) But I'm wondering if there is a simple solution
 here. 
 
 SELECT id, DATE_FORMAT(datecreated, '%c/%e/%y at: %l:%i
 %p'), email, name, comments FROM $table_name order by id limit
 $offset,10; 

I don't use MySQL, but PostgreSQL has a SET TIME ZONE statement you can
issue to define the local time zone for a session. Perhaps MySQL has a
similar thing?

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



SQL -- getting one row problem

2003-09-29 Thread David Gilden
Good afternoon,

Here is the output of my script, and cant understand why this is not working.
Thanks for any and all pointers!
Dave Gilden

[EMAIL PROTECTED]:~/cgi-bin$  mail_guest_to_jk.cgi 
Use of uninitialized value in concatenation (.) or string at ./mail_guest_to_jk.cgi 
line 33.

Use of uninitialized value in concatenation (.) or string at ./mail_guest_to_jk.cgi 
line 37.
DBD::mysql::st execute failed: You have an error in your SQL syntax near '' at line 1 
at ./mail_guest_to_jk.cgi line 60.
DBD::mysql::st fetchrow failed: fetch() without execute() at ./mail_guest_to_jk.cgi 
line 40.
Use of uninitialized value in concatenation (.) or string at ./mail_guest_to_jk.cgi 
line 41.
Use of uninitialized value in concatenation (.) or string at ./mail_guest_to_jk.cgi 
line 41.
Use of uninitialized value in concatenation (.) or string at ./mail_guest_to_jk.cgi 
line 41.
Use of uninitialized value in concatenation (.) or string at ./mail_guest_to_jk.cgi 
line 41.
Use of uninitialized value in concatenation (.) or string at ./mail_guest_to_jk.cgi 
line 41.



the script:
-
#!/usr/bin/perl -w

use DBI;
use strict;

## Sensitive stuff deleted :)

my ($sql,$dbh,$sth,$datecreated,$name,$email,$comments);

initialize_dbi;


 Read from Guestbook ###

### get id for last entry  
$sql =SELECT MAX(id) FROM $table_name;;

run_statement($sql);

my $id = $sth-{id};
print $id\n;

$sth-finish; 

$sql = SELECT id, DATE_FORMAT(DATE_ADD(datecreated, INTERVAL 2 HOUR), '%c/%e/%y at: 
%l:%i %p'),email, name, comments FROM $table_name where id = $id;;

run_statement($sql);
# get the one row selected
($id,$datecreated,$email,$name,$comments) = $sth-fetchrow;
print $id\n$datecreated\n$email\n$name\n$comments;
$dbh-disconnect; # close date base connection 
exit;


sub initialize_dbi{
   my $drh = DBI-install_driver( 'mysql' );
   $dbh = DBI-connect(DBI:mysql:$user_name:$sql_server, $user_name, $user_password);
   die Cannot connect: $DBI::errstr\n unless $ ;
}


sub run_statement{
my $stmt = shift;
$sth = $dbh-prepare($stmt);
$sth-execute;
}

__END__




==
 Cora Connection: Your West African Music Source
  Resources, Recordings, Instruments  More!
   http://www.coraconnection.com/ 
==

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



SQL -- getting one row problem -- clever mySQL trick

2003-09-29 Thread David Gilden
Hello out there...

I wanted to thank everyone who has kindly offered their assistance
with my current project.  Of course I have more questions,
But first I wanted to share how I solved my current issue.
It's displays a clever mySQL trick! -- see script below:

Dave Gilden
( kora musician / audiophile / web master @ cora connection /  Ft. Worth, TX, USA)

And here is a question for anyone who knows sendmail.

How can I add a 'CC' or even better a 'BCC' instead of 
using multiple email address comma delimited.


my $mailprog = '/usr/lib/sendmail';
my $recipient = '[EMAIL PROTECTED],[EMAIL PROTECTED]';

...some code...

sub send_mail {
my $data;
$email ||= '[EMAIL PROTECTED]';

open(MAIL, |$mailprog -t);
print MAIL To: $recipient\n;
print MAIL From: $name $email\n;
print MAIL Subject: $subject\n\n;
print MAIL lots of text from the database\n;
close(MAIL);
}




MySQL TRICK
###

#!/usr/bin/perl -w

use DBI;
use strict;

... some stuff removed ...
my $subject = Jakes's Lawncare Guestbook New Entry;

my ($id,$sql,$dbh,$sth,$datecreated,$name,$email,$comments);

initialize_dbi;


 Read from Guestbook ###

### get and store MAX(id) -- the last entry-- via SQL
$sql = SELECT [EMAIL PROTECTED]:=MAX(id) FROM $table_name;;
run_statement($sql);
$sql = SELECT id, DATE_FORMAT(DATE_ADD(datecreated, INTERVAL 2 HOUR),
 '%c/%e/%y at: %l:%i %p'),email, name, comments FROM $table_name where id = [EMAIL 
PROTECTED];;
run_statement($sql);
($id,$datecreated,$email,$name,$comments) = $sth-fetchrow;
$sth-finish; 
#debug
#print $id\n$datecreated\n$email\n$name\n$comments;
$dbh-disconnect; # close date base connection 


sub initialize_dbi{
   my $drh = DBI-install_driver( 'mysql' );
   $dbh = DBI-connect(DBI:mysql:$user_name:$sql_server, $user_name, $user_password);
   die Cannot connect: $DBI::errstr\n unless $ ;
}

sub run_statement{
my $stmt = shift;
$sth = $dbh-prepare($stmt);
$sth-execute;
}

__END__

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



calling other cgi's in PERL

2003-09-29 Thread David Gilden
Can anyone enlighten me on how to do this:
Goal: call  different PERL scripts from current PERL script.

Below is what I am trying to accomplish, but I am not sure I have the syntax correct.
(can't seem to find anything this in my PERL books) 
Thanks,
Dave
-
#!/usr/bin/perl -w

#some code...


# have current cgi redirect the web browser to a html page  
print redirect(/index.html);

# call another cgi -- that does something behind the scenes -- send an email or 
somthing.
print ./another-that-returns-no-html.cgi;
exit;


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



Passing a variable to a package function vs. a local function

2003-09-29 Thread Dan Fish
I'm a bit new to this so please bear with me...

I've written a script that uses CGI.pm something like this:

use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:all);

$query = new CGI;

blah...blah...
myfunc($query);
blah...blah...

sub myfunc{ my ($query) = @_;
$foo=$query-param(foo);
 ...more...blah...blah...
}

Everything works fine as is, but I'm trying to take the function myfunc
out and put it in a separate .pm file because I need to call it from several
cgi scripts.  When I put it in the .pm file, I get something like:   

Can't locate object method param via package Trend at
/usr/local/lib/perl5/site_perl/5.005/MMC/Dex.pm line 253, INFILE chunk
1150.

I do have:
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:all);
In the .pm file

What am I missing?

Thanks,
-Dan


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



Re: problem with Net::SSH::Perl using dsa key authentication

2003-09-29 Thread Haim Ashkenazi
Wiggins D'Anconia wrote:
 my %params = {
 protocol = 2,
 interactive = 1,
 identity_files = [EMAIL PROTECTED],
 };
 
 Right here  you are assigning a hash reference to a hash, which is
 essentially setting a key using the reference location with a value as
 undef. Then you pass the hash to the new constructor and it sees a
 single value which is why you are getting there warning/error about
 Reference found where even sized list expected...  Switch the braces
 in the above construct to parenthesis and it should work, or switch the
 hash to a hash dereference below and the hash to a scalar above.
well, this one did solve the even-sized list error/warning but not the
agent method error. I think I must run some kind of ssh-agent before, but
I have no idea how to implement this. (I actually have it running as the
parent of my X, but since I've added the Net::SSH::Perl::Auth, it just
ignores it. before I've added it, it accepted the linux ssh-agent as the
authentication and didn't prompt me for a password).

thanx
--
Haim

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



RE: problem with Net::SSH::Perl using dsa key authentication

2003-09-29 Thread Haim Ashkenazi
Tn wrote:

 Hi,
 
 As far as I can tell you are doing it right according to the manpages.
 However, I noticed that in
 http://www.squarebox.co.uk/cgi-squarebox/manServer/usr/share/man/man3/Ne
 t::SSH::Perl.3pm that $ssh-login() requires a password that you aren't
 supplying:
 
 $ssh-login(user1, pass1);
 
 I believe this refers to the linux password.  Perhaps if the password is
 not supplied for an interactive login then you will be prompted for it.
 But you could disable linux password authentication as an ssh option at
 least as a possible workaround:
 
 PasswordAuthentication=no # to be added to my %params
 
 As I recall the default config of sshd/ssh forces password
 authentication on top of publickey authentication as an extra security
 measure.  You might take a look at your sshd and ssh config files to see
 how they are set and a combination of tweaking them and the options in
 your script may fix the problem.
 
 The sshd/ssh setup that I prefer requires no password authentication if
 publickey authentication works, however it will use password
 authentication if publickey authentication does not work and I cut keys
 with a null passphrase for easier automation of script execution and
 interactive logins.
 
 The error message seems to refer to a ssh_agent setup.  Ssh_agent is a
 special daemon that caches private keys and their passphrases so that
 you don't have to keep supplying the latter on the command line to start
 new sessions.  I've never bothered setting it up but using it should be
 more secure than using keys with null passphrases.
 
 For reference:
 
 Instructions for ssh_agent configuration are at
 http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/custom-guide/s1-op
 enssh-client-config.html#S3-OPENSSH-CONFIG-SSH-AGENT.
 
 Manpages for openssh are at http://www.openssh.org/manual.html
 
 Manpages for perl ssh modules are at
 http://www.squarebox.co.uk/cgi-squarebox/manServer/usr/share/man/man3/
 
 I don't have a setup now for testing ssh or I would.
 
 Please let me know what works when you find it.
 
 -tristram
 [EMAIL PROTECTED]
Hi

I'm using ssh with only key authentication in most of my linux servers. the
problem is not in the configuration (i think). I guess it's a matter of
running ssh-agent from the perl interface (since I've entered the
Net::SSH::Perl::Auth it ignores the one that's already running as the
parent of my X session).

thanx
--
Haim

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



Perl Beginners Portals

2003-09-29 Thread Shlomi Fish

Hi all!

I believe learn.perl.org is very lacking:

1. Its design is ugly.

2. No links to many important online resources such as tutorials, books,
article collections, mailing lists, web forums, etc.

3. Concentration on commercial books.

4. No source code for the site is available and [EMAIL PROTECTED]
are not responsive.

5. Pretty much unmaintained for a long time.

Still, it has a pretty good Google popularity.

I did my best to resolve the problems inherent in it by setting up
http://perl-begin.berlios.de/. The site could still use some work, but
it's still better than learn.perl.org. Nevertheless, I would want to see
learn.perl.org becoming better.

When I started the perl-begin effort the beginners-workers decided I will
do a re-design of the learn.perl.org. After I was more or less finished, I
did not receive any reply when I tried to contact them. So I had no choice
but to set up my own site.

What are your opinions about the two sites? How can we make learn.perl.org
better?

Regards,

Shlomi Fish




--
Shlomi Fish[EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/

An apple a day will keep a doctor away. Two apples a day will keep two
doctors away.

Falk Fish

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



Re: problem with Net::SSH::Perl using dsa key authentication

2003-09-29 Thread Haim Ashkenazi
Wiggins D'Anconia wrote:
 my %params = {
 protocol = 2,
 interactive = 1,
 identity_files =[EMAIL PROTECTED],
 };
 
 Right here  you are assigning a hash reference to a hash, which is
 essentially setting a key using the reference location with a value as
 undef. Then you pass the hash to the new constructor and it sees a
 single value which is why you are getting there warning/error about
 Reference found where even sized list expected...  Switch the braces
 in the above construct to parenthesis and it should work, or switch the
 hash to a hash dereference below and the hash to a scalar above.
well, this one did solve the even-sized list error/warning but not the
agent method error. I think I must run some kind of ssh-agent before, but
I have no idea how to implement this. (I actually have it running as the
parent of my X, but since I've added the Net::SSH::Perl::Auth, it just
ignores it. before I've added it, it accepted the linux ssh-agent as the
authentication and didn't prompt me for a password).

thanx
--
Haim

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



RE: problem with Net::SSH::Perl using dsa key authentication

2003-09-29 Thread Haim Ashkenazi
Tn wrote:

 Hi,
 
 As far as I can tell you are doing it right according to the manpages.
 However, I noticed that in
 http://www.squarebox.co.uk/cgi-squarebox/manServer/usr/share/man/man3/Ne
 t::SSH::Perl.3pm that $ssh-login() requires a password that you aren't
 supplying:
 
 $ssh-login(user1, pass1);
 
 I believe this refers to the linux password.  Perhaps if the password is
 not supplied for an interactive login then you will be prompted for it.
 But you could disable linux password authentication as an ssh option at
 least as a possible workaround:
 
 PasswordAuthentication=no # to be added to my %params
 
 As I recall the default config of sshd/ssh forces password
 authentication on top of publickey authentication as an extra security
 measure.  You might take a look at your sshd and ssh config files to see
 how they are set and a combination of tweaking them and the options in
 your script may fix the problem.
 
 The sshd/ssh setup that I prefer requires no password authentication if
 publickey authentication works, however it will use password
 authentication if publickey authentication does not work and I cut keys
 with a null passphrase for easier automation of script execution and
 interactive logins.
 
 The error message seems to refer to a ssh_agent setup.  Ssh_agent is a
 special daemon that caches private keys and their passphrases so that
 you don't have to keep supplying the latter on the command line to start
 new sessions.  I've never bothered setting it up but using it should be
 more secure than using keys with null passphrases.
 
 For reference:
 
 Instructions for ssh_agent configuration are at
 http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/custom-guide/s1-op
 enssh-client-config.html#S3-OPENSSH-CONFIG-SSH-AGENT.
 
 Manpages for openssh are at http://www.openssh.org/manual.html
 
 Manpages for perl ssh modules are at
 http://www.squarebox.co.uk/cgi-squarebox/manServer/usr/share/man/man3/
 
 I don't have a setup now for testing ssh or I would.
 
 Please let me know what works when you find it.
 
 -tristram
 [EMAIL PROTECTED]
Hi

I'm using ssh with only key authentication in most of my linux servers. the
problem is not in the configuration (i think). I guess it's a matter of
running ssh-agent from the perl interface (since I've entered the
Net::SSH::Perl::Auth it ignores the one that's already running as the
parent of my X session).

thanx
--
Haim

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



Re: Passing a variable to a package function vs. a local function

2003-09-29 Thread Ramprasad A Padmanabhan
Dan Fish wrote:
I'm a bit new to this so please bear with me...

I've written a script that uses CGI.pm something like this:

use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:all);
$query = new CGI;

blah...blah...
myfunc($query);
blah...blah...
sub myfunc{ my ($query) = @_;
$foo=$query-param(foo);
 ...more...blah...blah...
}
Everything works fine as is, but I'm trying to take the function myfunc
out and put it in a separate .pm file because I need to call it from several
cgi scripts.  When I put it in the .pm file, I get something like:   

Can't locate object method param via package Trend at
/usr/local/lib/perl5/site_perl/5.005/MMC/Dex.pm line 253, INFILE chunk
1150.
I do have:
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:all);
In the .pm file
What am I missing?

Thanks,
-Dan
If you have name the package file as say Mypackage.pm
then in your mail program you will call the function as
Mypackage::myfunc($query).
Ram



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


Re: substr parsing mask

2003-09-29 Thread perl
I got it to work after adding a new var in apache modperl environment.

This works:
 $acct_no = $xgi-param(acct_no);
 print substr($acct_no, 0, 4, x x (length($acct_no)-4));

This did NOT work:
 print substr($xgi-param(acct_no), length($xgi-param(acct_no))-4,4);

Any explanation would be great.
-rkl

I tried to save a line by using
 On Sep 27, [EMAIL PROTECTED] said:

   substr($string, 0, -4, x x (length($string) - 4));

I couldn't get this to work correctly. it only returns the 4 characters
 of
the string whcih is correct. But it did not replace the preceding
characters with .

 It works for me:

   [EMAIL PROTECTED] [11:47am] ~ #103 perl -l
   $string = join '',  .. 9;
   substr($string, 0, -4, x x (length($string) - 4));
   print $string;
   __END__
   xx6789

 --
 Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
 RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 stu what does y/// stand for?  tenderpuss why, yansliterate of course.
 [  I'm looking for programming work.  If you like my work, let me know.  ]




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



RE: To quotes or not quotes parameter

2003-09-29 Thread Thomas Bätzler
[EMAIL PROTECTED] [EMAIL PROTECTED] asked:
 what is the proper way to pass a parameter for something like
 $cgi-param(username)?
 
 as far as i know it, this works for me:
 
 $cgi-param(username);

Don't do that. Using barewords as strings can
break your code if you later on introduce a
sub with the same name in your code. Besides,
this obviously doesn't work for Perl reserved
words anyways.

Instead, use either:

 $cgi-param(username);
 $cgi-param('username');

HTH,
Thomas

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



Re: Perl - HowTo operating with large file?

2003-09-29 Thread Juris
Hi!

Thanks, your solution is one way how solve this problem! I found other ...

sub remove_ary_dupes{
my @[EMAIL PROTECTED];
#Define hash
undef %saw;
@[EMAIL PROTECTED] = ();
#Hash owerwrite automaticly duplicated values! ;)
my @out = sort keys %saw;  # remove sort if undesired
return @out;
}
sub grep_log_file{
my @[EMAIL PROTECTED];
#if (undef $sparam[0]) {print No records found with @ARGV\n; exit 0}
my ($first, $match);
my $block_size=20480;
my ($tmp_block, $pos_corect,@ary_match, @res_ary);
open(F, $LOG_FILE) or die Error opening $LOG_FILE: $!;

#Read LOG file block by block
while (read(F,$first,$block_size)) {
$end_pos=rindex($first,\n);
# $first=~/(.*)\n(.*)$/; #Not used, because so slowly for long lines!
# Compare read line length with default block size!
# If not equal, its last block in cycle
   if (length($first) ne $block_size) {
$match=$first; $match = $tmp_block . $first;
$tmp_block=; $pos_corect=0;
} else {
$match=substr($first,0, $end_pos); $match=$tmp_block . 
$match ;
$pos_corect=$block_size-$end_pos;  
$tmp_block=substr($first,$end_pos,$block_size-$end_pos);
}
 my @log_lines=split(\n,$match);
 ##Grep all lines
 @log_lines=remove_ary_dupes(@log_lines); #Remove duplicated log 
lines!
 foreach my $j (@sparam) {
 push @ary_match, (grep /$j/, @log_lines);
 }
 #push @res_ary, @ary_match;
}
close (F);
return @ary_match;
}

Try this code, if have similar problem!

On Fri, 26 Sep 2003 20:13:21 +0530, Ramprasad A Padmanabhan 
[EMAIL PROTECTED] wrote:

Juris wrote:
I have one small problem!
HowTo read from large text file text in binary mode?
if i want read all file, i use this code:

my (@LOG_FILE);
open (FL, /var/log/maillog);
@LOG_FILE=FL;
close (FL);
#After this code execution file contents stored in array @LOG_FILE
@LOG_FILE=grep /$something/, @LOG_FILE
I not want read all file string by struing - it's so slowly, if file is 
large and contains more than 100 records!
I need read each 50 bytes, but how?
Please, help!




When you are opening big files never do
@array = FILE
This essentially reads the entire file into an array and is very 
expensive on memory.

you could do something like
while(FILE){
push @arr , $_ if(/$something/);
}
But IMHO this still that may not be the best way.

What I would do is

system(grep $something $filename  $tempfile);
# *Nothing* beats gnu grep when you parse large file
open(FILE,$tempfile);
# Now if you really want the lines in an array
@lines = FILE
Ram
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Objects, threads and so on

2003-09-29 Thread lists_perl_org
Hi all,

I'm quite new to Perl so please bear with me :)

I've experience in Delphi so I thought I knew about objects... it
seems I don't :(

I want to have a class I won't instanciate (static members and
variables), with global vars so I can access them and change them from
withing threads/forks. 

-- FILE test.pl

use FOO;

FOO-make();
FOO-make();

use Thread;

my $t = new Thread \th1;
my $u = new Thread \th2;

sub th1() { while (1) { FOO-make(); sleep(1); } }
sub th2() { while (1) { print \t; FOO-make(); sleep(2); } }

while (1) {}

-- FILE FOO.pm

package FOO;

%FOO::e = {};

sub make {
  my $self = shift;
  %FOO::e-{'something'} = %FOO:e-{'something'} + 1;
  print %FOO::e-{'something'}.\n;
}

-- RESULTS --

1
2
3
   3
4
5
   4
6
7
   5
8
...

Obviously it doesn't work.

I have tried a lot more of things and I don't know how to make it
work. The same applies if I use fork() instead threads.

Is there any way to make this work?

Thank you very much in advance!

Fernando Najera

 


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



Re: How to pass parameters to a module

2003-09-29 Thread Juris
Hi!

It's easy!
There is one sample:
sub do_somethig {
my @[EMAIL PROTECTED];
if (! ($passed_params[0]))  { print Not passed parametrs }
my @lines;
#Do something ...
return @lines;
}
On Thu, 25 Sep 2003 21:59:53 -0700, Rajesh Dorairajan 
[EMAIL PROTECTED] wrote:

Can someone explain how does one pass a parameter to a Perl Module? To
illustrate suppose I've My::Module
package My::Module;

BEGIN
{
  $scalar = $input;
}
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = ($scalar);
In the above script is there anyway to pass the $input variable to the
package My::Module from the calling script? Please excuse me if the code 
is
horrible, just trying to simplify what I want ;)

TIA

Rajesh


--
With best regards,
Juris
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

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


Get email adress from AD or exchange?

2003-09-29 Thread Samuelsson, David
Has anyone done this in Perl, is there an module that can help me? I am
aware of that I can use the Win32::Ole, but what I really want is an
more easier way of asking: 

For $user
Return mailadress

This can be done in VB quite easy, but I want to try and stay perlish
here. Any one have an clue?

//Dave




Hylafax - Windows Client

2003-09-29 Thread Paul Kraus
For a project / learning exp. I am trying to create a windows client
that will let me interact with a Hylafax server. I don't know enough
about the special ftp protocol it uses so I am try to just parse the log
files to get similar functionality using tk.

Now how can attach to a share using login credentials without mapping a
drive.

For instance...

//hylafax/hylafax/logs

But I need it to connect as a specific user/password.


Or alternately if you have some info on the ftp protocol that Hylafax
uses that would be great to. I did see a couple cpan modules but none of
them had any docs what so ever.

Paul


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



Generic database access?

2003-09-29 Thread Rob Richardson
Greetings!

Is there a Perl module --

Don't be silly!, I hear you reply.  There's a Perl module for
everything!

OK, let me rephrase that.  I would like a program, probably but not
necessarily in Perl, that can run on a Perl-equipped Unix server that
will give me remote access through the Internet to a database system in
a way similar to how Microsoft Access provides a GUI for creating and
editing databases.  What would you recommend?

Thanks!

Rob

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



Script runs once

2003-09-29 Thread rmck
Hello,

I have a perl script that is to stop and start at midnight, and write to a new log 
file. 

The problem is it runs once then does not run again?? 

Below is the script that I am tring to use?? 


bash-2.03#
#!/bin/perl -w
use warnings;
use strict;
 
my ( $sec, $min, $hour, $day, $mon, $year ) = localtime;
my $snoop   = '/usr/sbin/snoop -d ge0 -ta';
my $date = `date +%W`;
chop($date);
my $dir = /var/weeks/03_week_$date;

my $logfile = sprintf '/var/weeks/03_week_%d/%02d%02d%02d%02d%02d.sno',
`date +%W`, $year % 100, $mon + 1, $day, $hour, $min;
 
# create 03_week_dir if does not exist
unless(-d $dir){
mkdir $dir,0660;
} 
 
open LOG, '', $logfile or die Cannot open $logfile: $!;
# set default output filehandle and autoflush
select LOG;
$| = 1;
 
print '===' . localtime .  ==\n\n;
 
open SNOOP, $snoop | or die Cannot open pipe from $snoop: $!;
 
while ( SNOOP ) {
print;
# restart this process if midnight
( $sec, $min, $hour ) = localtime;
exec $0 if $sec + $min + $hour == 0;
}
bash-2.03# 

Thanks,
RM

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



Re: Objects, threads and so on

2003-09-29 Thread Ramprasad A Padmanabhan
Lists Perl Org wrote:
Hi all,

I'm quite new to Perl so please bear with me :)

I've experience in Delphi so I thought I knew about objects... it
seems I don't :(
I want to have a class I won't instanciate (static members and
variables), with global vars so I can access them and change them from
withing threads/forks. 

-- FILE test.pl

use FOO;

FOO-make();
FOO-make();
use Thread;

my $t = new Thread \th1;
my $u = new Thread \th2;
sub th1() { while (1) { FOO-make(); sleep(1); } }
sub th2() { while (1) { print \t; FOO-make(); sleep(2); } }
while (1) {}

-- FILE FOO.pm

package FOO;

%FOO::e = {};

sub make {
  my $self = shift;
  %FOO::e-{'something'} = %FOO:e-{'something'} + 1;
  print %FOO::e-{'something'}.\n;
}
-- RESULTS --

1
2
3
   3
4
5
   4
6
7
   5
8
...
Obviously it doesn't work.

I have tried a lot more of things and I don't know how to make it
work. The same applies if I use fork() instead threads.
Is there any way to make this work?

Thank you very much in advance!

Fernando Najera

 



Maybe you would do better to learn perl-syntax well before you jump into 
your actual application. A common problem for people conversant with 
many languages is that they always try translate their work in all 
languages though their command on all languages is not the same

A hash array reference is always written with $sign not %
so change
%FOO::e = {};   == $FOO::e
in all places

I havent gone thru the entire code , But I think you can take it further

Ram



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


Re: PERL DNS Lookup's using Socket

2003-09-29 Thread Dan Anderson
I don't know if you've been following the news but Verisign and some
others have funneled *.com and *.net to their web site for expired and
invalid domain names.  You should correct for such things when looking
up the IP.

-Dan


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



RE: Script runs once

2003-09-29 Thread TN
This problem looks familiar.  What will kill the first snoop?  The while
loop at the bottom assumes snoop is running and tries to run another
snoop on the same interface as the first.  I don't think that can be
done even from the command line because the first snoop will lock
/dev/ge0 (in promiscuous mode).  It will be easier and more robust to
use cron for restarting the process.

-tn

-Original Message-
From: rmck [mailto:[EMAIL PROTECTED] 
Sent: Monday, September 29, 2003 9:56 AM
To: [EMAIL PROTECTED]
Subject: Script runs once


Hello,

I have a perl script that is to stop and start at midnight, and write to
a new log file. 

The problem is it runs once then does not run again?? 

Below is the script that I am tring to use?? 


bash-2.03#
#!/bin/perl -w
use warnings;
use strict;
 
my ( $sec, $min, $hour, $day, $mon, $year ) = localtime;
my $snoop   = '/usr/sbin/snoop -d ge0 -ta';
my $date = `date +%W`;
chop($date);
my $dir = /var/weeks/03_week_$date;

my $logfile = sprintf '/var/weeks/03_week_%d/%02d%02d%02d%02d%02d.sno',
`date +%W`, $year % 100, $mon + 1, $day, $hour, $min;
 
# create 03_week_dir if does not exist
unless(-d $dir){
mkdir $dir,0660;
} 
 
open LOG, '', $logfile or die Cannot open $logfile: $!;
# set default output filehandle and autoflush
select LOG;
$| = 1;
 
print '===' . localtime .  ==\n\n;
 
open SNOOP, $snoop | or die Cannot open pipe from $snoop: $!;
 
while ( SNOOP ) {
print;
# restart this process if midnight
( $sec, $min, $hour ) = localtime;
exec $0 if $sec + $min + $hour == 0;
}
bash-2.03# 

Thanks,
RM

-- 
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]



RE: Generic database access?

2003-09-29 Thread TN
phpMyAdmin is great for managing MySQL databases remotely using a web
browser interface.  See http://www.phpmyadmin.net/

-tn


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



Re: Perl Newbie - Need good book recommendation

2003-09-29 Thread Dan Anderson
 Big advice #2.  Ebay.  I buy all new books and expensive books through
 trusted sellers for about a 50-60% savings.  Make sure you can pay media
 rate on the shipping.  $4.00.  I routinely buy books for $15-20 here.

I do the same thing, and would add the following sites:

http://www.alibris.com
http://www.half.com
http://www.addall.com

You can get used and new books for much less then the sticker price.

I would just add a word of caution though: sometimes you can find a
really cheap perl book for $4.  Double check that the edition is
relatively new and covers Perl 5.  Otherwise you may get a great deal on
a book about Perl 1.

-Dan


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



Re: Objects, threads and so on

2003-09-29 Thread Rob Dixon
Fernando wrote:

 I'm quite new to Perl so please bear with me :)

We have no choice: this is, after all, perl.beginners!

 I've experience in Delphi so I thought I knew about objects... it
 seems I don't :(

Yes you do :) But you're confusing methodologies with implementations.

 I want to have a class I won't instanciate (static members and
 variables), with global vars so I can access them and change them from
 within threads/forks.

Threads and forks are something layered on top of Perl, and therefore
implicitly non-standard, beyond an explicit Perl version.

 use FOO;

Which will try to compile FOO.pm and to execute FOO::import.

 FOO-make();
 FOO-make();

The constructor for a Perl object is, traditionally, 'new'. But
this is not bound by the language and can have any name that you
want. However this looks like two instantiations, which you said
you weren't doing, and both of which are discarded (in either
Delphi or Perl) so I don't see what you're trying to do here.

 use Thread;

 my $t = new Thread \th1;
 my $u = new Thread \th2;

 sub th1() { while (1) { FOO-make(); sleep(1); } }
 sub th2() { while (1) { print \t; FOO-make(); sleep(2); } }

Again I am disconcerted, as you have an object instantion
in each of two threads, which is immediately discarded.

 while (1) {}

 -- FILE FOO.pm

 package FOO;

 %FOO::e = {};

This wouldn't compile if you wore the helmet of Perl
salvation, being:

  use strict;   # always
  use warnings; # usually

You're trying to set a hash (being a list of paired values)
to a single value (which is an empty hash reference).

 sub make {
   my $self = shift;
   %FOO::e-{'something'} = %FOO:e-{'something'} + 1;
   print %FOO::e-{'something'}.\n;
 }

This declares 'FOO::make' because of your 'package' statement
above. Call it 'FOO::new' to make others in the Perl world
feel at home.

Any constructor parameters are values to help form the object.
Your constructor cannot have a $self parameter as, if
it is useful at all, it is to copy values from an existing
object of the same type or of a subclass. It will usually be
called 'clone'.

Back to your top line:

 So I can access them and change them from within threads/forks

Within a single thread, you could declare or require another
module containing

  package MODULE;

  our $var1;
  our $var2;

etc.

Which will be accessible externally as $MODULE::var1,
$MODULE::var2. You could also 'use' that code as an external
module which will let you access synonyms to those values
in the current package as $var1, $var2 etc. Unless you have
a comprehensive requirement IMO this is not worth considering.

Say more about your application and we will help further.

HTH,

Rob



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



Re: substr parsing mask

2003-09-29 Thread Jeff 'japhy' Pinyan
On Sep 29, [EMAIL PROTECTED] said:

I got it to work after adding a new var in apache modperl environment.

This works:
 $acct_no = $xgi-param(acct_no);
 print substr($acct_no, 0, 4, x x (length($acct_no)-4));

This did NOT work:
 print substr($xgi-param(acct_no), length($xgi-param(acct_no))-4,4);

They're not the same code.

  print substr(
$xgi-param('acct_no'),
0,
4,
x x (length($xgi-param('acct_no')) - 4)
  );

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



Re: assigning a multi-dimensional array (mda) to an mda?

2003-09-29 Thread Kevin Pfeiffer
In article [EMAIL PROTECTED], R. Joseph Newton wrote:

 Kevin Pfeiffer wrote:
 
 I thought the easy way to do this is to first assign my entire 'en' data
 structure to the 'de' structure and then add 'de' values as available.

 So I did this:

 $text{'main'}{'de'} =  $text{'main'}{'en'};

 $text{'main'}{'de'} = {  # German labels
 'alias_sub' =  ALIAS,
 'user_sub'  =  BENUTZER,
 };

 But this assignment doesn't seem to work. Can I not do this?
 
 I bet it does.  Just not the way you want it to.
[...]

I'll have to maybe try a smaller sample and then look at them with
Data::Dumper (I'm a little slow sometimes)

 *Hash-based structures do not have columns or support parallelism*

Writing it on the wall!  ;-)

 
 I'd suggest a little restructuring:
 
 $text{'main'} = {
 'alias_sub'  = {'en' = 'Alias', 'de' = 'Allas'},
 'user_sub'  = {'en'  = 'User', 'de' = 'Benutzer'},
 ...
 }

Too late for me, and I wanted something where someone could say, okay, now
lets add Bulgarian. So I keep each language separate.

 A little less elegant when it comes to accessing it, but if you see the
 potential for forgetting the German counterparts as serious, this would
 make it much less likely.

I think the better approach for me is that when my get_lang routine is
called to provide language for a prompt that if, for example,
$text{main}{de}{alias_sub} does not exist, that the other entry is
substituted. I think I can figure that out...

Thanks for the help and advice!

-- 
Kevin Pfeiffer
International University Bremen


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



extending modules

2003-09-29 Thread Kevin Pfeiffer
Hi,

I'm working on a nice frontend to the Unix::AliaseFile module for managing
'aliases'. In the process I've extended a couple methods in the module and
added a new one. 

There is a show_user method that returns all aliases of which a user is a
member; there's also a Toggle on/off that uses commenting to deactive but
not delete an alias (our sysadmin likes to do this); rename_user can also
now rename aliases, too, (since an alias might be a member of another alias
list).

My working copy is now called AliasFilePlus.

What do I do with this if I try to share it? The changes to the module
seemed too great (and too complex) for me to place them in the main program
and too little for a submodule. I've updated the docs and wrote ...based
on version xxx of Unix::AliasFile by Steve Snodgrass..., etc.

Right now the main program is set up so:

use lib .;
use AliasFilePlus;

Should I try to contact the author to ask if he's interested in the
extensions? If this fails, then what?

(After I clean up a couple things I'll post a link to it in case anyone is
interested in sharing critique).

Thanks in advance (list has some good questions lately I see; I will try to
catch up),

-Kevin


-- 
Kevin Pfeiffer
International University Bremen
Your message here

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



Re: Generic database access?

2003-09-29 Thread Sam Harris
search google for Webmon.
also check out phpadmin.

good luck

Sam Harris, 
Systems Administrator
Franklin University
201 S. Grant Avenue
Columbus, Ohio  43215-5399
Work: (614)-744-8322
Toll free: 1-877-341-6300 ext. 8322
[EMAIL PROTECTED]
http://www.franklin.edu/
 [EMAIL PROTECTED] 09/29/03 09:56 AM 
Greetings!

Is there a Perl module --

Don't be silly!, I hear you reply.  There's a Perl module for
everything!

OK, let me rephrase that.  I would like a program, probably but not
necessarily in Perl, that can run on a Perl-equipped Unix server that
will give me remote access through the Internet to a database system in
a way similar to how Microsoft Access provides a GUI for creating and
editing databases.  What would you recommend?

Thanks!

Rob

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

-- 
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]



How to draw lines with different line width?

2003-09-29 Thread Yi Chu
I am usiing GD::Graph::lines to draw a graph with multiple lines.  How do I specify so 
that lines can be of different width?
 
yi


-
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

Regarding Mail::Bulkmail 3.09 module

2003-09-29 Thread Chinku Simon
Hi,

I am facing a problem in using the Mail::Bulkmail 3.09 module.

I am using the following method to specify the configuration files.

Mail::Bulkmail-conf_files('C:/Perl/lib/Bulkmail.cfg');

and I have converted the script to an '.exe ' file. While I run the .exe file
I get the error 
Can't call method header on an undefined value at notessyncv6.pl line 825, CO
NF line 82.

The script runs fine when it is run as a .pl file

Thanks
Chinku 

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



Re: Objects, threads and so on

2003-09-29 Thread david
Lists Perl Org wrote:

 Hi all,
 
 I'm quite new to Perl so please bear with me :)
 
 I've experience in Delphi so I thought I knew about objects... it
 seems I don't :(
 
 I want to have a class I won't instanciate (static members and
 variables), with global vars so I can access them and change them from
 withing threads/forks.

not sure what you mean by that but looks like you want to have a global 
variable where the threads can manipulate and all the threads will see the 
same value once a thread modified the vairable. if so you need to lock the 
variable before letting the threads to access that variable. 

 
 -- FILE test.pl
 
 use FOO;
 
 FOO-make();
 FOO-make();
 
 use Thread;
 
 my $t = new Thread \th1;
 my $u = new Thread \th2;
 
 sub th1() { while (1) { FOO-make(); sleep(1); } }
 sub th2() { while (1) { print \t; FOO-make(); sleep(2); } }

threads-yield is usually a better choice to than sleep if you want the OS 
to know that it should pay attention to another thread.

 
 while (1) {}
 
 -- FILE FOO.pm
 
 package FOO;
 
 %FOO::e = {};
 
 sub make {
   my $self = shift;
   %FOO::e-{'something'} = %FOO:e-{'something'} + 1;
   print %FOO::e-{'something'}.\n;
 }
 
 -- RESULTS --
 
 1
 2
 3
3
 4
 5
4
 6
 7
5
 8
 ...
 
 Obviously it doesn't work.
 
 I have tried a lot more of things and I don't know how to make it
 work. The same applies if I use fork() instead threads.

forking a different process is different than making a new thread. 
obviously, very little is shared between a parent and a child process which 
makes sharing a global variables before multiple process a bit difficult. 

 
 Is there any way to make this work?
 

if i understand your question correctly, see if the following helps:

#!/usr/bin/perl -w
use strict;

use threads;
use threads::shared;

package AnotherNameSpace;

#--
#-- $var is global to AnotherNameSpace and will 
#-- be shared among all threads
#--
my $var : shared = 1;

sub inc{

#--
#-- let only one thread access $var at a time
#--
{

lock($var);
$var++;
print STDERR $_[0]$var\n;

}
}

package main;

sub get1{

while(1){
AnotherNameSpace::inc('');
threads-yield;
}
}
sub get2{

while(1){
AnotherNameSpace::inc(\t);
threads-yield;
}
}

my $t1 = threads-new(\get1);
my $t2 = threads-new(\get2);

$t1-join;
$t2-join;

__END__

prints:

10
11
12
13
14
15
...
538
539
540
541
542
543
...

lines begin with a tab is printed by one thread and those that do not being 
with the tab are printed by another thread. as you can see, they all syn 
up. without the locking, you might see something like:

601
598
602
599
603
600
604
601

which probably isn't what you expect.

david
-- 
$_=q,015001450154015401570040016701570162015401440041,,*,=*|=*_,split+local$;
map{~$_1{$,=1,[EMAIL PROTECTED]||3])=~}}0..s~.~~g-1;*_=*#,

goto=print+eval

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



Re: Generic database access?

2003-09-29 Thread Rob Richardson
Sam,

There's a lot of products named Webmon.  The ones I found on Google
didn't do what I want.  Which one are you thinking of?  Can you give me
a company name?

Thanks again!

Rob



__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



Is there a *nix shell variable for the path to perl?

2003-09-29 Thread Dan Anderson
Is there a (BA)SH/CSH/TSH/KSH variable to the Perl path?

I am creating a script that uses Perl I want to be able to share over
several servers.  Instead of having my users edit the file manually
(because I assume they would do something dumb) I want to create a shell
script to edit the script for them.

Thanks in advance,

-Dan


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



Re: Should loops return a value?

2003-09-29 Thread Steve Grazzini
On Mon, Sep 29, 2003 at 11:04:46PM +0300, Ville Jungman wrote:
 This is real example from what i was doing yesterday:
   if($subs-anna_tilavuus($x+$lisax,$y+$lisay,$z)  100){
  $subs-paivita($x);
  $udat{x}=$lisax;
  $udat{y}=$lisay;
   }elsif($subs-anna_tilavuus($x,$y+$lisay,$z)  100){
  $udat{y}=$lisay;
   }
 
 If using return values, this could be wrote as:
   ($udat{x},$udat{y})=
  if($subs-anna_tilavuus($x+$lisax,$y+$lisay,$z)  100){
 $subs-paivita($x);
 retlast($lisax,$lisay)
  }elsif($subs-anna_tilavuus($x,$y+$lisay,$z)  100){
 retlast(undef,$lisay);
  }
   ;

You can do this already with do blocks.

  my $condition = 1;

  ($x, $y) = do {
if ($condition) { 42, 43 }
else{ 44, 45 }
  };

  print $x : $y\n;

If it makes you happy, you can even add --

  sub retlast { @_ }

But the analogy with return/last is likely to confuse -- why can
you use retlast() in places where neither return() or last() make
any sense?

-- 
Steve

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



Re: extending modules

2003-09-29 Thread Rob Dixon
Kevin wrote:


 I've updated the docs and wrote ...based on version
 xxx of Unix::AliasFile by Steve Snodgrass..., etc.

Mister Snodgrass is a character in The Pickwick Papers
invented by Charles Dickens. He is no Foo or Bar.

Proud of the soil on which I stand :)

Rob Dixon
Leicester
ENGLAND



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



Re: extending modules

2003-09-29 Thread Jeff 'japhy' Pinyan
On Sep 29, Kevin Pfeiffer said:

I'm working on a nice frontend to the Unix::AliaseFile module for managing
'aliases'. In the process I've extended a couple methods in the module and
added a new one.

There is a show_user method that returns all aliases of which a user is a
member; there's also a Toggle on/off that uses commenting to deactive but
not delete an alias (our sysadmin likes to do this); rename_user can also
now rename aliases, too, (since an alias might be a member of another alias
list).

My working copy is now called AliasFilePlus.

What do I do with this if I try to share it? The changes to the module
seemed too great (and too complex) for me to place them in the main program
and too little for a submodule. I've updated the docs and wrote ...based
on version xxx of Unix::AliasFile by Steve Snodgrass..., etc.

Typically, you create a sub-module.

  package Unix::AliasFile::Extended;
  use base 'Unix::AliasFile';

  sub changed_method { ... }
  sub new_method { ... }

  1;

Then you just use Unix::AliasFile::Extended in any program where you would
have used Unix::AliasFile.

If you want to contact the author and ask him if he'd like to release a
new version of the Unix::AliasFile module with your code in it, go right
ahead.  Should that fail, the sub-class approach above is fine.

(After I clean up a couple things I'll post a link to it in case anyone is
interested in sharing critique).

I'd be happy to do that for you.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



Re: Is there a *nix shell variable for the path to perl?

2003-09-29 Thread Jeff Westman
Dan Anderson [EMAIL PROTECTED] wrote:
 Is there a (BA)SH/CSH/TSH/KSH variable to the Perl path?
 
 I am creating a script that uses Perl I want to be able to share over
 several servers.  Instead of having my users edit the file manually
 (because I assume they would do something dumb) I want to create a shell
 script to edit the script for them.

No, but you can create your own.  Use something like:

PERL=`which perl`

Alternative, just call perl from the command line, such as

$ perl yourScript.pl

instead of 

$ yourScript.pl

In the last case you would have to use a 'shebang' #!/path in the file
itself, whereas calling it from the command line, it takes it from the $PATH.


-Jeff


__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



Question on handling files.

2003-09-29 Thread Douglas Holeman
I have had a request to pull 100,000+ names from a mailing list of
600,000+. I was hoping to figure out a way to get perl to help me do
this.
 
I stumbled through this code but the problem is I just wanted to know
how to delete a line from the first list so I can be sure I dont pull
the same 'random' line twice.
 
Any help would be appreciated.  I know this code sucks but I am not a
programmer.
 
 
 
 
open FEDOUT, c:\\perl\\bin\\129out.csv or die The Program has failed
opening 129Out.csv: $!;
 
$x=1;
$z=633856;
print 1;
 
while ($x = 129000) {
open(FEDUP, All.csv) or die Can't find All.csv: $!\n;
 
 $y = int(rand($z)+1);
 
 $a=1;
 

 while ($a  $y) {
  $line = FEDUP;
#  print $a,  ,$y,Z=, $z, \n;
  $a=$a+1;
 
 }
 

 print $x,..., $y,..., $z,..., $a,..., $line,...,\n;
 print (FEDOUT $line);
 $a=1;
 $y=1;
 
 $x=$x+1;
close FEDUP;
 
}
 
print $x;
close FEDOUT;
close FEDUP;
 
 
Douglas Holeman
Prepress Manager
 


Re: Should loops return a value?

2003-09-29 Thread John W. Krahn
Steve Grazzini wrote:
 
 On Mon, Sep 29, 2003 at 11:04:46PM +0300, Ville Jungman wrote:
  This is real example from what i was doing yesterday:
if($subs-anna_tilavuus($x+$lisax,$y+$lisay,$z)  100){
   $subs-paivita($x);
   $udat{x}=$lisax;
   $udat{y}=$lisay;
}elsif($subs-anna_tilavuus($x,$y+$lisay,$z)  100){
   $udat{y}=$lisay;
}
 
  If using return values, this could be wrote as:
($udat{x},$udat{y})=
   if($subs-anna_tilavuus($x+$lisax,$y+$lisay,$z)  100){
  $subs-paivita($x);
  retlast($lisax,$lisay)
   }elsif($subs-anna_tilavuus($x,$y+$lisay,$z)  100){
  retlast(undef,$lisay);
   }
;
 
 You can do this already with do blocks.
 
   my $condition = 1;
 
   ($x, $y) = do {
 if ($condition) { 42, 43 }
 else{ 44, 45 }
   };

You don't need a do block, the conditional operator can handle it.

@udat{ 'x', 'y' } = $subs-anna_tilavuus( $x + $lisax, $y + $lisay, $z )
 100
  ? do { $subs-paivita( $x ); ( $lisax, $lisay ) }
  : $subs-anna_tilavuus( $x, $y + $lisay, $z )  100
  ? ( undef, $lisay )
  : ();


John
-- 
use Perl;
program
fulfillment

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



Re: Replacing variable data between fields - Revisited.

2003-09-29 Thread perlwannabe
 Perlwannabe wrote:

 I originally tried to do this, but it won't work.  The data doesn't
 _always_ have a tab before address, sometimes (although seldom) it
 has a space.  With grep I would miss the entire address.  However,
 if I were to just select everything and replace it with nothing, that
 would be the answer.  BTW...your solution above is right on the money
 for about 98% of the file.  However, by simply scanning the line and
 deleting everything between between HOW and NUMBER: that would give
 me 100%.  Any ideas?

 You could try this:

 s/\tHOW.+?\sNUMBER:\s*\S+\t/\t/;

Hah!!! I got it.  FINALLY!!!  Thank you so much for the help.  It was a
simple  matter of using s/// instead of tr///.  I am not sure why, but
it works...The tr/// function does not work at all...Any ideas why?

s{ (?=HOW) (.+?) (?=NUMBER\t) } { ( $a = $1 ) =~ s/$a/ /; $a   }ex;




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



remove blanks

2003-09-29 Thread perl
Is there a func or a onliner for removing blanks from both ends?

I'm using these:

$username =~ s/^\s+//;
$username =~ s/\s+$//;

There got to be one out there!

thanks,
-rkl

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



Re: remove blanks

2003-09-29 Thread James Edward Gray II
On Monday, September 29, 2003, at 07:04  PM, [EMAIL PROTECTED] wrote:

Is there a func or a onliner for removing blanks from both ends?

I'm using these:

$username =~ s/^\s+//;
$username =~ s/\s+$//;
We could combine those:

$username =~ s/^\s*(.*?)\s*$/$1/;

Hope that helps.

James

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


Re: Generic database access?

2003-09-29 Thread Mark G
Rob,

why not try one of r-desktops. I use TridiaVNC, which you can carry with
ssh.

Mark G
- Original Message - 
From: Rob Richardson [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, September 29, 2003 3:33 PM
Subject: Re: Generic database access?


 Sam,

 There's a lot of products named Webmon.  The ones I found on Google
 didn't do what I want.  Which one are you thinking of?  Can you give me
 a company name?

 Thanks again!

 Rob



 __
 Do you Yahoo!?
 The New Yahoo! Shopping - with improved product search
 http://shopping.yahoo.com

 -- 
 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]



RE: remove blanks

2003-09-29 Thread Hanson, Rob
I ran some benchmarks.

The two-liner outperformed the one-liners by a 10 to 1 ratio.  Code and
results below.


Benchmark: timing 10 iterations of OneLine, OneLine2, TwoLines...
  OneLine: 41 wallclock secs (39.30 usr +  0.00 sys = 39.30 CPU) @ 2544.79/s
  OneLine2: 34 wallclock secs (32.58 usr +  0.00 sys = 32.58 CPU) @
3069.56/s
  TwoLines:  3 wallclock secs ( 2.58 usr +  0.00 sys =  2.58 CPU) @
38789.76/s


use strict;
use Benchmark;

my $val =  . (foo x 200) . ;

timethese(100_000, {
'OneLine' = sub{trimOne($val)},
'OneLine2' = sub{trimOne2($val)},
'TwoLines' = sub{trimTwo($val)},
});

sub trimOne {
  my $s = shift;
  $s =~ s/^\s+|\s+$//g;
  die $s unless ($s eq (foox200));
}

sub trimOne2 {
  my $s = shift;
  $s =~ s/^\s*(.*?)\s*$/$1/g;
  die unless ($s eq foox200);
}

sub trimTwo {
  my $s = shift;
  $s =~ s/^\s+//;
  $s =~ s/\s+$//;
  die unless ($s eq foox200);
}


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Monday, September 29, 2003 8:04 PM
To: [EMAIL PROTECTED]
Subject: remove blanks


Is there a func or a onliner for removing blanks from both ends?

I'm using these:

$username =~ s/^\s+//;
$username =~ s/\s+$//;

There got to be one out there!

thanks,
-rkl

-- 
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]



Re: Question on handling files.

2003-09-29 Thread Bob Showalter
Douglas Holeman wrote:
 I have had a request to pull 100,000+ names from a mailing list of
 600,000+. I was hoping to figure out a way to get perl to help me do
 this.

 I stumbled through this code but the problem is I just wanted to know
 how to delete a line from the first list so I can be sure I dont pull
 the same 'random' line twice.

 Any help would be appreciated.  I know this code sucks but I am not a
 programmer.




 open FEDOUT, c:\\perl\\bin\\129out.csv or die The Program has
 failed opening 129Out.csv: $!;

 $x=1;
 $z=633856;
 print 1;

 while ($x = 129000) {
 open(FEDUP, All.csv) or die Can't find All.csv: $!\n;

  $y = int(rand($z)+1);

  $a=1;


  while ($a  $y) {
   $line = FEDUP;
 #  print $a,  ,$y,Z=, $z, \n;
   $a=$a+1;

  }


  print $x,..., $y,..., $z,..., $a,..., $line,...,\n;
  print (FEDOUT $line);
  $a=1;
  $y=1;

  $x=$x+1;
 close FEDUP;

 }

 print $x;
 close FEDOUT;
 close FEDUP;

This code is going to be *extremely* slow, because you are making many,
many, many passes over the huge 600K row file.

Here's a fairly efficient algorithm that requires only one pass through the
large file (after you know how many lines are in it). Pass the name of the
large file as the first command line argument:

  #!/usr/bin/perl
  use strict;
  my $x = 633_856;# no. of rows in big file
  my $y = 129_000;# no. of rows to select
  my %h;
  for (1..$y) {
  print $_\n unless $_ % 1000;
  my $i = int(rand($x)) + 1;
  exists $h{$i} and redo;
  $h{$i}++;
  }
  while() {
  exists $h{$.} and print;
  }

Here I'm basically creating a hash with 129k entries with keys randomly
selected from the range 1..633k. Then as we read through the file, we just
print each line whose number exists as a key in the hash.

Important: make sure your Perl has enough randbits. or you won't get a
distribution over this range. You'll need at least 20 bits and preferrably
31 or more. Use perl -V:randbits to check the figure.



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



Re: remove blanks

2003-09-29 Thread Bob Showalter
[EMAIL PROTECTED] wrote:
 Is there a func or a onliner for removing blanks from both ends?

 I'm using these:

 $username =~ s/^\s+//;
 $username =~ s/\s+$//;

 There got to be one out there!

Doing it in two steps is the way to go. Don't try to make one regex out of
it.

I usually write it this way, so I can process several variables at once:

   s/^\s+//, s/\s+$// for $foo, $bar, $baz;



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



Re: remove blanks

2003-09-29 Thread perl
this looks convenience

thanks,
-rkl

 [EMAIL PROTECTED] wrote:
 Is there a func or a onliner for removing blanks from both ends?

 I'm using these:

 $username =~ s/^\s+//;
 $username =~ s/\s+$//;

 There got to be one out there!

 Doing it in two steps is the way to go. Don't try to make one regex out of
 it.

 I usually write it this way, so I can process several variables at once:

s/^\s+//, s/\s+$// for $foo, $bar, $baz;





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



Re: Question on handling files.

2003-09-29 Thread Bob Showalter
Bob Showalter wrote:
   for (1..$y) {
   print $_\n unless $_ % 1000;

Whoops! You can leave the line above out. I just stuck it in there so I
could see the progress through the loop.

   my $i = int(rand($x)) + 1;
   exists $h{$i} and redo;
   $h{$i}++;
   }



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



RE: remove blanks

2003-09-29 Thread perl
That's some good stuff.

can you run a benchmark against these, contributed by others on this list,
as well?

$username =~ s/^\s*(.*?)\s*$/$1/;
$username =~ s/^\s*(.*?)\s*$/$1/;

thanks,
-rkl

 I ran some benchmarks.

 The two-liner outperformed the one-liners by a 10 to 1 ratio.  Code and
 results below.


 Benchmark: timing 10 iterations of OneLine, OneLine2, TwoLines...
   OneLine: 41 wallclock secs (39.30 usr +  0.00 sys = 39.30 CPU) @
 2544.79/s
   OneLine2: 34 wallclock secs (32.58 usr +  0.00 sys = 32.58 CPU) @
 3069.56/s
   TwoLines:  3 wallclock secs ( 2.58 usr +  0.00 sys =  2.58 CPU) @
 38789.76/s


 use strict;
 use Benchmark;

 my $val =  . (foo x 200) . ;

 timethese(100_000, {
 'OneLine' = sub{trimOne($val)},
 'OneLine2' = sub{trimOne2($val)},
 'TwoLines' = sub{trimTwo($val)},
 });

 sub trimOne {
   my $s = shift;
   $s =~ s/^\s+|\s+$//g;
   die $s unless ($s eq (foox200));
 }

 sub trimOne2 {
   my $s = shift;
   $s =~ s/^\s*(.*?)\s*$/$1/g;
   die unless ($s eq foox200);
 }

 sub trimTwo {
   my $s = shift;
   $s =~ s/^\s+//;
   $s =~ s/\s+$//;
   die unless ($s eq foox200);
 }


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Sent: Monday, September 29, 2003 8:04 PM
 To: [EMAIL PROTECTED]
 Subject: remove blanks


 Is there a func or a onliner for removing blanks from both ends?

 I'm using these:

 $username =~ s/^\s+//;
 $username =~ s/\s+$//;

 There got to be one out there!

 thanks,
 -rkl

 --
 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]



RE: remove blanks

2003-09-29 Thread perl
This is the correct reply.

That's some good stuff.

can you run a benchmark against these, contributed by others on this list,
as well?

$username =~ s/^\s*(.*?)\s*$/$1/;
s/^\s+//, s/\s+$// $username;

thanks,
-rkl

 I ran some benchmarks.

 The two-liner outperformed the one-liners by a 10 to 1 ratio.  Code and
 results below.


 Benchmark: timing 10 iterations of OneLine, OneLine2, TwoLines...
   OneLine: 41 wallclock secs (39.30 usr +  0.00 sys = 39.30 CPU) @
 2544.79/s
   OneLine2: 34 wallclock secs (32.58 usr +  0.00 sys = 32.58 CPU) @
 3069.56/s
   TwoLines:  3 wallclock secs ( 2.58 usr +  0.00 sys =  2.58 CPU) @
 38789.76/s


 use strict;
 use Benchmark;

 my $val =  . (foo x 200) . ;

 timethese(100_000, {
 'OneLine' = sub{trimOne($val)},
 'OneLine2' = sub{trimOne2($val)},
 'TwoLines' = sub{trimTwo($val)},
 });

 sub trimOne {
   my $s = shift;
   $s =~ s/^\s+|\s+$//g;
   die $s unless ($s eq (foox200));
 }

 sub trimOne2 {
   my $s = shift;
   $s =~ s/^\s*(.*?)\s*$/$1/g;
   die unless ($s eq foox200);
 }

 sub trimTwo {
   my $s = shift;
   $s =~ s/^\s+//;
   $s =~ s/\s+$//;
   die unless ($s eq foox200);
 }


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Sent: Monday, September 29, 2003 8:04 PM
 To: [EMAIL PROTECTED]
 Subject: remove blanks


 Is there a func or a onliner for removing blanks from both ends?

 I'm using these:

 $username =~ s/^\s+//;
 $username =~ s/\s+$//;

 There got to be one out there!

 thanks,
 -rkl

 --
 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]



building module/package

2003-09-29 Thread perl
Can someone help with build a simple module with one function in it?
Can't seem to get anythign working.

I guess something like:

test.pl
---
use mystuff;

print mystuff::trim($username);

mystuff.pm
--
#do i need any declaration line here
#is sub here or what?
#and where do i put this pm file?

sub trim
{ my $z = $_[0];
  $z =~ s/^\s+//;
  $z =~ s/\s+$//;
  return $z;
}

thanks,
-rkl

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



Re: building module/package

2003-09-29 Thread Daniel Staal


--On Monday, September 29, 2003 19:04 -0700 [EMAIL PROTECTED] 
[EMAIL PROTECTED] wrote:

test.pl
---
use mystuff;
print mystuff::trim($username);

mystuff.pm
--
# do i need any declaration line here
# is sub here or what?
# and where do i put this pm file?
sub trim
{ my $z = $_[0];
  $z =~ s/^\s+//;
  $z =~ s/\s+$//;
  return $z;
}
You're almost good.  Add '1;' to the end of mystuff.pm, just to 
return a true value when it compiles, and 'package mystuff;' to the 
beginning of the same so Perl knows it is a package.  Also 'use 
warnings' and 'use strict' would be good in both...

As for where you put it: wherever you want.  Just make sure that it 
gets included in the @INC path.  The easiest is in the same folder as 
test.pl (assuming you always run test.pl from there), since the 
current folder is in the path.

Daniel T. Staal

---
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: remove blanks

2003-09-29 Thread Jeff 'japhy' Pinyan
On Sep 29, Hanson, Rob said:

I ran some benchmarks.

The two-liner outperformed the one-liners by a 10 to 1 ratio.  Code and
results below.

Benchmark: timing 10 iterations of OneLine, OneLine2, TwoLines...
  OneLine: 41 wallclock secs (39.30 usr +  0.00 sys = 39.30 CPU) @ 2544.79/s
  OneLine2: 34 wallclock secs (32.58 usr +  0.00 sys = 32.58 CPU) @
3069.56/s
  TwoLines:  3 wallclock secs ( 2.58 usr +  0.00 sys =  2.58 CPU) @
38789.76/s

You'll get a better representation with the following benchmark:

  #!/usr/bin/perl

  use Benchmark 'cmpthese';

  my $s = . join(  , ('foo') x 100) .;

  cmpthese(-5, {
capture = \capture,
alt = \alt,
two = \two,
two_rev = \two_rev,
  });

  sub capture {
my $copy = $s;
$copy =~ s/^\s*(.*?)\s*$/$1/s;
  }

  sub alt {
my $copy = $s;
$copy =~ s/^\s+|\s+$//g;
  }

  sub two {
my $copy = $s;
s/^\s+//, s/\s+$// for $copy;
  }

  sub two_rev {
my $copy = $s;
$copy =~ s/^\s+//;
($copy = reverse $copy) =~ s/^\s+//;
$copy = reverse $copy;
  }

The output is thus:

Benchmark: running alt, capture, two, two_rev for at least 5 CPU seconds
   alt:  5 wallclock secs @   4163.86/s (n= 21777)
   capture:  5 wallclock secs @   4876.60/s (n= 25846)
   two:  6 wallclock secs @  24841.44/s (n=130666)
   two_rev:  5 wallclock secs @ 148958.27/s (n=774583)

Rate alt capture two two_rev
alt   4164/s  ---15%-83%-97%
capture   4877/s 17%  ---80%-97%
two  24841/s497%409%  ---83%


Notice the string this time.  It's got embedded whitespace.  This causes
the '\s+$' regex to perform HORRIBLY.  If you want to see why, try this:

  perl -mre=debug -e 'abc  def  ghi  jkl  mno =~ /\s+$/'

Notice that the string abc  def...  mno doesn't end in whitespace, but
that the engine checks for /\s+$/ at each chunk of whitespace.  Icky
awful.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]



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



validate chars for a string

2003-09-29 Thread perl
Since, everyone is so lively today, I'm going to push my luck today with
this list. I need a little help here with validating a string to have only
characters that I want, A-z and _ (underscore).

So, this is what I'm stuck on:

#should fail because of space
$username=bob by;

if(isValidChars($username))
 ...

#is there a better way but it isn't working anyway.
sub isValidChars
{ my $retVal;

  @chars=split(//,$_[0]);

  for(@chars)
  {
if($_ =~ /A-z/) { print good [ . $_ . ]\n; $retVal=1; }
else { print bad [ . $_ . ]\n; $retVal=0; break; }
  }
  return $retval;
}


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



patches

2003-09-29 Thread Gupta, Sharad


Hi All,

Say i give one of my application to a customer. The customer runs it and finds a bug 
in there.
I don't want to give a fixed application again to the customer and ask him to go 
through the pain of installing it again.

Instead i create a patch and tell customer to install that patch.


The question is How to i create a patch, and how customer would install it.


Thanx,
-Sharad 



Re: patches

2003-09-29 Thread George Schlossnagle
man patch

On Monday, September 29, 2003, at 11:24  PM, Gupta, Sharad wrote:



Hi All,

Say i give one of my application to a customer. The customer runs it 
and finds a bug in there.
I don't want to give a fixed application again to the customer and ask 
him to go through the pain of installing it again.

Instead i create a patch and tell customer to install that patch.

The question is How to i create a patch, and how customer would 
install it.

Thanx,
-Sharad

-- George Schlossnagle
-- Principal Consultant
-- OmniTI Computer Consulting, Inc.
-- +1.410.872.4910 x202
-- 1024D/1100A5A0 1370 F70A 9365 96C9 2F5E  56C2 B2B9 262F 1100 A5A0
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: validate chars for a string

2003-09-29 Thread Jeff 'japhy' Pinyan
On Sep 29, [EMAIL PROTECTED] said:

Since, everyone is so lively today, I'm going to push my luck today with
this list. I need a little help here with validating a string to have only
characters that I want, A-z and _ (underscore).

You'll want to use a regular expression, or perhaps just the tr///
operator.

sub isValidChars
{ my $retVal;

  @chars=split(//,$_[0]);

  for(@chars)
  {
if($_ =~ /A-z/) { print good [ . $_ . ]\n; $retVal=1; }

First, you probably mean /[A-z]/.  Second, you probably mean /[A-Za-z_]/.
Third, it's silly to do this character-by-character.

else { print bad [ . $_ . ]\n; $retVal=0; break; }

break is spelled last in Perl.

  }
  return $retval;
}

Here are a few variations:

  sub isValidChars {
my $str = shift;
if ($str =~ /^[A-Za-z_]+$/) { return 1 }
else { return 0 }
  }

which can be written as simply

  sub isValidChars {
return shift =~ /^[A-Za-z_]+$/;
  }

and, in fact, the 'return' isn't necessary:

  sub isValidChars { shift =~ /^[A-Za-z_]+$/ }

Or you could do the opposite:  make sure the string DOESN'T have any
ILLEGAL characters in it.  The only problem with this is that an empty
string is considered valid.  That's why this approach includes a length()
test.

  sub isValidChars {
my $str = shift;
return length($str) and $str !~ /[^A-Za-z_]/;
  }

That returns true if and only if $str is non-zero in length and DOES NOT
contain a NON-[A-Za-z_] character.

Another way to do it is with tr///.

  sub isValidChars {
my $str = shift;
return length($str) and ($str =~ tr/A-Za-z_//c) == 0;
  }

This time, we use length() again, but we use the tr/// operator, instead
of the m// operator.  The tr/// takes a character class, basically, and
the /c modifier at the end means take the opposite of this class.  So
$str =~ tr/A-Za-z_//c is scanning $str for any NON-[A-Za-z_] characters.
tr/// returns the number of matching characters found.  If the number of
non-[A-Za-z_] characters is zero, and the length isn't zero, then it's a
valid string.

Which method should you use?  I'd probably use the simplest form of the
first isValidChars() I showed.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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



Re: validate chars for a string

2003-09-29 Thread perl
Lots of good stuff here. This oneliner is what makes perl cool but it's
like speaking in tongue -:)

   sub isValidChars { shift =~ /^[A-Za-z_]+$/ }


Thanks,
-rkl

 On Sep 29, [EMAIL PROTECTED] said:

Since, everyone is so lively today, I'm going to push my luck today with
this list. I need a little help here with validating a string to have
 only
characters that I want, A-z and _ (underscore).

 You'll want to use a regular expression, or perhaps just the tr///
 operator.

sub isValidChars
{ my $retVal;

  @chars=split(//,$_[0]);

  for(@chars)
  {
if($_ =~ /A-z/) { print good [ . $_ . ]\n; $retVal=1; }

 First, you probably mean /[A-z]/.  Second, you probably mean /[A-Za-z_]/.
 Third, it's silly to do this character-by-character.

else { print bad [ . $_ . ]\n; $retVal=0; break; }

 break is spelled last in Perl.

  }
  return $retval;
}

 Here are a few variations:

   sub isValidChars {
 my $str = shift;
 if ($str =~ /^[A-Za-z_]+$/) { return 1 }
 else { return  }
   }

 which can be written as simply

   sub isValidChars {
 return shift =~ /^[A-Za-z_]+$/;
   }

 and, in fact, the 'return' isn't necessary:

   sub isValidChars { shift =~ /^[A-Za-z_]+$/ }

 Or you could do the opposite:  make sure the string DOESN'T have any
 ILLEGAL characters in it.  The only problem with this is that an empty
 string is considered valid.  That's why this approach includes a length()
 test.

   sub isValidChars {
 my $str = shift;
 return length($str) and $str !~ /[^A-Za-z_]/;
   }

 That returns true if and only if $str is non-zero in length and DOES NOT
 contain a NON-[A-Za-z_] character.

 Another way to do it is with tr///.

   sub isValidChars {
 my $str = shift;
 return length($str) and ($str =~ tr/A-Za-z_//c) == 0;
   }

 This time, we use length() again, but we use the tr/// operator, instead
 of the m// operator.  The tr/// takes a character class, basically, and
 the /c modifier at the end means take the opposite of this class.  So
 $str =~ tr/A-Za-z_//c is scanning $str for any NON-[A-Za-z_] characters.
 tr/// returns the number of matching characters found.  If the number of
 non-[A-Za-z_] characters is zero, and the length isn't zero, then it's a
 valid string.

 Which method should you use?  I'd probably use the simplest form of the
 first isValidChars() I showed.

 --
 Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
 RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 stu what does y/// stand for?  tenderpuss why, yansliterate of course.
 [  I'm looking for programming work.  If you like my work, let me know.  ]


 --
 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 quotes or not quotes parameter

2003-09-29 Thread perl
what is the proper way to pass a parameter for something like
$cgi-param(username)?

as far as i know it, this works for me:

$cgi-param(username);
$cgi-param(username);
$cgi-param('username');

thanks,
-rkl

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