Perl and Python (Re: [prog] Re: [Techtalk] How to write web proxy in Python?)

sherzodr at ultracgis.com sherzodr at ultracgis.com
Thu Jan 9 16:51:56 EST 2003


 :Python, because Perl is almost unique in certain characteristics (its
 :scoping is global unless you "use strict;" isn't it? and subroutines
 :take a single list rather than named arguments, and I had trouble with
 :references, because of the function of $ both as a dereferencer and
 :coercing to scalar).


I'm not a Python guy, but I wanted to comment to the message really quick.
Perl5 supports OO interface as well, which wasn't mentioned.

As to the subroutines taking a single list rather then named arguments, 
it's not quite accurate, I think? All the arguments will be available
in the special array variable, "@_", but it doesn't mean you have to 
treat it as an array. You can write functions that take named arguments
in ANY order. The following send_email() function, for instance,
sends a simply email message. It supports such arguments
as 'subject', 'message', 'to', 'from', which have their own predefined
default values, which you can override if you choose so: 

# Usage: send_email(subject=>"Hello World", message=>"This is from Perl");
send_email {
   my %args = (
	to 	=> 'sherzodr at cpan.org',
	from 	=> 'Geek at geeks.com',
	subject => '[No Subject],
	message => '***EMPTY MESSAGE***',
 	@_,
  );

  open(MAIL, "|/usr/sbin/sendmail -t -oi") or die $!;
  print MAIL "From: $args{from}\nTo:$args{to}\n";
  print MAIL "Subject: $args{subject}\n\n";
  print MAIL $args{message};
  close(MAIL) or die "Couldn't send the email to $args{to}: $!\n";
} 


Since I'm not sure about Python, was woundering how does Python deal
with function arguments.

Sherzod





More information about the Programming mailing list