Perl next operator - Perl Send mail vote down 0 vote down 0 Views : 241
Tagged in : Perl
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




    Login to add Comments .