Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^6: Have you netted a Perl Monk or Perl Pretender in 5 minutes or less?

by Anonymous Monk
on Sep 29, 2005 at 15:37 UTC ( #496148=note: print w/replies, xml ) Need Help??


in reply to Re^5: Have you netted a Perl Monk or Perl Pretender in 5 minutes or less?
in thread Have you netted a Perl Monk or Perl Pretender in 5 minutes or less?

To understand that line you must know the effects of using unless (and if I'm asking the questions that will quickly turn into what Perl considers true and false values) as well as execution order in a statement. Put concicely, it says that if $c exists and is true maintain it's value, otherwise set it to 1.
Wrong. It is an anomoly caused by the interaction between lexical scopes created by "my" and postfix conditionals. To put it correctly, if $c is false, then set it to one. If $c is true then set it to undef. If you actually try running that snippet you'll learn what it really does.
  • Comment on Re^6: Have you netted a Perl Monk or Perl Pretender in 5 minutes or less?
  • Download Code

Replies are listed 'Best First'.
Re^7: Have you netted a Perl Monk or Perl Pretender in 5 minutes or less?
by benrwebb (Scribe) on Sep 29, 2005 at 19:16 UTC
    Correct you are, my bad. I'm used to calling that in a different context so I looked back at the code I had actually been using. This is what would actually work the way I described:
    use strict; use warnings; my $c = 1; my $d = undef; sub sbr { $c = 2 unless $c; print "c = $c\n"; $d = 4 unless $d; print "d = $d\n"; } sbr();


    Thanks for correcting my mistake

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2020-02-26 16:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (117 votes). Check out past polls.

    Notices?