[24941] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7191 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 29 14:06:56 2004

Date: Wed, 29 Sep 2004 11:05:11 -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, 29 Sep 2004     Volume: 10 Number: 7191

Today's topics:
    Re: #define-like feature in Perl <noreply@gunnar.cc>
    Re: #define-like feature in Perl <1usa@llenroc.ude.invalid>
    Re: #define-like feature in Perl <1usa@llenroc.ude.invalid>
    Re: #define-like feature in Perl <noreply@gunnar.cc>
    Re: #define-like feature in Perl <shawn.corey@sympatico.ca>
    Re: CGI scripts and modular design? <postmaster@castleamber.com>
    Re: counting number of occurrences of every possible su <nobull@mail.com>
    Re: FileDeletionByDate - Error (tomcat)
    Re: help with eval <simplitia@gmail.com>
    Re: help with eval <1usa@llenroc.ude.invalid>
    Re: help with eval <1usa@llenroc.ude.invalid>
    Re: help with eval <simplitia@gmail.com>
    Re: help with eval <nobull@mail.com>
    Re: help with eval <1usa@llenroc.ude.invalid>
    Re: HTTP::Cookies cookie_jar %rest hash <comdog@panix.com>
        Newbie: String concatenation limited to 256 characters? (Piet)
        Newbie: String concatenation limited to 256 characters? (Piet)
    Re: Newbie: String concatenation limited to 256 charact <1usa@llenroc.ude.invalid>
        Odd sort() problem <bigal187@invalid.rx.eastcoasttfc.com>
    Re: Odd sort() problem <1usa@llenroc.ude.invalid>
    Re: Odd sort() problem <bigal187@invalid.rx.eastcoasttfc.com>
    Re: Order of subroutines (Aris Xanthos)
    Re: Precedence of exponentiation (Hunter Johnson)
    Re: Precedence of exponentiation (Malcolm Dew-Jones)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 29 Sep 2004 17:53:59 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: #define-like feature in Perl
Message-Id: <2s045jF1evornU1@uni-berlin.de>

Yash wrote:
> In a perl 5.8 program, We have to use a long list of variables in a
> certain order in a number of places. It is something like:
> my ($var1, $field2, $a3, $b4, .....) ;
> 	.
> 	.
> 	.
> foreach $x ($var1, $field2, $a3, $b4, .....) {
> 	$x = -1 ;
> }
> 	.	
> 	.
> 	.
> print join(",",($var1, $field2, $a3, $b4, .....)) ;
> 
> Instead of having to repeat the names of the fields and their order,
> in all places of use, we would like to have something like
> #define FIELD_LIST $var1, $field2, $a3, $b4, .....

How about using a hash, and define the order in a constant:

     use constant FIELD_LIST => qw(var1 field2 a3 b4);
     my %hash = (var1 => 1, field2 => 2, a3 => 3, b4 => 4);

     print join ',', @hash{ (FIELD_LIST) };

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


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

Date: 29 Sep 2004 16:02:04 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: #define-like feature in Perl
Message-Id: <Xns95737A6C7670Aasu1cornelledu@132.236.56.8>

Ron Parker <ron.parker@povray.org> wrote in 
news:slrncllhr1.fdv.ron.parker@mail.parkrrrr.com:

> On 29 Sep 2004 13:07:09 GMT, A. Sinan Unur wrote:

>>> print join ',', values %hash;
> 
> $ perldoc -f values
> =item values HASH
> 
> Returns a list consisting of all the values of the named hash.  (In a
> scalar context, returns the number of values.)  The values are
> returned in an apparently random order.
> ----
> 
> You don't think that "random order" thing might be a problem?

Of course I do ... But the OP's example set all variables to the same 
value. My intent was for the OP to think about this a little and come up 
with the appropriate question. There are several ways of dealing with this. 
One quick & easy way would be to define the order:

my @order = qw(var1, field2, a3, b4);

and use a hash slice:

print join ',', @hash{@order};

There is also a FAQ entry that might be helpful.

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: 29 Sep 2004 16:03:17 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: #define-like feature in Perl
Message-Id: <Xns95737AA16370Easu1cornelledu@132.236.56.8>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in news:2s045jF1evornU1@uni-
berlin.de:

