in reply to Surprised by join

In brief, join() is a plain function. It does not evaluate its first argument (or any argument) more than once. In your example, $i is incremented, but after the join function has been called and returns.

I'm pretty sure that the only things that evaluate an argument more than once will accept a BLOCK type argument. For example, sort BLOCK LIST or map BLOCK LIST. Curly braces. A bit of code to be evaluated on each iteration.

my $result = ''; my @list = qw(one two three four five six seven eight); $result .= (shift @list).':'.(shift @list) while @list; print $result, $/; __OUTPUT__ one:twothree:fourfive:sixseven:eight

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re^2: Surprised by join
by EdwardG (Vicar) on Jun 08, 2004 at 13:27 UTC

    I gathered this, and I understand the post increment, what I'm wondering about is sensible alternatives to my final code. I accept that join might not be the right tool, but surely there is something better than my concatenation in a for loop, or your while loop?

    PS: stop changing your node, I don't know what I'm replying to! :)