Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: next within one subroutine that looks to another subroutine

by trs80 (Priest)
on Feb 13, 2002 at 20:44 UTC ( [id://145279]=note: print w/replies, xml ) Need Help??


in reply to next within one subroutine that looks to another subroutine

One possible method would be:
#!/usr/bin/perl -w use strict; my @list = qw(Charles Cody Gina); # pass the array to the sub to avoid value reuse. &action(@list); sub action { my @list = @_; for my $i(@list) { # tests the return value of decide and only prints # if it is true (1) print "$i\n" if decide($i); } } sub decide { my $i = shift; # returns 1 if it is a match otherwise nothing # is returned. return 1 if $i =~ m/^C/; # you could add an explicit return 0 if you want # return 0; }

If your conditional is more complex then the example you would want to most likely put the if before the print and then use an else condition for a failed decide.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-29 09:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found