G'day biohak,
Welcome to the monastery.
Firstly, please don't alter your OP without indicating what you've changed. See "How do I change/delete my post?" for an explanation of why not and how to indicate changes.
The code you currently have posted has many issues:
Using this dummy data (as I've no idea what your real data looks like):
$ cat pm_1077685_A.txt Line 1: no plate info Line 2: ... PlateID 123 ... Line 3: ... PlateID 456 ... Line 4: no plate info $ cat pm_1077685_B.txt Line 1: no plate info Line 2: ... PlateID 789 ... Line 3: ... PlateID ... Line 4: no plate info $ cat pm_1077685_C.txt Line 1: no plate info Line 2: ... PlateID 000 ... Line 4: no plate info
This script shows similar processing to what you appear to be attempting and includes examples of the points I've made above.
#!/usr/bin/env perl use strict; use warnings; use autodie; my @filenames = qw{pm_1077685_A.txt pm_1077685_B.txt pm_1077685_C.txt} +; for my $filename (@filenames) { my $in_path = "./$filename"; print "Processing: '$in_path'\n"; open my $in_fh, '<', $in_path; while (<$in_fh>) { print "\t$_"; if (/PlateID/) { if (/PlateID (\d+)/) { my $plate_id = $1; print "\t\tProcess PlateID '$plate_id' from '$in_path' +\n"; } else { print "\t\tpopup_error_window($in_path)\n"; last; } } } }
Output:
$ pm_example.pl Processing: './pm_1077685_A.txt' Line 1: no plate info Line 2: ... PlateID 123 ... Process PlateID '123' from './pm_1077685_A.txt' Line 3: ... PlateID 456 ... Process PlateID '456' from './pm_1077685_A.txt' Line 4: no plate info Processing: './pm_1077685_B.txt' Line 1: no plate info Line 2: ... PlateID 789 ... Process PlateID '789' from './pm_1077685_B.txt' Line 3: ... PlateID ... popup_error_window(./pm_1077685_B.txt) Processing: './pm_1077685_C.txt' Line 1: no plate info Line 2: ... PlateID 000 ... Process PlateID '000' from './pm_1077685_C.txt' Line 4: no plate info
-- Ken
In reply to Re: Busting out of an inner loop to next file in foreach loop
by kcott
in thread Busting out of an inner loop to next file in foreach loop
by biohak
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |