How do I break out of a loop in Perl?

I'm trying to use a break statement in a for loop, but since I'm also using strict subs in my Perl code, I'm getting an error saying:

Bareword "break" not allowed while "strict subs" in use at ./final.pl line 154.

Is there a workaround for this (besides disabling strict subs)?

My code is formatted as follows:

for my $entry (@array){
    if ($string eq "text"){
         break;
    }
}

Answers


Oh, I found it. You use last instead of break

for my $entry (@array){
    if ($string eq "text"){
         last;
    }
}

Need Your Help

alias_attribute vs read_attribute and write_attribute

ruby activerecord ruby-on-rails-4 rails-activerecord

I'm using ActiveRecord without rails. Everything works fine except for a weird quirk with some helper methods I'm writing that I'm hoping someone can explain. I've got a model of a legacy databas...

linq to sql duplicates in query eith join

c# visual-studio-2010 linq sql-server-2008

I have a linq to sql query that produces duplicates. i can seem to figure out how to eliminate these duplicate records. Maybe someone on here can help. The idea is to retrieve the sum of the "total...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.