Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

arithmetic operation in print

Status
Not open for further replies.

sedawk

Programmer
Joined
Feb 5, 2002
Messages
247
Location
US
I want print an arithmetic equation in a print command, for example.

Code:
for (my $i = 0 ; $i < 4; $i++){
   print "the number is " . $i . "and the next one is " . $i+1;
}

But the compiler produced an error about arithmetic operation. How to do that?

Thanks
 
Code:
for (my $i = 0 ; $i < 4; $i++){
   print "the number is " . $i . " and the next one is " . ($i+1)."\n";
}
 
just a twist on how to do this:

Code:
for (my $i = 0 ; $i < 4; $i++){
   print "the number is $i and the next one is @{[$i+1]}\n";
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top