Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^5: finding number of contiguous letters

by blazar (Canon)
on May 24, 2007 at 10:32 UTC ( #617201=note: print w/replies, xml ) Need Help??

in reply to Re^4: finding number of contiguous letters
in thread finding number of contiguous letters

For example suppose a list is composed of ( <a>, <b>, <c> ) where each of the a, b, c are one or more sub calls that may mutate some value, which may be used by others further down the list, will the list values be evaluated in order of a, b, c, or is it undefined?

IIUC, why don't you find out yourself?

#!/usr/bin/perl -l use strict; use warnings; BEGIN { my $foo; sub foo () { $foo } for my $n (qw/a b c d e f/) { no strict 'refs'; *$n = sub () { warn $n; $foo++ }; } } my $arr=(a,b,c,d,e,f); print foo, $arr; __END__

Replies are listed 'Best First'.
Re^6: finding number of contiguous letters
by otto (Beadle) on May 25, 2007 at 00:27 UTC
    Yes, I could find out, but then that would be assuming that all perl interpreters would behave the same for all os'es, compile options, etc. I try to never assume something in the use of a language, because if it is not specified, then any behavior is acceptable, and per spec. Any programmer that uses undefined behavior assuming it will be consistent, is just wanting bugs. Lisp applicative v. normal orders are an example that come to mind of differing evalution methods, each with their benefits and costs. This is why I was asking if perl the language spec'd list element evaluation order...

    Since I was toying around, and since this was lisp-ish, and since eval order would play a huge role in reducing the problem to a tight-lispish-perlish sub, not withstanding the far better solutions via perl's other functions, I was curious if perl did spec eval order, or not...

    The question still stands, is there a language spec regarding evaluation order of list elements.

      Fair enough++, so you have my apologies if my tone sounded too arrogant. One important point about Perl 5 though, is that it does not have a real spec: it is defined by its own implementation. This is an inconvenience that the Perl 6 crowd are trying to correct. OTOH I'm quite sure that evaluation order is from left to right and was about to paste here the paragraph in perldoc perlsyn saying so. Unfortunately simple searches can't seem to find it and I don't know if it's there at all... and I don't know where else it may be.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://617201]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2020-10-27 23:47 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (259 votes). Check out past polls.