|
| Author |
Message |
kings_on_steeds Senior Member

Joined: 05 Apr 2004 Posts: 290 Location: Bookham, Surrey, UK
    
|
Posted: Mon Apr 18, 2005 3:42 pm Post subject: |
|
|
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

Joined: 15 Mar 2004 Posts: 661 Location: Manchester, UK
    
|
Posted: Mon Apr 18, 2005 4:21 pm Post subject: |
|
|
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

Joined: 03 Feb 2004 Posts: 3776 Location: Michigan
  votes: 4
|
Posted: Mon Apr 18, 2005 6:50 pm Post subject: |
|
|
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

Joined: 06 Jan 2004 Posts: 562 Location: Netherlands
    
|
Posted: Mon Apr 18, 2005 7:54 pm Post subject: |
|
|
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

Joined: 05 Apr 2004 Posts: 290 Location: Bookham, Surrey, UK
    
|
Posted: Tue Apr 19, 2005 9:15 pm Post subject: |
|
|
| it worked. yahh, thanks guys. |
|
| Back to top |
|
 |
|