brachysclereid has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I am new to perl. I am trying to write a simple script that will pass through an array subtracting the value of the an element from that of the next and so on. Reporting each answer on a new line. One of my many problems is that I am not sure how to refer to the n+1 element in an array: Here what I have so far:
Any help would be much appreciated! Thanks, Art#!/usr/bin/perl use warnings; open(FILE, "filename.txt") or die("Unable to open file"); @List = <FILE>; close(FILE); foreach $line (@List) { print ($line+1) - $line); print "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: subtractionn in an array
by roboticus (Chancellor) on Mar 21, 2012 at 16:51 UTC | |
|
Re: subtractionn in an array
by RichardK (Parson) on Mar 21, 2012 at 16:50 UTC | |
|
Re: subtractionn in an array
by Rudolf (Pilgrim) on Mar 21, 2012 at 17:10 UTC | |
by brachysclereid (Initiate) on Mar 21, 2012 at 17:57 UTC | |
by Lotus1 (Vicar) on Mar 21, 2012 at 17:48 UTC | |
by Rudolf (Pilgrim) on Mar 21, 2012 at 23:30 UTC | |
|
Re: subtractionn in an array
by GrandFather (Saint) on Mar 21, 2012 at 21:04 UTC |