in reply to Re: hash of hash
in thread hash of hash

hi i have achieved the desired output by using the following code.I tried to store the output in a variable and get average out of it but could not.Can some one help me out

#!/usr/bin/perl use strict; use warnings; use IO::All; #use Data::Dumper; my @lines = io('Salesofcar.txt')->chomp->slurp; splice @lines, 0, 1; # remove first line my %hash; foreach my $line (@lines) { $line =~ s/^\s+//; my @cols = split /\s+/, $line; my $key = join '-',splice @cols, 0, 2; my %com; @com{qw( In2017 In2018 In2019} = @cols; $hash{$key} = { %com }; } use Data::Dumper; $Data::Dumper::Sortkeys=1; print Dumper(\%hash);

Replies are listed 'Best First'.
Re^3: hash of hash
by hippo (Archbishop) on Feb 17, 2019 at 16:55 UTC
    Can some one help me out

    The code you posted does not even compile:

    $ perl -cw 1230041.pl Can't find string terminator ")" anywhere before EOF at 1230041.pl lin +e 17.

    Here's what I would suggest in your situation.

    1. Fix all the compilation errors.
    2. Go through the resulting code and try to explain to yourself what each individual line is doing and how it is performing that action. If you can't do that for any of the lines, remove them and replace them with something simpler which you do understand.
    3. Having done 1 and 2 you now have some code which runs and which you understand. Now create an algorithm for anything else that you want the script to do.
    4. Code up the new algorithm.
    5. Test the new code. If it fails to meet your requirements go to 1.
Re^3: hash of hash
by choroba (Cardinal) on Feb 17, 2019 at 16:52 UTC
    I doubt the code works. Where does the qw operator end?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      hi it worked for me.can you tell me how to attach the documents so that i would send the output screenshot attached to it.I do not see any way to attach the documents

        You said that you'd achieved your desired output, yet the code posted doesn't work. You are either not running this code and have posted something else, or wrong. Either post the code you're actually running, or fix the issues discussed in the reply I linked to. You can't post screenshots here, and there's no need in this case.