0

i have a file of the form

(9430, 3656) (9147, 14355) (133, 14393) (7917, 9513) (3719, 12775)

lets say i need to store it as a hash.such that 9430=>3656 and so on.I tried using split but it takes whitespaces for right hand values.How can i do it the better way?

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by d5e5
1
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;

my $rec = '(9430, 3656) (9147, 14355) (133, 14393) (7917, 9513) (3719, 12775)';

$rec =~ s/['(),]//g; #Remove everything except digits and spaces

my %hash = split / /, $rec; #Split on space character and assign to hash

print Dumper(\%hash);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.