>>>>> "CO" == Chas Owens <chas.ow...@gmail.com> writes:

  CO> On Sun, Jul 12, 2009 at 14:31, Dan<d...@entropy.homelinux.org> wrote:
  >> Hi people.
  >> 
  >> Is the order of results from a join() operation guaranteed ( assuming my
  >> array doesn't change, of course )?
  CO> snip

  CO> Interesting, the docs for the join function make no guarantee about
  CO> the order of the join; however, the historic order has been first
  CO> element, second element, etc.  This is unlikely to change (if for no
  CO> other reason than it would make join useless).  Also, in the tests for
  CO> the Perl interpreter, there is the following code:

  CO> @x = (1, 2, 3);
  CO> if (join(':',@x) eq '1:2:3') {print "ok 1\n";} else {print "not ok 1\n";}

  CO> This seems to be a fairly strong promise that join will operate in the
  CO> expected manor.

intersting point. the docs say:

        Joins the separate strings of LIST into a single string with
        fields separated by the value of EXPR, and returns that new
        string.  Example:

but the key point (implied i would say) is that the order of a list is
immutable. lists are read only and on the stack so they must be
processed left to right. this is how foreach works as well as
map/grep. so even though it doesn't state this explicitly, it is safe to
assume join keeps the ordering. not only is it expected but massive
amounts of code assumes it and it is the only logical way it could be
done. joining in a different order would definitely be mentioned in the
docs.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to