On Tue, Apr 27, 2004 at 12:12:31PM +0530, [EMAIL PROTECTED] wrote: > can i take input to associative array from the user like this: > %words=<stdin>; Were it possible or not, it would be dangerous. A nice rule of programming to follow is that user input is evil and wrong, and must be checked. If someone was to supply three fields, bad things would happen. For example: test.pl: #!/usr/bin/perl use warnings; use strict;
my %words=<STDIN>; foreach my $key (keys %words) { print "$key = $words{$key}\n"; } $ ./test.pl a b c d <--^D pressed after this line a = b c = d (note the newlines from the input are being included, you'd probably need to clean it up) The badness happens here: $ ./test.pl a b c <--^D pressed after this line Odd number of elements in hash assignment at ./test.pl line 5, <STDIN> line 3. a = b Use of uninitialized value in concatenation (.) or string at ./test.pl line 7, <STDIN> line 3. c = -- Robin <[EMAIL PROTECTED]> JabberID: <[EMAIL PROTECTED]> Hostes alienigeni me abduxerunt. Qui annus est? PGP Key 0x776DB663 Fingerprint=DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663
pgp00000.pgp
Description: PGP signature