Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
ejaggers said:I don't want $x set if sub() returns false
[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]strict[/green][red];[/red]
[black][b]use[/b][/black] [green]warnings[/green][red];[/red]
[maroon]&print_if_positive[/maroon][red]([/red]-[fuchsia]3[/fuchsia][red])[/red][red];[/red]
[maroon]&print_if_positive[/maroon][red]([/red][fuchsia]0[/fuchsia][red])[/red][red];[/red]
[maroon]&print_if_positive[/maroon][red]([/red][fuchsia]5[/fuchsia][red])[/red][red];[/red]
[gray][i]# passing argument by reference[/i][/gray]
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$num[/blue] = -[fuchsia]5[/fuchsia][red];[/red]
[olive][b]if[/b][/olive] [red]([/red][maroon]&func[/maroon][red]([/red]\[blue]$num[/blue][red])[/red][red])[/red] [red]{[/red]
[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [red]"[/red][purple]result = [blue]$num[/blue][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[red]}[/red]
[blue]$num[/blue] = [fuchsia]0[/fuchsia][red];[/red]
[olive][b]if[/b][/olive] [red]([/red][maroon]&func[/maroon][red]([/red]\[blue]$num[/blue][red])[/red][red])[/red] [red]{[/red]
[black][b]print[/b][/black] [red]"[/red][purple]result = [blue]$num[/blue][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[red]}[/red]
[blue]$num[/blue] = [fuchsia]7[/fuchsia][red];[/red]
[olive][b]if[/b][/olive] [red]([/red][maroon]&func[/maroon][red]([/red]\[blue]$num[/blue][red])[/red][red])[/red] [red]{[/red]
[black][b]print[/b][/black] [red]"[/red][purple]result = [blue]$num[/blue][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[red]}[/red]
[gray][i]# passing input argument by value and output argument by reference[/i][/gray]
[blue]$num[/blue] = -[fuchsia]5[/fuchsia][red];[/red]
[black][b]my[/b][/black] [blue]$result[/blue] = [fuchsia]0[/fuchsia][red];[/red]
[olive][b]if[/b][/olive] [red]([/red][maroon]&func2[/maroon][red]([/red][blue]$num[/blue], \[blue]$result[/blue][red])[/red][red])[/red] [red]{[/red]
[black][b]print[/b][/black] [red]"[/red][purple]result = [blue]$result[/blue][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[red]}[/red]
[blue]$num[/blue] = [fuchsia]0[/fuchsia][red];[/red]
[blue]$result[/blue] = [fuchsia]0[/fuchsia][red];[/red]
[olive][b]if[/b][/olive] [red]([/red][maroon]&func2[/maroon][red]([/red][blue]$num[/blue], \[blue]$result[/blue][red])[/red][red])[/red] [red]{[/red]
[black][b]print[/b][/black] [red]"[/red][purple]result = [blue]$result[/blue][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[red]}[/red]
[blue]$num[/blue] = [fuchsia]3[/fuchsia][red];[/red]
[blue]$result[/blue] = [fuchsia]0[/fuchsia][red];[/red]
[olive][b]if[/b][/olive] [red]([/red][maroon]&func2[/maroon][red]([/red][blue]$num[/blue], \[blue]$result[/blue][red])[/red][red])[/red] [red]{[/red]
[black][b]print[/b][/black] [red]"[/red][purple]result = [blue]$result[/blue][purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[red]}[/red]
[gray][i]# *** procedures/functions ***[/i][/gray]
[url=http://perldoc.perl.org/functions/sub.html][black][b]sub[/b][/black][/url] [maroon]positive[/maroon] [red]{[/red]
[black][b]my[/b][/black][red]([/red][blue]$num[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[gray][i]# return positive number or zero[/i][/gray]
[url=http://perldoc.perl.org/functions/return.html][black][b]return[/b][/black][/url] [red]([/red][blue]$num[/blue] > [fuchsia]0[/fuchsia] && [blue]$num[/blue][red])[/red][red];[/red]
[red]}[/red]
[black][b]sub[/b][/black] [maroon]print_if_positive[/maroon] [red]{[/red]
[black][b]my[/b][/black] [red]([/red][blue]$arg[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[gray][i]# print only if result is true[/i][/gray]
[olive][b]if[/b][/olive] [red]([/red][black][b]my[/b][/black] [blue]$res[/blue] = [maroon]&positive[/maroon][red]([/red][blue]$arg[/blue][red])[/red][red])[/red] [red]{[/red]
[black][b]print[/b][/black] [red]"[/red][purple]number = [blue]$res[/blue] is positive.[purple][b]\n[/b][/purple][/purple][red]"[/red] [red];[/red]
[red]}[/red]
[red]}[/red]
[black][b]sub[/b][/black] [maroon]func[/maroon] [red]{[/red]
[black][b]my[/b][/black][red]([/red][blue]$num[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[gray][i]#print "func: numref = $num\n";[/i][/gray]
[gray][i]#print "func: numval = ${$num}\n";[/i][/gray]
[olive][b]if[/b][/olive] [red]([/red][blue]$[/blue][red]{[/red][blue]$num[/blue][red]}[/red] > [fuchsia]0[/fuchsia][red])[/red] [red]{[/red]
[blue]$[/blue][red]{[/red][blue]$num[/blue][red]}[/red] = [blue]$[/blue][red]{[/red][blue]$num[/blue][red]}[/red] [blue]*[/blue] [fuchsia]100[/fuchsia][red];[/red]
[black][b]return[/b][/black] [fuchsia]1[/fuchsia][red];[/red]
[red]}[/red]
[olive][b]else[/b][/olive] [red]{[/red]
[black][b]return[/b][/black] [fuchsia]0[/fuchsia][red];[/red]
[red]}[/red]
[red]}[/red]
[black][b]sub[/b][/black] [maroon]func2[/maroon] [red]{[/red]
[black][b]my[/b][/black] [red]([/red][blue]$input[/blue], [blue]$output[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[olive][b]if[/b][/olive] [red]([/red][blue]$input[/blue] > [fuchsia]0[/fuchsia][red])[/red] [red]{[/red]
[blue]$[/blue][red]{[/red][blue]$output[/blue][red]}[/red] = [blue]$input[/blue] [blue]*[/blue] [fuchsia]10[/fuchsia][red];[/red]
[black][b]return[/b][/black] [fuchsia]1[/fuchsia][red];[/red]
[red]}[/red]
[olive][b]else[/b][/olive] [red]{[/red]
[black][b]return[/b][/black] [fuchsia]0[/fuchsia][red];[/red]
[red]}[/red]
[red]}[/red]
number = 5 is positive.
result = 700
result = 30
my $temp = sub();
$x = $temp if $temp;
$x = map {$_ || $x} sub();