Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have created this script to speed up a document creation.
#!/usr/bin/perl # $node = 65; for($i = 1; $i < $node; $i++ ){ print "NODE SITE_$i\n"; print "\tLABEL $i\n"; print "\tPOSITION CENTER_IMAGE\n\n"; }
It prints out :
NODE SITE_64 LABEL 64 POSITION CENTER_IMAGE
I'm trying to get to print POSITION CENTER_IMAGE 0r360,but add 5 to every iteration i.e.
POSITION CENTER_IMAGE 0r360 POSITION CENTER_IMAGE 5r360 POSITION CENTER_IMAGE 10r360.
Can someone help and me to get to the right place. Thanks

Replies are listed 'Best First'.
Re: Add 5 to a number
by runrig (Abbot) on Jul 01, 2016 at 22:23 UTC
    Why not just multiply by 5:
    for my $i (0..10) { my $n = $i*5; print "$n\n"; }
Re: Add 5 to a number
by BillKSmith (Monsignor) on Jul 02, 2016 at 13:03 UTC
    As long as 'r360' never changes:
    #!/usr/bin/perl use strict; use warnings; my $node = 65; for my $i (1..$node-1){ print "NODE SITE_$i\n"; print "\tLABEL $i\n"; my $n = 5 * ($i - 1); print "\tPOSITION CENTER_IMAGE ${n}r360\n\n"; }

    OUTPUT

    NODE SITE_1 LABEL 1 POSITION CENTER_IMAGE 0r360 NODE SITE_2 LABEL 2 POSITION CENTER_IMAGE 5r360 NODE SITE_3 LABEL 3 POSITION CENTER_IMAGE 10r360 ... NODE SITE_63 LABEL 63 POSITION CENTER_IMAGE 310r360 NODE SITE_64 LABEL 64 POSITION CENTER_IMAGE 315r360
    Bill
Re: Add 5 to a number
by Anonymous Monk on Jul 02, 2016 at 23:41 UTC
    Great, thanks for showing me the way, and also my mistake in posted code.