[22070] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4292 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 19 18:18:22 2002

Date: Thu, 19 Dec 2002 15:10:17 -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           Thu, 19 Dec 2002     Volume: 10 Number: 4292

Today's topics:
    Re: Negation inside a pattern match <goldbb2@earthlink.net>
    Re: perl regexp to extract table out of HTML ->>>> use  <willis3140@com.yahoo>
        Precedence of => (was Re: Why does Perl handle "return  <goldbb2@earthlink.net>
    Re: Replacing text strings contains more than 1 dot <krahnj@acm.org>
        search and replace text in many files (BobbyD)
        sorting in hashes of hashes <srsriram@xyz.com>
    Re: sorting in hashes of hashes <krahnj@acm.org>
    Re: sorting in hashes of hashes <mgjv@tradingpost.com.au>
    Re: sorting in hashes of hashes (Jay Tilton)
        SSH: remote protocol version not found (Leaffoot)
    Re: Strange behaviour with windows task scheduler <willis3140@com.yahoo>
        Test please ignore (Mangesh)
    Re: Tracking User's OS type? <bik.mido@tiscalinet.it>
    Re: Using print in Mail::Internet to write message to a <krahnj@acm.org>
        Using print in Mail::Internet to write message to a fil (Jeff W)
    Re: Using print in Mail::Internet to write message to a <lou.moran@gellerandwind.com>
    Re: Why do beginners read files into an array? (Kevin Newman)
    Re: Why does Perl handle "return undef;" differently th <asimmons@mitre.org>
    Re: Why does Perl handle "return undef;" differently th <uri@stemsystems.com>
    Re: Why does Perl handle "return undef;" differently th <bkennedy@hmsonline.com>
    Re: Why does Perl handle "return undef;" differently th <asimmons@mitre.org>
    Re: Why does Perl handle "return undef;" differently th <mgjv@tradingpost.com.au>
    Re: Wierd loop/chdir behavior <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 19 Dec 2002 18:07:13 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Negation inside a pattern match
Message-Id: <3E025121.3800E7CA@earthlink.net>

Sami Leino wrote:
> 
> Hi.
> 
> I need to write mail filtering rules for Postfix, and for this purpose
> I intended to use Perl Compatible Regular Expressions (PCRE). In
> Postfix header filter files I can use REJECT for rejecting messages,
> but it seems that I cannot use OK or ACCEPT for accepting messages.
> Therefore, I would need to convert an ACCEPT rule to REJECT rule using
> negation inside the regexp.
> 
> Here's an example use case:
> 
> * I want to accept all messages that are coming from "allowed.com",
>   but reject all messages that are coming from elsewhere.
> 
> If I would like to reject all messages that are coming from
> "bogus.com", the filter entry would be something like this:
> 
> /^From: (.*)bogus.com$/ REJECT
> 
> So, how do I convert this to use negation? I tried to use the negation
> notation '?!' to achieve this, but had no luck with it.  Does anyone
> have an idea about this?

How about:
  /^(?!From: .*?\@allowed\.com\z)/ REJECT
[untested]

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Thu, 19 Dec 2002 22:35:34 GMT
From: w i l l <willis3140@com.yahoo>
Subject: Re: perl regexp to extract table out of HTML ->>>> use HTML::TableExtract;
Message-Id: <pnf40vovn7hlu0f20s8kij71c3t97sicgu@4ax.com>

use HTML::TableExtract;

use HTML::TableExtract;
http://search.cpan.org/dist/HTML-TableExtract/
http://search.cpan.org/dist/HTML-TableExtract/
http://search.cpan.org/dist/HTML-TableExtract/
http://search.cpan.org/dist/HTML-TableExtract/



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

Date: Thu, 19 Dec 2002 17:12:59 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Precedence of => (was Re: Why does Perl handle "return undef;" differently then "return;")
Message-Id: <3E02446B.C9D307D5@earthlink.net>

Brian McCauley wrote:
[snip]
> > printArgValues(
> > {
> >  '1st' => 1,
> >  '2nd' => test(),
> >  '3rd' => 3
> > }
> > );
> 
> > Because test() returns an empty list, that whole hash definition
> > gets shifted over -- so '2nd' ends up pointing to '3rd' -- I
> > understand this, it just seems like very strange behavior.
> 
> Yes the existance of the LIST v SCALAR context in Perl subroutine
> calls can cause some very strange behavior.
> 
> But basically what you are arguing against is the very existance of
> subroutines that can return lists in Perl.  I don't think you'll win
> that one.
> 
> Actually, if I'd been inventing Perl from scratch then I'd have made
> the => operator have a higher precedence than the plain comma and
> made => give a scalar context to it's RHS.  But it's too late now - we
> can't go back in time and change histroy.

In perl6, the => operator will create 'pair' objects, rather than merely
being a fancy comma operator.  I'm fairly sure that a consequence of
this will be for it to give scalar context to it's RHS (and maybe to
it's LHS, too).

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Thu, 19 Dec 2002 21:10:42 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Replacing text strings contains more than 1 dot
Message-Id: <3E023587.66F5858D@acm.org>

raj wrote:
> 
> perl -pi -e 's/oldstring/newstring' filename

$ perl -pi -e 's/oldstring/newstring' filename
Substitution replacement not terminated at -e line 1.


> HTH.

Not really.



John
-- 
use Perl;
program
fulfillment


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

Date: 19 Dec 2002 13:01:34 -0800
From: robert.davidson@lackland.af.mil (BobbyD)
Subject: search and replace text in many files
Message-Id: <33e016f7.0212191301.7938578d@posting.google.com>

Hello Perlers,
It's been a few months since I've been tasked to do some text editing.
 I'm sure something simple out there exists.  I would like to create a
perl script to be used in an alias on a Unix platform that will search
and replace one or more strings in every file down a tree.  Couldn't I
create an alias that begins with "find ." and then run the perl script
on each file it finds.  Since find is recursive, it should search down
the tree.  In most cases the string will be just one word, not that it
matters.  I'm thinking that the alias call will look like:

SRtext oldtext newtext

And the alias definition would be:
alias SRtext 'find . -type -f | xargs perlscriptname "$1" "$2"'


Thanks in advance,

BobbyD


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

Date: Thu, 19 Dec 2002 14:05:34 -0600
From: sriram <srsriram@xyz.com>
Subject: sorting in hashes of hashes
Message-Id: <3E02268E.8809F4DA@xyz.com>

Hi,

I need help with sorting by value in hashes of hashes.

I have the following structure:

%grades = (
        student1 => {
                        sub1 => 10,
                        sub2 => 20,
                },
        student2 => {
                        sub1 => 30,
                        sub2 => 40,
                },
        student3 => {
                        sub1 => 20,
                        sub2 => 60,
                },
        student4 => {
                        sub1 => 50,
                        sub2 => 50,
                },
        student5 => {
                        sub1 => 90,
                        sub2 => 100,
                },
        );

I want to be able to sort by the score in a subject.
If i sort by "sub1", to get an output like:
Student     Sub1  Sub2
----------------------
student5    90    100    
student4    50     50
student2    30     40
student3    20     60
student1    10     20
----------------------


Thanks
Sriram


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

Date: Thu, 19 Dec 2002 21:52:34 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: sorting in hashes of hashes
Message-Id: <3E023F57.994082A4@acm.org>

sriram wrote:
> 
> I need help with sorting by value in hashes of hashes.
> I have the following structure:
> 
> %grades = (
>         student1 => {
>                         sub1 => 10,
>                         sub2 => 20,
>                 },
>         student2 => {
>                         sub1 => 30,
>                         sub2 => 40,
>                 },
>         student3 => {
>                         sub1 => 20,
>                         sub2 => 60,
>                 },
>         student4 => {
>                         sub1 => 50,
>                         sub2 => 50,
>                 },
>         student5 => {
>                         sub1 => 90,
>                         sub2 => 100,
>                 },
>         );
> 
> I want to be able to sort by the score in a subject.
> If i sort by "sub1", to get an output like:
> Student     Sub1  Sub2
> ----------------------
> student5    90    100
> student4    50     50
> student2    30     40
> student3    20     60
> student1    10     20
> ----------------------


print "Student     Sub1  Sub2\n", '-' x 22, "\n";
for ( sort { $grades{$b}{sub1} <=> $grades{$a}{sub1} } keys %grades ) {
    printf "%-10s%6d%6d\n", $_, $grades{$_}{sub1}, $grades{$_}{sub2};
    }
print '-' x 22, "\n";



John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 19 Dec 2002 22:15:59 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: sorting in hashes of hashes
Message-Id: <slrnb04hcj.865.mgjv@verbruggen.comdyn.com.au>

On Thu, 19 Dec 2002 14:05:34 -0600,
        sriram <srsriram@xyz.com> wrote:
> Hi,
> 
> I need help with sorting by value in hashes of hashes.

Did you check the answers in the Perl FAQ?

$ perldoc -q sort

How do I sort an array by (anything)?
How do I sort a hash (optionally by value instead of key)?

> I have the following structure:
> 
> %grades = (
>         student1 => {
>                         sub1 => 10,
>                         sub2 => 20,
>                 },
[snip]
>         );
> 
> I want to be able to sort by the score in a subject.
> If i sort by "sub1", to get an output like:

If sub1 is equal, do you care about the sort order after that?
Depending on your version of Perl, records with identical sub1 could
end up in the same order as they are now (newer versions of Perl have
a stable sorting algorithm), or they could be more or less randomly
reordered.

> Student     Sub1  Sub2
> ----------------------
> student5    90    100    
> student4    50     50
> student2    30     40
> student3    20     60
> student1    10     20
> ----------------------

# This sorts by sub1 (descending) first, then sub2 (descending), then
# student name (ascending)
sub cmp_grades
{
    $grades{$b}{sub1} <=> $grades{$a}{sub1} ||
    $grades{$b}{sub2} <=> $grades{$a}{sub2} ||
    $a cmp $b
}

for my $student (sort cmp_grades keys %grades)
{
    printf "%-10s %4d %4d\n", $student, 
        $grades{$student}{sub1}, $grades{$student}{sub2};
}

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | What's another word for Thesaurus?
                        | 


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

Date: Thu, 19 Dec 2002 22:46:47 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: sorting in hashes of hashes
Message-Id: <3e0245c6.63360187@news.erols.com>

sriram <srsriram@xyz.com> wrote:

: I have the following structure:
: 
: %grades = (
:         student1 => {
:                         sub1 => 10,
:                         sub2 => 20,
:                 },

[etc]

:         );
: 
: I want to be able to sort by the score in a subject.
: If i sort by "sub1", to get an output like:
: Student     Sub1  Sub2
: ----------------------
: student5    90    100    
: student4    50     50
: student2    30     40
: student3    20     60
: student1    10     20
: ----------------------

    #!perl -l
    use warnings;
    use strict;

    my %grades = (
        student1 => { sub1 => 10, sub2 => 20, },
        student2 => { sub1 => 30, sub2 => 40, },
        student3 => { sub1 => 20, sub2 => 60, },
        student4 => { sub1 => 50, sub2 => 50, },
        student5 => { sub1 => 90, sub2 => 100, },
    );

    print for
        'Student     Sub1  Sub2',
        '----------------------',
        map(
            sprintf(
                "%-8s    %3d    %3d",
                $_, @{$grades{$_}}{'sub1', 'sub2'}
            ),
            sort(
                { $grades{$b}{sub1} <=> $grades{$a}{sub1} }
                keys %grades
            )
        ),
        '----------------------';



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

Date: 19 Dec 2002 14:07:36 -0800
From: leaffoot@hotmail.com (Leaffoot)
Subject: SSH: remote protocol version not found
Message-Id: <d7bd06a3.0212191407.6605f44c@posting.google.com>

I am new to SSH so I hope someone can tell me what this means.
I'm on a Win XP box, Perl 5.6.1

When I try to connect using SSH, I get this message:
"rlouden: Remote protocol version ., remote software version  "

So it seems to be unable to find the remote version of anything.
It also reports:
rlouden: Net::SSH::Perl Version 1.23_01, protocol version 1.5.
rlouden: No compat match: .
Your vendor has not defined Fcntl macro F_SETFL, used at
C:/Perl/site/lib/Net/SSH/Perl.pm line 218.

I have noted that there is an F_SETFL.h file available when one
installs C++; but that's all I know about it.
Here's the code I use:

use Net::SSH::Perl;

my $host = 'myhost.com';
my $user = 'mylogin';
my $pwd = 'mypassword';
my $ssh_params = ['debug',1];

#for SSH
my %sshhash = ('debug'=>1,
               'port'=>21,
               'protocol'=>"2,1",
               'interactive'=>1); 

my $ssh = Net::SSH::Perl->new($host,%sshhash);

$ssh->login($user, $pwd);

The script never actually makes it to the login line.
Thanks for any help!
Becka Louden


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

Date: Thu, 19 Dec 2002 22:35:35 GMT
From: w i l l <willis3140@com.yahoo>
Subject: Re: Strange behaviour with windows task scheduler
Message-Id: <drf40vot9ng15kfpn422s1gi3jkdlsmjp8@4ax.com>

is the script running as you?
does you script need your password? is it up to date?

On 18 Dec 2002 20:57:38 GMT, Stephen Patterson
<s.patterson@freeuk.com> wrote:

>I have a couple of scripts which are invoked by the task scheduler on
>windows 2000, and which occasionally fail to run for no apparent reason
>(i.e. it works fine if I run it myself).
>
>I've adjusted the scripts to create log files, from which I can tell that
>when the scripts fail, the task scheduler is not executing them. 

if the task scheduled never executes the script how can it fail?

>
>Any ideas?  The scripts are on a network drive, could this be affecting
>things?



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

Date: 19 Dec 2002 13:34:24 -0800
From: mangeshp16@hotmail.com (Mangesh)
Subject: Test please ignore
Message-Id: <1faf7f3f.0212191334.10c9ac17@posting.google.com>

this is test question. please ignore


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

Date: Thu, 19 Dec 2002 23:19:47 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Tracking User's OS type?
Message-Id: <en440vst45ib63nr8djm752o3udfmdsv87@4ax.com>

On Wed, 18 Dec 2002 15:42:08 -0500, "John" <johnthompson1@hotmail.com>
wrote:

>> > However, I can't seem to find how to track what OS the user is using.

>> There's $ENV{HTTP_USER_AGENT} which (for linux, galeon) at least holds the
>> browser type and operating system among other things.

So will he be another one of those who force me into using 
'wget -U MSIE5.0 ...'?!?


Michele
-- 
>It's because the universe was programmed in C++.
No, no, it was programmed in Forth.  See Genesis 1:12:
"And the earth brought Forth ..."
- Robert Israel on sci.math, thread "Why numbers?"


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

Date: Thu, 19 Dec 2002 22:20:46 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Using print in Mail::Internet to write message to a file (or how  else can I do this?)
Message-Id: <3E0245F3.5C52F8C0@acm.org>

Jeff W wrote:
> 
> I'm using the Mail::Internet package to print a message to a file.
> Below are my test case and the error I get.
> 
> I'm trying to do mail processing in a perl script called by qmail on
> pair.com.  Everything else seems to work.  I can parse and process
> headers.  But I can't figure out how to write the incoming Email
> message, in it's entirety (without modification) to a mail file.
> 
> all comments welcome
> thanks
> /j
> ================================
> ps - please post to the newsgroup - my posting Email is inactive to
> defeat spammers
> 
> =======================
> #!/usr/bin/perl

use warnings;
use strict;

> use Mail::Internet;
> 
> my $mail = Mail::Internet->new(STDIN) ;
> 
> $outfilename = "> log2";
> open (LOGFIL, $outfilename);

You should _always_ verify that the file opened correctly.


> $mail->print(LOGFIL);
> close (LOGFIL);
> 
> exit 0;
> =================================================
> The print statement produces the error:
> 
> Can't use string (LOGFIL) as a symbol ref while "strict refs" in use
> at /usr/local/lib/perl5/site_perl/5.6.1/Mail/Header.pm line 714,
> <STDIN> line 24.


perldoc Mail::Internet
[snip]
       print ( [ FILEHANDLE ] )
           Print the header, body or whole message to file
           descriptor FILEHANDLE.  $fd should be a reference to a
           GLOB. If FILEHANDLE is not given the output will be
           sent to STDOUT.

               $mail->print( \*STDOUT );  # Print message to STDOUT



John
-- 
use Perl;
program
fulfillment


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

Date: 19 Dec 2002 13:39:23 -0800
From: jeffw_00@kwcpa.com (Jeff W)
Subject: Using print in Mail::Internet to write message to a file (or how else can I do this?)
Message-Id: <501727be.0212191339.266dea95@posting.google.com>

I'm using the Mail::Internet package to print a message to a file. 
Below are my test case and the error I get.

I'm trying to do mail processing in a perl script called by qmail on
pair.com.  Everything else seems to work.  I can parse and process
headers.  But I can't figure out how to write the incoming Email
message, in it's entirety (without modification) to a mail file.

all comments welcome
thanks
/j
================================
ps - please post to the newsgroup - my posting Email is inactive to
defeat spammers

=======================
#!/usr/bin/perl
use Mail::Internet;

my $mail = Mail::Internet->new(STDIN) ;

$outfilename = "> log2";
open (LOGFIL, $outfilename);
$mail->print(LOGFIL);
close (LOGFIL);

exit 0;
=================================================
The print statement produces the error:

Can't use string (LOGFIL) as a symbol ref while "strict refs" in use
at /usr/local/lib/perl5/site_perl/5.6.1/Mail/Header.pm line 714,
<STDIN> line 24.


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

Date: Thu, 19 Dec 2002 17:25:16 -0500
From: Lou Moran <lou.moran@gellerandwind.com>
Subject: Re: Using print in Mail::Internet to write message to a file (or how else can I do this?)
Message-Id: <umh40vgpuodt7estvb203chga79h0246uq@4ax.com>

On 19 Dec 2002 13:39:23 -0800, jeffw_00@kwcpa.com (Jeff W) wrote:

SNIP
>all comments welcome
>thanks
SNIP

I added use diagnotics; as I often do when use warnings; seems
cryptic.  Perhaps error message this will help:

barney ellem ~ $ perl aaa.pl
^D
Can't use string ("LOGFIL") as a symbol ref while "strict refs" in use
at
        /usr/local/lib/perl5/site_perl/5.6.1/Mail/Internet.pm line
253, <STDIN> line 1 (#1)
    (F) Only hard references are allowed by "strict refs".  Symbolic
    references are disallowed.  See perlref.

Uncaught exception from user code:
        Can't use string ("LOGFIL") as a symbol ref while "strict
refs" in use at /usr/local/lib/perl5/site_perl/5.6.1/Mail/Internet.pm
line 253, <STDIN> line 1.
        Mail::Internet::print('Mail::Internet=HASH(0x80f815c)',
'LOGFIL') called at aaa.pl line 10


--
There's more than one way to do it, but only some of them work


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

Date: 19 Dec 2002 12:06:33 -0800
From: knewman00@yahoo.com (Kevin Newman)
Subject: Re: Why do beginners read files into an array?
Message-Id: <8ed70cf8.0212191206.6039fe0a@posting.google.com>

"Tintin" <me@privacy.net> wrote in message news:<atsbcs$25vnp$1@ID-172104.news.dfncis.de>...
> "Kevin Newman" <knewman00@yahoo.com> wrote in message
> news:8ed70cf8.0212181703.5b3fc1b@posting.google.com...
> > "Tintin" <me@privacy.net> wrote in message
>  news:<atpnn4$1cv63$2@ID-172104.news.dfncis.de>...
> > > Can anyone come up with a plausible reason why so many beginners write
>  code
> > > like:
> > >
> > > open FILE, "data.txt";
> > > @var=<FILE>;
> > > close FILE;
> > >
> > > foreach $line (@var) {
> > >    print $line;
> > > }
> > >
> > > Where does this logic come from?
> > >
> > > The only reason I can come up with is that the newbies are learning from
>  bad
> > > examples.
> >
> > Speaking as a beginner, what's the "correct" way to do it?
> 
> There's no "correct" ways, just more appropriate ways depending on what you
> want to do.
> 
> Suppose you are processing a 20GB file on a system with 512MB of memory and
> your script wants to read a file and display lines matching a particular
> pattern.
> 
> The more "appropriate" way of doing it is:
> 
> open FILE, "file.data" or die "Can not open file.data $!\n";
> 
> while (<FILE>)  {
>    next unless (/some pattern/);
>    print;
> }
> 
> close FILE;
> 
> Now compare that to
> 
> open FILE, "file.data" or die "Can not open file.data $!\n";
> 
> @data = <FILE>;
> 
> foreach (@data) {
>     next unless (/some pattern/);
>     print;
> }
> 
> 
> BOOM!  There goes your memory!

Okay, that makes sense.  For a minute, I thought you were saying that
it's never appropriate to write code like @data = <FILE>; .  Also,
it's good that you posted an alternative way to accomplish the task
and the reason why it should be done in this alternative fashion.

Thanks,

kln


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

Date: Thu, 19 Dec 2002 14:21:56 -0500
From: "Aaron Simmons" <asimmons@mitre.org>
Subject: Re: Why does Perl handle "return undef;" differently then "return;"
Message-Id: <att672$7ji$1@newslocal.mitre.org>

OK, I think everyone is missing my point, so let's go straight to the code
(lines 310-311 of CGI.pm VERSION:2.752):
return unless defined($name) && $self->{$name}; # line 310
return wantarray ? @{$self->{$name}} : $self->{$name}->[0]; # line 311

I am not saying line 311 needs to force a scalar return.  All I am saying is
why can't line 310 be this:
return undef unless defined($name) && $self->{$name}; # line 310


For this very specific question, the fact that param() can handle
multivalues is irrelevant--does anyone disagree with me there?!?

--
Aaron Simmons
G066-Software Systems Eng, Lead
(703) 883-3394
AaronSimm1 (AIM)



"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x7adj1q3ng.fsf@mail.sysarch.com...
> >>>>> "AS" == Aaron Simmons <asimmons@mitre.org> writes:
>
>   AS> Thank you.  That really does explain it.  I do believe in general
>   AS> doing a "return undef;" is the safest thing to do.  Can anyone
>   AS> give me an example of why doing a "return;" would be better then a
>   AS> "return undef;"?
>
> in fact as others have stated, you have it backwards. bare return is
> MUCH safer and better than return undef. you would be much better off
> learning this.
>
> what is printed in this code:
>
> sub bad {
> return undef ;
> }
>
> $bad = bad() ;
> if ( $bad ) {
> print "bad scalar\n" ;
> }
> @bad = bad() ;
> if ( @bad ) {
> print "bad array\n" ;
> }
>
> what you are forgetting in your tirade is perl's powerful use of
> context. many builtin functions and module operations use it to decide
> on what to return. cgi.pm's param() func does that for a reason, so you
> can get one or all values of a param under your control!
>
> if you had no values entered in a form's multivalued widget, what would
> you want to happen here:
>
> if ( @vals = param( 'multi' ) {
>
> local $" = ':' ;
> print "we got [@vals]\n" ;
> }
>
> with your wrong suggestion it would be a bug if no values were entered
> in the form.
>
> the scalar() function was created to FORCE scalar context when the
> caller wants it. print and all sub calls (without prototypes) provide
> list context so scalar is needed to do what you want. so use it and stop
> complaining. perl is not going to change this behavior so i suggest you
> change the way you think about it. you need to learn more about contexts
> and how to work with them and not against them.
>
> uri
>
> --
> Uri Guttman  ------  uri@stemsystems.com  --------
http://www.stemsystems.com
> ----- Stem and Perl Development, Systems Architecture, Design and
Coding ----
> Search or Offer Perl Jobs  ----------------------------
http://jobs.perl.org




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

Date: Thu, 19 Dec 2002 19:49:49 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Why does Perl handle "return undef;" differently then "return;"
Message-Id: <x77ke5okkj.fsf@mail.sysarch.com>

>>>>> "AS" == Aaron Simmons <asimmons@mitre.org> writes:

STOP TOP POSTING

  AS> OK, I think everyone is missing my point, so let's go straight to the code
  AS> (lines 310-311 of CGI.pm VERSION:2.752):
  AS> return unless defined($name) && $self->{$name}; # line 310
  AS> return wantarray ? @{$self->{$name}} : $self->{$name}->[0]; # line 311

  AS> I am not saying line 311 needs to force a scalar return.  All I am saying is
  AS> why can't line 310 be this:
  AS> return undef unless defined($name) && $self->{$name}; # line 310


  AS> For this very specific question, the fact that param() can handle
  AS> multivalues is irrelevant--does anyone disagree with me there?!?

because that would be a BUG. do you understand the term bug?

i don't think you have good comprehension skills. notice that line 311
calls wantarray? that is checking for context. the code in 310 doesn't
check for context. it relies on return DOING THE RIGHT THING.

you didn't even try to answer my questions on what happens here:

  >> what is printed in this code:
  >> 
  >> sub bad {
  >> return undef ;
  >> }
  >> 
  >> $bad = bad() ;
  >> if ( $bad ) {
  >> print "bad scalar\n" ;
  >> }
  >> @bad = bad() ;
  >> if ( @bad ) {
  >> print "bad array\n" ;
  >> }


do you have any understanding about scalar vs list context? returning a
real undef in a LIST CONTEXT IS WRONG. period. you are wrong. no one
agrees with you. perl is not going to change. lincoln will not change
cgi.pm for this reason.

get over it. and STOP TOP POSTING. you are showing little brains in both
this thread and the way you post. 

uri

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


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

Date: Thu, 19 Dec 2002 15:02:16 -0500
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Why does Perl handle "return undef;" differently then "return;"
Message-Id: <OoicnVL6maWtu5-jXTWcpA@giganews.com>


"Aaron Simmons" <asimmons@mitre.org> wrote in message
news:att672$7ji$1@newslocal.mitre.org...
> OK, I think everyone is missing my point, so let's go straight to the code
> (lines 310-311 of CGI.pm VERSION:2.752):
> return unless defined($name) && $self->{$name}; # line 310
> return wantarray ? @{$self->{$name}} : $self->{$name}->[0]; # line 311
>
> I am not saying line 311 needs to force a scalar return.  All I am saying
is
> why can't line 310 be this:
> return undef unless defined($name) && $self->{$name}; # line 310
>
>
> For this very specific question, the fact that param() can handle
> multivalues is irrelevant--does anyone disagree with me there?!?

First of all, see:

http://www.dickalba.demon.co.uk/usenet/guide/faq_topp.html

Second, no one is missing your point.  Uri already gave you an example of
code expects param() to return an empty list when the parameter is not
present.  Quoting him:

> > if ( @vals = param( 'multi' ) {
> >
> > local $" = ':' ;
> > print "we got [@vals]\n" ;
> > }
> >
> > with your wrong suggestion it would be a bug if no values were entered
> > in the form.

There is really isn't much more to say about it.  If you really really want
a param() that does what you want, then create your own class that inherits
from it and make your changes.

--Ben Kennedy




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

Date: Thu, 19 Dec 2002 15:31:22 -0500
From: "Aaron Simmons" <asimmons@mitre.org>
Subject: Re: Why does Perl handle "return undef;" differently then "return;"
Message-Id: <atta99$7rr$1@newslocal.mitre.org>

Yes, you all are correct.  Changing "return" to "return undef" would cause
the capturing of multivalue data to contain one argument of undef if that
name didn't exist in the query string or POST'ed data.

Example:
my @colors = $cgi->param('colorChoices');

I know understand it.  Thanks!

By the way what exactly is "TOP POSTING"?

-Aaron





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

Date: Thu, 19 Dec 2002 21:04:29 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Why does Perl handle "return undef;" differently then "return;"
Message-Id: <slrnb04d6l.865.mgjv@verbruggen.comdyn.com.au>

On Thu, 19 Dec 2002 15:31:22 -0500,
	Aaron Simmons <asimmons@mitre.org> wrote:
> 
> I know understand it.  Thanks!

Good.

> By the way what exactly is "TOP POSTING"?

If you had followed the URL that Ben Kennedy posted in the message you
replied to, you would have known. For your convenvience, because we're
so helpful, here it is again:

http://www.dickalba.demon.co.uk/usenet/guide/faq_topp.html

Martien
-- 
                        | 
Martien Verbruggen      | Begin at the beginning and go on till you
Trading Post Australia  | come to the end; then stop.
                        | 


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

Date: Thu, 19 Dec 2002 18:10:50 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Wierd loop/chdir behavior
Message-Id: <3E0251FA.4D602AA1@earthlink.net>

Steve Walker wrote:
[snip]
[snip]
> The weirdness is that the chdir to the target directory fails EVERY
> OTHER pass of the loop.
[snip]
> if (chdir(glob "$ddir"))

   perldoc -f glob

Read about what happens in scalar context.


-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

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 4292
***************************************


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