-1
 use strict;
 use warnings;

 $manifest=read_file("release.ms1");
 print "$manifest\n";

 my @new=split('\.',$manifest);

 my %data=@new;

 print "$data('vcs version')";

content of the release.ms1

vcs.version:12312321
vcs.path:CiscoMain/IT/GIS/trunk

Error:

vcs.version:12312321

vcs.path:CiscoMain/IT/GIS/trunk

vcsversion:12312321

vcspath:CiscoMain/IT/GIS/trunk

Odd number of elements in hash assignment at ./script.pl line 33.

Use of uninitialized value in print at ./script.pl line 35.

I need output like :

version=12312321
path=CiscoMain/IT/GIS/trunk
Kalaiyarasan
  • 267
  • 3
  • 6
  • 13

1 Answers1

1

Your split function is assigning:

$new[0] = 'vcs'
$new[1] = 'version:12312321\nvcs'
$new[2] = 'path:CiscoMain/IT/GIS/trunk'

When you assign a list to a hash, it has to have an even number of elements, since they're required to be alternating keys and values.

It looks like what you actually want to do is split $manifest on newlines and colons, and replace the dots in the keys with space.

my @new = split(/[.\n]/, @manifest;
my %data;
for (my $i = 0; $i < @new; $i += 2) {
    my $key = $new[$i];
    $key =~ s/\./ /g;
    $data{$key} = $new[$i+1];
}

Finally, your syntax for accessing an element of the hash is wrong. It should be:

print $data{'vcs version'};

The hash key is surrounded with curly braces, not parentheses.

Barmar
  • 741,623
  • 53
  • 500
  • 612