in reply to golf: shortest way to parse a pipe delimited file
Where abcd has your data.perl -MData::Dumper -lanF'\|' -e '$p{$F[0]}=[@F[1..$#F]]}END{print Dum +per \%p' abcd
Assuming standard golfing rules where you give the body of a function that takes whatever parameters are useful:
Either way, I'm at 41 characters#!/usr/bin/perl my %p; sub func { my($x,@x)=$_[0]=~/([^\|\n]+)/g;$p{$x}=\@x # Or ... chomp(my($x,@x)=split'\|',pop);$p{$x}=\@x } open SRC, 'abcd'; while (<SRC>) { func($_); } use Data::Dumper; print Dumper \%p;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: golf: shortest way to parse a pipe delimited file
by tilly (Archbishop) on Nov 10, 2005 at 15:36 UTC | |
by bageler (Hermit) on Nov 10, 2005 at 19:38 UTC | |
by tilly (Archbishop) on Nov 11, 2005 at 05:45 UTC | |
|
Re^2: golf: shortest way to parse a pipe delimited file
by bageler (Hermit) on Nov 10, 2005 at 19:42 UTC | |
by Roy Johnson (Monsignor) on Nov 10, 2005 at 20:06 UTC |