Sonali has asked for the wisdom of the Perl Monks concerning the following question:
Hello Perl monks,
I am a Perl newbie
I am try to get the name of the hash which is in another Perl file, and then access the hash elements, but when I run my program I am getting these errors
Use of uninitialized value $line in pattern match (m//) at test.pm line 17.
Use of uninitialized value $typ_s in string at test.pm line 20.
My code goes like this
package hash; use strict; use warnings; $test = { 'hash1' => { 'paramA' => '00' , 'paramB' => 'FF' , }, 'hash2' => { 'paramA' => '01' , 'paramB' => '02' , }, 'hash3' => { 'paramA' => '00' , 'paramB' => '03' , }, };
This hash structure is generated, so I can't modify it
This the Perl file which contains the hash that needs to be extracted
This is the Perl script I have written to extract the hash
#!/usr/local/bin/perl use strict; use warnings; Generate(); sub Generate { Process_File('hash.pm'); } sub Process_File { my $filename = shift; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; my $line; $line =~ m/\'hash1\'/; my $typ_s = $line->{paramA}; my $paramB = $line->{paramB}; print "$typ_s"; }
Help me!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Accessing the hash name in perl
by duyet (Friar) on Mar 22, 2017 at 12:34 UTC | |
Re: Accessing the hash name in perl
by 1nickt (Canon) on Mar 22, 2017 at 12:58 UTC | |
by Sonali (Novice) on Mar 23, 2017 at 10:40 UTC | |
by huck (Prior) on Mar 23, 2017 at 13:13 UTC | |
Re: Accessing the hash name in perl
by hippo (Bishop) on Mar 22, 2017 at 12:28 UTC | |
Re: Accessing the hash name in perl
by haukex (Archbishop) on Mar 22, 2017 at 14:24 UTC | |
by vrk (Chaplain) on Mar 22, 2017 at 15:11 UTC | |
by haukex (Archbishop) on Mar 22, 2017 at 15:30 UTC | |
by afoken (Chancellor) on Mar 23, 2017 at 07:35 UTC | |
Re: Accessing the hash name in perl
by Discipulus (Canon) on Mar 23, 2017 at 08:11 UTC |
Back to
Seekers of Perl Wisdom