[23570] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5777 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 10 21:05:49 2003

Date: Mon, 10 Nov 2003 18:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 10 Nov 2003     Volume: 10 Number: 5777

Today's topics:
    Re: Dispatching sub in $var to SUPER without stringy ev <mb@uq.net.au>
    Re: Dispatching sub in $var to SUPER without stringy ev <mb@uq.net.au>
    Re: Dispatching sub in $var to SUPER without stringy ev <uri@stemsystems.com>
        LWP::UserAgent and SSL is it impossible? <paul@not2bspammed.com>
    Re: Perl help <lmbylsma@psych.upenn.edu>
    Re: Perl help (Tad McClellan)
        Perl Newbie (Harshit K)
    Re: Perl Newbie <ak+usenet@freeshell.org>
    Re: Perl Newbie <uri@stemsystems.com>
        print statement spanning multiple lines <voitec@zzzzzzzzz.com>
        Problems with Sendmail <Phantom_guitarist@thirteenthcoventry.co.uk.invalid>
    Re: Problems with Sendmail <noreply@gunnar.cc>
    Re: Style question: map versus foreach <dmcbride@naboo.to.org.no.spam.for.me>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 11 Nov 2003 10:06:51 +1000
From: Matthew Braid <mb@uq.net.au>
Subject: Re: Dispatching sub in $var to SUPER without stringy eval
Message-Id: <bop96q$o30$1@bunyip.cc.uq.edu.au>

Ben Morrow wrote:

> Matthew Braid <mb@uq.net.au> wrote:
> 
>>2. I make the AUTOLOAD this way so I don't _have_ to make a sub. In the 
>>case of the dispatching call (ie where Baz overrode Foo) I could do so, 
>>but I've often had trouble mixing OO with goto&. The docs don't mention 
>>it at all, so I'm never quite sure what I'm supposed to put - goto 
>>&$self->SUPER::whatever?
> 
> 
> No, you have to make sure that you *don't* shift the object off @_ and
> then call
> 
> goto &SUPER::method;
> 
> . I have to confess that I'm not entirely sure what this does to
> method dispatch... so it's possible that it won't work if &method is
> defined in a super-super-class. :)

It looks like goto&, OO and AUTOLOAD don't mix well. The code at the end 
of this message resulted in:

TEST2: BAZ
BAZ ERROR: Goto undefined subroutine &SUPER::baz at test.pl line 46.

BLING ERROR: Goto undefined subroutine &SUPER::bling at test.pl line 46.

ULTRATEST: GRUMBLE!
which means goto& worked for when the function is defined in one of the 
superclasses (SUPER::new worked as did SUPER::grumble), but not when the 
function is emulated by AUTOLOAD (SUPER::baz failed) or when its defined 
in a super-super class (SUPER::bling failed).

> 
>>4. I'm going to have to look at this further. Some of this is old code 
>>that I inherited and for the life of me I can't tell you why the eval is 
>>there. I take it that the die results would look the same either way?
> 
> 
> Yes... I guess someone may have been thinking to catch the fact that
> the method didn't exist, and never got round tuit... UNIVERSAL::can is
> a better choice for that, though.

I'll look into UNIVERSAL::can. In the mean time I'll just get rid of the 
eval entirely, save myself some opcodes :)

MB



------------------------------

Date: Tue, 11 Nov 2003 10:08:24 +1000
From: Matthew Braid <mb@uq.net.au>
Subject: Re: Dispatching sub in $var to SUPER without stringy eval
Message-Id: <bop99n$o30$2@bunyip.cc.uq.edu.au>

Matthew Braid wrote:

