--- Bryan Harris <[EMAIL PROTECTED]> wrote: > Wild, I had no idea perl supported all these notations...
LOL!!! There are more.... TMTOWTDI: There's More Than One Way To Do It. > >> I'd like to concatenate two variables-- > >> $newVar = $old1 . $old2; > >> -- where $old1 might be undefined. Is there any way to > >> set a flag so that this just results in $old2 instead of > >> the compiler throwing an error? > > > > Version 1 (much preferable): > > $newVar = $old1 ? $old1 . $old2 : $old2; > > > > Version 2 (okay-ish): > > $old1 ||= ''; > > $newVar = $old1 . $old2; > > What is ||="? Is that the same as > > $old1 = ($old1 || ""); Basically. Think of it as being in the group with += and *= .... You can also use that structure for catenation with .= Similarly (but not really the same), you can do here-docs like this: my $here_doc =<<END; this is all text going into the variable. You can even embed $stuff as if it were double-quoted. (but if you put any quotes around 'END' it acts as if they were around the whole block.... and that 'END' isn't a problem, because it has to me atthe start of a line to count. END > What's the single double quote? (in $old1 ||= '';) That's just a false-but-defined empty string. Nothing magical. > > Version 3 (ugly but workable): > > > > $newVar = ($old1||'') . $old2; > > Hmm.. I thought this was the prettiest one! =) Then use that one, by all means! It's just a matter of taste. Use what makes sense to you. =o) > > Version 4 (requires lexical warnings): > > { no warnings; > > $newVar = $old1 . $old2; > > } > > Version 5 (ugh): > > { local $^W = undef; > > $newVar = $old1 . $old2; > > } > > *WHY* would you "rather not" check to see if it's defined first? > > I guess because I'm kind-of a purist when I shouldn't be. I just meant that there has to be a test. It doesn't have to use if/else keywords. :) This is a complex if/then/else, but no keywords: my $v = $x ? 1 : $y ? 2 : $z ? 3 : undef; > Thanks for the tips. > - Bryan Any time. ;o] __________________________________________________ Do you Yahoo!? Yahoo! Shopping - Send Flowers for Valentine's Day http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]