in reply to Re: Re: Re: string context and list operators (was Re: Array in scalar context.)
in thread Array in scalar context.
print( join(' a ',@stuff), $/ ); print( scalar join(' a ',@stuff), $/ );
Yes, but...
print scalar join ' a ', @stuff, $/;In this last example, join will take the $/ as just one more argument, with the result that you'll get one last " a " after the 10, before the newline. The reason it does this is because of join's behavior as a list operator. Just about any function in Perl will behave this way, if it is called this way. print is usually called this way, but just about anything can be. Like I said, Perl blurs the distinction between functions and operators. Context, as in most of Perl, is everything. One is almost tempted to say that Perl is a context-oriented language and that this could be viewed as an entirely separate paradigm, an alternative to imperative or object-oriented or functional programming. Almost.
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/
|
|---|