Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: How can I get the last element of an array inside of fetchall_arrayref?

by Lewisa (Novice)
on Mar 23, 2021 at 17:57 UTC ( [id://11130223]=note: print w/replies, xml ) Need Help??


in reply to Re: How can I get the last element of an array inside of fetchall_arrayref?
in thread How can I get the last element of an array inside of fetchall_arrayref?

Hey Hippo. Thank you! You are correct, I missed that error on my end. However, how can I print inside of the fetchall_arrayref loop and still get the last element, 3? All of my data is connected within that loop and the second I leave the loop they're no longer connected, correct?

Replies are listed 'Best First'.
Re^3: How can I get the last element of an array inside of fetchall_arrayref?
by hippo (Bishop) on Mar 23, 2021 at 18:45 UTC

    Your variables (scalars and arrays in this case) which are declared outside the loop will continue to hold their values once the loop is finished - just like they do in your second example. Try it and see!

    Scoping is an important topic in programming generally, not just in Perl. It will be worth your time to read and learn more about it. The usual reference given is Coping with scoping which covers lots more than you will need for this particular question - but it is all good stuff.


    🦛

      Thanks a lot! I will read that top to bottom as I thought I understood scope but I'm clearly missing a few key points.
      Hey Hippo. I thought that I responded to your comment. Thank you! I thought I had a great understand of scope but I see that I'm missing a few key points. I will be reading that link you posted.

Log In?
Username:
Password:

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

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

    No recent polls found