qw(l i s t) vs (l, i, s, t)

2003-07-22 Thread Tor Hildrum
Not sure if this belongs here, but anyway:

[hildrum:~] tor% perl -e '@ARGV = qw(1 2); if(scalar(@ARGV)==qw(2 3) ) 
{print yes\n}'
yes
[hildrum:~] tor%

[hildrum:~] tor% perl -e '@ARGV = qw(1 2); if(scalar(@ARGV)==(2, 3) ) 
{print yes\n}'
[hildrum:~] tor%



[hildrum:~] tor% perl -e '@ARGV = qw(1 2 3); if(scalar(@ARGV)==(2, 3) ) 
{print yes\n}'
yes
[hildrum:~] tor%

[hildrum:~] tor% perl -e '@ARGV = qw(1 2 3); if(scalar(@ARGV)==qw(2 3) ) 
{print yes\n}'
[hildrum:~] tor%

Could someone please explain what is happening here?
I came across it, and had a hard time trying to figure out what was 
going on.

Tor



Re: qw(l i s t) vs (l, i, s, t)

2003-07-22 Thread Stefan Stiasny
hi

 Could someone please explain what is happening here?
 I came across it, and had a hard time trying to figure out what was 
 going on.
in 5.6.1 it seems to work the correct way, i.e. the first two examples
aren't true, while the third and fourth evaluate as true. maybe something
was changed in the behaviour of qw, it seems that it in scalar context,
it behaves like an array, not like a constant list with the comma 
operator ...

anyway, it sounds more like a bug report thant fwp
sc

-- 
stefan stiasny [EMAIL PROTECTED] 
In an evolving universe, who stands still moves backwards.


Re: qw(l i s t) vs (l, i, s, t)

2003-07-22 Thread Jasper McCrea
Tor Hildrum wrote:
 
 Not sure if this belongs here, but anyway:
 
 [hildrum:~] tor% perl -e '@ARGV = qw(1 2); if(scalar(@ARGV)==qw(2 3) )
 {print yes\n}'
 yes
 [hildrum:~] tor%
 
 [hildrum:~] tor% perl -e '@ARGV = qw(1 2); if(scalar(@ARGV)==(2, 3) )
 {print yes\n}'
 [hildrum:~] tor%
 
 
 
 [hildrum:~] tor% perl -e '@ARGV = qw(1 2 3); if(scalar(@ARGV)==(2, 3) )
 {print yes\n}'
 yes
 [hildrum:~] tor%
 
 [hildrum:~] tor% perl -e '@ARGV = qw(1 2 3); if(scalar(@ARGV)==qw(2 3) )
 {print yes\n}'
 [hildrum:~] tor%

What version of perl are you using? On 5.6.0 and 5.8.0 the first two are false
for me (as I'd expect).

Although thinking about it, qw doesn't have a comma anywhere, so why would it
use the comma operator to return the last element? That wouldn't make much
sense. Would it?

I have no idea. I don't know why I'm bothering to add my 2 pennies worth.

Jasper
-- 
Lloyd Christmas: Excuse me, miss, what's the soup du jour?
Waitress:The Soup of the Day.
Lloyd Christmas: Mmmm...sounds good, think I'll have that.


Re: qw(l i s t) vs (l, i, s, t)

2003-07-22 Thread Yitzchak Scott-Thoennes
On Tue, 22 Jul 2003 03:48:53 +0200, [EMAIL PROTECTED] wrote:

Could someone please explain what is happening here?
I came across it, and had a hard time trying to figure out what was 
going on.

When you use an array in scalar context (e.g. scalar(@ARGV)==foo, or even
just @ARGV==foo), it gives the number of elements in the array (either
2 or 3 in your examples).

When you use a comma-operator in scalar context (e.g. (2,3)) it throws
away the left operand and returns the right one.

qw() should act just like a comma'd list, so scalar(qw(2 3)) should be
3.  You aren't seeing this, so I suspect you to be using an extremely
old version of perl where qw() didn't work as well.  If you upgrade to
5.005_55 or higher you should see qw() acting better.


Re: Fun - Each character at most once

2003-07-22 Thread Adam Rice
Quoting A. Pagaltzis ([EMAIL PROTECTED]):
 Basically, with all ASCII characters used at most once, you can't
 really write anything that needs to actually operate on data in
 any more but the most trivial ways.

Actually, using the technique from Ronald J Kimball's JAPH, you can encode any
ASCII Perl program less than about 36 characters. Here's a really boring
example:

s{}[ !#%B-'*EAHCJIONLR.4VU0],$_^=qPSKMQbGYFDwixojd~gprZtn:;eval

I wrote a program to generate these, but has an unfun tendency to take forever
when the solution is non-trivial so I won't post it. If there was a better
technique than brute force to find the answers that might be fun, but I just
can't get my head around it.

If you allow the full-range of 8-bit characters, rather than just ASCII, you
can encode much longer programs, up to 120 characters or so, definitely enough
to do non-trivial computation.

Adam

-- 
Adam Rice -- [EMAIL PROTECTED] -- Blackburn, Lancashire, England


Re: qw(l i s t) vs (l, i, s, t)

2003-07-22 Thread Jean-Pierre Vidal
Le Mardi 22 Juillet 2003 01:48, Tor Hildrum a écrit :
 Not sure if this belongs here, but anyway:

[snip...]

as said Randal :

In modern versions of Perl [...] returning either
- a list in a list context,
- or the last element of a list in a scalar context.

(don't forget 'scalar @array' return the lenght of the array)

we are in scalar context, because scalar(@ARGV):

@ARGV = qw(1 2); # scalar(@ARGV) is 2 (number of elements)
scalar qw(2, 3) # is 3, last element of the list = false

@ARGV = qw(1 2); # is 2
scalar(2, 3) # is 3  = false

@ARGV = qw(1 2 3); # is 3
scalar (2, 3) # is 3  = true

@ARGV = qw(1 2 3); # 3
scalar qw(2 3) # is 3 = true

This is the result in perl 5.8 on linux

so the problem seems in the version of perl you are running, if I understand 
the answers from Yitzchak Scott-Thoennes, Jasper McCrea and Stefan Stiasny, 
and obviously Randal.

Thanks for my fwp since I have learned more about perl...
My apologies for my Frenchglish

Jean-Pierre
-- 
Jean-Pierre Vidal


Re: qw(l i s t) vs (l, i, s, t)

2003-07-22 Thread Randal L. Schwartz
 John == John Douglas Porter [EMAIL PROTECTED] writes:

John Randal L. Schwartz [EMAIL PROTECTED] wrote:
 ... the last element of a list in a scalar context.

John Randal said ...a list in a scalar context.  /me faints.

I said last element of a list in a scalar context.   Don't misparse.
There's still no such thing as a list in a scalar context.

You can't quote me out of context.
And you can't get that context out of me.

:-)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!