[24464] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6647 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 2 18:06:13 2004

Date: Wed, 2 Jun 2004 15:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 2 Jun 2004     Volume: 10 Number: 6647

Today's topics:
    Re: Am I a programmer or a scripter? <me@privacy.net>
    Re: graphing link list nodes...  modules? (hennessy)
    Re: Installation of CPAN modules under Darwin <spamtrap@dot-app.org>
    Re: Installation of CPAN modules under Darwin (Jim Keenan)
        Perl tutorial at U Penn on Friday 4 June (Mark Jason Dominus)
        problem with rand on OSX <cabneySPAM@SPAMucsdSPAM.SPAMedu>
    Re: Unexpected subroutine behaviour without & <noreply@gunnar.cc>
    Re: Unexpected subroutine behaviour without & <tadmc@augustmail.com>
    Re: Unexpected subroutine behaviour without & <dwall@fastmail.fm>
    Re: Unexpected subroutine behaviour without & (Kevin Collins)
    Re: Unexpected subroutine behaviour without & <usenet@morrow.me.uk>
    Re: Unexpected subroutine behaviour without & (Kevin Collins)
    Re: Unexpected subroutine behaviour without & (Anno Siegel)
    Re: Unexpected subroutine behaviour without & (Kevin Collins)
    Re: Unexpected subroutine behaviour without & (Anno Siegel)
    Re: Unexpected subroutine behaviour without & (Kevin Collins)
    Re: Unexpected subroutine behaviour without & (Kevin Collins)
    Re: Unexpected subroutine behaviour without & <usenet@morrow.me.uk>
    Re: Unexpected subroutine behaviour without & <ittyspam@yahoo.com>
    Re: Unexpected subroutine behaviour without & <noreply@gunnar.cc>
    Re: Unexpected subroutine behaviour without & <usenet@morrow.me.uk>
    Re: Unexpected subroutine behaviour without & <noreply@gunnar.cc>
    Re: WinXP : Terminating on signal SIGALRM(14) <david@tvis.co.uk>
    Re: YAPC::2004 <uri.guttman@fmr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 3 Jun 2004 08:28:12 +1200
From: "Tintin" <me@privacy.net>
Subject: Re: Am I a programmer or a scripter?
Message-Id: <2i6rihFjvejaU1@uni-berlin.de>


"I H H" <iohihuh@INyaVAhooLID.com> wrote in message
news:fNkvc.18012$g4.347049@news2.nokia.com...
> I am just humble pimple on camel's hump, Tool used by Universe, A Script
> Editor, perl just flows trough me.)

Almost sounds like Perl poetry, except it doesn't compile.




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

Date: Wed, 02 Jun 2004 18:14:32 -0000
From: hennessy@earl-grey.cloud9.net (hennessy)
Subject: Re: graphing link list nodes...  modules?
Message-Id: <10bs68865stgrfb@corp.supernews.com>

In article <c9l28f$q1l$1@wisteria.csv.warwick.ac.uk>,
Ben Morrow  <usenet@morrow.me.uk> wrote:
>http://www.research.att.com/sw/tools/graphviz/

PERFECT!

(I think I'll try the GraphViz module though, or one of its children..)

Thanks!
- Matt
-- 
"When in doubt, use brute force."
- Ken Thompson


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

Date: Wed, 02 Jun 2004 15:37:20 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Installation of CPAN modules under Darwin
Message-Id: <HZWdnSJnNvnvsSPdRVn-sA@adelphia.com>

Jim Keenan wrote:

> I followed the 4-command procedure above this morning, but did not get
> the desired results.  This is what appeared:
> 
>     [List-Compare-0.3 427]$ sudo make install
>     Password:
>     Writing
>     ///Library/Perl/5.8.1/darwin-thread-multi-2level/auto/List/Compare/.packlist

Check your PATH. It looks like /usr/bin appears before /usr/local/bin - if
the second is there at all.

You can verify which Perl you're running with 'perl -v'.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: 2 Jun 2004 15:04:11 -0700
From: jkeen_via_google@yahoo.com (Jim Keenan)
Subject: Re: Installation of CPAN modules under Darwin
Message-Id: <196cb7af.0406021404.27735976@posting.google.com>

Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c9kpos$jq1$1@wisteria.csv.warwick.ac.uk>...
> > As you can see, the first problem is that the regular procedure
> > installed the module relative to the Perl 5.8.1 that came with the
> > iBook -- but I want it installed relative to the Perl 5.8.4 that I
> > just installed.
> 
> In that case you have to say
> 
> /usr/local/bin/perl Makefile.PL
> 
> > 2) Is there any way I can set my system up to say:  From this day
> > forward, consider my Perl 5.8.4 (installed under /usr/local/bin) to be
> > my default Perl for the purpose of installing modules, whether by the
> > manual procedure used above or by use of the CPAN.pm shell?  (I
> > understand that I now have to code the shebang line as
> > #!/usr/local/bin/perl rather than #!/usr/bin/perl -- but that applies
> > only to Perl scripts.)
> 
> Probably the best soln to this is to puth /usr/local/bin first in your PATH.
> 
Ben:  I implemented your second suggestion first, placing
/usr/local/bin at the very front of my path in my .bash_profile --
even before $PATH.  Having done that, I didn't need to implement your
first suggestion; I just called 'perl Makefile.PL'.

It worked like a charm, as evidenced by the fact that I can now view
the docs thru perldoc, man or info.  I will next try this using the
CPAN shell.  Thanks for your assistance.

Jim Keenan


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

Date: Wed, 2 Jun 2004 20:24:47 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Perl tutorial at U Penn on Friday 4 June
Message-Id: <c9ld2f$4j4$1@plover.com>


[ This announcement was marked with "Distribution: phl".  
  If you received it, then your news administrator specifically
  requested to receive messages that were marked for distribution only
  within the Philadelphia area. ]


This year I will be giving a new tutorial at the big Perl conference
in Portland next month.  As usual, I would like to practice it
beforehand.  I will be doing that on Friday.

The tutorial is titled:

        "Welcome to my ~/bin"

                                 WHEN


Friday, 4 June.

The tutorial will start around 6:30 PM and will last until about
10:00, including a 30-minute break in the middle.

Food may be provided.

                                 WHAT

Here is the brochure description:

        Over the years, Dominus has built up a large collection of
        handy utilities in Perl. He'll take you on a tour of these
        utilities and show you what they do and how they work.

        Class content will vary, but will include at least some of the following:

        * dump, pmud: lightweight keyed databases
        * getstore: copy a web page to a local file
        * googles: what google searches are leading people to my web site?
        * mailhold: challenge-response for incoming email
        * makethumbnails: build image thumbnail pages
        * mark: manage collections of files
        * mypsmerge, mypstrim, mypsup2: PostScript formatting and conversion
        * print: replacement printer daemon
        * ticker: watch files grow
        * unrecv: make email archive directories smaller
        * watcher: watch a collection of web pages and report whenever one changes

                                WHERE

The classes will be held in Wu-Chen auditorium on the first floor of
the new Melvin and Claire Levine Hall at the University of
Pennsylvania.  Levine Hall is located at 3330 Walnut Street in
Philadelphia.

For directions to the University, see

        http://www.facilities.upenn.edu/visitUs/

A map is available at:

        http://www.facilities.upenn.edu/mapsBldgs/view_map.php3?id=407


                                 WHO

My usual bio says:

        Mark-Jason Dominus has been programming in Perl since 1992. He
        is the author of the 'Memoize', 'Text::Template', and
        'Tie::File' modules, the author of the 'perlreftut' man page,
        and an occasional contributor to the Perl core.  He won the
        2001 Larry Wall award for Practical Utility.

For more details about me, see

        http://perl.plover.com/yak/aboutme.html

For more details about classes I teach, see

        http://perl.plover.com/yak/


                                 WHOW

Please do circulate this notice to any people or mailing lists that
you think might want to see it.

My grateful thanks go to Helen Anderson and the University of
Pennsylvania School of Engineering and Applied Science for providing
the space and AV equipment for these classes.

                                WHUH?

Questions?  Send me email.



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

Date: 2 Jun 2004 15:48:07 -0600
From: "C. A." <cabneySPAM@SPAMucsdSPAM.SPAMedu>
Subject: problem with rand on OSX
Message-Id: <40be4b17$1_1@omega.dimensional.com>

I expect each child to have a different $slp, but they are identical:

=8<================
#! /usr/bin/perl -w

use strict;

my ( $pid, @jobs, $n );

$|++;

for (0..2)
{
        # three children, we'll need their pid's later...
        $pid = fork();
        last if $pid == 0;
        push @jobs, $pid;
}

