Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!tut.cis.ohio-state.edu!usenet.ins.cwru.edu!ncoast!allbery From: allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) Newsgroups: comp.lang.perl Subject: Re: null? or not null? Message-ID: <1991Jan22.011051.24363@NCoast.ORG> Date: 22 Jan 91 01:10:51 GMT References: Reply-To: allbery@ncoast.ORG (Brandon S. Allbery KB8JRR) Followup-To: comp.lang.perl Organization: North Coast Computer Resources (ncoast) Lines: 63 As quoted from by rm55+@andrew.cmu.edu (Rudolph T. Maceyko): +--------------- | # prints just once -- why? | grep(print, "grep: yes\n", (&function())[7,8]); +--------------- Because this unwinds to: print "grep: yes\n"; print (&function())[7]; print (&function())[8]; The syntax of grep is "grep operation list"; in this case, the operation is "print" and the list is ("grep: yes\n", (&function())[7], (&function())[8]). +--------------- | Doesn't PERL distinguish undefined variables from those whose values are | "undef?" If so, an element of an array slice should have the value of the | requested element if it has one (could be undef), or remain undefined. +--------------- No, "undef" means the undefined state. +--------------- | following script prints both lines, no matter which of the two | assignments is used. | | #($a,$b) = (1); | ($a,$b) = (1,undef); | print '! defined $b', "\n" unless defined $b; | print '! $b', "\n" unless $b; +--------------- Correct: since $b is not defined, (defined $b) is false and the first print is executed. Since the undefined value is treated as false (actually, as the null string) in a conditional, the second print is executed. +--------------- | print $], "\n"; | print(($a,$b,$c) + 0, "\n"); | $b = 1; | print(($a,$b,$c) + 0, "\n"); | $c = 1; | print(($a,$b,$c) + 0, "\n"); | | prints | | $Header: perly.c,v 3.0.1.9 90/11/10 01:53:26 lwall Locked $ | Patch level: 41 | | 0 | 0 | 1 +--------------- Got me there; I'm not *that* much of a Perl guru. ++Brandon -- Me: Brandon S. Allbery VHF/UHF: KB8JRR on 220, 2m, 440 Internet: allbery@NCoast.ORG Packet: KB8JRR @ WA8BXN America OnLine: KB8JRR AMPR: KB8JRR.AmPR.ORG [44.70.4.88] uunet!usenet.ins.cwru.edu!ncoast!allbery Delphi: ALLBERY