Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Strange syntax question

by Utilitarian (Vicar)
on Aug 14, 2013 at 16:15 UTC ( #1049440=note: print w/replies, xml ) Need Help??

in reply to Strange syntax question

from perldoc perlop:
C-style Logical Defined-Or Although it has no direct equivalent in C, Perl's "//" operator + is related to its C-style or. In fact, it's exactly the same as " +||", except that it tests the left hand side's definedness instead o +f its truth. Thus, "$a // $b" is similar to "defined($a) || $b" (exc +ept that it returns the value of $a rather than the value of "defined($a +)") and yields the same result as "defined($a) ? $a : $b" (except that +the ternary-operator form can be used as a lvalue, while "$a // $b" cannot). This is very useful for providing default values for variables. If you actually want to test if at least one of $a +and $b is defined, use "defined($a // $b)". The "||", "//" and "&&" operators return the last value evaluat +ed (unlike C's "||" and "&&", which return 0 or 1). Thus, a reason +ably portable way to find out the home directory might be: $home = $ENV{HOME} // $ENV{LOGDIR} // (getpwuid($<))[7] // die "You're homeless!\n"; In particular, this means that you shouldn't use this for selec +ting between two aggregates for assignment: @a = @b || @c; # this is wrong @a = scalar(@b) || @c; # really meant this @a = @b ? @b : @c; # this works fine, though As more readable alternatives to "&&" and "||" when used for co +ntrol flow, Perl provides the "and" and "or" operators (see below). +The short-circuit behavior is identical. The precedence of "and" a +nd "or" is much lower, however, so that you can safely use them after a + list operator without the need for parentheses: unlink "alpha", "beta", "gamma" or gripe(), next LINE; With the C-style operators that would have been written like th +is: unlink("alpha", "beta", "gamma") || (gripe(), next LINE); Using "or" for assignment is unlikely to do what you want; see +below.

print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049440]
[Corion]: Option a) would mean launching cmd.exe /k c:\path\to\ batchfile- launching-perl- script.cmd. Option b) would be to add pause as the last line of said batch file.
[LanX]: First day after holidays ... and already stressed by the fact that colleagues changed stuff without communication ... apparently I'm the only one trying to fight entropy
[Corion]: LanX: The command is always in the history if you typed it in before. If you didn't type the command into the command line, it will not be there. I think there is doskey which can stuff command lines into the history
LanX damns the cult of CB ;-)
[LanX]: please forget my last 3 posts
[LanX]: Yeah option a doesn't go into history
[LanX]: probably I need to teach the app to restart after C-c Kill
[Corion]: LanX: Maybe have an infinite-loop cmd file? Much easier than trying to manage that from within Perl IMO
[Corion]: Alternatively, relaunch the application from cron (or a Windows cron) every minute

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2017-03-27 15:50 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.