Skip to content

Instantly share code, notes, and snippets.

@Code-Hex
Last active November 9, 2017 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Code-Hex/bc2dba508ffd6aa9e3945c4876960def to your computer and use it in GitHub Desktop.
Save Code-Hex/bc2dba508ffd6aa9e3945c4876960def to your computer and use it in GitHub Desktop.
Maybe easy to get csv data??
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use feature qw/say/;
use Text::CSV;
my $csvfile = 'hello.csv';
my $csv = Text::CSV->new({ binary => 1 }) or die "Cannot use CSV: ".Text::CSV->error_diag();
open my $fh, '<', $csvfile or die "Could not open $csvfile: $!";
my $i = 0;
$csv->column_names ($csv->getline($fh));
while (my $row = $csv->getline_hr($fh)) {
say join ', ', ($row->{name}, $row->{age}, $row->{hobby});
}
$csv->eof;
close $fh;
name age hobby
kei 22 perl
taro 20 soccer
hanako 20 eating
foo 38 bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment