-4

I am trying to assign the hash values to variables, but I'm unable to get each value assigned to a varIAble. Please share your thoughts

say my %data = Dumper($data);   

$VAR1 = {
          'cnt' => 2000,
          'inc' => 30,
          'start' => 1440154820,
          'end' => 1440154860,
          'values' => [
                        '0.001234',
                        '0.001878',
                        '0.001849',

expected output

$start = 0.001234:1440154820
$end = 0.001849:1440154860

Hi, I am trying to get these values assigned to variables as below from the above hash

$value1 = 0.001234:1440154820   # like $VAR1{values[0]:$VAR1{start}
$value2 = 0.001849:1440154860   # $VAR1{values[2]:$VAR1{end}
Borodin
  • 126,100
  • 9
  • 70
  • 144
coolent
  • 21
  • 10
  • 2
    You say you're trying to do this. But you haven't shown us any of the code you've tried. We can, of course, just give you the answer. But it's probably more useful if we see the mistakes that you've made and explain where you're going wrong. – Dave Cross Aug 21 '15 at 11:54

1 Answers1

0

Is this what you're asking for?

use strict;
use warnings;

my $data = {
  cnt    => 2000,
  inc    => 30,
  start  => 1440154820,
  end    => 1440154860,
  values => [0.001234, 0.001878, 0.001849],
};

my $start = join ':', $data->{values}[0], $data->{start};
my $end   = join ':', $data->{values}[2], $data->{end};

print "\$start = $start\n";
print "\$end   = $end\n";

output

$start = 0.001234:1440154820
$end   = 0.001849:1440154860
Borodin
  • 126,100
  • 9
  • 70
  • 144