User Control Panel
Advertisements

HELP US, HELP YOU!

- 1 form a variabul.

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl
View unanswered posts
Author Message
kings_on_steeds
Senior Member
Senior Member


Joined: 05 Apr 2004
Posts: 290
Location: Bookham, Surrey, UK
Reputation: 35.1Reputation: 35.1Reputation: 35.1Reputation: 35.1

PostPosted: Mon Apr 18, 2005 3:42 pm    Post subject: Reply with quote

dose anyone know how to take 1 away from a variabul? i am a little stuck.

Quote:
$var1 == 6;
-1
print $var1;

prints 5
Back to top
Gavin
God Like
God Like


Joined: 15 Mar 2004
Posts: 661
Location: Manchester, UK
Reputation: 36.2Reputation: 36.2Reputation: 36.2Reputation: 36.2

PostPosted: Mon Apr 18, 2005 4:21 pm    Post subject: Reply with quote

Do you mean just:

Code:
my $var1 = 6;<br />my $var1 = $var1 - 1;

_________________
MSN: gavin [at] gavinbrittain [dot] co [dot] uk
E-Portfolio: www.gavinbrittain.co.uk (New version comming soon)
Back to top
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Mon Apr 18, 2005 6:50 pm    Post subject: Reply with quote

If you're subtracting (or adding) just 1, you can just use -- and ++

Code:
$var = 6;<br />$var--; # subtract 1<br />$var++; # add 1

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Mon Apr 18, 2005 7:54 pm    Post subject: Reply with quote

Note you can also use quick operators, so instead of doing

Code:
my $a = 5;<br />$a = $a + 10;<br />$a = $a - 10;<br />$a = $a / 10;

You can also do...
Code:
my $a = 5;<br />$a += 10;<br />$a -= 10;<br />$a /= 10;

It works on pretty much every operator (though I'm not sure about **, exponent). Either way, this is usually a tad bit faster (although you won't notice it that much.. but hey, any speed profit is welcome) because perl does not have to create a symbolic copy of $a before doing something with it (instead it can use the original value, which saves one "stack copy").

Technical details aside, it's pretty nifty (and usually a lot cleaner).
Back to top
kings_on_steeds
Senior Member
Senior Member


Joined: 05 Apr 2004
Posts: 290
Location: Bookham, Surrey, UK
Reputation: 35.1Reputation: 35.1Reputation: 35.1Reputation: 35.1

PostPosted: Tue Apr 19, 2005 9:15 pm    Post subject: Reply with quote

it worked. yahh, thanks guys.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Perl All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group