> Ben Morrow wrote:
> 
>> Matthew Braid <mb@uq.net.au> wrote:
>>
>>> 2. I make the AUTOLOAD this way so I don't _have_ to make a sub. In 
>>> the case of the dispatching call (ie where Baz overrode Foo) I could 
>>> do so, but I've often had trouble mixing OO with goto&. The docs 
>>> don't mention it at all, so I'm never quite sure what I'm supposed to 
>>> put - goto &$self->SUPER::whatever?
>>
>>
>>
>> No, you have to make sure that you *don't* shift the object off @_ and
>> then call
>>
>> goto &SUPER::method;
>>
>> . I have to confess that I'm not entirely sure what this does to
>> method dispatch... so it's possible that it won't work if &method is
>> defined in a super-super-class. :)
> 
> 
> It looks like goto&, OO and AUTOLOAD don't mix well. The code at the end 
> of this message resulted in:
> 
> TEST2: BAZ
> BAZ ERROR: Goto undefined subroutine &SUPER::baz at test.pl line 46.
> 
> BLING ERROR: Goto undefined subroutine &SUPER::bling at test.pl line 46.
> 
> ULTRATEST: GRUMBLE!
> which means goto& worked for when the function is defined in one of the 
> superclasses (SUPER::new worked as did SUPER::grumble), but not when the 
> function is emulated by AUTOLOAD (SUPER::baz failed) or when its defined 
> in a super-super class (SUPER::bling failed).
> 
>>
>>> 4. I'm going to have to look at this further. Some of this is old 
>>> code that I inherited and for the life of me I can't tell you why the 
>>> eval is there. I take it that the die results would look the same 
>>> either way?
>>
>>
>>
>> Yes... I guess someone may have been thinking to catch the fact that
>> the method didn't exist, and never got round tuit... UNIVERSAL::can is
>> a better choice for that, though.
> 
> 
> I'll look into UNIVERSAL::can. In the mean time I'll just get rid of the 
> eval entirely, save myself some opcodes :)
> 
> MB
> 
Whoops - here's the code:

package UltraTest;

sub grumble {
   print "ULTRATEST: GRUMBLE!\n";
}

package SuperTest;

sub bling {
   print "SUPERTEST: BLING!\n";
}

package Test;

use base qw/SuperTest/;

sub new {
   my $class = shift;
   return bless({}, (ref($class) or $class or __PACKAGE__));
}

sub AUTOLOAD {
   my $self = shift;
   my $var = $AUTOLOAD;
   $var =~ s/^.*:://;
   if ($var eq 'baz') {
     print "TEST: BAZ\n";
   } else {
     die "TEST: FAIL $var!\n";
   }
}

package Test2;

use base qw/Test UltraTest/;

sub AUTOLOAD {
   my $var = $AUTOLOAD;
   $var =~ s/^.*:://;
   if ($var eq 'baz') {
     print "TEST2: BAZ\n";
   }
   $var = "SUPER::$var";
   goto &$var;
}

package main;

my $test = Test2->new;
eval {$test->baz};
print "BAZ ERROR: $@\n" if $@;
eval {$test->bling};
print "BLING ERROR: $@\n" if $@;
eval {$test->grumble};
print "GRUMBLE ERROR: $@\n" if $@;



------------------------------

Date: Tue, 11 Nov 2003 01:27:19 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Dispatching sub in $var to SUPER without stringy eval
Message-Id: <x7ekwfzocp.fsf@mail.sysarch.com>

>>>>> "MB" == Matthew Braid <mb@uq.net.au> writes:

  MB> Ben Morrow wrote:
  >> Matthew Braid <mb@uq.net.au> wrote:
  >> 
  >>> 2. I make the AUTOLOAD this way so I don't _have_ to make a sub. In
  >>> the case of the dispatching call (ie where Baz overrode Foo) I
  >>> could do so, but I've often had trouble mixing OO with goto&. The
  >>> docs don't mention it at all, so I'm never quite sure what I'm
  >>> supposed to put - goto &$self->SUPER::whatever?
  >> No, you have to make sure that you *don't* shift the object off @_
  >> and
  >> then call
  >> goto &SUPER::method;
  >> . I have to confess that I'm not entirely sure what this does to
  >> method dispatch... so it's possible that it won't work if &method is
  >> defined in a super-super-class. :)

  MB> It looks like goto&, OO and AUTOLOAD don't mix well. The code at the
  MB> end of this message resulted in:

huh? they mix perfectly well together. you just need to know the correct
recipes.


  MB> TEST2: BAZ
  MB> BAZ ERROR: Goto undefined subroutine &SUPER::baz at test.pl line 46.

  MB> BLING ERROR: Goto undefined subroutine &SUPER::bling at test.pl line 46.

SUPER is not a real sub but a pseudo method. so you have to call it via
a method call. magic goto requires a real sub as its argument.

  MB> ULTRATEST: GRUMBLE!
  MB> which means goto& worked for when the function is defined in one of
  MB> the superclasses (SUPER::new worked as did SUPER::grumble), but not
  MB> when the function is emulated by AUTOLOAD (SUPER::baz failed) or when
  MB> its defined in a super-super class (SUPER::bling failed).