> How about using a hash, and define the order in a constant:
> 
>      use constant FIELD_LIST => qw(var1 field2 a3 b4);
>      my %hash = (var1 => 1, field2 => 2, a3 => 3, b4 => 4);
> 
>      print join ',', @hash{ (FIELD_LIST) };

Hi Gunnar,

Sorry, my response to Ron Parker's follow-up replicates your answer. I had 
not seen your post yet.

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Wed, 29 Sep 2004 18:14:51 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: #define-like feature in Perl
Message-Id: <2s05coF1eb79vU1@uni-berlin.de>

A. Sinan Unur wrote:
> Gunnar Hjalmarsson wrote:
>> How about using a hash, and define the order in a constant:
>> 
>>     use constant FIELD_LIST => qw(var1 field2 a3 b4);
>>     my %hash = (var1 => 1, field2 => 2, a3 => 3, b4 => 4);
>>
>>     print join ',', @hash{ (FIELD_LIST) };
> 
> Sorry, my response to Ron Parker's follow-up replicates your
> answer. I had not seen your post yet.

No reason to apologize. It just confirms that it might be an
appropriate approach, right? ;-)

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


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

Date: Wed, 29 Sep 2004 12:31:19 -0400
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: #define-like feature in Perl
Message-Id: <BqB6d.12692$tT2.1058572@news20.bellglobal.com>

Yash wrote:
> Hi,
> 
> In a perl 5.8 program, We have to use a long list of variables in a
> certain order in a number of places. It is something like:
> my ($var1, $field2, $a3, $b4, .....) ;
> 	.
> 	.
> 	.
> foreach $x ($var1, $field2, $a3, $b4, .....) {
> 	$x = -1 ;
> }
> 	.	
> 	.
> 	.
> print join(",",($var1, $field2, $a3, $b4, .....)) ;
> 
> 
> Instead of having to repeat the names of the fields and their order,
> in all places of use, we would like to have something like
> #define FIELD_LIST $var1, $field2, $a3, $b4, .....
> 
> and user FIELD_LIST in all places.
> This is important for us as the fields and their order may change as
> the program evolves.
> Can somebody suggest a better alternative?
> 
> Thanks

See perldoc perlrun for the -P option.

	--- Shawn


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

Date: 29 Sep 2004 15:20:30 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: CGI scripts and modular design?
Message-Id: <Xns957369331FA99castleamber@130.133.1.4>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in news:2ru3msF1eom8pU1@uni-
berlin.de:

> John Bokma wrote:
>> Gunnar Hjalmarsson wrote:
>>> John Bokma wrote:
>>>> Some don't give shell access.
>>> 
>>> Assuming we are talking about pure Perl modules, why would you
>>> need shell access to upload them to a local library?
>> 
>> make?
> 
> Okay, but make isn't necessary. Simply uploading the .pm files to the
> right directories is sufficient. I did that successfully for several
> years as long as I had a hosting account without shell access.

If it's pure Perl, ok. But when you need a C compiler... And let's hope you 
can access that one. Otherwise you need access to the same OS, or worse 
depending on how you link.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                           personal page:       http://johnbokma.com/
        Experienced programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html


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

Date: Wed, 29 Sep 2004 17:53:51 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: counting number of occurrences of every possible substring in multiple files
Message-Id: <cjep2l$4s7$1@sun3.bham.ac.uk>



Tad McClellan wrote:

> C3 <> wrote:
> 
>>I am trying to write a program that reads multiple files and prints out the 
>>number of occurrences of n-length byte sequences across these files. the 
>>value of n must be specified on the command-line.
>>
>>Since I'll be dealing with binary files, 
> 
> 
> 
>    perldoc -f binmode
> 
> 
> 
>>I want the ASCII codes of the 
>>characters printed out.
> 
> 
> 
> Huh?
> 
> If it is a text file, then it contains ASCII codes.

Er that's not the general case.  If it's a text file it contains 
seqences of bytes that encode codepoints in some character set encoding.

With any luck there's a mapping from that encoding onto Unicode.

If you are even luckier you'll be able to simply tell Perl about the 
encoding and and it will read the file as a series of Unicode code points.

In the simplest case an ASCII text filecontains only bytes with values 
0x00-0x7F which directly encode the corresponding codepoints in ASCII.

But is not the default case for Perl to assume assume text files are 
utf8?  (Of course any well-formed ASCII text file is also a well-formed 
utf8 text file).

> If it is a binary file, then it may contain some other encoding.

