Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to subtract 1 from all array elements in perl

Tags:

perl

I have an array which contains values. I need to subtract 1 from each array elements & save there itself.

For Example:

chop $tve_005;
@words = split (/,/, $tve_005);

and now @words contains:

524210
1713409
311919
1422134
16658312

But infact values need to be used in the rest of the codes are: (subtract by 1 always)

524209
1713408
311918
1422133
16658311

How can I subtract and save it the same array.

like image 513
Brijesh Avatar asked Dec 08 '22 07:12

Brijesh


1 Answers

Alternatively to Pradeep's solution, some characters shorter:

#!/usr/bin/perl

my @words = (524210,1713409,311919,1422134,16658312);

$_-- for @words;
like image 72
zb226 Avatar answered Dec 28 '22 22:12

zb226