Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Your due diligence includes validating assumptions (sometimes just peppering code with print and print Dumper statements), and taking the time to understand the solutions presented.

I mentioned in the original post that I assumed that $responsetextall[$i][$j]{set}{Client}{redirect_uris} contained an array reference. You could confirm that like this:

print ref($responsetextall[$i][$j]{set}{Client}{redirect_uris}), "\n";

Which should print:

ARRAY

If it doesn't, your question was misleading. That's fine. If you use Data::Dumper you should be able to get better insight into what your data structure actually looks like:

use Data::Dumper; print Dumper $responsetextall[$i][$j]{set}{Client}{redirect_uris};

If the output to that is anything besides an array ref, you'll have to adjust how you're unpacking it later on.

I composed the following test to verify that my solution works as intended (after removing the in, which must have sneaked in from some recent Python work):

#!/usr/bin/env perl use strict; use warnings; my @responsetextall; $responsetextall[0][0]{set}{Client}{redirect_uris} = [qw(foo bar baz)] +; print ref($responsetextall[0][0]{set}{Client}{redirect_uris}), "\n"; my $redi; $redi = $responsetextall[0][0]{set}{Client}{redirect_uris}; for my $i (0 .. $#$redi) { print $redi->[$i], "\n"; }

The output is:

ARRAY foo bar baz

So it is working, and is printing more than a single element. Also, your for loop is not the Perl way of doing things. If you don't need to care about the index, just iterate over the list:

for my $element (@$redi) { print "$element\n"; }

Nicer, right? Please look at perlref, perlreftut, and the REFERENCES section of perlcheat for additional information on how to manipulate references. perlsyn and perlintro should have more discussion on for or foreach loops.


Dave


In reply to Re^3: Printing first element of an array in worksheet by davido
in thread Printing first element of an array in worksheet by chandantul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (3)
    As of 2021-04-17 11:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?