Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: simplish script (I think)

by jeffenstein (Friar)
on Sep 25, 2020 at 08:10 UTC ( #11122191=note: print w/replies, xml ) Need Help??


in reply to Re: simplish script (I think)
in thread simplish script (I think)

Your second "foreach" is not necessary.

I think the OP is trying to do this with the second foreach:

for(my $i=1; $i < @array; $i++){ print "The difference is ", $array[$i] - $array[$i-1], "\n"; }

Replies are listed 'Best First'.
Re^3: simplish script (I think)
by NetWallah (Canon) on Sep 25, 2020 at 15:04 UTC
    You are correct(++) - I misread the curly brackets.

    Another way he can achieve this - arguably more readable is:

    my @a=@array; # make a copy, since we will destroy @a my $prev=pop @a; for (reverse @a){ print $prev - $_, "\n"; $prev=$_; }

                    "Imaginary friends are a sign of a mental disorder if they cause distress, including antisocial behavior. Religion frequently meets that description"

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2020-12-06 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (65 votes). Check out past polls.

    Notices?