Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found