Skip to content

Instantly share code, notes, and snippets.

@Ovid
Created January 7, 2015 20:56
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 Ovid/e0778e99f188341726df to your computer and use it in GitHub Desktop.
Save Ovid/e0778e99f188341726df to your computer and use it in GitHub Desktop.
Can we get a version of .perl which forces string context?
# Given:
# $ cat plans.csv
# this,that
# one,two
# same,same
#!/usr/bin/env perl6
# vim: ft=perl6
my $fh = open('plans.csv', :r);
my %pairs = gather for $fh.lines {
if /^^ (\w+) ',' (\w+) $$/ {
take $0 => $1;
}
}
say %pairs.perl;
# ("this" => Match.new(orig => "this,that", from => 5, to => 9, ast => Any, list => ().list, hash => EnumMap.new()), "same" => Match.new(orig => "same,same", from => 5, to => 9, ast => Any, list => ().list, hash => EnumMap.new()), "one" => Match.new(orig => "one,two", from => 4, to => 7, ast => Any, list => ().list, hash => EnumMap.new())).hash
# If I force string context (~$1), I get this:
# ("same" => "same", "one" => "two", "this" => "that").hash
# I don't want to force string context when I put it in the hash because I might want the Match data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment