in reply to Abritrary multiple spaces as delimiter
my $string = "122 Genesis Chamber Mark Tedin A U "; my ( $second ) = $string =~ m/\s{2,}(.+?)\s{2,}/; print "$second\n";
That works if, as I stated, you are sure that the second field is surrounded by at least two whitespace characters.
Update: I want to point out that I specifically avoided the intense temptation to use unpack for two reasons: First, though the thought crossed my mind that this might be a dataset with aligned columns (fixed-width fields), the OP didn't specify that to be the case, and so since I had to make some assumption about the data, I chose the two-or-more space delimiter assumption rather than the fixed-width field assumption. My second reason was that the OP asked to solve the problem with a regexp, unpack wasn't on the table.
However, if it turns out that we are dealing with fixed-width fields, the regexp solution is simply the wrong tool for the job, and unpack is the right tool. My advice to the OP is to use the unpack solution if the data is in a fixed-width field format, or to consider one of the regexp solutions provided if the data's format is non-fixed-width.
Dave
|
|---|