Re: [Boston.pm] catenation of undef with string, 2 cases
Uri Guttman <uri-X/[email protected]>
| Newsgroups | gmane.comp.lang.perl.perl-mongers.boston |
|---|---|
| Organization | Perl Hunter |
| Message-ID | <[email protected]> |
On 11/09/2016 03:24 PM, Mike Small wrote: > Uri Guttman <uri-X/[email protected]> writes: > >> On 11/09/2016 02:04 PM, Bill Ricker wrote: >>> I think Uri and Ricky have it nailed. >>> >>> You can >>> wrap with do{ no warnings; ... } or >>> protect the concatenation with 42 . ($b//q()); or equivalent ?: or or >>> use $b .= 42 ; if order doesn't matter (it usually does, though) >>> or initialized $b to '' instead of undef, knowing it will be >>> concatenated (but in that case be sure it's tested for Truth not >>> Definedness) >>> >>> >> just to add on, i use .= so often. i like to build up strings and then >> return the whole string. i never initialize them to '' as i know .= >> works without warning. this is true for scalars and data structures as >> i said before. any lvalue undef can be used in this way. >> >> uri >> > Thanks everyone. Especially thanks for relating it to +=. I have trouble > remembering the handy special cases but when it's somewhat systematic > that helps. > another systemic and related thing in perl is autovivification. i have seen newbies always check for undef and then assigning a hash/array ref before adding elements to the hash/array. this is how some other langs require things to be done. perl has always had neat shortcuts like autoviv and no undef warnings on +=, .= and ++ because those are very popular operations and having perl do some init behind the scenes for you is way cool. uri