http://www.perlmonks.org?node_id=11119039


in reply to Re^4: Perl custom sort for Portuguese Lanaguage
in thread Perl custom sort for Portuguese Lanaguage

In that case it's fairly easy. I used Text::CSV to read the data file, but AFAIK it doesn't support ignoring comment lines. If you are certain your files are always going to be as simple as you showed, only two columns separated by | and no |s anywhere else, no quoted fields, etc., then it's also possible to parse the file manually with a regex, for example:

open my $fh, '<:encoding(UTF-8)', $filename or die "$filename: $!"; my @rows = map { /^([^|]+)\|([^|]+?)$/ or die $_; [$1,$2] } grep { /\S/ && !/^\s*#/ } <$fh>; close $fh;

And then you can use @rows instead of @$rows in my example above.

Update: Minor simplification to code.

Update 2: And soonix makes a good point that continuing to use Text::CSV is also most likely fine, since it's probably safe to assume that you don't have any actual data that starts with #.