Re: Login code

2009-01-08 Thread David Dorward

Brent Clark wrote:

Would anyone have any example code of sessions for logins.


CGI::Session has some example code:

http://search.cpan.org/~markstos/CGI-Session-4.40/lib/CGI/Session.pm

If you want to use the Catalyst framework, their tutorial has a section 
on handling logins with sessions:


http://search.cpan.org/~hkclark/Catalyst-Manual-5.7016/lib/Catalyst/Manual/Tutorial/Authentication.pod

--
David Dorward
http://dorward.me.uk/

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




Re: Send email using SMTP

2009-01-08 Thread Adam Jimerson
Gunnar Hjalmarsson wrote:

 Adam Jimerson wrote:
 I solved my problem using the sendmail with the code below in my script:

 open (MAIL, |/usr/sbin/sendmail -t );
 print MAIL From: someaddr...@somedomain\n;
 print MAIL To: someaddre...@somedomain\n;
 print MAIL Content-Type: text/plain\n;
 print MAIL Subject: Very simple email test\n\n;
 print MAIL Body of the message;
 close (MAIL);
 
 This is kind of off topic, but are you using the -T switch on your
 script? When I tried to open /usr/bin/mail with that switch on I get a
 error message about an insecure environment command.
 
 Did it just say insecure environment? On my box it says: Insecure
 $ENV{PATH} ..., which means that you need to untaint the $ENV{PATH}
 variable. The easiest way to do that is:
 
  $ENV{PATH} = '';
 
 Please read more about Perl security in perldoc perlsec.
 

I wasn't able to remember what it exactly said, but yes it is about 
$ENV{PATH}, on my machine perldoc perlsec is riddled with formating problems 
it looks like, here is a copy of what I mean:

