develooper Front page | perl.beginners | Postings from September 2009

hash question

Thread Next
September 25, 2009 10:05
hash question
Message ID:
I don't see what I am doing wrong in printing out the values in the
hash. I am inputting a file with records of varying number of fields and
want to put them in a hash. My output says Use of uninitialized value in
concatenation (.) or string at line 35, <INFILE> line 1.
 => test2

Sample input file "test2,MS-Windows-NT,Silver,NPRO30DINCR,Client
JXWGTI7R5CHD1 WINDOWS NT,Schedule test2_full_1700 FULL 604800"

use strict;
use warnings;

  print "Enter the filename of input file with full path\n";
        my $input_file = <>;


# check to see if input file exist
        if ( -e $input_file) {
                open( INFILE, "<", "$input_file") or

                die "$input_file does not exists: $!";
                my %policy_Hash=();
                my ($parameters);
                while (<INFILE>) {
                        my @n = split /,/, $_;
                my $number_of_elements = scalar @n;
print scalar @n, "\n";
                my ($policy_name,$i,$element);
                ($policy_name,$parameters) = split( /,/, $_, 2 );
print "policy_name = $policy_name has $number_of_elements elements\n";

                for ( $i=0; $i <= $number_of_elements-1; $i++ ) {
                        $element = (split /,/, $_)[$i];
                        print "this is element i=$i  $element\n";
                        $policy_Hash{$policy_name}{ 'element_$i'}=
(split /,/, $_)[$i];
#                       $policy_Hash{$policy_name}{ 'element_$i'}=
                my ($key,$value);
                while ( $key,$value= each(%policy_Hash) ) {
                        print "$key => $value \n";
                } #end while

This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. References to "Merrill Lynch" are references to any company in the Merrill Lynch & Co., Inc. group of companies, which are wholly-owned by Bank of America Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a Condition to Any Banking Service or Activity * Are Not Insured by Any Federal Government Agency. Attachments that are part of this E-communication may have additional important disclosures and disclaimers, which you should read. This message is subject to terms available at the following link: By messaging with Merrill Lynch you consent to the foregoing.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About