I feel that a REGEX makes the intent clear. Efficiency should not be an issue.
use strict; use warnings; my $string = 'field1 ' . 'field2 ' . 'field3 ' . 'field4 ' . 'field5 ' . 'field6 ' . 'field7 ' . 'field8 ' . 'field9 ' . 'file name here ' . 'field11 ' . 'field12 ' . 'field`3 ' . 'field14 ' . 'field15 ' . 'field16 ' . 'field17 ' . 'field18 ' . 'field19' ."\n" ; my $skip_field = qr /[^\s]+\s+/; # Include any non-whitspace character my $file_field = qr /[\w\s]+/; # Include word characters and spaces my ($file_name) = $string =~ m/\A$skip_field{9}($file_field)\s$skip_field{9}\z/; print $file_name, "\n";
In reply to Re: parse a line with varied number of fields
by BillKSmith
in thread parse a line with varied number of fields
by raggmopp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |