Solution: http://perlmonks.org/?node_id=1068407
---- Hey, I have a nested structure that I want to test. The problem that I'm having is I can't figure out how to tell Test::Deep to use a regex for hashref keys. In the example below, the "markets" hashref's keys can be any string, and ideally I want something like re('.') for the key.EDIT: { There seems to be some confusion here. The only reason I said I wanted a re('.') for the key is because the key can be anything and I need to tell Test::Deep to inspect the value of that key. }
How do I tell it to do each hashref's value, akin to the array_each() for arrays? I'm not set in stone regarding a module, so if anyone has better suggestions to accomplish this, please tell me.{ 'markets' => { re('.') => { 'primaryname' => re('.'), 'volume' => re('^[-+.\d]+$'), 'lasttradeprice' => re('^[-+.\d]+$'), 'marketid' => re('^\d+$'), 'secondarycode' => re('.'), 'primarycode' => re('.'), 'lasttradetime' => re('.'), 'label' => re('.'), 'secondaryname' => re('.'), 'buyorders' => array_each( { 'quantity' => re('^[-+.\d]+$'), 'price' => re('^[-+.\d]+$'), 'total' => re('^[-+.\d]+$'), }, ), 'sellorders' => array_each( { 'quantity' => re('^[-+.\d]+$'), 'price' => re('^[-+.\d]+$'), 'total' => re('^[-+.\d]+$'), }, ), 'recenttrades' => array_each( { 'quantity' => re('^[-+.\d]+$'), 'price' => re('^[-+.\d]+$'), 'total' => re('^[-+.\d]+$'), 'id' => re('.'), 'time' => re('.'), }, ), }, }, }
In reply to [SOLVED] Test::Deep regex on hash keys by Zoffix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |