perl tips

Uncategorized

perl tips

Iterating through arrays

for( @arr ){
    print $_, $/;
}

Iterating through multiple arrays

# Stop at end of shortest
while( @arr1 && @arr2 ){
    print shift @arr1, " ", shift @arr2, $/;
}

# Stop at end of longest
while( @arr1 || @arr2 ){
    print shift @arr1, " ", shift @arr2, $/;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.