in reply to Re^3: Accessing single element without args
in thread Accesing single element without args

That makes sense :). I will try to use it if my code reviewer approves :)

A final query on my question. As i want to print only r[0], is there a way to set the array @r to only r[0] during interface_control call

. I mean like this
push (@r, $r[0])

I know inside interface_control sub, i can set this, but interface_control can call from outside set this value ?

Replies are listed 'Best First'.
Re^5: Accessing single element without args
by Athanasius (Archbishop) on Mar 31, 2015 at 06:09 UTC

    No. Your original post shows that @r is created as a lexical variable within sub interface_control. So, even if you could somehow access @r from outside the sub, you would have to do so either:

    • before the sub is called; in which case any changes you made would be overriden within the sub before the print statement is reached; or
    • after the sub returns; in which case any changes you made (to a now non-existent variable!) would be too late to affect the printing behaviour.

    I’m not familiar with PadWalker, but following Anonymous Monk’s comment above, I had a quick look. As I understand it, PadWalker allows you to access variables in subroutines higher than your current position in the call stack. As you want to access a variable within a subroutine you will be calling, this module won’t help you either. :-(

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      I’m not familiar with PadWalker, but following Anonymous Monk’s comment above, I had a quick look. As I understand it, PadWalker allows you to access variables in subroutines higher than your current position in the call stack. As you want to access a variable within a subroutine you will be calling, this module won’t help you either. :-(

      Yeah, you're pretty much correct ...

      though peek_sub *might* yield some result but it probably won't ... its not worth even thinking about it let alone trying it out

      coping with scoping OP does not :)