Note: Beware! Default reply-to is to the list.
Hi,

As usual, writing a clear email about a problem has wrung most of the
answer out of the apparent fog. Nevertheless ....

>From page 59 of INTERMEDIATE PERL (alpaca book)

1 my @input_numbers = (1, 2, 4, 8, 16, 32, 64);
# $len = @input_numbers;
2 my @indices_of_odd_digit_sums = grep {
3    my $number = $input_numbers[$_];
4    my $sum;
5    $sum += $_ for split //, $number;
6    $sum % 2;

7 } 0..$#input_numbers;  # OR 0..$len;

8 print "\n\t the input nos. @input_numbers";
9 print "\n\t the index nos. @indices_of_odd_digit_sums of the
  odd_digit_sums\n\n";


>From line 7, just where does the syntax of $#input_numbers come from?
<Notes, not $#$input_numbers  as I might have expected in my innocence>

The only ref to $# that I find is a deprecated alternative to printf
listed in LEARNING PERL (2nd edn. p.134). This evaluates to the same
as my $len but must be the only place in perl where # is anything
other than a comment marker.

I can uncomment the line after line 1 and replace the syntax as
commented on line 7, which would be my way and it works fine

0..$input_numbers also works but, as you would know, generates minor
warnings.

How would I get a non-deprecated alternative that would not entail
declaring the scalar $len and not generate any warnings and without
code revision before line 7.

bestest
Anne

_______________________________________________
Za-pm mailing list
Za-pm@pm.org
http://mail.pm.org/mailman/listinfo/za-pm

posts also archived on Mail Archive
http://www.mail-archive.com/za-pm@pm.org/

Reply via email to