in reply to Cube/digit script.

You have warnings on! Why don't you read the warning you get? Useless use of exponentiation (**) in void context means that your $j**3 line isn't doing anything with its return value. Perhaps you meant $j **= 3 which would set $j to itself cubed.

I assume you have a sum() function defined somewhere. And your variable scoping leaves something to be desired -- specifically, proper variable scoping. Rewriting only the scoping of your program, I'd do:

my @numbers; for my $i (100 .. 999) { my @num = split(//, $i); foreach my $j (@num) { $j **= 3; } if (sum(@num) == $i) { push @numbers, $i; } }
I have another comment. Why did you use 'for' in one loop and 'foreach' in another? They're not different things, and you're not using the C-style loop, so there's no reason one of them should have a different name from the other.

All in all, I would rewrite this program to use far fewer temporary variables:

my @numbers = grep { sum(map { $_ ** 3 } split //) == $_ } 100 .. 999;
That might be a bit too succinct for you, but it does the same thing as yours.

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart