in reply to Re^7: Perl custom sort for Portuguese Lanaguage
in thread Perl custom sort for Portuguese Lanaguage
Thanks! I see you're filtering lines beginning with # when they occur at the beginning of the file; the way I understood the OP's sample data is that the comments can occur anywhere. And my worry was that, even though in the OP's data this is probably not the case, filter-based solutions will remove lines that may actually not be comments, and I wasn't sure if there was a easy solution for this?
use warnings; use strict; use Data::Peek; use Text::CSV_XS qw/csv/; DDumper csv( in=>*DATA, escape_char=>"\\", filter => sub { $_[1][0] !~ m/^\s*#/ }); __DATA__ # This is a comment a,b,c # Also a comment x,y,z "#not",a,comment \#also,not,"a comment"
Output:
[ [ 'a', 'b', 'c' ], [ '' ], [ 'x', 'y', 'z' ], [ '' ] ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Perl custom sort for Portuguese Lanaguage
by Tux (Canon) on Jul 09, 2020 at 14:14 UTC | |
by haukex (Archbishop) on Jul 09, 2020 at 14:20 UTC |