PERL: hash values as strings? + while () on @Array?

by =?iso-8859-1?Q?=22Alberto=2E=B7=2EVallini=22?= <vallinis(at)yahoo.com>

 Date:  Tue, 19 Sep 2000 20:17:13 +0200
 To:  hwg-techniques(at)mail.hwg.org
  todo: View Thread, Original
Some books declare that HASH VALUES in Perl are always considered as=20
STRINGS and never as numbers. None the less, trivial mathematical=20
operations such as:

%h=3D("one"=3D>1);
$j=3D$h{"one"};
$sum=3D$j+1;

can be carried out safely; a print method would reveal the $sum variable=20
being correctly updated to 2, and no warnings get displayed with the -w=20
command line parameter.
Now:
1) is it due to the fact that the "+" operator converts the hash value to a=
=20
number?
2) if so, is it true that hash values can never be handled safely as=20
numbers? Or is the allegation that hash values are always reproduced as=20
strings simply unaccurate?
3) does there exist a Perl function that forces a string to be evaluated as=
=20
a number, like the javascript parseInt()?
4) does there exist a Perl function that can return me the type of the=20
value I'm handling in a scalar, such as the javascript typeof?
5) Last but not least: many a Perl book refer to examples of while loops=20
applied to an Array by providing conditions such as: while (@anArray) ; the=
=20
assumption is the cycle will stop with the last element of the array. Now=20
either I'm quite dumb or there must be something wrong: any time I attempt=
=20
such a looping, I enter an infinite loop. None the less books keep saying=20
it is feasable, right that way. I can quote by Laura Lemay (whose Perl book=
=20
is fairly good, despite I would not reccomend her books on Html and surely=
=20
not her book about javascript):
"You can ... supply an array variable anywhere a scalar value is expected-=
=20
for example in any of these expressions: ... while (@arrayname) { }." Laura=
=20
Lemay "teach yourself Perl in 21 days" pag 84.
Useless to say I never thought a programming language can be acquired in 21=
=20
days, in fact here I am!
very much TIA!


Alberto.=B7.Vallini  - vallinis(at)yahoo.com
http://www.geocities.com/earthalliances/
"when everything else fails, sleep"


__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA