COMP111Lecture18/Slide6Returning Values (1)You can return a value from a function, and use it anyexpression as in C++:$ cat sum2#!/usr/local/bin/perl5-wsa = l;$b = 2;$c =sumaandb()+l;print "value of c: $cln";sub sum a and btreturn sa + sb,$ sum2value of c: 4s
COMP111 Lecture 18 / Slide 6 Returning Values (1) ▪ You can return a value from a function, and use it any expression as in C++: $ cat sum2 #!/usr/local/bin/perl5 -w $a = 1; $b = 2; $c = sum_a_and_b() + 1; print "value of c: $c\n"; sub sum_a_and_b{ return $a + $b; } $ sum2 value of c: 4 $
COMP111Lecture18/Slide7Returning Values (2)A subroutine can also return a list of values$ cat listl#!/usr/local/bin/perl5-wsa = l;$b = 2;@c = list of a and b();print "list of c: @cln";sub list ofa and btreturn(sa,sb);s listllist of c: 1.2s
COMP111 Lecture 18 / Slide 7 Returning Values (2) ▪ A subroutine can also return a list of values: $ cat list1 #!/usr/local/bin/perl5 -w $a = 1; $b = 2; @c = list_of_a_and_b(); print "list of c: @c\n"; sub list_of_a_and_b{ return ($a,$b); } $ list1 list of c: 1 2 $