r/programming • • May 08 '15

Five programming problems every Software Engineer should be able to solve in less than 1 hour

https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
2.5k Upvotes

2.1k comments sorted by

View all comments

Show parent comments

1

u/the_woo_kid May 08 '15

In calling the subroutines, why did you prepend them with '&' in both my $sum = &forsum + &whilesum + &recsum(@list) and returnn shift(@) + &recsum(@)?

1

u/sarahbau May 08 '15

Mostly out of habit. It's honestly been a few years since I've used Perl professionally, so I can't remember 100% how I got into the habit. I do remember that it was useful for what I worked on, as calling &foo without arguments will send @_ to foo. Almost all of what I worked on was object oriented perl though, so most calls were $foo->bar(); I think using &foo or even &foo() just became convention for any non-object oriented function call.

It works without the &, if you add () to forsum and whilesum. Otherwise, perl doesn't allow bare words with strict.