Think about Loose Coupling | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Thank you for the fast replay.
I tried to use the following regex my($path,$value) = ($row =~ /(.*),(.*)/); to split the string. but if there are no commas it won't work. Which regex should I use in order to always put the string into $path so I can only check if $value is defined? for example: if "abc" it will be $path = "abc" and $value is undefined. if "abc,5" it will be $path = "abc" and $value = 5 if "a,b,c,5" it will be $path = "a,b,c" and $value = 5 The algo I would like to implement : As I see it the steps are: 1. if the string has commas: 1.a. get the last comma and check if the last substring is a number - if so put it in hash like this: $hash{$path} = $value; 1.b. if the substring after the last comma isn't a number - $hash{$path} = 1; 2. if string has no commas: $hash{$string} = 1; how to implement this? In reply to Re^2: difference in regex
by ovedpo15
|
|