[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Fwd: Re: OT programming languages/ systems for advanced applications on Linux



Should have gone to the list; sorry Lina:

-------- Original Message --------
Subject: Re: OT programming languages/ systems for advanced applications on Linux
Date: Sat, 24 Dec 2011 16:35:29 +0000
From: Tony van der Hoff <tony@vanderhoff.org>
To: lina <lina.lastname@gmail.com>

On 24/12/11 15:43, lina wrote:

Tonight I am pretty free, so started to read something about perl.

#!/usr/bin/perl

print "Hello World! \n";

$a = 3;

print "$a  \n";

@food = {"apples", "pears", "eels"};

@music = {"whistel", "flute"};

@moremusic = {"organ", @music, "harp"};

push(@food, "eggs");

print @food;
print "@food";

I am so CONFUSED why the output is:
Hello World!
3
HASH(0x19ec998)eggsHASH(0x19ec998) eggs

print @food

is wrong? or something wrong with my box.


Yep, that's PERL for you. Having taken over the maintenance of a large
PERL project, I've come to the conclusion that it's IMHO the worst
programming language ever invented. Totally non-intuitive.

"Hello World" is obvious, as is "3".

@food = {"apples", "pears", "eels"};
Assuming you wanted to create an array, containing those 3 elements, the
correct syntax is
@food = ("apples", "pears", "eels");
You can then print @food; and print "@food";

The construct in braces creates an anonymous hash with an odd number of
elements (bad), and places that in the first array element.
You could retrieve it using "print %{@food[0]}"

The push adds 'eggs' as the second array element, so you'd need to
"print @food[1];" to retrieve that.

Mindboggling, eh? And so it continues for the rest of the language.

You'd probably find it useful to add "use warnings" as the second line
of your program, for the interpreter to emit slightly more help.

--
Tony van der Hoff        | mailto:tony@vanderhoff.org
Buckinghamshire, England |


Reply to: