stackoverflow0208

parse string with pairs of values into hash the Perl6 way

解析下面的文本, 將其轉(zhuǎn)換為散列:

width=13
height=15
name=Mirek

Answer1

my $text = "width=13\nheight=15\nname=Mirek";
$text ~~ / [(\w+) \= (\N+)]+ %% \n+ /;
my %params = $0>>.Str Z=> $1>>.Str;

Answer2

my %params = $text.comb(/\w+\=\N+/)>>.split("=").flat;

Answer3

my %params = $text.split("\n")>>.split("=").flat;

Answer4

my %params = $text.lines>>.split("=").flat;

Sorting hash kv pairs

http://stackoverflow.com/questions/39307797/can-i-return-multiple-pairs-from-a-map-feeding-into-a-hash?rq=1

怎么得到散列的元素個(gè)數(shù)?
How to get the count of no. of keys in a perl 6 %HASH?

%hash.elems 
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容