I'm kind of partial to setting the input record separator when there is a consistent separator between records, and then it's usually possible to fashion a regex to pluck out the values from a single record:
#!/usr/bin/env perl use Modern::Perl; local $/ = ""; # split records on a blank line while (<DATA>) { if ( m[Orderbook\ ID: \s* (.+?) \n \s* Symbol: \s* (.+?) \n \s* ISIN: \s* (.+?) \n ]xs ){ say "$1:$3:$2"; # comment the previous line and uncomment the next three if yo +u really # want to strip whitespace from your values, unlike your first # example # my $l = "$1:$3:$2"; # $l =~ s/\s+//g; # say $l; } } __DATA__ [Sample data removed by request of the original poster.]
Aaron B.
Available for small or large Perl jobs; see my home node.
In reply to Re: matching strings into array from txtfile and printing on same line
by aaron_baugher
in thread matching strings into array from txtfile and printing on same line
by kamchez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |