in reply to golf: shortest way to parse a pipe delimited file

This will do it, but I don't know how you would score it for comparison.

perl -anF"\|" -le"$f{shift@F}=[@F[1..$#F]]" pipe.txt

And you need this to prove it worked

P:\test>perl -MData::Dumper -anF"\|" -le"$f{shift@F}=[@F[1..$#F]]}{pri +nt Dumper \%f" pipe.txt $VAR1 = { '6' => [ 'foo', 'bar', 'bax' ], '3' => [ 'foo', 'bar', 'bax' ], '7' => [ 'foo', 'bar', 'bax' ], '9' => [ 'foo', 'bar', 'bax' ], '2' => [ 'foo', 'bar', 'bax' ], '8' => [ 'foo', 'bar', 'bax' ], '1' => [ 'foo', 'bar', 'bax' ], '4' => [ 'foo', 'bar', 'bax' ], '10' => [ 'foo', 'bar', 'bax' ], '5' => [ 'foo', 'bar', 'bax' ] };

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: golf: shortest way to parse a pipe delimited file
by bageler (Hermit) on Nov 10, 2005 at 19:49 UTC
    very nice, but unfortunately my command line doesn't like it at all:
    Bareword found where operator expected at -e line 1, near "0F" (Missing operator before F?) syntax error at -e line 1, near "}=" Execution of -e aborted due to compilation errors.
    This is how you'd score it:
    #1234567890123456789012345678901234567890123456789012345 perl -anF"\|" -le"$f{shift@F}=[@F[1..$#F]]" pipe.txt
    42.
      my command line doesn't like it at all

      Then adapt it to your shell. Something like this might work,

      perl -anF'|' -le'$f{shift@F}=[@F[1..$#F]]' pipe.txt

      but I don't use your shell so that is a guess, and I cannot test it as it wouldn't work on my shell.

      This is how you'd score it:

      That doesn't seem quite fair, as to use your example, you would need at least this to make it work:

      #!/usr/bin/perl #12345678901234567890123456789012345678901234567890123456789012345 open SRC, '<pipe.txt';%prod=map{chomp;split/\|/;shift@_,[@_]}<SRC>

      Which I get to be a total of 89 and that's without the command line to run it!


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        the context is that of a subroutine though. You go out of context and the rules change ;)
Re^2: golf: shortest way to parse a pipe delimited file
by sauoq (Abbot) on Nov 12, 2005 at 23:26 UTC
    This will do it, but I don't know how you would score it for comparison.

    Well, no matter how you score it, I gotcha by two. :-)

    perl -F'\|' -lane'($k,@v)=@F;$f{$k}=[@v]'

    -sauoq
    "My two cents aren't worth a dime.";
    

      Update: Oh crap!

      In that case, gotcha by 1 :)

      perl -F'\|' -lane'($k,@v)=@F;$f{$k}=\@v'

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Not quite. That @v is global... you need [@v] because you won't be making a copy otherwise. Here's mine...

        356,0 sauoq@fozzie:~$ perl -MData::Dumper -F'\|' -lane'($k,@v)=@F;$f{$ +k}=[@v]}{print Dumper \%f' foo|bar|baz qux|zab|oof $VAR1 = { 'qux' => [ 'zab', 'oof' ], 'foo' => [ 'bar', 'baz' ] };
        And yours...
        357,0 sauoq@fozzie:~$ perl -MData::Dumper -F'\|' -lane'($k,@v)=@F;$f{$ +k}=\@v}{print Dumper \%f' foo|bar|baz qux|zab|oof $VAR1 = { 'qux' => [ 'zab', 'oof' ], 'foo' => $VAR1->{'qux'} };

        -sauoq
        "My two cents aren't worth a dime.";