On Apr 25, 8:40 pm, anit...@gmail.com wrote:
> Hi,
>
> I am new to perl and trying to parse a text file into a hash table.
> Could someone point me in the right direction?
>
> My text file:
> start -days 1,2,3,4,5 -month 2,4,8,10 -message "I want you to start
> this" -running -group "rungroup"
>
> Hash table should look like this:
>
> myhash(start) = ""
> myhash(days) = 1,2,3,4,5
> myhashh(month) = 2,4,8,10
> myhash(message) = "I want you to start this"
> myhash(running) = ""
> myhash(group) = "rungroup"
Please try to use Perl notation in your posts to Perl newsgroups.
$myhash{group} = "rungroup"
Your task shouldn't be too difficult but we need to know a couple of
things:
Where did the empty string in $myhash{start} come from?
What are the rules about quotes? For now I'll assume there can be no
quote characters in the data.
Do you want to validate the data or can we assume the input fits the
pattern?
use strict;
use warnings;
use Data:

umper;
$_='start -days 1,2,3,4,5 -month 2,4,8,10 -message "I want you to
start this" -running -group "rungroup"';
my %myhash = /\G(?:^|-)(\w+)\s+("[^"]*"|(?=-)|[^" ]*)\s*/g;
tr/"//d for values %myhash;
print Dumper \%myhash;