@yash0101
You have to define the variable $type before you use it somewhere, otherwise, the place where its used will be filled with a null value.
My suggestion is that you add the following to the beginning of your script:
-
use strict;
-
use warnings;
-
If you had them in place, you would have seen the following output to your screen:
-
Global symbol "%Hash" requires explicit package name at hashtest.pl line 20.
-
Global symbol "$type" requires explicit package name at hashtest.pl line 20.
-
Global symbol "$type" requires explicit package name at hashtest.pl line 21.
-
Global symbol "%Hash" requires explicit package name at hashtest.pl line 23.
-
Global symbol "$type" requires explicit package name at hashtest.pl line 23.
-
Execution of hashtest.pl aborted due to compilation errors.
-
Also, this line:
is not correct. The first semi-colon needs to be rmoved so it looks like this:
Another issue is that $type is the value and the way you are referencing it is as if it were a key, so you will always get the following error:
-
Use of uninitialized value within %Hash in concatenation (.) or string at hashtest.pl line 24.
-
To have this code work the way you expect it, you will have to have it as follows:
-
use strict;
-
use warnings;
-
-
-
# Variables
-
my $type = "1000";
-
my %Hash=('add' => " test $type ");
-
-
-
#print " $Hash{$type}";
-
print("$Hash{add}");
-
I hope this helps.
Regards,
Jeff