If it's a binary file then it's a series of bytes.  These bytes may to 
may not encode characters.



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

Date: 29 Sep 2004 08:06:48 -0700
From: t.piotrowski@gmail.com (tomcat)
Subject: Re: FileDeletionByDate - Error
Message-Id: <404ed500.0409290706.2e1be9ee@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<cjbam6$ps6$1@mamenchi.zrz.TU-Berlin.DE>...

> No idea, you have given far too little information.  Read the
> documentation that comes with File::Recurse.
> 
> Anno


Ok - I'll try to find the answer in documentation. I'm beginner in
Perl and I thought that it could be easier to solve this (like in
event of 'case sensitive').

Anyway, thanks for help
Tomek


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

Date: 29 Sep 2004 09:32:58 -0700
From: "Alex  Lee" <simplitia@gmail.com>
Subject: Re: help with eval
Message-Id: <1096475578.421864.34580@k17g2000odb.googlegroups.com>

Hi,
I don't  think eval return errors unless you tell it to: its stored in
@$.  I am using eval, and perhaps many other people are as well, to
trap syntax errors - thats the whole point. If you don't believe me
try:

eval ' 6+/ ';
or eval '6 /0';

The above example will return nothing , no error message, unless you
add:
warn $@ if $@;

Iam mot planning to use this on a server side script, thus i don't
think eval in this case is very 'evil' nor dangerous ;)   In fact it is
very useful, as I said before, to trap fatal errors. 
 
thanks. 
al ;)



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

Date: 29 Sep 2004 16:51:55 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: help with eval
Message-Id: <Xns957382DFF3152asu1cornelledu@132.236.56.8>

"Alex  Lee" <simplitia@gmail.com> wrote in news:1096475578.421864.34580
@k17g2000odb.googlegroups.com:

> Hi,
> I don't  think eval return errors unless you tell it to: its stored in
> @$.  

ITYM @$. This is something Tad has already pointed out.

I will suggest reading perldoc -f eval as your understanding seems to be 
muddled and you are throwing terms around without paying attention to their 
meanings.

> I am using eval, and perhaps many other people are as well, to
> trap syntax errors - thats the whole point. If you don't believe me
> try:
> 
> eval ' 6+/ ';
> or eval '6 /0';

You should not use eval for syntax errors. That's what the Perl compiler is 
for.

> The above example will return nothing , no error message, unless you
> add:
> warn $@ if $@;

I am sure this is not a surprise to Tad.

> In fact it is very useful, as I said before, to trap fatal errors. 

Clearly, as we all know.

As for your original question:

> I am getting this weird error message from eval even when @$ is not
> set. example:
> eval '**1';
> 
> yeilds erorr outpu:
> Number found where operator expected at (eval 1) line 1, near "**1"
> (Missing operator before 1?)

That is not a weird message. It is telling you exactly what is happening. 
The exponentiation operator is a binary operator and hence requires two 
operands.

If you had read the docs for eval, you would have noticed:

Beware that using "eval" neither silences perl from printing warnings 
to STDERR, nor does it stuff the text of warning messages into $@. 

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: 29 Sep 2004 17:08:17 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: help with eval
Message-Id: <Xns957385A63ADAasu1cornelledu@132.236.56.8>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
news:Xns957382DFF3152asu1cornelledu@132.236.56.8: 

> "Alex  Lee" <simplitia@gmail.com> wrote in
> news:1096475578.421864.34580 @k17g2000odb.googlegroups.com:
> 
>> Hi,
>> I don't  think eval return errors unless you tell it to: its stored
>> in @$.  
> 
> ITYM @$. This is something Tad has already pointed out.

Sorry Tad! Tad pointed out that there is no such variable. The correct 
variable is $@. I'll keep quiet for the rest of the day :)

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: 29 Sep 2004 10:13:19 -0700
From: "Alex  Lee" <simplitia@gmail.com>
Subject: Re: help with eval
Message-Id: <1096477999.707653.91720@k17g2000odb.googlegroups.com>

This is getting kind of weird: all I ask was how I can silence eval. Oh
excuse my 'simple' language, to prevent eval from sending 'all' warning
messages to STDERR:

anyway i found an excellent post to this question on:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=58gati%24nj9%40soda.CSUA.Berkeley.EDU&rnum=5&prev=/groups%3Fq%3DNumber%2Bfound%2Bwhere%2Boperator%2Bexpected%2Bat%2Bperl%2Beval%26hl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3D58gati%2524nj9%2540soda.CSUA.Berkeley.EDU%26rnum%3D5
in case someone else there have the same question. 

