Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: $! and string context Message-ID: <8766@jpl-devvax.JPL.NASA.GOV> Date: 17 Jul 90 18:06:25 GMT References: <1990Jul16.173905.12516@uvaarpa.Virginia.EDU> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 32 In article <1990Jul16.173905.12516@uvaarpa.Virginia.EDU> worley@compass.com writes: : : X-Name: Larry Wall : : That's fine as a workaround. However, I'll make it so that if errno : is 0, it returns the null string in a string context. Then the boolean : value will be unsurprising. : : That sounds rather winning. But what I found strange at first was : that the conditional was a string context, given that I think of truth : values as 0/1. It's a consequence of how str_true is defined in perl.h. It says #define str_true(str) (Str = (str), \ (Str->str_pok ? \ ((*Str->str_ptr > '0' || \ Str->str_cur > 1 || \ (Str->str_cur && *Str->str_ptr != '0')) ? 1 : 0) \ : \ (Str->str_nok ? (Str->str_u.str_nval != 0.0) : 0 ) )) If the scalar currently has a valid string value, it chooses that in preference to the numeric value because the floating comparison will be slower on many machines than the integerish comparisons in the string branch. But since $! is the only thing in Perl that returns different canonical values depending on the string or numeric context, it doesn't much matter that boolean contexts are actually string contexts by preference. And I just made $! not matter. I'm sure Gilbert and Sullivan could have turned this into a song... Larry