Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Syntax Question Related to "join" on a Complex Data Structure

by choroba (Cardinal)
on Oct 25, 2016 at 21:19 UTC ( [id://1174736]=note: print w/replies, xml ) Need Help??


in reply to Syntax Question Related to "join" on a Complex Data Structure

Just tell Perl what to dereference:
my $transcripts_line = join "\t", @{ $transcripts{$transcript_ip}{$tra +nscript_id} }{@transcripts_columns};

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Syntax Question Related to "join" on a Complex Data Structure
by perldigious (Priest) on Oct 25, 2016 at 21:46 UTC

    That worked. I was so close... For dereferencing I had tried (and it obviously failed).

    my $transcripts_line = join "\t", @{ $transcripts{$transcript_ip}{$tra +nscript_id}{@transcripts_columns} };

    So the location of that dereference closing bracket made all the difference. I need to stare at this (and look deeper with print) for a minute or two until it makes sense to me why I should be dereferencing a list from just the first two keys before taking a hash slice of that list with the @transcripts_columns array... That's what it looks like your code is doing to me at first glance anyway, perhaps I'm even interpreting that wrong.

    Thanks choroba. I'll upvote tomorrow, I'm out of votes for the day.

    I love it when things get difficult; after all, difficult pays the mortgage. - Dr. Keith Whites
    I hate it when things get difficult, so I'll just sell my house and rent cheap instead. - perldigious
Re^2: Syntax Question Related to "join" on a Complex Data Structure
by perldigious (Priest) on Oct 26, 2016 at 14:21 UTC

    Well, I did look deeper, and I mostly understand what's going on now, but one thing does still surprise me.

    say $transcripts{$transcript_ip}{$transcript_id}; + # gives me the hash reference of the lowest (3rd deep + hash) say %{ $transcripts{$transcript_ip}{$transcript_id} }; + # gives me that entire hash (key value pairs) say %{ $transcripts{$transcript_ip}{$transcript_id} }{@transcri +pts_columns}; # gives me my desired slice of that hash (key value p +airs) say keys { %{ $transcripts{$transcript_ip}{$transcript_id} }{@transcri +pts_columns} }; # gives me my desired slice of that hash (keys only) say @{ $transcripts{$transcript_ip}{$transcript_id} }{@transcri +pts_columns}; # gives me my desired slice of that hash (values only +)

    What slightly surprised me is that the 3rd line above (with the leading %) gives the key value pairs and not just the values, but that made sense when I considered that I did essentially ask it to give me a hash and of course Perl would give a list of key value pairs when I do that. What still surprises me is that the last line simply by changing the leading % to a @ gives just the values to the list. Don't get me wrong though, that's darned convenient, and I'm really glad Perl does that.

    I didn't even realize that's the same thing I had done before in the first line of code I gave in my original post until I went back and considered it more. For some reason that made complete sense to me at the time... or more likely I guessed, got lucky, and didn't inspect further because I didn't have to at the time. :-)

    I love it when things get difficult; after all, difficult pays the mortgage. - Dr. Keith Whites
    I hate it when things get difficult, so I'll just sell my house and rent cheap instead. - perldigious

      Hi perldigious,

      What slightly surprised me is that the 3rd line above (with the leading %) gives the key value pairs and not just the values

      Key/Value Hash Slices were added in Perl v5.20 (the rest of the Slices doc is probably worth a read too).

      Hope this helps,
      -- Hauke D

        Key/Value Hash Slices were added in Perl v5.20 (the rest of the Slices doc is probably worth a read too).

        Thanks for mentioning that here; as to my knowledge that is the first time it has been.

        It had gone completely under my radar; and -- along with the index/value array slices -- looks to be a really useful addition.

        IMO that is probably the most useful addition since they added defined-OR back in 5.10.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.

        Thanks haukex, appreciate the links to the perldata doc. I usually can only get where I need to be in the docs via a Google search. Everything I know about slices I picked up from the last chapter of "Learning Perl 6th Edition", which only briefly points out that it can be done on arrays and hashes and the basics of how to do it. I'm pretty sure that's where I picked up the @gimme_this_slice_of_values{ @for_this_list_of_keys } trick. It's not like they could dive too deep in to usage on more complex data structures that would require dereferencing, and since they wrote that book under Perl 5.14 the Key/Value Hash Slice variation wasn't covered.

        I love it when things get difficult; after all, difficult pays the mortgage. - Dr. Keith Whites
        I hate it when things get difficult, so I'll just sell my house and rent cheap instead. - perldigious

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1174736]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-03-29 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found