al ;)



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

Date: Wed, 29 Sep 2004 18:17:17 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: help with eval
Message-Id: <cjeqei$5rh$1@sun3.bham.ac.uk>



Alex Lee wrote:

> I am getting this weird error message from eval even when @$ is not
> set.
> example:
> eval '**1';
> 
> yeilds erorr outpu:
> Number found where operator expected at (eval 1) line 1, near "**1"
> (Missing operator before 1?)

The problem is that Perl compilation errors are not really errors in the 
sense of being exceptions that that eval() can catch.

Compilation errors are more like mandatory warnings that also set a flag 
that tiggers an "Execution ... aborted due to compilation errors" when 
compilation completes.  In eval() (at least in recent Perls) you 
actually get the last compliation error rather than "Execution ... 
aborted due to compilation errors" returned in $@.

To capture others you need something like:

#!/usr/bin/perl
use strict;
use warnings;

my ($stderr,$err);

{
   open my $e_fh, '>', \$stderr or die $!;
   # The orginal STDERR filehandle is special and
   # cannot be redirected to a scalar but it can be
   # temporarily replaced
   local *STDERR = $e_fh;
   eval '**1';
   $err = $@;
}

print "Last error: $err\nOther errors: $stderr\n";

 > I am using the active state 806  perl version: 5.8.0

Note - I tested this in 5.8.4.  I know this stuff has changed a lot in 
recent versions of Perl.  I suspect this may not work in 5.8.0.



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

Date: 29 Sep 2004 17:48:57 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: help with eval
Message-Id: <Xns95738C8B64508asu1cornelledu@132.236.56.8>

"Alex  Lee" <simplitia@gmail.com> wrote in
news:1096477999.707653.91720@k17g2000odb.googlegroups.com: 

> This is getting kind of weird: all I ask was how I can silence eval.
> Oh excuse my 'simple' language, to prevent eval from sending 'all'
> warning messages to STDERR:

Ah-em, you would have gotten that answer if you had simply read:

perldoc -f eval


-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Wed, 29 Sep 2004 10:55:27 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: HTTP::Cookies cookie_jar %rest hash
Message-Id: <290920041055272840%comdog@panix.com>

In article <9901b9fa.0409281933.7508018@posting.google.com>, bigDWK
<daveGoogle@davewking.com> wrote:

> From the HTTP::Cookies man page it shows this function


> $c_jar->scan(\&cookieCB);
> 
> sub cookieCB
> {
>      my($ver, $keyC, $valC, $path, $domain, $port, $path_spec,
> $secure, $maxage, $discard, %attr) = @_;

that last argument should be a scalar.  HTTP::Cookies::scan is
going to call this function and give it an anonymous hash
as the last argument.

See the docs for HTTP::Cookies::set_cookie().


> }

-- 
brian d foy, comdog@panix.com


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

Date: 29 Sep 2004 10:21:44 -0700
From: pit.grinja@gmx.de (Piet)
Subject: Newbie: String concatenation limited to 256 characters?
Message-Id: <39cbe663.0409290921.1f67d3f9@posting.google.com>

Hello,
I have written a small script that parses an (ugly) HTML file line by
line and converts the relevant information to CSV. During parsing, I
heavily use string concatenation to glue together parts of text that
belong together (but might be separated in the original file by tags
or newlines). In the code, the expression
$oldstring = $oldstring.$newstring
occurs very often.
Frequently, the strings get longer than 256 characters. At this point,
the string concatenation refuses to add anything to $oldstring. How is
it possible to avoid that?
Thanks in advance for answers on  a (maybe very newbish) question
Piet


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

Date: 29 Sep 2004 10:25:31 -0700
From: pit.grinja@gmx.de (Piet)
Subject: Newbie: String concatenation limited to 256 characters?
Message-Id: <39cbe663.0409290925.2e735196@posting.google.com>

Hello,
I have written a small script that parses an (ugly) HTML file line by
line and converts the relevant information to CSV. During parsing, I
heavily use string concatenation to glue together parts of text that
belong together (but might be separated in the original file by tags
or newlines). In the code, the expression
$oldstring = $oldstring.$newstring
occurs very often.
Frequently, the strings get longer than 256 characters. At this point,
the string concatenation refuses to add anything to $oldstring. How is
it possible to avoid that?
Thanks in advance for answers on  a (maybe very newbish) question
Piet


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

