in reply to Re: use of diamond operator for multiple files
in thread use of diamond operator for multiple files

Hey, thanks for the answer.

Yes the code works, but I wanted to see other solutions. I would say it is to optimize code length.

Yes I am asking exactly this: The shortest amount of code needed to gather into two arrays from two files all lines that don't start with a > character, and that do end in a newline character.

Thank you!
  • Comment on Re^2: use of diamond operator for multiple files

Replies are listed 'Best First'.
Re^3: use of diamond operator for multiple files
by davido (Cardinal) on Apr 23, 2014 at 18:39 UTC

    This isn't what I would consider a golfy solution, but it is more brief:

    my @data; for my $file (qw(this.txt that.txt)) { open my $fh, '<', $file or die $!; push @data, []; while( <$fh> ) { push @{$data[-1]}, $_ if /\n\z/ && ! /^>/; } }

    If you want that in the form of a subroutine:

    @data = read_files( qw(this.txt that.txt) ); sub read_files { my @data; for my $file ( @_ ) { open my $fh, '<', $file or die $!; push @data, []; while( <$fh> ) { push @{$data[-1]}, $_ if /\n\z/ && ! /^>/; } return @data; }

    (Untested)


    Dave