nono has asked for the wisdom of the Perl Monks concerning the following question:

#! /usr/bin/perl use strict;use warnings; my %data; open(IN,"data.file"); while(<IN>){ chomp; my @line=split(/\t/,$_); $data{$line[10]}{$line[3]}=$line[2]; foreach my {$line[10]}(keys %data){ print"$data{$line[10]}\t$data{line[3]}\t$data{$line[2]}\n" }}
I did that script but when I run it , I got this error message
Missing $ on loop variable at mouse5.pl line 16.
please could anyone help me in that issue

Replies are listed 'Best First'.
Re: hash in perl
by blindluke (Hermit) on Jan 24, 2015 at 20:41 UTC

    Please use the  <code> </code> tags around your code. It's barely readable.

    This line is probably the cause of your problem:

    foreach my {$line[10]}(keys %data) {

    ... but it's hard to suggest anything when we don't know what your code is supposed to do.

    Take a look at the example of correct foreach use in the documentation that came with your Perl.

    - Luke

Re: hash in perl
by ww (Archbishop) on Jan 24, 2015 at 20:56 UTC

    We'd have a better chance to be helpful -- one of the Monastery's primary reasons for being -- if you marked up your code

    with <code>...code here...</code> tags
    so we could easily read it and ascertain which line has the missing sigil or other problem (hint, hint: "other problem" see blindluke's reply, above).

    So, please, go back and edit your original node (by opening it in your browser; moving down to the text-input box; and insert code tags as explained by the instructions immediately below the (small) text-entry box for "Title:".

    your failure to read and heed the instructions made it difficult to tell which line the "error message" referrenced (and yes, given a slow Sat. afternoon with weather too crummy to encourage me to do the work outside I should, I found the line that led to the message, but that was only after some imaginative, non-standard re-formatting). And yes, there are other approaches that a Monk could have used... BUT! all of them make us do work that's not directly relevant to your problem.
    Since you're asking for the help, make it easy for us to provide it.

    And while you await an answer, please read Markup in the Monastery... and consider also On asking for help and How do I post a question effectively?.



    Come, let us reason together: Spirit of the Monastery