Skip to content

Instantly share code, notes, and snippets.

@hayajo
Created October 20, 2011 03:09
Show Gist options
  • Save hayajo/1300322 to your computer and use it in GitHub Desktop.
Save hayajo/1300322 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use 5.008_001;
use Text::CSV;
use Data::Dumper;
use constant COLUMNS => [ qw/NAME EMAIL MEMO/ ];
my $csv = Text::CSV->new({ auto_diag => 1 });
$csv->column_names(@{ &COLUMNS });
my $fcol = [ $csv->column_names ]->[0];
while (my $row = $csv->getline_hr(*{DATA})) {
if ($row->{$fcol} =~ /^\s*#/) {
warn "comment line: $row->{$fcol}";
next;
}
warn Dumper $row;
}
__DATA__
#1 comment line 1
#2 comment line 2 (spaces head)
#3 comment line 3 (tab head)
hoge,[email protected],hogehogehoge
fuga,[email protected],fugafugafuga
piyo,[email protected],piyopiyopiyo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment