in reply to matching strings into array from txtfile and printing on same line

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.

  • Comment on Re: matching strings into array from txtfile and printing on same line
  • Download Code

Replies are listed 'Best First'.
Re^2: matching strings into array from txtfile and printing on same line
by Kenosis (Priest) on Jun 16, 2012 at 05:07 UTC

    Nice work, Aaron!