Dumper result how check array size

Viewed 77

in my script I have result for example when I print

$Data::Dumper::Sortkeys = 1;
print Dumper \%slownik2;

I have for example result:

$VAR1 = {
          '22' => [
                    '29.9',
                    '29.7',
                    '29.5',
                    '29.3',
                    '29.0',
                    '28.1'
                  ],
          '58' => [
                    '29.3'
                  ],
          '66' => [
                    '29.8',
                    '29.8'
                  ],
          '72' => [
                    '28.7'
                  ],
          '91' => [
                    '27.8'
                  ],
          '92' => [
                    '29.9'
                  ],
          '96' => [
                    '28.6'
                  ]
        };

And I think this is ok. Now I have a question how now check array size this dumper result in a loop for individual hash. I would like to do that if array size of individual hash dumper is == 1 then form example print something else array size for individual hash result is >1 then do nothing. Than you for your help

1 Answers

I am guessing that:

  1. you have a hash as an input of your Dumper
  2. each value of your hash is an array
  3. what you want to do is to print the key or value of each record only when the array contained in your value(s) has only one record.
  4. List item

If that's the case I would suggest writing your own print-routine by:

  1. iterating your hash (using foreach)
  2. getting the length of each array contained in the corresponding value
  3. printing this record using print

p.s. It would help if you provide an example of the output you expect.

Related