in reply to diamond operator multiple input

You should be more specific about what "does not work" means. What happens? What did you expect to happen?

My guess (without running code) is that lc forces scalar context on its single argument. You want a list, so this will work better:

my ($dginput, $volinput) = map { chomp; lc } <>;

Consider that because Perl is not a lazy language, it'll read everything from STDIN and throw away all but the first two elements. That could be a lot of work.

Replies are listed 'Best First'.
Re^2: diamond operator multiple input
by johngg (Canon) on Jan 22, 2009 at 13:26 UTC

    Doing map { chomp; lc } <>; generates a "Useless use of lc in void context ..." error, lc $_ seems to solve that. You could avoid reading the whole file by explicitly doing a scalar <> twice.

    $ cat zzzz AAAA BBBB CCCC DDDD EEEE $ perl -e ' > ( $dg, $vo ) = map { map { chomp; lc $_ } scalar <> } 1 .. 2; > print qq{$dg, $vo\n}; > print q{-} x 15, qq{\n}; > print for <>;' zzzz aaaa, bbbb --------------- CCCC DDDD EEEE $

    I hope this is of interest.

    Cheers,

    JohnGG

    Update: As ikegami points out, the warning I saw seems to be a figment of my imagination. Please ignore that part of the post.

      I cancan't replicate your warning.
      >perl -we"my ($dginput, $volinput) = map { chomp; lc } <>;" a b c ^Z

      Not even if I remove the assignment.

      >perl -we"map { chomp; lc } <>;" a b c ^Z

      Tested with 5.6, 5.8 and 5.10

        Neither can I now and the window I was working in is long since closed so I can't see what I did to generate it :-(

        As you say, this

        $ perl -we ' > ( $dg, $vo ) = map { map { chomp; lc } scalar <> } 1 .. 2; > print qq{$dg, $vo\n}; > print q{-} x 15, qq{\n}; > print for <>;' zzzz aaaa, bbbb --------------- CCCC DDDD EEEE $

        works without any warnings. I will update my original node.

        Cheers,

        JohnGG

Re^2: diamond operator multiple input
by ikegami (Patriarch) on Jan 21, 2009 at 23:32 UTC
    That will read until EOF, won't it?

      Exactly, just like every readline in list context except for a while loop.

        But lc imposes a scalar context
        >perl -le"lc sub { print wantarray?1:0 }->();" 0

        By using your code, lines further down in the file will be discarded whereas they weren't in the OP's code.