"Kumar, Praveen (cahoot)" wrote: > Hello,
Hi Praveen.K [Is that what your friends call you in conversation?] > > I am completely new to perl, and i am trying to write a small > script, which based on the input given displays the value in an array. But > when i try to execute the script i somehow fail saying "Use of uninitialized > value in concatenation (.) or string at ./pscr1 line 9, <STDIN> line 1." Well, since you are just starting out, it is very important to develop good habits right from the start. > I am also enclosing the script, can some one let me know what is the problem > with this. > > #!/usr/bin/perl -w use strict; # Always use warnings; # Until you know exactly why you are not using them. For now--always > > print "This is your first program\n"; > @list=qw(good better best); is more readable as: @list = qw(good better best); > > $name="nobody"; same as above > > print "Please enter u'r name\n"; The second-person possessive is correctly spelled "your". Typos are one thing, intentional misspelling is very annoying to educated adults.. > > $name = <STDIN>; > chomp ($name); > print "Hello $name\n"; > if ($name eq "Tom") > { > print "You are $list{$0}\n"; Indent. Choose a number of spaces to use, then always indent the lines inside any block by that amount Let's try this again with meaningful formatting: if ($name eq "Tom") { print "You are $list[0]\n"; }elsif ($name eq "Dick") { print "You are $list{1]\n"; }elsif ($name eq "Harry") { print "You are $list[2]\n"; }else { print "nobodyi\n"; } The other change I made above was to bring the elsif statements onto the same line as the closing brace. The difference is that, in the above, you can tell visually how the whole if/eslif/else structure executes together. One very good test is to look at the code from a distance where you can't actuall read it, and see if you can still tell what executes together. Bill already gave you part of the answer to your immediate question, but there is another problem, In your list element you say $list{$0}. That $0 variable has not been assigned. A number is just a number. It sound like you don't quite understand the difference between arrays and hashes. What are you using for reference materials on Perl? You really need to study at least a little of the language before you start writing. Imitation does not work very well. You have to know why each character in your code is there. I want to fill you in on a couple things that will make all your code easier to understand and debug. Perl is a language that can support a very natural style, but you have to use it.in a natural way to take advantage of it. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>