if ( $pid != 0 ) {
        $SIG{CHLD} = 'IGNORE';
} else {
        my $slp = int rand 20;

        print "child gets $slp second(s)\n";
        exit 0;
}
=8<================

uname -r -v -m
7.3.0 Darwin Kernel Version 7.3.0: Fri Mar  5 14:22:55 PST 2004;\
 root:xnu/xnu-517.3.15.obj~4/RELEASE_PPC  Power Macintosh
perl --version

This is perl, v5.8.1-RC3 built for darwin-thread-multi-2level
(with 1 registered patch, see perl -V for more detail)

Yours,

CA
-- 


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

Date: Wed, 02 Jun 2004 19:57:47 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <2i6j7gFj8bkvU1@uni-berlin.de>

Kevin Collins wrote:
> I've just stumbled across a strange problem on my HP-UX systems.
> The following code will demonstrate the problem:
> 
> #!/usr/bin/perl -w

Why the -w switch? "use warnings;" is enough.

> my @list = qw(cc aa bb aa dd zz ee);
> print join(" ", sort(UniqArray(@list))) . "\n";

Considering the code in UniqArray(), you could as well just say:

     print join(" ", sort UniqArray()) . "\n";

> sub UniqArray
> {
>     # This function takes an array reference

No, it doesn't. It takes the array @list, which is a package lexical.
The list in @_, which contains copies of the elements in @list since
you passed the array (not array reference) @list, is not used.

> I'm wondering why I need to call &UniqArray(@list) instead of
> UniqArray(@list)?

Can't explain that.

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



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

Date: Wed, 2 Jun 2004 13:03:41 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <slrncbs5jt.541.tadmc@magna.augustmail.com>

Kevin Collins <spamtotrash@toomuchfiction.com> wrote:

> print join(" ", sort(UniqArray(@list))) . "\n";
                                 ^^^^^

That might as well not be there, UniqArray() never examines its arguments.


> sub UniqArray
> {

>     foreach (@list)


You should not communicate with subroutines via global variables,
you should pass arguments instead.


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


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

Date: Wed, 02 Jun 2004 18:16:10 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <Xns94FC9127E86FCdkwwashere@216.168.3.30>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:

> Kevin Collins wrote:

>> sub UniqArray
>> {
>>     # This function takes an array reference
> 
> No, it doesn't. It takes the array @list, which is a package
> lexical. The list in @_, which contains copies of the elements in
> @list since you passed the array (not array reference) @list, is
> not used. 

It could be a bit shorter, too.

    sub UniqArray    {
        # This function takes an array reference and returns
        # an array without dups
    
        my %seen;
        return grep {not $seen{$_}++} @{$_[0]};
    }

>> I'm wondering why I need to call &UniqArray(@list) instead of
>> UniqArray(@list)?
> 
> Can't explain that.

Me neither.


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

Date: Wed, 02 Jun 2004 18:21:25 GMT
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <slrncbs6l5.93b.spamtotrash@doom.unix-guy.com>

In article <2i6j7gFj8bkvU1@uni-berlin.de>, Gunnar Hjalmarsson wrote:
> Kevin Collins wrote:
>> I've just stumbled across a strange problem on my HP-UX systems.
>> The following code will demonstrate the problem:
>> 
>> #!/usr/bin/perl -w
> 
> Why the -w switch? "use warnings;" is enough.

True - I added the "use warnings" to the script because I was running:

/some/path/to/perl myscript
/some/other/path/to/perl myscript

and wanted to make sure I had warnings enabled (with using -w on the command
line).

>> my @list = qw(cc aa bb aa dd zz ee);
>> print join(" ", sort(UniqArray(@list))) . "\n";
> 
> Considering the code in UniqArray(), you could as well just say:
> 
>      print join(" ", sort UniqArray()) . "\n";

Damn - I hate it when I blunder a code post! I incorrectly posted the wrong
version of my test code. That foreach line should be: 

foreach (@_)


>> sub UniqArray
>> {
>>     # This function takes an array reference
> 
> No, it doesn't. It takes the array @list, which is a package lexical.
> The list in @_, which contains copies of the elements in @list since
> you passed the array (not array reference) @list, is not used.
> 
>> I'm wondering why I need to call &UniqArray(@list) instead of
>> UniqArray(@list)?
> 
> Can't explain that.
> 


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

Date: Wed, 2 Jun 2004 18:23:05 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <c9l5u9$sqg$1@wisteria.csv.warwick.ac.uk>


Quoth Kevin Collins <spamtotrash@toomuchfiction.com>:
> Hi,
> 
> 	I've just stumbled across a strange problem on my HP-UX systems. The
> following code will demonstrate the problem:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> use warnings;
> 
> my @list = qw(cc aa bb aa dd zz ee);
> print join(" ", sort(UniqArray(@list))) . "\n";
> print join(" ", sort(&UniqArray(@list))) . "\n";
> 
> sub UniqArray
> {
>     # This function takes an array reference and returns
>     # an array without dups
>     
>     # local variables
>     my %tmp;
>     my @returns;
> 
>     foreach (@list)

Well, there's a bug here. You are accessing the global @list directly;
what you mean is

for (@_) {

This makes no difference though...

>     {
>         # if the hash element has a value, then don't
>         # add it to return list since we've already added it
>         push (@returns, $_) unless ($tmp{$_});
>         $tmp{$_}++;
>     }
> 
>     return @returns;
> }
> 
> I have two different "home built" versions of Perl (5.6.1 and 5.8.0) and two
> HP-supplied versions (5.6.1 and 5.8.0).
> 
> The output I would expect:
> 
> aa bb cc dd ee zz
> aa bb cc dd ee zz
> 
> However, here is what I see:
> 
> Custom 5.6.1:
> 
> ee zz dd aa bb aa cc
> aa bb cc dd ee zz
> 
> Custom 5.8.0:
> 
> ee zz dd aa bb aa cc
> aa bb cc dd ee zz
> 
> HP's 5.6.1:
> 
> ee zz dd aa bb aa cc
> aa bb cc dd ee zz
> 
> HP's 5.8.0:
> 
> aa bb cc dd ee zz
> aa bb cc dd ee zz
> 
> I also checked Perl 5.8.0 on RedHat 9.0 and see my expected results.

Using

This is perl, v5.8.2 built for i686-linux-thread-multi

I get the following results:

#!/usr/bin/perl -l

my @list = qw/cc aa bb aa dd zz ee/;

sub uniq {
    my (@r, %t);
    
#    print "ARGS:", @_;

    for (@_) {
        push @r, $_ unless $t{$_};
        $t{$_}++;
    }

    return @r;
}

print sort uniq @list;
print sort uniq(@list);
print sort(uniq @list);
print sort(uniq(@list));
print sort &uniq(@list);

__END__

ee zz dd aa bb aa cc
ee zz dd aa bb aa cc
ee zz dd aa bb aa cc
aa bb cc dd ee zz
aa bb cc dd ee zz

Uncommenting the 'print "ARGS:"' line makes it clear what is happening:
in the first three cases, perl is using uniq as the sort subroutine.
This is probably a bug of some sort; I would say that at least my second
test ought to produce the expected results.

Ben

-- 
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
                                                               ben@morrow.me.uk


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

Date: Wed, 02 Jun 2004 18:24:56 GMT
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <slrncbs6ro.93b.spamtotrash@doom.unix-guy.com>

In article <slrncbs335.93b.spamtotrash@doom.unix-guy.com>, Kevin Collins wrote:
> Hi,
> 
> 	I've just stumbled across a strange problem on my HP-UX systems. The
> following code will demonstrate the problem:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> use warnings;
> 
> my @list = qw(cc aa bb aa dd zz ee);
> print join(" ", sort(UniqArray(@list))) . "\n";
> print join(" ", sort(&UniqArray(@list))) . "\n";
> 
> sub UniqArray
> {
>     # This function takes an array reference and returns
>     # an array without dups
>     
>     # local variables
>     my %tmp;
>     my @returns;
> 
>     foreach (@list)
>     {
>         # if the hash element has a value, then don't
>         # add it to return list since we've already added it
>         push (@returns, $_) unless ($tmp{$_});
>         $tmp{$_}++;
>     }
> 
>     return @returns;
> }

The code above was not quite correct (I inadvertantly included a different
version of the code). It should be:

#!/usr/bin/perl

use strict;
use warnings;

my @list = qw(cc aa bb aa dd zz ee);
print join(" ", sort(UniqArray(@list))) . "\n";
print join(" ", sort(&UniqArray(@list))) . "\n";

sub UniqArray
{
    # This function takes an array and returns
    # an array without dups
    
    # local variables
    my %tmp;
    my @returns;

    foreach (@_)
    {
        # if the hash element has a value, then don't
        # add it to return list since we've already added it
        push (@returns, $_) unless ($tmp{$_});
        $tmp{$_}++;
    }

    return @returns;
}



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

Date: 2 Jun 2004 18:37:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <c9l6pn$bo5$1@mamenchi.zrz.TU-Berlin.DE>

Kevin Collins <spamtotrash@toomuchfiction.com> wrote in comp.lang.perl.misc:
> Hi,
> 
> 	I've just stumbled across a strange problem on my HP-UX systems. The
> following code will demonstrate the problem:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> use warnings;
> 
> my @list = qw(cc aa bb aa dd zz ee);
> print join(" ", sort(UniqArray(@list))) . "\n";
> print join(" ", sort(&UniqArray(@list))) . "\n";
> 
> sub UniqArray

[definition snipped]

> I have two different "home built" versions of Perl (5.6.1 and 5.8.0) and two
> HP-supplied versions (5.6.1 and 5.8.0).
> 
> The output I would expect:
> 
> aa bb cc dd ee zz
> aa bb cc dd ee zz
> 
> However, here is what I see:
> 
> Custom 5.6.1:
> 
> ee zz dd aa bb aa cc
> aa bb cc dd ee zz

[more similar results]

Perl's "sort" is a peculiar beast in that its (optional) first argument
can be the name of a subroutine.  The name is given as a bareword, and
so

    sort(UniqArray(@list))

is ambiguous syntax.  It can be parsed as intended, or as a sort where
UniqArray is used as the comparison routine.  The parentheses around
@list in the second reading are redundant, but possible.

"&UniqArray" apparently forces the intended interpretation, but both
are possible.  Why different builds of Perl differ in their
interpretation is another question.

I snipped the code in UniqArray because it has nothing to do with the
issue, but actually it would deserve comment also.

Anno


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

Date: Wed, 02 Jun 2004 18:45:38 GMT
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <slrncbs82e.93b.spamtotrash@doom.unix-guy.com>

In article <slrncbs5jt.541.tadmc@magna.augustmail.com>, Tad McClellan wrote:
> Kevin Collins <spamtotrash@toomuchfiction.com> wrote:
> 
>> print join(" ", sort(UniqArray(@list))) . "\n";
>                                  ^^^^^
> 
> That might as well not be there, UniqArray() never examines its arguments.
> 
> 
>> sub UniqArray
>> {
> 
>>     foreach (@list)
> 
> 
> You should not communicate with subroutines via global variables,
> you should pass arguments instead.

Yes, I know - see my follow-up post where I included the "correct" code...

Kevin


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

Date: 2 Jun 2004 18:48:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <c9l7di$bo5$2@mamenchi.zrz.TU-Berlin.DE>

David K. Wall <dwall@fastmail.fm> wrote in comp.lang.perl.misc:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> 
> > Kevin Collins wrote:
> 
> >> sub UniqArray
> >> {
> >>     # This function takes an array reference
> > 
> > No, it doesn't. It takes the array @list, which is a package
> > lexical.

Lexical variables are independent of any package, the term "package
lexical" makes no sense.  @list is a a file-global lexical array.

[correct explanation snipped]

Anno


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

Date: Wed, 02 Jun 2004 18:54:41 GMT
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <slrncbs8jd.93b.spamtotrash@doom.unix-guy.com>

In article <c9l5u9$sqg$1@wisteria.csv.warwick.ac.uk>, Ben Morrow wrote:
> 
> Quoth Kevin Collins <spamtotrash@toomuchfiction.com>:
>> Hi,
>> 
>> 	I've just stumbled across a strange problem on my HP-UX systems. The
>> following code will demonstrate the problem:
>> 
>> #!/usr/bin/perl -w
>> 
>> use strict;
>> use warnings;
>> 
>> my @list = qw(cc aa bb aa dd zz ee);
>> print join(" ", sort(UniqArray(@list))) . "\n";
>> print join(" ", sort(&UniqArray(@list))) . "\n";
>> 
>> sub UniqArray
>> {
>>     # This function takes an array reference and returns
>>     # an array without dups
>>     
>>     # local variables
>>     my %tmp;
>>     my @returns;
>> 
>>     foreach (@list)
> 
> Well, there's a bug here. You are accessing the global @list directly;
> what you mean is
> 
> for (@_) {

Yeah, I've reposted with the correct code.

> 
> This makes no difference though...
> 
>>     {
>>         # if the hash element has a value, then don't
>>         # add it to return list since we've already added it
>>         push (@returns, $_) unless ($tmp{$_});
>>         $tmp{$_}++;
>>     }
>> 
>>     return @returns;
>> }
>> 
>> I have two different "home built" versions of Perl (5.6.1 and 5.8.0) and two
>> HP-supplied versions (5.6.1 and 5.8.0).
>> 
>> The output I would expect:
>> 
>> aa bb cc dd ee zz
>> aa bb cc dd ee zz
>> 
>> However, here is what I see:
>> 
>> Custom 5.6.1:
>> 
>> ee zz dd aa bb aa cc
>> aa bb cc dd ee zz
>> 
>> Custom 5.8.0:
>> 
>> ee zz dd aa bb aa cc
>> aa bb cc dd ee zz
>> 
>> HP's 5.6.1:
>> 
>> ee zz dd aa bb aa cc
>> aa bb cc dd ee zz
>> 
>> HP's 5.8.0:
>> 
>> aa bb cc dd ee zz
>> aa bb cc dd ee zz
>> 
>> I also checked Perl 5.8.0 on RedHat 9.0 and see my expected results.
> 
> Using
> 
> This is perl, v5.8.2 built for i686-linux-thread-multi
> 
> I get the following results:
> 
> #!/usr/bin/perl -l
> 
> my @list = qw/cc aa bb aa dd zz ee/;
> 
> sub uniq {
>     my (@r, %t);
>     
> #    print "ARGS:", @_;
> 
>     for (@_) {
>         push @r, $_ unless $t{$_};
>         $t{$_}++;
>     }
> 
>     return @r;
> }
> 
> print sort uniq @list;
> print sort uniq(@list);
> print sort(uniq @list);
> print sort(uniq(@list));
> print sort &uniq(@list);
> 
> __END__
> 
> ee zz dd aa bb aa cc
> ee zz dd aa bb aa cc
> ee zz dd aa bb aa cc
> aa bb cc dd ee zz
> aa bb cc dd ee zz
> 

I've just run your code and this is the output I see:

ccaabbaaddzzee
ccaabbaaddzzee
ccaabbaaddzzee
ccaabbaaddzzee
aabbccddeezz

I'm not clear at all how you are getting the results you've shown...

> Uncommenting the 'print "ARGS:"' line makes it clear what is happening:
> in the first three cases, perl is using uniq as the sort subroutine.
> This is probably a bug of some sort; I would say that at least my second
> test ought to produce the expected results.
> 
> Ben
> 


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

Date: Wed, 02 Jun 2004 19:02:17 GMT
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <slrncbs91l.93b.spamtotrash@doom.unix-guy.com>

In article <c9l6pn$bo5$1@mamenchi.zrz.TU-Berlin.DE>, Anno Siegel wrote:
> Kevin Collins <spamtotrash@toomuchfiction.com> wrote in comp.lang.perl.misc:
>> Hi,
>> 
>> 	I've just stumbled across a strange problem on my HP-UX systems. The
>> following code will demonstrate the problem:
>> 
>> #!/usr/bin/perl -w
>> 
>> use strict;
>> use warnings;
>> 
>> my @list = qw(cc aa bb aa dd zz ee);
>> print join(" ", sort(UniqArray(@list))) . "\n";
>> print join(" ", sort(&UniqArray(@list))) . "\n";
>> 
>> sub UniqArray
> 
> [definition snipped]
> 
>> I have two different "home built" versions of Perl (5.6.1 and 5.8.0) and two
>> HP-supplied versions (5.6.1 and 5.8.0).
>> 
>> The output I would expect:
>> 
>> aa bb cc dd ee zz
>> aa bb cc dd ee zz
>> 
>> However, here is what I see:
>> 
>> Custom 5.6.1:
>> 
>> ee zz dd aa bb aa cc
>> aa bb cc dd ee zz
> 
> [more similar results]
> 
> Perl's "sort" is a peculiar beast in that its (optional) first argument
> can be the name of a subroutine.  The name is given as a bareword, and
> so
> 
>     sort(UniqArray(@list))
> 
> is ambiguous syntax.  It can be parsed as intended, or as a sort where
> UniqArray is used as the comparison routine.  The parentheses around
> @list in the second reading are redundant, but possible.
> 
> "&UniqArray" apparently forces the intended interpretation, but both
> are possible.  Why different builds of Perl differ in their
> interpretation is another question.

That makes sense to me. Honestly, now that I read what you've written and
look closer at 'perldoc -f sort', I am surprised this hasn't burned me before.

Its possible that in other cases I am using a Perl builtin function and Perl
just handles it correctly.

> 
> I snipped the code in UniqArray because it has nothing to do with the
> issue, but actually it would deserve comment also.

Yes - shot myself in the foot by posting the wrong code. I did repost the
correct code.

> Anno


Thanks,

Kevin


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

Date: Wed, 2 Jun 2004 19:11:54 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <c9l8pq$1br$1@wisteria.csv.warwick.ac.uk>


Quoth Kevin Collins <spamtotrash@toomuchfiction.com>:
> > Using
> > 
> > This is perl, v5.8.2 built for i686-linux-thread-multi
> > 
> > I get the following results:
> > 
> > #!/usr/bin/perl -l
> > 
> > my @list = qw/cc aa bb aa dd zz ee/;
> > 
> > sub uniq {
> >     my (@r, %t);
> >     
> > #    print "ARGS:", @_;
> > 
> >     for (@_) {
> >         push @r, $_ unless $t{$_};
> >         $t{$_}++;
> >     }
> > 
> >     return @r;
> > }
> > 
> > print sort uniq @list;
> > print sort uniq(@list);
> > print sort(uniq @list);
> > print sort(uniq(@list));
> > print sort &uniq(@list);
> > 
> > __END__
> > 
> > ee zz dd aa bb aa cc
> > ee zz dd aa bb aa cc
> > ee zz dd aa bb aa cc
> > aa bb cc dd ee zz
> > aa bb cc dd ee zz
> > 
> 
> I've just run your code and this is the output I see:
> 
> ccaabbaaddzzee
> ccaabbaaddzzee
> ccaabbaaddzzee
> ccaabbaaddzzee
> aabbccddeezz
> 
> I'm not clear at all how you are getting the results you've shown...

Well, except for the fact that I missed out the

$, = ' ';

line, presumably this is yet another difference between perl versions...
actually, I'm not quite sure why the list is reversed. 5.8's sort is supposed
to be stable...

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


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

Date: Wed, 2 Jun 2004 15:35:13 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <20040602153107.G8971@dishwasher.cs.rpi.edu>

On Wed, 2 Jun 2004, Ben Morrow wrote:

> > > my @list = qw/cc aa bb aa dd zz ee/;
> > >
> > > sub uniq {
> > >     my (@r, %t);
> > >
> > > #    print "ARGS:", @_;
> > >
> > >     for (@_) {
> > >         push @r, $_ unless $t{$_};
> > >         $t{$_}++;
> > >     }
> > >
> > >     return @r;
> > > }
> > >
> > > print sort uniq @list;
> > > print sort uniq(@list);
> > > print sort(uniq @list);
> > > print sort(uniq(@list));
> > > print sort &uniq(@list);
> > >
> > > __END__
> > >
> > > ee zz dd aa bb aa cc
> > > ee zz dd aa bb aa cc
> > > ee zz dd aa bb aa cc
> > > aa bb cc dd ee zz
> > > aa bb cc dd ee zz

> actually, I'm not quite sure why the list is reversed. 5.8's sort is supposed
> to be stable...

The sort subroutine is returning the array @r.  Because %t is a lexical,
it will be empty each time the sort subroutine is called.  Therefore, the
size of @r each time the routine is called will be either 1 or 2 (it will
be 1 only in the case where two identical elements are being compared).
Both of these values are positive, which is the means of telling sort to
put $b before $a.  Assuming sort only compares two elements in the
original order (that is, $a is always listed before $b in the original
list), it is easy to see why the results would come back in the reverse
order.

Paul Lalli


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

Date: Wed, 02 Jun 2004 22:09:29 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <2i6qufFjgdkiU1@uni-berlin.de>

Anno Siegel wrote:
>> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>>> Kevin Collins wrote:
>>>> 
>>>> sub UniqArray
>>>> {
>>>>     # This function takes an array reference
>>> 
>>> No, it doesn't. It takes the array @list, which is a package 
>>> lexical.
> 
> Lexical variables are independent of any package, the term "package
> lexical" makes no sense.  @list is a a file-global lexical array.

Thanks for the correction. But I had to test:

     use strict;
     use warnings;

     package A;
     my $lexical = 'apple';
     our $global = 'orange';

     package B;
     #my $lexical = 'banana';
     print '$lexical = ', $lexical, "\n";
     print '$global = ', ($global or '(empty)'), "\n";

I couldn't do "my $lexical" once again without a warning, but I
noticed something else that surprised me. The above code outputs:
$lexical = apple
$global = orange

while I had expected:
$lexical = apple
$global = (empty)

When Perl doesn't find a global variable in the current package, does
it look for a varable with the same name in other packages?

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



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

Date: Wed, 2 Jun 2004 20:24:23 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <c9ld1n$4gh$1@wisteria.csv.warwick.ac.uk>


Quoth Gunnar Hjalmarsson <noreply@gunnar.cc>:
>      use strict;
>      use warnings;
> 
>      package A;
>      my $lexical = 'apple';
>      our $global = 'orange';
> 
>      package B;
>      #my $lexical = 'banana';
>      print '$lexical = ', $lexical, "\n";
>      print '$global = ', ($global or '(empty)'), "\n";
> 
> I couldn't do "my $lexical" once again without a warning, but I
> noticed something else that surprised me. The above code outputs:
> $lexical = apple
> $global = orange
> 
> while I had expected:
> $lexical = apple
> $global = (empty)
> 
> When Perl doesn't find a global variable in the current package, does
> it look for a varable with the same name in other packages?

Nope. our declares a lexical name in the current scope which is bound to
the global variable of the same name in the current package. If you
change your 'our' to 'use vars', it'll do what you expect (or rather,
give a strict error).

Ben

-- 
"If a book is worth reading when you are six,                * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis


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

Date: Wed, 02 Jun 2004 23:03:36 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Unexpected subroutine behaviour without &
Message-Id: <2i6u3uFk1bjfU1@uni-berlin.de>

Ben Morrow wrote:
> Quoth Gunnar Hjalmarsson <noreply@gunnar.cc>:
>> When Perl doesn't find a global variable in the current package,
>> does it look for a varable with the same name in other packages?
> 
> Nope. our declares a lexical name in the current scope which is
> bound to the global variable of the same name in the current
> package. If you change your 'our' to 'use vars', it'll do what you
> expect (or rather, give a strict error).

Hmm.. So that's the difference between "use vars" and "our"...  Since
I still care about 5.005 compatibility, I haven't really begun to use
"our". Sometimes I wonder if I ever will master even the basics of
Perl. :(

Anyway, thanks Ben and Anno for the lesson!

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



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

Date: Wed, 02 Jun 2004 22:08:42 +0100
From: zzapper <david@tvis.co.uk>
Subject: Re: WinXP : Terminating on signal SIGALRM(14)
Message-Id: <ucgsb05lt5a3mjdmhlll7nsalhnik1t2qu@4ax.com>

On Wed, 02 Jun 2004 14:41:58 +0100, wrote:

>On Wed, 2 Jun 2004 13:31:03 +0000 (UTC), wrote:
>
>>
>>Quoth zzapper <david@tvis.co.uk>:
>>> Hi,
>>> I don't know how OT this is, please advise of a better NG as required.
>>> 
>>> I have a Perl App (ActiveState 5.8.3) from which I create an
>>> executable with pp. I can create the exe fine but when I try to run it
>>> I get "Terminating on signal SIGALRM(14)" on my new PC (XP Home)
>>> 
>>> This however works fine on my old PC (XP Prof) 
>>> 
>>> (From Googling I suspect Norton Antivirus may be 2 blame (only on new
>>> PC)
BTW what is likely causing the SIGALRM(14), and what could it be
useful for?

zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


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

Date: 02 Jun 2004 12:14:52 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: YAPC::2004
Message-Id: <lipt8iuebn.fsf@localhost.localdomain>

>>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:

  TM> Uri Guttman <uri@stemsystems.com> wrote:
  >>>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:
  >> 
  >>>>>>> "Tad" == Tad McClellan <tadmc@augustmail.com> writes:
  Tad> If you're going to be at YAPC this summer, consider setting aside
  Tad> Thursday to get about half of a Stonehenge Alpaca (Intermediate) 
  Tad> class for free!
  >> 
  Tad> http://yapc.org/America/day2.shtml
  >> 
  Tad> I have a very high opinion of the presenter. (heh)
  >> 
  RLS> Actually, I do too. (heh)
  >> 
  >> i think he is a low down dirty rotten scoundrel and scalawag 

  TM> You forgot "bully".

ok, you're a bully too!

take that!

i may drop in and heckle you if i have nothing better to do.

uri


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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