Reputation: 9326
I would like to know if there is an easy way for parsing a string like this
set PROMPT = Yes, Master?
What I would like to do, is parse one part of this string up to the equal sign and parse the second part after the equal sign into another string.
Upvotes: 1
Views: 802
Reputation: 53496
Something like...
$phrase = 'set PROMPT = Yes, Master?';
@parts = split /=/, $phrase;
or
($set, $value) = split /=/, $phrase, 2;
[updated] Changes per comments.
Upvotes: 6
Reputation: 156434
Try matching this regex /\s*set\s*(\w+)\s*=\s*(.*)\s*$/
and setting the parts with $1
and $2
:
my $str = 'set PROMPT = Yes, Master?';
my ($k, $v) = ($1, $2) if $str =~ /\s*set\s*(\w+)\s*=\s*(.*)\s*$/;
print "OK: k=$k, v=$v\n"; OK: k=PROMPT, v=Yes, Master?
Upvotes: 2