all SUPER does is allow you to call a method on the object but start the
method search in a different (the parent of the current class IIRC)
place. it does nothing different regarding AUTOLOAD. if an AUTOLOAD in
the parent class's @ISA tree is found, it will be called.

  MB> I'll look into UNIVERSAL::can. In the mean time I'll just get rid of
  MB> the eval entirely, save myself some opcodes :)

don't mung UNIVERSAL as it will be visible to every other module
forever. not a smart thing.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Mon, 10 Nov 2003 17:49:02 -0700
From: Paul Lemmons <paul@not2bspammed.com>
Subject: LWP::UserAgent and SSL is it impossible?
Message-Id: <2mWrb.1138$Js3.103993@news.uswest.net>

I have spent most of the day trying to get this to work. I have visited 
hundreds of web pages and it appears to be a common frustration but 
nobody seems to be posting any solutions I am beginning to wonder if it 
is impossible.

I want to script a login to a secure web site in perl. The web site is 
using session cookies and SSL. It is not using basic authentication. No 
matter what I try I always get "Authentication failed!" returned from 
the server.

If I understand correctly how this should work, I would get a successful 
response from this request along with a cookie that I would use for all 
subsequent requests. I am not getting that cookie because I am not 
getting success.

If this truly is impossible, please, someone say so so I can quit 
beating my head against this. If you have actually gotten this to work I 
would be thrilled if you could share your solution!

Thank you!!

===============================================
Here is my code. It is fairly straight forward:
===============================================

#!/usr/local/bin/perl
use HTTP::Cookies;
use HTTP::Request;
use HTTP::Request::Common;
use LWP::UserAgent;

$cookie_jar = new HTTP::Cookies(ignore_discard => TRUE);


$ua  = new LWP::UserAgent;
$ua->agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) 
Gecko/20031007 Firebird/0.7');
$ua->cookie_jar($cookie_jar);

$content = 
join('&','Username=myuserid','Password=mypassword','URL=%2Fdefault.asp');

$req = new HTTP::Request 'POST' => 
'https://xxx.yyy.com/_mem_bin/verifpwd.asp';
$req->header('Host'             => 'xxx.yyy.com');
$req->header('Keep-Alive'       => '300');
$req->header('Connection'       => 'Keep-Alive');
$req->header('Accept'           => 
'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1');
$req->header('Accept-Language'  => 'en-us,en;q=0.5');
$req->header('Accept-Encoding'  => 'gzip,deflate');
$req->header('Accept-Charset'   => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7');
$req->header('Referer'          => 
'https://xxx.yyy.com/public/login.asp?/default.asp');
$req->header('Content-Type'     => 'application/x-www-form-urlencoded');
$req->header('Content'          => $content);

print "-----------------------------------------------------\n";
print "HTTP::Request\n";
print "-----------------------------------------------------\n";
print $req->as_string();

$res = $ua->request($req);

$cookie_jar->extract_cookies($res);
$cookie_jar->save("cookie_jar");
print "-----------------------------------------------------\n";
print "Cookie after UA Request\n";
print "-----------------------------------------------------\n";
print $cookie_jar->as_string();

if ($res->is_success)
{
    print "-----------------------------------------------------\n";
    print "UA->Request\n";
    print "-----------------------------------------------------\n";
    print $res->request->as_string();
    print "-----------------------------------------------------\n";
    print "Contents\n";
    print "-----------------------------------------------------\n";
    print $res->content;
    print "\n-----------------------------------------------------\n";
    print "Done\n";
    print "-----------------------------------------------------\n\n\n";
}
else
{
    print $res->error_as_HTML;
}



===============================================
The output of the program is:
===============================================


-----------------------------------------------------
HTTP::Request
-----------------------------------------------------
POST https://xxx.yyy.com/_mem_bin/verifpwd.asp
Connection: Keep-Alive
Accept: 
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding: gzip,deflate
Accept-Language: en-us,en;q=0.5
Host: xxx.yyy.com
Referer: https://xxx.yyy.com/public/login.asp?/default.asp
Content-Type: application/x-www-form-urlencoded
Content: Username=myuserid&Password=mypassword&URL=%2Fdefault.asp
Keep-Alive: 300


-----------------------------------------------------
Cookie after UA Request
-----------------------------------------------------
Set-Cookie3: ASPSESSIONIDASBBDDQA=JKCCBIMAFOFOBNLMJLHOLFAL; path="/"; 
domain=xxx.yyy.com; path_spec; discard; version=0
Set-Cookie3: TriedToLogin=1; path="/"; domain=xxx.yyy.com; path_spec; 
discard; version=0
-----------------------------------------------------
UA->request
-----------------------------------------------------
POST https://xxx.yyy.com/_mem_bin/verifpwd.asp
Connection: Keep-Alive
Accept: 
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding: gzip,deflate
Accept-Language: en-us,en;q=0.5
Host: xxx.yyy.com
Referer: https://xxx.yyy.com/public/login.asp?/default.asp
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) 
Gecko/20031007 Firebird/0.7
Content-Type: application/x-www-form-urlencoded
Content: Username=myuserid&Password=mypassword&URL=%2Fdefault.asp
Keep-Alive: 300


-----------------------------------------------------
Contents
-----------------------------------------------------
Authentication failed. Please try logging in again.<br>Use the back 
button on your browser to try again.
-----------------------------------------------------
Done
-----------------------------------------------------



------------------------------

Date: Mon, 10 Nov 2003 19:53:29 -0500
From: "Lauren M. Bylsma" <lmbylsma@psych.upenn.edu>
Subject: Re: Perl help
Message-Id: <bopbue$12hr$1@netnews.upenn.edu>

I guess I was unclear, sorry I'm new to this.  This is the output I would
want from the portion of the data file I provided earlier:

3.92090           1
16.37657         1
19.26123         1
22.21257         1
25.54742         1
214.23345       0
238.11100       0
287.04997       0
379.90897       0
431.91602       0

So I would want that stored into one array.  I guess column isn't the
technical term but they sure look like columns to me.

-Lauren


"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbr059j.cmu.tadmc@magna.augustmail.com...
> Lauren M. Bylsma <lmbylsma@psych.upenn.edu> wrote:
>
> > Subject: Perl help
>
>
> Please put the subject of your post in the Subject of your post.
>
> Have you seen the Posting Guidelines that are posted here frequently?
>
>
> > What I want to do is take the numbers under Channel 13 and put them in
an
> > array then Channel 14 in a separate array.  Then I want to add another
> > column to each.
>
>
> "column"?
>
> What column?
>
> I do not see any columns.
>
> You would need a multi-dim array in order to have columns.
>
>
> > For channel 13 I want this other column to contain all 1's.
> > For Channel 14 I want this column to contain all 0's.
>
>
> I'll need to ignore that part of the specification, as I don't
> understand what it means...
>
>
> > Then I want to put
> > them together
> > into one big array and sort it by number from smallest to largest.
>
>
> --------------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my @combined;
> {  local $/ = '';  # enable paragraph mode
>    while (<DATA>) {
>       next unless /^"CHANNEL" "(\d+)"/;
>       my @nums = split /\n/, scalar <DATA>;  # read the next para
>       push @combined, @nums;
>    }
> }
>
> print "$_\n" for sort { $a <=> $b } @combined;
>
> __DATA__
> "INFORMATION"
> "b2jun0302"
> ""
> ""
> ""
> ""
> ""
>
> "SUMMARY"
> "13" "Evt-" "correct" 1
> "14" "Evt-" "incorrect" 1
> "19" "Evt-" "rcor" 1
> "20" "Evt-" "rincor" 1
> "32" "Marker" "untitled"
>
> "CHANNEL" "13"
> "Evt-"
> "No comment"
> "correct"
>
> 3.92090
> 16.37657
> 19.26123
> 22.21257
> 25.54742
>
> "CHANNEL" "14"
> "Evt-"
> "No comment"
> "incorrect"
>
> 214.23345
> 238.11100
> 287.04997
> 379.90897
> 431.91602
> --------------------------------------
>
>
> -- 
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas




------------------------------

Date: Mon, 10 Nov 2003 19:51:43 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl help
Message-Id: <slrnbr0g5f.dg4.tadmc@magna.augustmail.com>


[ Please do not post upside-down.
  Please do not quote an _entire_ article.
  Please do not quote .sigs.
  Have you seen the Posting Guidelines that are posted here frequently?
]


Lauren M. Bylsma <lmbylsma@psych.upenn.edu> wrote:

> This is the output I would
> want from the portion of the data file I provided earlier:
> 
> 3.92090           1
> 16.37657         1
> 19.26123         1
> 22.21257         1
> 25.54742         1
> 214.23345       0
> 238.11100       0
> 287.04997       0
> 379.90897       0
> 431.91602       0



> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnbr059j.cmu.tadmc@magna.augustmail.com...

>> --------------------------------------
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>>
>> my @combined;
>> {  local $/ = '';  # enable paragraph mode
>>    while (<DATA>) {
>>       next unless /^"CHANNEL" "(\d+)"/;


   my $extra = $1 == 13 ? '1' : '0';   # untested


>>       my @nums = split /\n/, scalar <DATA>;  # read the next para
>>       push @combined, @nums;


   push @combined, map "$_   $extra", @nums;  # also untested


>>    }
>> }
>>
>> print "$_\n" for sort { $a <=> $b } @combined;



-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 10 Nov 2003 16:01:28 -0800
From: harshit2000k@yahoo.com (Harshit K)
Subject: Perl Newbie
Message-Id: <2cff8447.0311101601.55c8d72c@posting.google.com>

Hi all,

I am sorry if this is a repeated question, maybe I missed it out. I am
a newbie to perl, so could you suggest some good books on perl.

Thanks


------------------------------

Date: Tue, 11 Nov 2003 00:37:53 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: Perl Newbie
Message-Id: <slrnbr0bqo.1iv.ak+usenet@norge.freeshell.org>

In article <2cff8447.0311101601.55c8d72c@posting.google.com>, Harshit K wrote:
> I am sorry if this is a repeated question, maybe I missed it out. I am
> a newbie to perl, so could you suggest some good books on perl.


    http://www.perl.org/books.html


-- 
Andreas Kähäri


------------------------------

Date: Tue, 11 Nov 2003 01:21:44 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Perl Newbie
Message-Id: <x7he1bzom0.fsf@mail.sysarch.com>

>>>>> "AK" == Andreas Kahari <ak+usenet@freeshell.org> writes:

  AK> In article <2cff8447.0311101601.55c8d72c@posting.google.com>, Harshit K wrote:
  >> I am sorry if this is a repeated question, maybe I missed it out. I am
  >> a newbie to perl, so could you suggest some good books on perl.


  AK>     http://www.perl.org/books.html

and even better is the perl books site:

	books.perl.org

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Tue, 11 Nov 2003 01:48:56 GMT
From: "Voitec" <voitec@zzzzzzzzz.com>
Subject: print statement spanning multiple lines
Message-Id: <ceXrb.6024$aT.23@news-server.bigpond.net.au>

Hi,

St00pid question time:
How can I make a print statement span several lines without affecting the
final formatting?

I'm sure there was a 'line continuation' character of some sort which we
could insert.

For example, instead of having
        print
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbb";

we can have
        print "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" LINE CONTINUE CHAR
                    "bbbbbbbbbbbbbbbbbbbb";

I just want to get my indenting look a bit better.
I can always use 2 print statements instead but do I need to?

Thanks
Voitec




------------------------------

Date: Mon, 10 Nov 2003 23:09:02 -0000
From: "Phantom_guitarist" <Phantom_guitarist@thirteenthcoventry.co.uk.invalid>
Subject: Problems with Sendmail
Message-Id: <bop5rh$egk$1@news6.svr.pol.co.uk>

I am currently having problems creating a script to send an email from perl.
I have got the script down to the bare minimum;

