A.R.M. (kinkyturtle) wrote,
A.R.M.
kinkyturtle

  • Mood:

OK, I officially love Perl now!

So I'm reading chapter 3 of the Llama Book, and I find out that by using lists, you can define more than one variable at a time... which means that unlike in most other programming languages, you can swap the values of two variables without having to use a third!

For instance, if I'm writing a program to calculate Fibonacci numbers, instead of having to write the incrementing step as:

$extra = $b;
$b += $a;
$a = $extra;


all I need to write is:

($a, $b) = ($b, $a+$b);

and get the job done in one line instead of three, and with two variables instead of three!

print "Perl RAWKS!\n"
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 22 comments