Camelia
Prev: Overview

slurp

examples/files/slurp_csv_file.p6
#!/usr/bin/env perl6
use v6;

my $filename = 'examples/phonebook.txt';

my @lines = lines $filename.IO;
for @lines -> $line {
    say "L: $line";
}

#my %phonebook = map {split ",", $_}, @lines;
#my %phonebook = map {$_.comb(/\w+/)}, @lines;

my %phonebook = slurp($filename).comb(/\w+/);

my $name = prompt "Name:";
say %phonebook{$name};

examples/phonebook.txt
Foo,123
Bar,78
Baz,12321

Prev: Overview

Table of Contents

Comments

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: