in reply to Sub Return Help

Your code exits the sub after the 1st line of your file is read because the return is inside the while loop. This prints each host within the sub. Nothing is returned explicitly:
use warnings; use strict; sub get_host { open( HOST, "<hosts.txt" ); while (<HOST>) { my ($line) = $_; chomp($line); print "hostname = $line\n"; } } get_host(); __END__ hostname = hostone hostname = hosttwo

Replies are listed 'Best First'.
Re^2: Sub Return Help
by PerlCramps (Novice) on May 07, 2015 at 11:12 UTC
    Thank you :)
Re^2: Sub Return Help
by PerlCramps (Novice) on May 07, 2015 at 15:18 UTC
    This helps me the value of the subroutine; I would like to be able to assign the subroutine to a variable call $host and use as need for other fuctions. Is that possible or am I approaching the process all wrong?? Thanks