<mordy> you can’t
<alnewkirk> 0- -0
<mordy> there might be some module which abstracts this for you
<mordy> but it’s 2-3 lines and there’s no nice way to circumvent it. while hashes and arrays might ‘seem’ similar they’re quite different
<mordy> one nasty way:
* jjore assumes it’d be good for vreg to figure out how to do this.
<mordy> yes it would
<mordy> hrrm.. bold
<mordy> also, don’t forget about scalar references and globs
<alnewkirk> v-reggie, define “child objects”
<mordy> and code references
<vreg> and FORMAT and IO and LVALUE and
<uri> vreg: those aren’t objects. they are glob slots
<vreg> ah
<vreg> okah
* jjore figures it’d be good to start with two types: just non-references like “foo” and arrays. Then figure out how to do hashes. Then scalar references. Then, etc. The principles are the same but it’s increasing the difficulty.
<alnewkirk> I just wrote something up on “vague requirements”
<mst> vreg: where did you find out about those from?
<vreg> mst: http://perldoc.perl.org/functions/ref.html
<mst> vreg: ok, those are things that a reference can be taken to
<mst> vreg: a JSON structure can only contain scalars, arrays and hashes
<mst> vreg: so if you’re still on the same exercise ARRAY and HASH are the only ones you need to care about
<vreg> am i incorrect in thinking if $value doesn’t refer to (point to?) a hash or array it is considered a scalar?
<mordy> in your specific usecase, yes
<mst> vreg: $value is always a scalar. in this case, it is a scalar containing a reference to something.
<mordy> err.. i mean you’re not incorrect
<mst> vreg: but, in terms of JSON, if it isn’t a reference to a hash or array then it’ll be a scalar.
<vreg> if it’s bottomed out does that mean
<vreg> ah
* vreg cheers up a bit.
<mst> vreg: well, actually, there’s one other case
<vreg> can i just test for if $value->{…} is a scalar?
<mst> vreg: JSON has a boolean type, which will be returned as a JSON::XS::Boolean object or something
<mordy> vreg: your recursion function is iterative. the ‘bottoming-out’ is inherent. what you need to worry about is dereferencing something that’s not a reference
<mst> vreg: but those print out just fine, so meh
<vreg> and that would indicate it’s not pointing to an array or hash?
<mst> vreg: here’s what I’d write.
<mst> vreg: my $ref = ref($thing); if ($ref eq ‘HASH’) { } elsif ($ref eq ‘ARRAY’) { } elsif ($ref) { die “Can’t deal with reference type ${ref} yet” } else { }
<uri> bah
<alnewkirk> humbug
<vreg> okay
<mst> vreg: I’ve always been fond of writing code that has an “I didn’t expect this to happen, blow up explaining what did”
<mst> and the word ‘yet’ reminds you that it isn’t an inherent design constraint
<mst> just “I didn’t write code for this so far”
<vreg> when i try to think of “reference to” the first thing i think of is “pointer to”
<vreg> is that bad?
<uri> yes
<uri> refs are much more than pointers
<dhoss> what the hell is the other thing in C, there’s pointers and…
<dhoss> is it just references?
<uri> dhoss: just nasty fast pointers
<uri> best thing pointers can do that refs can’t is incrementing through an array.
<apeiron> C++ has references.
<uri> worst this is pointers can core dump all the fucking time
* apeiron forgets what they are and what they do but knows they’re different from pointers somehow
<Thuryn> pointers don’t core dump.
<uri> Thuryn: you know what i mean
<Thuryn> programs dump core when you fuck up your pointers.
<mst> pointers tend to be the quickest and easiest way to induce a SEGV
<jjore> Lol. segv is ignorable.
<dhoss> i thought i misunderstood more things in C
<Thuryn> pointers are like motorcycles. they’re awesome, but you’re likely to crash everything if you don’t respect them.
<dhoss> haha
<jjore> too bad pointers don’t come with annotation for dealing with locality
<jjore> Oh well, I’m sure there’s some mutant C++ thing that does this.
<dhoss> i just can’t really get on the C++ boat
<tm604> I got on the C++ boat years ago, still trying to work out how to start it though :(
<dhoss> i wanna learn C better
Session Close: Sun Feb 12 00:00:01 2012

 
© 2011 Techdot IRC Resources Suffusion theme by Sayontan Sinha