|
|
Perl next operator - Perl
|
Views : 261
|
|
Tagged in : Perl
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
Solution
When you're in a Perl for loop (iterating over an array or hash), and you want to move on to the next element in your array or hash, just use the Perl next operator, like this:
Example 1:
for (@array)
{
if (SOME_TEST_CONDITION)
{
# move on to the next loop element
next;
}
# more code here ...
}
Example 2:
for (@records)
{
# skip blank lines
next if /^[ \t]*$/;
# skip comment lines
next if /#/;
# skip printing lines
next if /print/;
next if /printf/;
# much more code here ...
}
|
|
By Nithya, On - 2010-02-04 |
|
|
|