Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^2: if(my) scope

by oha (Friar)
on Oct 12, 2009 at 08:53 UTC ( #800633=note: print w/replies, xml ) Need Help??

in reply to Re: if(my) scope
in thread if(my) scope

i just realized that:
open my $fh, '<', $file or die;
so i'm asking myself if the possibility to setup a scope variable inside the argument of a function call is extended to _if_ statements too?

Replies are listed 'Best First'.
Re^3: if(my) scope
by ikegami (Patriarch) on Oct 12, 2009 at 09:20 UTC

    This is fine:

    if (open(my $fh, '<', $qfn)) { from $fh... } # $fh is out of reach here

    Perl doesn't care where the my is to the point that it allows the following (even though the behaviour is officially undefined):

    my $fh if ...;
      that's another thing:
      if(my $x = expr) { ... } # my always executed my $x if expr; # my is conditional if(expr) { my $x } # as above
      what i was saying is that if i can my on a arg of a function, maybe i can do the same in the "argument" of a if


        "as above" is unclear. I think you meant "my is conditional", but it's really "my always executed" (in the scope in which it resides).
        c() or my $x; # XXX Conditionally executed c() and my $x; # XXX Conditionally executed my $x if c(); # XXX Conditionally executed (same as previous) sub foo { my $x } # OK Always executed if (c()) { my $x } # OK Always executed die; my $x; # OK Always executed

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2022-01-21 06:28 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (57 votes). Check out past polls.