Hanna Hanna - 1 year ago 128
Perl Question

Perl - subroutine

There is perl subroutine called 'filter'. It accepts any number of arguments and returns a list of all the positive numeric arguments(including 0). Negative numbers and strings are ignored

For example: If the arguments are "6", "3G", "Matthew","-9","8.3", "+2", "0" and "books", then a list (6,8.3,2,0) will be returned.
If there is no positive number then -1 will be returned.

Answer Source

Here's one way to do it:

fmt.Println("Start of session")
defer fmt.Println("Room Empty")
for i := 0; i < 6; i++ {
    s := Student{Name: "Student" + strconv.Itoa(i)}
    defer s.Leave()
fmt.Println("End of session")

playground example

The deferred functions are executed on return from the function in reverse order.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download