Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

How to execute a function each time a "while" loop iteration occurs?

by rmcdougal01 (Initiate)
on Dec 21, 2019 at 23:51 UTC ( [id://11110493]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11110493]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 07:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found