in reply to Issues with Split

my ($type, $restofstring) = /^type=(\w+) (.+)$/; for $restofstring(split){

You are splitting the entire line read ($_), not what (.+) matched ($restofstring). And you are overwriting $restofstring.

You need a different loop variable, and you need to pass $restofstring as second argument to split.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^2: Issues with Split
by cipher (Acolyte) on Jun 14, 2016 at 05:06 UTC
    Thanks, I am still trying to get this fixed based on your recommendations. I will update this thread once I make any progress.
      Here is what afoken was talking about -- instead of this:
      my ($type, $restofstring) = /^type=(\w+) (.+)$/; for $restofstring (split) { my ($key, $val) = split /=/, $restofstring; $hash{$type}{$key} = $val; }
      you should do this:
      my ($type, $restofstring) = /^type=(\w+) (.+)$/; for $token ( split ' ', $restofstring ) { my ($key, $val) = split /=/, $token; $hash{$type}{$key} = $val; }
        Thanks a lot, this code works. Appreciate your help.