Perl automatically enables a set of special security checks, called 
ESC[4mtaintESC[24
m ESC[4mmodeESC[24m,
   when it detects its program running with differing real and effective 
user or
   group IDs.  The setuid bit in Unix permissions is mode 04000, the 
setgid bit mode
   02000; either or both may be set.  You can also enable taint mode 
explicitly by
   using the ESC[1m-T ESC[22mcommand line flag. This flag is 
ESC[4mstronglyESC[24m sugge
sted for server it is like that through out the whole thing, is it like 
this for anyone else?

Do I need to specify anything for the $ENV{PATH} or do I just leave it 
blank, sorry for asking but this might be faster then trying to decyhper the 
perldoc.


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




Re: Send email using SMTP

2009-01-08 Thread Gunnar Hjalmarsson

Adam Jimerson wrote:

Gunnar Hjalmarsson wrote:

Adam Jimerson wrote:
are you using the -T switch on your 
script? When I tried to open /usr/bin/mail with that switch on I get a 
error message about an insecure environment command.


Did it just say insecure environment? On my box it says: Insecure 
$ENV{PATH} ..., which means that you need to untaint the $ENV{PATH} 
variable. The easiest way to do that is:


 $ENV{PATH} = '';

Please read more about Perl security in perldoc perlsec.


I wasn't able to remember what it exactly said, but yes it is about 
$ENV{PATH}, on my machine perldoc perlsec is riddled with formating problems


You can always read it online: http://perldoc.perl.org/perlsec.html

Do I need to specify anything for the $ENV{PATH} or do I just leave it 
blank


It depends. You have to take into consideration whether your program 
relies on any of the paths. If not, it's fine to leave it blank.


--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

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




Re: Send email using SMTP

2009-01-08 Thread Mike Williams
On Thu, Jan 8, 2009 at 2:17 PM, Adam Jimerson vend...@charter.net wrote:

 
  Please read more about Perl security in perldoc perlsec.
 

 I wasn't able to remember what it exactly said, but yes it is about
 $ENV{PATH}, on my machine perldoc perlsec is riddled with formating
 problems
 it looks like, here is a copy of what I mean:

 Perl automatically enables a set of special security checks, called
 ESC[4mtaintESC[24
 m ESC[4mmodeESC[24m,


You can read the output of perldoc perlsec on the web at:
http://perldoc.perl.org/perlsec.html

What version of perl are you using?  What OS?

I've seen similar problems with perldoc a few years ago while using perl
5.6.1 on early versions of fedora and on windows.

You can also try perldoc -t perlsec which should get rid of most of the
ESC... stuff.

It will still leave some junk in places where perldoc is meant to display
bold or underlined characters, but it should get rid of most of the terminal
control stuff.

Mike


Re: make command throws error Perl script no found C:/Program No such file or directory

2009-01-08 Thread viji19812001
On Jan 6, 5:32 pm, rc...@pcug.org.au (Owen) wrote:
  Hi,

  I have perl5.10.0 installed under C:/ and using bash prompt to run a
 makecommand.

 How are you doing that?



  When I issue themakecommandit throws error

  Perl Script not found C:/Program no such file or directory

 Where is the script that you are trying to run?



  Perl is not installed in Program files it under c:

 It is not worried about perl, it is worried about the script



  Also I do understand it could be a spacing problem due to which it is
  not able to get Program Files.
  But Iam sure what it is trying to find in program files.

  I have C:/Perl/bin/perl5.10.0 added to my PATH variable.

  How do I sort out this issue.
  Or does program files contain some other requirement needed by the
 makefile.
  Please let me know.

 What is themakefile? Note that 'make' is not a perlcommand.

 Owen

Hi,

Iam running a windows machine and using cgywin.I need to run a
couple of bash commands in windows environment as it is the
requirement of the installation kit.
Basic requirements that is needed for instaaltion are
cgywin
VC++
Perl

Installed those and when I need to run a make command in one
particular directory of the kit it throws me this error.
Please suggest


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




Re: make command throws error Perl script no found C:/Program No such file or directory

2009-01-08 Thread Owen
 On Jan 6, 5:32 pm, rc...@pcug.org.au (Owen) wrote:
  Hi,

  I have perl5.10.0 installed under C:/ and using bash prompt to run
 a
 makecommand.

 How are you doing that?



  When I issue themakecommandit throws error

  Perl Script not found C:/Program no such file or directory

 Where is the script that you are trying to run?



  Perl is not installed in Program files it under c:

 It is not worried about perl, it is worried about the script



  Also I do understand it could be a spacing problem due to which it
 is
  not able to get Program Files.
  But Iam sure what it is trying to find in program files.

  I have C:/Perl/bin/perl5.10.0 added to my PATH variable.

  How do I sort out this issue.
  Or does program files contain some other requirement needed by the
 makefile.
  Please let me know.

 What is themakefile? Note that 'make' is not a perlcommand.

 Owen

 Hi,

 Iam running a windows machine and using cgywin.I need to run a
 couple of bash commands in windows environment as it is the
 requirement of the installation kit.
 Basic requirements that is needed for instaaltion are
 cgywin
 VC++
 Perl

 Installed those and when I need to run a make command in one
 particular directory of the kit it throws me this error.




I do not think it is possible to help you.

There is not enough information on what you are doing

Is there a forum for the program you are trying to install?

Look for the perl script and try and locate where it is. Go to that
directory and then run the make command

Owen







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




Neater way to declare variables

2009-01-08 Thread Taylor, Andrew (ASPIRE)
Hello

 

I have a script that is (at one point) reading through a file.  The file
is processed line by line and each line split into an array like so: 

 

while ($TESTFILE)

{

  my $cur_line=$_;

  chomp ($cur_line);



  my @split_line = split( /$t_delim/, $cur_line );

 

 

# In a number of places, I have code that looks like the following.

 

  my $default_type;

 

  if( $split_line[0] eq DEFAULT_INPUT )

  {

$default_type = INPUT;

  } 

 

  if ( $split_line[0] eq DEFAULT_OUTPUT )

  {

$default_type = OUTPUT;

  }

 

# processing continues...

# more stuff here

# blah blah blah

# etc. etc.

 

 

}

 

This works OK, but I'm trying to avoid declaring variables seperately
from assigning them (wherever possible), and trying to keep the size of
the script down without losing human legibility.  

 

Is there a neater/cleverer way of doing this?

 

Cheers

Andy Taylor

 

 

 


Andrew Taylor | Capgemini | Telford

ASPIRE Data Warehouse Support

T : +44 (0)1952 430684 | www.capgemini.com http://www.capgemini.com/ 

 

 


 


Capgemini is a trading name used by the Capgemini Group of companies which 
includes Capgemini UK plc, a company registered in England and Wales (number 
943935) whose registered office is at No. 1 Forge End, Woking, Surrey, GU21 6DB.
This message contains information that may be privileged or confidential and is 
the property of the Capgemini Group. It is intended only for the person to whom 
it is addressed. If you are not the intended recipient, you are not authorized 
to read, print, retain, copy, disseminate, distribute, or use this message or 
any part thereof. If you receive this message in error, please notify the 
sender immediately and delete all copies of this message.


Re: Neater way to declare variables

2009-01-08 Thread Mr. Shawn H. Corey
On Thu, 2009-01-08 at 11:56 +, Taylor, Andrew (ASPIRE) wrote:
 This works OK, but I'm trying to avoid declaring variables seperately
 from assigning them (wherever possible), and trying to keep the size
 of
 the script down without losing human legibility.  
 
 Is there a neater/cleverer way of doing this?
 

Programming is as much about organization and communication as it is
about coding.  It is possible to write your code too densely to be
easily understood.

However you can shorten some of your code.

while ($TESTFILE)
{
  chomp;
  my @split_line = split( /$t_delim/, $_ );


my %Default_types = (
  DEFAULT_INPUT = 'INPUT',
  DEFAULT_OUTPUT = 'OUTPUT',
);

$default_type = $Default_types{$split_line[0]} || undef;


-- 
Just my 0.0002 million dollars worth,
  Shawn

Programming is as much about organization and communication as it is about 
coding.

It would appear that we have reached the limits of what it is possible to 
achieve with computer technology, although one should be careful with such 
statements, as they tend to sound pretty silly in 5 years.
  --John von Neumann, circa 1950



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




Re: Neater way to declare variables

2009-01-08 Thread Telemachus
On Thu Jan 08 2009 @ 11:56, Taylor, Andrew (ASPIRE) wrote:
 # In a number of places, I have code that looks like the following.
 
  
 
   my $default_type;
 
  
 
   if( $split_line[0] eq DEFAULT_INPUT )
 
   {
 
 $default_type = INPUT;
 
   } 
snip
 This works OK, but I'm trying to avoid declaring variables seperately
 from assigning them (wherever possible), and trying to keep the size of
 the script down without losing human legibility.

You can use the statement modifier conditional form, in which case, the if
follows the assignment. Many people find this easier to read for such a simple
test:

my $default_type = INPUT if $split_line[0] eq DEFAULT_INPUT;

See here for more: http://perldoc.perl.org/perlsyn.html#Statement-Modifiers

Hope this helps, T


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




Re: Neater way to declare variables

2009-01-08 Thread Jenda Krynicky
From: Taylor, Andrew \(ASPIRE\) andrew.tayl...@hmrcaspire.com
 I have a script that is (at one point) reading through a file.  The file
 is processed line by line and each line split into an array like so: 
 
 while ($TESTFILE)
 {
   my $cur_line=$_;
   chomp ($cur_line);

while (defined(my $cur_line = $TESTFILE)) {
  chomp($cur_line);

   my $default_type;
   if( $split_line[0] eq DEFAULT_INPUT )
   {
 $default_type = INPUT;
   } 
   if ( $split_line[0] eq DEFAULT_OUTPUT )
   {
 $default_type = OUTPUT;
   }

my $default_type = do {
  if ($split_line[0] eq DEFAULT_INPUT ) {
INPUT
  } elsif ($split_line[0] eq DEFAULT_OUTPUT ) {
OUTPUT
  }
};

Jenda
= je...@krynicky.cz === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Re: Send email using smtp

2009-01-08 Thread Jenda Krynicky
From: Gunnar Hjalmarsson nore...@gunnar.cc
 Steve Bertrand wrote:
  Fúlvio Figueirôa wrote:
  I solved my problem using sendmail with the code below:
 
  open (MAIL, |/usr/sbin/sendmail -t );
  print MAIL From: someaddr...@somedomain\n;
  print MAIL To: someaddre...@somedomain\n;
  print MAIL Content-Type: text/plain\n;
  print MAIL Subject: Very simple email test\n\n;
  print MAIL Body of the message;
  close (MAIL);
 
  I've had issues with doing things this way in the past. From my
  experience with the above code, if there is a fault, the message will
  not be sent, nor will it be queued to be sent later. Depending on the
  situation, not having the program follow proper SMTP protocol could be a
  problem if a message is not delivered, and there is no trace of it in
  any queue.
 
  Perhaps someone here can verify that there is a workaround, but I would
  highly recommend at least handing off the message so that a proper MTA
  can take care of any network-type issues for you, even if the MTA is on
  the localhost.

 That comment confuses me. AFAIK, sendmail *is* an MTA (mail transfer
 agent), which e.g. handles queuing, and the above code passes a message
 to sendmail. I also believe that there are built-in defaults in sendmail
 that help you conform to certain aspects of the SMTP protocol.

sendmail is both an MTA and a commandline program for handing stuff
over to the MTA. The problem with this way to sending emails from
scripts is that it's hard to handle the errors reported directly by
the sendmail commandline program. Once this step succeeds, the email
is gonna be kept in the queue, retried etc. But if the sendmail
refuses the email right away, you'll never know. You'd have to check
the return value of the close(MAIL) to find out whether it succeeded
and capture and parse the /usr/bin/sendmail's STDERR to know what
failed.

It's generaly safer to leave this to a module. Either one that calls
the /usr/bin/sendmail in such a way that you do get the error info or
one that contains the MTA via SMTP, not via the commandline program.

Jenda
= je...@krynicky.cz === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




RegExp Searching - part deux

2009-01-08 Thread Paul M
What happens if I have a simple string:

my $line = 1elem21elema2a 1 bad13elema2 1 bad elemb2 bad 2 z 
1elemc2c13elemc2b13elemb2e13elem2;

That must follow simply rules:
Find every alpha character string between the numbers one and two. The string 
may not include the number one two or three.

SO:
1 bad13elema2 = no good, contains 1 and 3
1 bad 1elemb2 = no good, contains space
13elema2 = no good, contains 3

???



  

Re: RegExp Searching - part deux

2009-01-08 Thread Paul M
That was easier:
#!/usr/bin/perl

use strict; 
use warnings;

#my $line = 1elem21elema2a 1 bad13elema2eone 1 bad 1elemb2bone 2 
bad1elemc2c13elemc2btwo13elemb2etwo13elem2;
my $line = elem1elemaa  bad/elemae1  bad elembb1  
badelemcc/elemcb2/elembe2/elem1;
my $cnt = 0;

my @insides = $line =~ m{ elem1(.*?)\/elem1 }gmsx; 
for my $inside ( @insides ){
    print $inside;
     while( $inside =~ m{ ([^\s\/]*) }gmsx ){
      my $element = $1;
      $cnt = $cnt +1;
     #  unless( $element =~ m{ \A \/ }msx ){ 
           print \n$cnt=$1\n; 
         } 
    #} 
} 

4 any one to use :)
Let me know if you see any problems...
Thanks again everyone!

--- On Thu, 1/8/09, Paul M pjm...@yahoo.com wrote:
From: Paul M pjm...@yahoo.com
Subject: RegExp Searching - part deux
To: beginners@perl.org
Date: Thursday, January 8, 2009, 8:18 AM

What happens if I have a simple string:

my $line = 1elem21elema2a 1 bad13elema2 1 bad elemb2 bad 2 z
1elemc2c13elemc2b13elemb2e13elem2;

That must follow simply rules:
Find every alpha character string between the numbers one and two. The string
may not include the number one two or three.

SO:
1 bad13elema2 = no good, contains 1 and 3
1 bad 1elemb2 = no good, contains space
13elema2 = no good, contains 3

???



  


  

Re: Neater way to declare variables

2009-01-08 Thread Ron Bergin
On Jan 8, 3:56 am, andrew.tayl...@hmrcaspire.com (Andrew Taylor)
wrote:
 Hello

 I have a script that is (at one point) reading through a file.  The file
 is processed line by line and each line split into an array like so:

 while ($TESTFILE)

 {

   my $cur_line=$_;

   chomp ($cur_line);

while (my $cur_line = $TESTFILE) {
 chomp $cur_line;

   my @split_line = split( /$t_delim/, $cur_line );

 # In a number of places, I have code that looks like the following.

   my $default_type;

   if( $split_line[0] eq DEFAULT_INPUT )

   {

     $default_type = INPUT;

   }

   if ( $split_line[0] eq DEFAULT_OUTPUT )

   {

     $default_type = OUTPUT;

   }

snip


 This works OK, but I'm trying to avoid declaring variables seperately
 from assigning them (wherever possible), and trying to keep the size of
 the script down without losing human legibility.  

 Is there a neater/cleverer way of doing this?


my $default_type = $split_line[0] =~ /INPUT/ ? 'INPUT' : 'OUTPUT';


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




Re: How to know no. of times the script has been executed?

2009-01-08 Thread Mike Ward
sanket vaidya wrote:

  
 Hi all,
  
 I want to do something like this.
  
 Invoke a cmd (using system command) print a welcome message  execute the
 remaining part of script.
  
 Now what I want is
 1. cmd should only be invoked with welcome message if the script is
 executed first time.
 2. I want the remaining part of script to be executed till we exit the cmd
 session.
  
 e.g.
  
 script.pl
  
 system 'start cmd /k echo Welcome'
  
 {
  
 remaining part of script
  
 }
  
 cmd should be invoked only once at start of session  the remaining part
 should be executed till the end of session.
  
 Any hints. How to do that?

I'd just store the number of times it's been run in a .file in the home
directory (/home/user/.myscript). If the file doesn't yet exist, then it's
the first time the script has run. Otherwise read the number from the file,
and increment it.

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




perl books

2009-01-08 Thread Mike McClain
I have 'Programming Perl' and 'Learning Perl' and was fortunate 
enough to get 2 copies of 'Perl Cookbook' for Christmas, one of 
which I plan to return for exchange. After looking over O'Reilly's 
offerings I've narrowed my choices to these:

Mastering Perl By brian d foy
Perl Best Practices By Damian Conway
Mastering Algorithms with Perl By Jon Orwant, Jarkko Hietaniemi, John Macdonald
Intermediate Perl By Randal L. Schwartz, brian d foy, Tom Phoenix
Perl Hacks By chromatic , Damian Conway, Curtis Poe
Advanced Perl Programming, Second Edition By Simon Cozens
Perl for System Administration By David N. Blank-Edelman

I'm a primarily hardware tech and not programming for money and I guess
my question might ought to be which has the most meat in it?

Suggestions are invited particularily those accompanied by reasons.

Thanks,
Mike

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




OO confusion

2009-01-08 Thread root
The following script gives me confusing results. 
I've not delved into OOP before and am surprised when something 
appears to work but gives wrong answers.
Explicitly Digest::MD5's md5_hex gives wrong answers if called as
Digest::MD5-md5_hex. OK, I've figured out that it shouldn't be called
like that after the fact but am surprised that it appeared to work,
throwing no warnings or errors.
Err I forget, Debian 4.0 Etch (mostly), Perl 5.8.4 $ CPU = P1.

root@/deb40a:~/perl.practice md5sum md5_hex; ./md5_hex md5_hex; 
./md5_hex -d md5_hex; ./md5_hex -o md5_hex  # on one line
724d24ef7d8353f2061534850fd11bef  md5_hex
724d24ef7d8353f2061534850fd11bef  md5_hex
5e4c8a2bd461ae80cd9d0d08e1da12a3  md5_hex
724d24ef7d8353f2061534850fd11bef  md5_hex

Elucidation will be appreciated.
Thanks,
Mike

#!/usr/bin/perl
#   md5_hex 1/1/09 (c) Mike McClain
#   return md5 as /usr/bin/md5sum

use strict; #   this can be removed when all bugs are fixed
use warnings;   #   duplicates -w
use integer;
use Digest::MD5 qw(md5_hex);#   md5_hex 32 bytes long

$|++;   #   unbuffered STDOUT

my $myDebug = 0;
my $useOO = 0;
my( $target, $calcdMD5);

##  get CL switches
while( @ARGV  ($ARGV[0] =~ /-[do]/io) )
{   $myDebug = shift @ARGV  if( @ARGV  ($ARGV[0] =~ /-d/io) );
$useOO = shift @ARGVif( @ARGV  ($ARGV[0] =~ /-o/io) );
}
#   set debug from the CL as md5_hex -d3
$myDebug = substr($myDebug, 2)  if( length($myDebug)  2);

# print out the globals
if ( $myDebug  ($myDebug =~ /1/) )
{   print \$myDebug = $myDebug.\n;
print \$useOO = $useOO.\n;
print \...@argv = @ARGV\n;
}

foreach( @ARGV)
{   $target = $_;
if( $useOO)
{   open(FILE, $target) or die Can't open '$target': $!;
binmode(FILE);
print Digest::MD5-new-addfile(*FILE)-hexdigest,   $target\n;
close(FILE);
}
else
{   $calcdMD5 = cksum_file($target);
print $calcdMD5,   , $target, \n; 
}
}

#   --- end of main ---

sub cksum_file  #   ($file)
{   # return md5_hex sum of file or 0 if file doesn't exist
my $file = shift;
my $digest;
local $/;   # slurp mode

return '0'  if( ! -e $file);
open INFILE, $file || die Unable to open $file: $! stopped ;
binmode(INFILE);
my $data = INFILE ;
close INFILE;
if ( $myDebug ) #   this gives wrong answers
{   $digest = Digest::MD5-md5_hex($data); }
else
{   $digest = md5_hex($data); }
$digest;
}
__END__


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




Re: recursively find and print non-ascii characters in file

2009-01-08 Thread Mike McClain
On Thu, Jan 08, 2009 at 01:52:02AM +, Rob Dixon wrote:
 Chas. Owens wrote:
  File::Find::find(
 
 File::Find exports find() by default. It is better either to use the import or
 to prevent it altogether with
 
   use File::Find ();
 
 in the first place.
 
 Rob

In what way is it better?
Thanks,
Mike

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




Re: OO confusion

2009-01-08 Thread Chas. Owens
On Thu, Jan 8, 2009 at 17:47, root mike.j...@nethere.com wrote:
The following script gives me confusing results.
 I've not delved into OOP before and am surprised when something
 appears to work but gives wrong answers.
Explicitly Digest::MD5's md5_hex gives wrong answers if called as
 Digest::MD5-md5_hex. OK, I've figured out that it shouldn't be called
 like that after the fact but am surprised that it appeared to work,
 throwing no warnings or errors.
snip

It is giving the right answer.  You are asking the wrong question.
Module-method($arg) is roughly equivalent to Module::method('Module',
$arg).  What you are seeing is the md5sum of 'Digest::MD5'.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

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




Re: recursively find and print non-ascii characters in file

2009-01-08 Thread Chas. Owens
On Thu, Jan 8, 2009 at 14:10, Mike McClain mike.j...@nethere.com wrote:
 On Thu, Jan 08, 2009 at 01:52:02AM +, Rob Dixon wrote:
 Chas. Owens wrote:
  File::Find::find(

 File::Find exports find() by default. It is better either to use the import 
 or
 to prevent it altogether with

   use File::Find ();

 in the first place.

 Rob

 In what way is it better?
 Thanks,
 Mike

It is better in that File::Find doesn't pollute your name space with
its functions and variables.  I mistakenly thought that File::Find did
not export anything (I guess I am so used to typing $File::Find::name
that I assumed nothing was exported).


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

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




Re: Send email using smtp

2009-01-08 Thread Steve Bertrand
Jenda Krynicky wrote:
 From: Gunnar Hjalmarsson nore...@gunnar.cc
 Steve Bertrand wrote:
 Fúlvio Figueirôa wrote:
 I solved my problem using sendmail with the code below:

 open (MAIL, |/usr/sbin/sendmail -t );
 print MAIL From: someaddr...@somedomain\n;
 print MAIL To: someaddre...@somedomain\n;
 print MAIL Content-Type: text/plain\n;
 print MAIL Subject: Very simple email test\n\n;
 print MAIL Body of the message;
 close (MAIL);
 I've had issues with doing things this way in the past. From my
 experience with the above code, if there is a fault, the message will
 not be sent, nor will it be queued to be sent later. Depending on the
 situation, not having the program follow proper SMTP protocol could be a
 problem if a message is not delivered, and there is no trace of it in
 any queue.

 Perhaps someone here can verify that there is a workaround, but I would
 highly recommend at least handing off the message so that a proper MTA
 can take care of any network-type issues for you, even if the MTA is on
 the localhost.
 That comment confuses me. AFAIK, sendmail *is* an MTA (mail transfer 
 agent), which e.g. handles queuing, and the above code passes a message 
 to sendmail. I also believe that there are built-in defaults in sendmail 
 that help you conform to certain aspects of the SMTP protocol.
 
 sendmail is both an MTA and a commandline program for handing stuff 
 over to the MTA. The problem with this way to sending emails from 
 scripts is that it's hard to handle the errors reported directly by 
 the sendmail commandline program. Once this step succeeds, the email 
 is gonna be kept in the queue, retried etc. But if the sendmail 
 refuses the email right away, you'll never know. You'd have to check 
 the return value of the close(MAIL) to find out whether it succeeded 
 and capture and parse the /usr/bin/sendmail's STDERR to know what 
 failed.

Thank you.

I should have clarified the difference between sendmail the command-line
user agent, and Sendmail, listening as an MTA. Jenda spells out in a
more understandable way the consequences of using the command-line
`sendmail' from a Perl script.

 It's generaly safer to leave this to a module. Either one that calls 
 the /usr/bin/sendmail in such a way that you do get the error info or 
 one that contains the MTA via SMTP, not via the commandline program.

...it is clearly much safer to have error codes left for you in the
event that an email can not be delivered. Many modules will allow you to
catch the error and save the message even if the initial attempt to
contact an SMTP server fails.

In most circumstances, knowing that an email did not go out is
desirable. Further that, it's even better to have that attempted email
be saved, and if necessary, retried later.

Regarding my comment ...even if the MTA is on the localhost., Sendmail
runs by default on all FreeBSD systems I've ever built or used. Using a
module, you can hand off the message to localhost:25 or what-have-you,
and you can be sure that so long as you receive 'localhost' system
messages, you will be made aware if a queued message could not be
delivered to the destination domain's MX. Compare that to using the
command line sendmail, you will likely never know if the message
succeeded or not.

Thanks Jenda, for your clarification. It is much appreciated.

Steve

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




Re: OO confusion

2009-01-08 Thread John W. Krahn

root wrote:
The following script gives me confusing results. 
I've not delved into OOP before and am surprised when something 
appears to work but gives wrong answers.

Explicitly Digest::MD5's md5_hex gives wrong answers if called as
Digest::MD5-md5_hex. OK, I've figured out that it shouldn't be called
like that after the fact but am surprised that it appeared to work,
throwing no warnings or errors.
Err I forget, Debian 4.0 Etch (mostly), Perl 5.8.4 $ CPU = P1.

root@/deb40a:~/perl.practice md5sum md5_hex; ./md5_hex md5_hex; 
./md5_hex -d md5_hex; ./md5_hex -o md5_hex  # on one line

724d24ef7d8353f2061534850fd11bef  md5_hex
724d24ef7d8353f2061534850fd11bef  md5_hex
5e4c8a2bd461ae80cd9d0d08e1da12a3  md5_hex
724d24ef7d8353f2061534850fd11bef  md5_hex

Elucidation will be appreciated.
Thanks,
Mike

#!/usr/bin/perl
#   md5_hex 1/1/09 (c) Mike McClain
#   return md5 as /usr/bin/md5sum

use strict; #   this can be removed when all bugs are fixed
use warnings;   #   duplicates -w
use integer;
use Digest::MD5 qw(md5_hex);#   md5_hex 32 bytes long

$|++;   #   unbuffered STDOUT

my $myDebug = 0;
my $useOO = 0;
my( $target, $calcdMD5);

##  get CL switches
while( @ARGV  ($ARGV[0] =~ /-[do]/io) )
{   $myDebug = shift @ARGV  if( @ARGV  ($ARGV[0] =~ /-d/io) );
$useOO = shift @ARGVif( @ARGV  ($ARGV[0] =~ /-o/io) );
}
#   set debug from the CL as md5_hex -d3
$myDebug = substr($myDebug, 2)  if( length($myDebug)  2);

# print out the globals
if ( $myDebug  ($myDebug =~ /1/) )
{   print \$myDebug = $myDebug.\n;
print \$useOO = $useOO.\n;
print \...@argv = @ARGV\n;
}

foreach( @ARGV)
{   $target = $_;


More proper as:

foreach my $target ( @ARGV )



if( $useOO)
{   open(FILE, $target) or die Can't open '$target': $!;
binmode(FILE);


With modern versions of Perl you can use lexically scoped filehandles 
and the three argument form of open() which can include binmode in the mode:


 {   open(my $FILE, ':raw', $target) or die Can't open '$target': 
$!;




print Digest::MD5-new-addfile(*FILE)-hexdigest,   $target\n;
close(FILE);
}
else
{   $calcdMD5 = cksum_file($target);
print $calcdMD5,   , $target, \n; 
}

}

#   --- end of main ---

sub cksum_file  #   ($file)
{   # return md5_hex sum of file or 0 if file doesn't exist
my $file = shift;
my $digest;
local $/;   # slurp mode

return '0'  if( ! -e $file);

open INFILE, $file || die Unable to open $file: $! stopped ;


You have a precedence problem as the high precedence of the '||' 
operator means that this will not die() even if open() fails.  You need 
to either use parentheses for open's arguments or use the low precedence 
'or' operator.


Also, I wouldn't use a file test operator because the result from open() 
will already tell you whether the file exists or not.




binmode(INFILE);
my $data = INFILE ;
close INFILE;
if ( $myDebug ) #   this gives wrong answers
{   $digest = Digest::MD5-md5_hex($data); }
else
{   $digest = md5_hex($data); }
$digest;
}
__END__



John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

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




How to check whether user types exit in cmd?

2009-01-08 Thread sanket vaidya
Hi all,
 
I am invoking dos using 
system 'start cmd /k echo Welcome'
in my script
 
 
Now I want following:
 
If user types exit on does screen
{
do something
}
 
How to check whether user types 'exit' on dos screen.
 
Also I want 
 
If user closes the cmd window (by clickin 'x')
{
do something
}
 
How to do that?
 
Thanks  Regards,

Sanket Vaidya


http://www.patni.com
World-Wide Partnerships. World-Class Solutions. 
_ 

This e-mail message may contain proprietary, confidential or legally privileged 
information for the sole use of the person or entity to whom this message was 
originally addressed. Any review, e-transmission dissemination or other use of 
or taking of any action in reliance upon this information by persons or 
entities other than the intended recipient is prohibited. If you have received 
this e-mail in error kindly delete this e-mail from your records. If it appears 
that this mail has been forwarded to you without proper authority, please 
notify us immediately at netad...@patni.com and delete this mail.
_


RE: How to know no. of times the script has been executed?

2009-01-08 Thread sanket vaidya
 
Thanks for hint Mike. I think now I will be able to proceed.

-Original Message-
From: Mike Ward [mailto:m...@farematrix.com] 
Sent: Thursday, January 08, 2009 9:59 PM
To: beginners@perl.org
Subject: Re: How to know no. of times the script has been executed?

sanket vaidya wrote:

  
 Hi all,
  
 I want to do something like this.
  
 Invoke a cmd (using system command) print a welcome message  execute 
 the remaining part of script.
  
 Now what I want is
 1. cmd should only be invoked with welcome message if the script is 
 executed first time.
 2. I want the remaining part of script to be executed till we exit the 
 cmd session.
  
 e.g.
  
 script.pl
  
 system 'start cmd /k echo Welcome'
  
 {
  
 remaining part of script
  
 }
  
 cmd should be invoked only once at start of session  the remaining 
 part should be executed till the end of session.
  
 Any hints. How to do that?

I'd just store the number of times it's been run in a .file in the home
directory (/home/user/.myscript). If the file doesn't yet exist, then it's
the first time the script has run. Otherwise read the number from the file,
and increment it.

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


http://www.patni.com
World-Wide Partnerships. World-Class Solutions. 
_ 

This e-mail message may contain proprietary, confidential or legally privileged 
information for the sole use of the person or entity to whom this message was 
originally addressed. Any review, e-transmission dissemination or other use of 
or taking of any action in reliance upon this information by persons or 
entities other than the intended recipient is prohibited. If you have received 
this e-mail in error kindly delete this e-mail from your records. If it appears 
that this mail has been forwarded to you without proper authority, please 
notify us immediately at netad...@patni.com and delete this mail.
_

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