Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: finding number of contiguous letters

by otto (Beadle)
on May 24, 2007 at 00:04 UTC ( #617140=note: print w/replies, xml ) Need Help??


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

Blazar,

You got me thinking, I'm going to play with this some more, but first... are sub arguments, ie a list, evaluated in order?

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?

I quickly looked at the sub function and the comma operator which did not shed any light, or at least I didn't see it...

.. Otto

Replies are listed 'Best First'.
Re^5: finding number of contiguous letters
by blazar (Canon) on May 24, 2007 at 10:32 UTC
    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__
      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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2020-10-21 19:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (223 votes). Check out past polls.

    Notices?