victorz22 has asked for the wisdom of the Perl Monks concerning the following question:
Hello I am trying to truncate text between two hash keys and get all the strings in between those two strings. I have a function that can parse between two strings but when I try to parse between two strings that contain the '=>' characters I get an uninitialized variable error. Thank you monks for your endless wisdom :)
#Function call That works my $hashData = truncateText($inputText, "begin", "end"); #Desired function call that doesn't work my $hashData = truncateText($inputText, "begin =>", "end =>"); #Truncating Function sub truncateText{ #Truncates text by removing everything before and and after the pa +ssed in variables my($text, $beginString, $endString) = @_; my $truncatedText; if($text =~ /\b\Q$beginString\E\b(.*?)\b\Q$endString\E\b/s){ $truncatedText = $1; } return $truncatedText; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parsing to get data between '=>' characters
by choroba (Cardinal) on Apr 19, 2017 at 23:53 UTC | |
by victorz22 (Sexton) on Apr 20, 2017 at 00:46 UTC | |
|
Re: parsing to get data between '=>' characters
by duyet (Friar) on Apr 20, 2017 at 05:32 UTC | |
by jahero (Pilgrim) on Apr 20, 2017 at 05:58 UTC |