Prev: FAQ 9.19 How do I return the user's mail address?
Next: "Bizarre copy of HASH in sassign..." bug
From: jidanni on 11 Aug 2010 12:54 I don't think this is returning the empty string ("") actually: $ man perlop s/PATTERN/REPLACEMENT/msixpogce Searches a string for a pattern, and if found, replaces that pattern with the replacement text and returns the number of substitutions made. Otherwise it returns false (specifically, the empty string). $ echo iiii|perl -nwle 'print 1 + s/i//g' 5 $ echo iiii|perl -nwle 'print 1 + s/j//g' 1 $ echo iiii|perl -nwle 'print 1 + ""' #if it really were the empty string, this would happen: Argument "" isn't numeric in addition (+) at -e line 1, <> line 1. 1 So maybe the man page should be reworded to say just what in fact is going on.
From: Uri Guttman on 11 Aug 2010 14:11 >>>>> "j" == jidanni <jidanni(a)jidanni.org> writes: j> I don't think this is returning the empty string ("") actually: j> $ man perlop j> s/PATTERN/REPLACEMENT/msixpogce j> Searches a string for a pattern, and if found, replaces that pattern with the replacement j> text and returns the number of substitutions made. Otherwise it returns false (specifically, j> the empty string). j> $ echo iiii|perl -nwle 'print 1 + s/i//g' why all the work with echo and -n? perl -wle 'print 1 + "iii" =~ /i/' 2 shows the same issues without all the extra cruft it is returning the double valued false that other booleans also return. it is both the empty string AND 0 and you can see that with various inspection subs like ones in Scalar::Util. so you can use a boolean result in numeric or string expressions and never get a warning. it probably says null string because explaining that it really is both is very wordy and would have to be explained everywhere a boolean is returned. not enough of a big deal to worry about. uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
|
Pages: 1 Prev: FAQ 9.19 How do I return the user's mail address? Next: "Bizarre copy of HASH in sassign..." bug |