Advertisement
Guest User

Untitled

a guest
Dec 18th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.46 KB | None | 0 0
  1. multi read-csv($filename, $dict where { $dict }) {
  2.     my @lines = $filename.IO.lines.list;
  3.     my $hdr := split ',', @lines[0].cache;
  4.  
  5.     sub parse_row($row) {
  6.         my $parts := split ',', $row;
  7.         my %row_dict;
  8.         for (zip $hdr, $parts) { %row_dict{$_[0]} = $_[1] };
  9.         return %row_dict;
  10.     }
  11.  
  12.     map &parse_row, @lines[1..*];
  13. }
  14.  
  15. multi read-csv($filename, $dict where { !$dict }){
  16.     map { split(',', $_) }, $filename.IO.lines
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement