प्रिंटिंग के लिए पर्ल के "डेटा :: डूपर" के रूबी समकक्ष Ruby equivalent of Perl Data::Dumper का डुप्लिकेट नहीं है। यह सवाल 3.5 साल से अधिक पुराना है और इसलिए जांच करना है कि तब से रुबी में कोई नया विकल्प उपलब्ध है।गहरी नेस्टेड हैश/एरेज़
मैं रूबी के Dumper
रूबी में समकक्ष की तलाश में हूं। मुझे परवाह नहीं है कि पर्पर पर्दे के पीछे क्या करता है। मैंने गहरे घोंसले वाले हैंश और पेर्ल में सरणी मुद्रित करने के लिए इसे बड़े पैमाने पर उपयोग किया है। अब तक मुझे रूबी में कोई विकल्प नहीं मिला है (या मुझे रूबी में उपलब्ध विकल्पों का अच्छा उपयोग करने का कोई तरीका नहीं मिला है)।
यह मेरा पर्ल कोड और उसके आउटपुट है:
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my $hash;
$hash->{what}->{where} = "me";
$hash->{what}->{who} = "you";
$hash->{which}->{whom} = "she";
$hash->{which}->{why} = "him";
print Dumper($hash);
उत्पादन:
$VAR1 = {
'what' => {
'who' => 'you',
'where' => 'me'
},
'which' => {
'why' => 'him',
'whom' => 'she'
}
};
बस प्यार डम्पर। :)
माणिक में, मैं pp
, p
, inspect
और yaml
की कोशिश की।
#!/usr/bin/ruby
require "pp"
require "yaml"
hash = Hash.new{ |h,k| h[k] = Hash.new(&h.default_proc) }
hash[:what][:where] = "me"
hash[:what][:who] = "you"
hash[:which][:whom] = "she"
hash[:which][:why] = "him"
pp(hash)
puts "Double p did not help. Lets try single p"
p(hash)
puts "Single p did not help either...lets do an inspect"
puts hash.inspect
puts "inspect was no better...what about yaml...check it out"
y hash
puts "yaml is good for this test code but not for really deep nested structures"
आउटपुट:
{:what=>{:where=>"me", :who=>"you"}, :which=>{:whom=>"she", :why=>"him"}}
Double p did not help. Lets try single p
{:what=>{:where=>"me", :who=>"you"}, :which=>{:whom=>"she", :why=>"him"}}
Single p did not help either...lets do an inspect
{:what=>{:where=>"me", :who=>"you"}, :which=>{:whom=>"she", :why=>"him"}}
inspect was no better...what about yaml...check it out
---
:what:
:where: me
:who: you
:which:
:whom: she
:why: him
yaml is good for this test code but not for really deep nested structures
धन्यवाद यहाँ गहरे लाल रंग का और इसके उत्पादन में मेरी एक ही कोड है।
क्या आप द्वारा * YAML इस परीक्षण कोड के लिए अच्छा है मतलब बल्कि बहुत ही गहन नेस्टेड संरचनाओं के लिए नहीं है * ? –
यम आउटपुट दर्दनाक (मेरे लिए कम से कम) डूपर की तुलना में पढ़ने और व्याख्या करने के लिए है जब यह गहरी हैश/सरणी की बात आती है। – slayedbylucifer
डाउनवॉट्स? किस लिए? सवाल के साथ क्या गलत है? – slayedbylucifer