rmcdougal01 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, This is my very first post, I am using the "Learning Perl" book (7th eddition). I can't find a solution for my problem in this book, and googling has yield no results. I want to execute a particular function each time an iteration completes using the while loop:

sub cp_domains { open(my $fh, $domainFile) or die "Coult not open file '$domainFile +'"; while (my $row = <$fh>) { chomp $row; my @domain = split /:/, $row; resolve_domain($domain[0]); } #close($fh); }

The first time the “while” loop iterates it would correctly execute the function, but subsequent times is not returning anything. Can anyone provide me with some guidance?

  • Comment on How to execute a function each time a "while" loop iteration occurs?
  • Download Code

Replies are listed 'Best First'.
Re: How to execute a function each time a "while" loop iteration occurs?
by LanX (Saint) on Dec 22, 2019 at 00:03 UTC
    The code looks right, besides indentation.

    I suppose you need to debug the input data or the resolve_domain function.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      Hello Rolf,

      Thank you for confirming the code was correct, sorry for the indentation.

      Yes, you were I took another hard look and my print statement was incorrect hence not seeing subsequent iterations.