#!/usr/bin/perl
print "Content-type:text/html\n\n";
&mail('myemail@myaddress.co.uk','myemail@myaddress.co.uk','Test
Message','Test Message');
print "<br>Mail Sent";

sub mail
 {
 print "Preparing to send<br>";
 # first param is recipient
 # second is from
 # third is subject
 # fourth is message
 $mailprog = '/usr/sbin/sendmail';
 $recipient = $_[0];
 $from = $_[1];
 $subject = $_[2];
 $message = $_[3];
 print "To: $recipient\n<br>";
 print "From: $from\n<br>";
 print "Subject: $subject\n\n<br>";
 print $message;
 print "<br>";

 open(MAIL,'|$mailprog')|| &error("Cant locate mail program");
  print MAIL "To: $recipient\n";
  print MAIL "From: $from\n";
  print MAIL "Subject: $subject\n\n";
  print MAIL $message;
 close (MAIL);
 }
sub error
 {
 print "Content-type:text/html\n\n";
 print $_[0];
 exit;


but for some reason this doesn't work.  It doesn't display any messages and
the script runs fine.  I have contact the domain hosting I am with
(http://www.kthosting.com) and they couldn't give me any reason why the
script doesn't work.  They have a FromMail.cgi script on their site and that
seems to work ok on sending to my address.  If any one knows of any issues
that I am maybe overlooking your help would be very much appreciated.


Stefan






------------------------------

Date: Tue, 11 Nov 2003 00:34:56 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Problems with Sendmail
Message-Id: <bop7h4$1gef2t$1@ID-184292.news.uni-berlin.de>

Phantom_guitarist wrote:
> If any one knows of any issues that I am maybe overlooking your
> help would be very much appreciated.

     open(MAIL,'|$mailprog -t')|| &error("Cant locate mail program");
-------------------------^^^

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



------------------------------

Date: Tue, 11 Nov 2003 00:54:36 GMT
From: Darin McBride <dmcbride@naboo.to.org.no.spam.for.me>
Subject: Re: Style question: map versus foreach
Message-Id: <grWrb.362981$pl3.319787@pd7tw3no>

Abigail wrote:

> Darin McBride (dmcbride@naboo.to.org.no.spam.for.me) wrote on MMMDCCXXIII
> September MCMXCIII in <URL:news:RKQrb.361373$6C4.143831@pd7tw1no>:
> ::  Abigail wrote:
> ::  
> :: > If you're going to assume the maintainer doesn't know basic concepts
> :: > of Perl, all bets are off. Then one might want to avoid hashes and
> :: > regexes too.
> ::  
> ::  True to a point.  However, there is no cleaner way to do hashes or
> ::  regexes.  There is a clearer way to do map in void context: foreach.
> 
> But could you give an objective reason why foreach is "clearer" than
> map (after defining what "clearer" is)? Or is it your own preference?

<sigh>  I thought I had.  Let me try again:

The only real difference between map and foreach is that map returns a
value, while foreach doesn't [1].  Thus, if you intend on ignoring the
return, don't create it in the first place and just use foreach.

[1] Foreach actually returns the same way any block does - the last
statement executed in the last time through the loop is the return
value.  But this is not generally useful.  It only makes perl more
consistant.

> What makes foreach cleaner than while? Or is while cleaner than
> foreach? Which one ought to go?  Or can we have foreach, for, while,
> until, goto, and bare blocks, but not map in void context?

While vs foreach is another discussion (I wish we'd stick to a single
topic, but that's not generally possible on usenet, I suspect).  If the
only data I have to work with is whether we're in void context or not,
then neither while nor foreach are different.  However, they have other
strengths which would come up should we actually debate those.  Again,
use whichever one makes the most readable sense.

Until vs while is easy - again, the most readable one wins.  If your
assertion is positive, use while, if it is negative, use until.

And now we're really straying off the topic of this thread.

> You can do loops in the following ways:

[ If you're trying to be pedantic, you missed some. ]

>  1  C style for

Good for when you have a C-style index.

>  2  Perl style foreach

Good for when you have a perl-style index.

>  3  for statement modifier

Good when what you're trying to do is an action, and it happens to be
looped, rather than what you're trying to do is loop, and during the
loop you want to do something.  Use the right loop construct for what
you're trying to do rather than try to jimmy the wrong construct into
doing what you want (which is what you have to do in most other
languages with limited choices).

>  4  while
>  5  until

These are the same as each other with the minor difference noted above
- one's assertion is positive while the other is negative.  Good when
you're waiting for a condition to be false/true, and until that
happens, you want to do stuff.

>  6  bare blocks

Hmmm - there is probably a bit more needed here (redo?)  I would
definitely not recommend this.

>  7  s///g

Good if you're making regex substitutions.

>  8  m//

Good if you're trying to find many of the same thing in a given string.

>  9  goto

Not generally good for looping - there is usually a better construct
for what you're trying to do.

> 10  map

Good if you're mapping one space (array) onto another space (array).

> 11  grep

Good for finding a subset of a given array.

> Don't pick on map in void context. Could you please pick one, and make
> a case against the other 10, and not just map?

Use the one that fits the job you have for it.  Both map and m// are
there to create an array.  If you don't want the array, I fail to see
why you'd use m//, but for map, foreach is exactly equivalent in the
void context.  Use it.

> ::  The main point of map is the return value.  The main point of foreach
> ::  is the iteration over an array (no return value implied).
> ::  
> ::         o   Avoid using grep() (or map()) or `backticks` in a void
> ::             context, that is, when you just throw away their
> ::             return values.  Those functions all have return val-
> ::             ues, so use them.  Otherwise use a foreach() loop or
> ::             the system() function instead.
> ::  
> ::  I think this is the whole debate.  Unfortunately, there's no real
> ::  explicit justification here.
> 
> Which makes it just the personal preference of one man, doesn't it?

No - it means that the perlstyle authors (who are probably more
proficient in perl than the both of us put together) thought this would
be obvious and unneeding of justification.

> ::  Given that map and foreach do almost exactly the same thing with only
> ::  the desired contexts being different, it makes sense to me that one
> ::  would use the version one desires based on that context difference.
> ::  Thus, when I see map in void context, the first thought in my mind is
> ::  "they didn't get the return from map!".
> 
> Ah, yes. Logical. There are thousands and thousands of user defined
> functions whose return value isn't collected. There are many Perl
> defined functions and operators whose return value isn't collected.
> 
> Noone ever makes a fuss. But if the function of which the return

I do.  If there are two user defined functions that do exactly the same
thing, but one allocates and returns an array, and the other does not
but has the same desired side effects, I would expect people to use the
appropriate one depending on whether they want the array returned or
not.  I don't see any difference.

> value isn't collected is called "map", hundreds of Perl programmer
> brains go into overload, and the programmers start running around
> like chickens without their heads. "They didn't get the return from
> map! They didn't get the return from map! Keep your daughters inside!
> Keep your daughters inside! The end of times in coming! The antichrist
> has arrived!"

I'm not sure that the Six Degrees of Godwin game would have anticipated
this as "legitimate topic drift".

> I really don't get it. map in void context isn't doing anything else
> than the countless of other functions in void context that are called
> because of their side effects. Yet it sparks gigabytes of discussions.

Only because there is an exact duplicate of map functionally that is
there for void context.

> ::                                           Then, after scrutinising the
> ::  map's block (as it's usually a block not an expression), I may figure
> ::  out that they intended to have void (e.g., only doing it for the side
> ::  effect).  And then, if that's not the source of the problem, I can go
> ::  on.
> 
> But if the function wasn't called "map", but "zeebleflup", and it was
> used in void context, would you get confused as well? What if it was
> called "apply_this_function_over_the_elements_of_a_list"?

Well, if it were called "zeebleflup", I'd be looking for zeebleflup's
definition to understand what the heck it is, and why someone thought
that this was a brilliant name to give a function.

You see, I'm not worried about some "map" crusade.  I'm looking for
readability.  I'd be just as curious about why someone calls map in
void context as someone calling $my_circle->get_radius() in void
context.  If someone was looking at the return to a function that
obviously shouldn't have one, I'd be just as curious (although I can't
think of an example function name that would cause me to think this
offhand).

> ::  However, if they had used foreach to begin with, I might have been
> ::  able to skip over the code altogether knowing that "ignoring the
> ::  return" is exactly what was intended.
> 
> Again, why do you assume that if map was used in void context the
> programmer was in error, and you have to confirm yourself it wasn't the
> case, and you don't have this Pavlov reaction with other functions? What
> makes map trigger this behaviour?

Who said I don't have this reaction to any other function?  Perhaps
some of your previous sparring partners are that way, but you paint me
unfairly with the same brush.  If I were into the same ad hominum style
debate, I'd start wondering about your knee-jerk reactions...

> ::  Simply have your code say what you mean rather than trick the virtual
> ::  machine into doing what you want by side effect.
> 
> If I write:
> 
>     map {BLOCK} LIST;
> 
> I write *exactly* what I mean. I want to map an operation over a list.
> It simple can't be named simpler.

If we were writing LISP where that's what map means, that's fine.  But
in perl, if you want to "map an operation over a list", that's called
"foreach".

> ::                                                    In general, side
> ::  effects make code harder to understand.
> 
> Then you shouldn't be programming in Perl. Because in Perl, you can't
> do much useful without side effects.

Hmmm... I dunno - I've managed to do a lot of useful stuff without side
effects in perl.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5777
***************************************


home help back first fref pref prev next nref lref last post