Date: 29 Sep 2004 17:52:05 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Newbie: String concatenation limited to 256 characters?
Message-Id: <Xns95738D131929Dasu1cornelledu@132.236.56.8>

pit.grinja@gmx.de (Piet) wrote in news:39cbe663.0409290925.2e735196
@posting.google.com:

> Hello,
> I have written a small script that parses an (ugly) HTML file line by
> line and converts the relevant information to CSV. During parsing, I
> heavily use string concatenation to glue together parts of text that
> belong together (but might be separated in the original file by tags
> or newlines). In the code, the expression
> $oldstring = $oldstring.$newstring
> occurs very often.
> Frequently, the strings get longer than 256 characters. At this point,
> the string concatenation refuses to add anything to $oldstring. How is
> it possible to avoid that?
> Thanks in advance for answers on  a (maybe very newbish) question
> Piet

Your post appeared twice. Please don't post multiple copies of the same 
question.

You'll need to provide a short self-contained script that still exhibits 
the problem to support such an outrageous claim.

#! perl

use strict;
use warnings;


my $str = 'a';

$str .= 'a' for (1 .. 999_999);

print length($str), "\n";

__END__



-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Wed, 29 Sep 2004 09:59:02 -0700
From: "187" <bigal187@invalid.rx.eastcoasttfc.com>
Subject: Odd sort() problem
Message-Id: <2s07v9F1fvtn5U1@uni-berlin.de>

I friend of mine recently accessed me for a little one liner to nicely
display all the paths in the $PATH vartiable on his NT 5.1 (aka XP Pro)
machine: (sorry for word wrap)

   C:\> perl -e "print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b) }
           split(/;/, $ENV {'PATH'})), qq{\n};"

   C:\Program Files\Borland\JBuilder6\jdk1.3.1\bin
   C:\Program Files\Executive Software\Diskeeper\
   C:\Program Files\ATI Technologies\ATI Control Panel
   C:\usr\local\wbin
   C:\Inetpub\wwwroot\perl\bin\
   C:\PROGRA~1\Borland\CBUILD~1\Projects\Bpl
   C:\PROGRA~1\Borland\CBUILD~1\Bin
   C:\Inetpub\wwwroot\perl\bin
   C:\WINDOWS\system32
   C:\WINDOWS
   C:\WINDOWS\System32\Wbem


I get the same sort of oddness on my Linux machine as well:

   $ perl -e 'print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b) }
        split(/:/, $ENV{"PATH"})), qq{\n};'

   /home/oracle/OraHome1/bin
   /usr/bin
   /usr/X11R6/bin
   /misc/java/sdk/j2sdk1.4.1_02/bin
   /home/bigal187/bin
   /usr/sbin
   /sbin
   /usr/local/bin
   /usr/local/sbin
   /usr/local/BerkeleyDB.4.2/bin/
   /usr/lib/qt/bin
   /bin

Both Perl's are 5.6.1, though my Linux also has 5.8.2 which does
similar, though different order:

   $ perl5.8.2 -e 'print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b) }
        split(/:/, $ENV{"PATH"})), qq{\n};'

   /home/oracle/OraHome1/bin
   /home/bigal187/bin
   /misc/java/sdk/j2sdk1.4.1_02/bin
   /usr/X11R6/bin
   /usr/bin
   /usr/sbin
   /bin
   /sbin
   /usr/local/bin
   /usr/local/sbin
   /usr/local/BerkeleyDB.4.2/bin/
   /usr/lib/qt/bin

What is going on here? Why is sort doing this? I've used sort(), map(),
and grep() in cascaded form like this before without this problem;
split() returns an array, which get sucked into sort(), who spits it
back out to join(), does it not?




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

Date: 29 Sep 2004 17:07:05 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Odd sort() problem
Message-Id: <Xns95738571CB6EBasu1cornelledu@132.236.56.8>

"187" <bigal187@invalid.rx.eastcoasttfc.com> wrote in news:2s07v9F1fvtn5U1
@uni-berlin.de:

