perl addition operator. query.

G

gerry.brennan

Hi is there a way to do the following in perl.


for ($i = 0; $i < $EndNo; $i++)
{
print("$i+1\n");
}

inline addition.
 
A

A. Sinan Unur

(e-mail address removed) wrote in @i40g2000cwc.googlegroups.com:
Hi is there a way to do the following in perl.


for ($i = 0; $i < $EndNo; $i++)
{
print("$i+1\n");

print $i + 1, "\n";

or

UGLY: print "@{[ $i + 1 ]}\n";

for my $i ( 1 .. $EndNo ) {
print "$i\n";
}

Sinan
--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 
M

Mintcake

Hi is there a way to do the following in perl.


for ($i = 0; $i < $EndNo; $i++)
{
print("$i+1\n");
}

inline addition.

Any expression may be embedded in a string (although as already pointed
out it can be UGLY)

Since arrays can be interpolated into double quoted strings (e.g.
"foo@bar") you just interpolate an anonymous array containing a single
element.

e.g.

my $var = 123;
print ">>> @{[$var]} <<<\n";

gives:
 
C

Charles DeRykus

A. Sinan Unur said:
(e-mail address removed) wrote in @i40g2000cwc.googlegroups.com:
...
or

UGLY: print "@{[ $i + 1 ]}\n";

another UGLY one: print "${ \($i+1) }\n";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top