If there is one thing I have learned (through hard-earned experience), DON'T ASSUME. If you want to ensure operations occur in the order you intend, use parentheses to force it. It makes it much more likely to get the result you desire. That with the suggestions of tybalt89, Corion, kcott, and LanX I believe will give you the results you want.

Test code:

#!/usr/bin/perl use strict; use warnings; use Test::More; sub ten { 10 } sub ten_() { 10 } my @expected = ( 9, ); { my @result = (); for my $i ( 9 .. 10 - 1 ) { push @result, $i; } is_deeply( \@result, \@expected, q{9 .. 10 - 1 without constant (OP)}, ); } { my @result = (); for my $i ( 9 .. ten() - 1 ) { push @result, $i; } is_deeply( \@result, \@expected, q{9 .. 10 - 1 with constant() (OP)}, ); } { my @result = (); for my $i ( 9 .. ten -1 ) { push @result, $i; } is_deeply( \@result, \@expected, q{9 .. 10 - 1 with constant (OP)}, ); } { my @result = (); for my $i ( 9 .. ( ten() - 1 ) ) { push @result, $i; } is_deeply( \@result, \@expected, q{9 .. 10 - 1 with constant() and parnes (proposed-me)}, ); } { my @result = (); for my $i ( 9 .. ( ten -1 ) ) { push @result, $i; } is_deeply( \@result, \@expected, q{9 .. 10 - 1 with constant and parens (proposed-me)}, ); } { my @result = (); for my $i ( 9 .. ten_() - 1 ) { push @result, $i; } is_deeply( \@result, \@expected, q{9 .. 10 - 1 with constant() (proposed-11143893)}, ); } { my @result = (); for my $i ( 9 .. ten_ - 1 ) { push @result, $i; } is_deeply( \@result, \@expected, q{9 .. 10 - 1 with constant (proposed-11143893)}, ); } { my @result = (); for my $i ( 9 .. ( ten_() - 1 ) ) { push @result, $i; } is_deeply( \@result, \@expected, q{9 .. 10 - 1 with constant() and parens (proposed-11143893/me)}, ); } { my @result = (); for my $i ( 9 .. ( ten_ - 1 ) ) { push @result, $i; } is_deeply( \@result, \@expected, q{9 .. 10 - 1 with constant and parens (proposed-11143893/me)}, ); } my @expected_2 = ( 9, 10, ); { my @result = (); for my $i ( 9 .. ten ) { push @result, $i; } is_deeply( \@result, \@expected_2, q{9 .. 10 with constant (OP)}, ); } { my @result = (); for my $i ( 9 .. ten_ ) { push @result, $i; } is_deeply( \@result, \@expected_2, q{9 .. 10 with constant (proposed-11143893)}, ); } done_testing(); __END__

Test results:

$ perl test.pl ok 1 - 9 .. 10 - 1 without constant (OP) ok 2 - 9 .. 10 - 1 with constant() (OP) not ok 3 - 9 .. 10 - 1 with constant (OP) # Failed test '9 .. 10 - 1 with constant (OP)' # at test.pl line 38. # Structures begin differing at: # $got->[1] = '10' # $expected->[1] = Does not exist ok 4 - 9 .. 10 - 1 with constant() and parnes (proposed-me) not ok 5 - 9 .. 10 - 1 with constant and parens (proposed-me) # Failed test '9 .. 10 - 1 with constant and parens (proposed-me)' # at test.pl line 60. # Structures begin differing at: # $got->[1] = '10' # $expected->[1] = Does not exist ok 6 - 9 .. 10 - 1 with constant() (proposed-11143893) ok 7 - 9 .. 10 - 1 with constant (proposed-11143893) ok 8 - 9 .. 10 - 1 with constant() and parens (proposed-11143893/me) ok 9 - 9 .. 10 - 1 with constant and parens (proposed-11143893/me) ok 10 - 9 .. 10 with constant (OP) ok 11 - 9 .. 10 with constant (proposed-11143893) 1..11 # Looks like you failed 2 tests of 11.

Hope that helps.


In reply to Re: replacing literals with constants by atcroft
in thread replacing literals with constants by hexcoder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.