> I friend of mine recently accessed me for a little one liner to nicely
> display all the paths in the $PATH vartiable on his NT 5.1 (aka XP Pro)
> machine: (sorry for word wrap)
> 
>    C:\> perl -e "print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b) }
>            split(/;/, $ENV {'PATH'})), qq{\n};"

I like one liners but I avoid them precisely for this type of problem: 
lc{$a} should be lc($a) or just lc $a.

So, the problem is not sort :)
-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Wed, 29 Sep 2004 11:00:43 -0700
From: "187" <bigal187@invalid.rx.eastcoasttfc.com>
Subject: Re: Odd sort() problem
Message-Id: <2s0bj9F1f8ihqU1@uni-berlin.de>

A. Sinan Unur wrote:
> "187" <bigal187@invalid.rx.eastcoasttfc.com> wrote in
> news:2s07v9F1fvtn5U1 @uni-berlin.de:
>
>> I friend of mine recently accessed me for a little one liner to
>> nicely display all the paths in the $PATH vartiable on his NT 5.1
>> (aka XP Pro) machine: (sorry for word wrap)
>>
>>    C:\> perl -e "print qq{\n}, join(qq{\n}, sort { lc{$a} cmp lc($b)
>>            } split(/;/, $ENV {'PATH'})), qq{\n};"
>
> I like one liners but I avoid them precisely for this type of problem:
> lc{$a} should be lc($a) or just lc $a.

Oh, the humanity! Actually I tend to stay away from them too, but my
friend wanted a simple one liner that could stick into a dos BATch file,
and not using any external scripts, which I prefer to use instead.

But what I really don't understand is why it doesn't result in a compile
error? lc{$a}, one would think, is not a valid statement.

I admit should I have used -w in there:

   Odd number of elements in anonymous hash at -e line 1.
   Odd number of elements in anonymous hash at -e line 1.
   Odd number of elements in anonymous hash at -e line 1.
   [......]

Then proceeds to print in random order. (That is, before I fixed it.)

> So, the problem is not sort :)

I didn't think it was :)




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

Date: 29 Sep 2004 09:26:53 -0700
From: Aris.Xanthos@ling.unil.ch (Aris Xanthos)
Subject: Re: Order of subroutines
Message-Id: <b3b0e6f5.0409290826.20165010@posting.google.com>

Thank you for your answers, all of them help.

Indeed I should have used strict and warnings.

Aris Xanthos


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

Date: 29 Sep 2004 08:35:03 -0700
From: jhunterj@gmail.com (Hunter Johnson)
Subject: Re: Precedence of exponentiation
Message-Id: <1c912331.0409290735.22d5dea1@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<cjduep$eme$2@mamenchi.zrz.TU-Berlin.DE>...
> Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> 
> [...]
> 
> > I agree that it would have been better if Perl parsed -a ** b as 
> > (-a) ** b, but...
> 
> I disagree.  Traditional mathematics construes -x as (-1) * x, and
> consequently -a ** b = (-1) * (a ** b) = -(a ** b), because ** binds
> tighter than *.

Then just as consequently a ** -b = (a ** -1) * b, also because **
binds tighter than *. I think there's an error in the assumptions
somewhere.

Hunter
--
http://www.hunterandlori.com


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

Date: 29 Sep 2004 09:37:23 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Precedence of exponentiation
Message-Id: <415ae4c3@news.victoria.tc.ca>

Hunter Johnson (jhunterj@gmail.com) wrote:
: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<cjduep$eme$2@mamenchi.zrz.TU-Berlin.DE>...
: > Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
: > 
: > [...]
: > 
: > > I agree that it would have been better if Perl parsed -a ** b as 
: > > (-a) ** b, but...
: > 
: > I disagree.  Traditional mathematics construes -x as (-1) * x, and
: > consequently -a ** b = (-1) * (a ** b) = -(a ** b), because ** binds
: > tighter than *.

: Then just as consequently a ** -b = (a ** -1) * b, also because **
: binds tighter than *. I think there's an error in the assumptions
: somewhere.

No, if a ** -b, was written in (say) Latex instead of plain text then it
would look kinda like

	 -b
	a

I.e. the -b is a superscript, but you just can't see that in a plain text
file.


As for -a ** b, I just checked this in my old university first year
calculus book, in the beginning where they go over basic concepts.  
Coincidentally or not, they have examples that cover both the situations,
and

	    2
	x=-y

has a graph that opens to the left.  I.e. it's x = (-1) * (y**2), just
like Anno said.



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

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


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