in reply to Print Uniqe elements of arry of hash

Rewrite your sample code to include some sample data and generate some output that shows the issue so that we have some chance of reproducing your results. The comment above the INPUT1 data indicates that there are 9 columns, there are in fact 10 and the last one (index 9) seems more likely to contain the data you want to test against.

You can use a __DATA__ section with sample INPUT1 data there. Probably you only need 5 lines of data to demonstrate the issue.


Perl reduces RSI - it saves typing
  • Comment on Re: Print Uniqe elements of arry of hash

Replies are listed 'Best First'.
Re^2: Print Uniqe elements of arry of hash
by sesemin (Beadle) on Oct 15, 2008 at 02:03 UTC
    Thanks grandfather,

    I think I confused everyone. As you indicated there are 10 columns and I am working with the forth and the ninth (index 3 and 8). This code does not work unless I remove the comment form "# push(@genes_number, $current_line[ 1 ]);" and comment "push(@{$genes_number{$k}}, $current_line [ 1 ]);"

    Here is the complete code that reads the first file and store the data into the %gc_ag. In the data section I have included the first few rows of first file and the second file.

      This dog won't hunt.

         Global symbol "$k" requires explicit package name at sesemin.pl line 72.
         syntax error at sesemin.pl line 72, near "})"
      
      where, by the time I sorted out the files and such, line 72 is:&count_unique (@{$genes_number{$k});

      Even fixing the trivial syntax error, one's left with the undefined $k at this point. I could guess at what $k is supposed to be here... but I think it's time for you to do some work !

      Happy to try to help, but you need to put more effort in at your end, so that the code you offer:

      1. actually runs -- with strict and warnings.
      2. does not require other files to be downloaded -- let alone placed in special directories. (see below)
      3. does not require command line arguments -- whatever you need to demonstrate should be inside the code.
      4. illustrates the issue you have, with the minimum of code.
      5. supports the question you've posed... "I am trying to achieve blah to which end I have written blather which is supposed to mangle stuff so, but what I get is a crick in my neck...., as demonstrated in the very wonderful code here...
      6. and all the other good advice in How do I post a question effectively?


      If your code only has one input file, then __DATA__ is the obvious replacement.

      If your code has several inputs, then this will do the trick. First, comment out (or remove) the original open commands and replace as illustrated:

      #open FOO, "my_favourite.yum" or die "horribly $!" ; open FOO, '<', &my_favourite_yum or die "horribly $!" ;
      then at the end of your example code place:
      #______________________________________ # ... description of the data ... sub my_favourite_yum { \(<<'~~FILE') } ... contents of my_favourite.yum go here ... ~~FILE #______________________________________ # ... description.... sub my_other_favourite { \(<<'~~FILE') } ... contents of my_other_favourite go here ... ~~FILE #______________________________________
      where:
      1. obviously, the name of the sub must match the name in the relevant open, but may be anything you like that helps the reader.
      2. the end of file marker '~~FILE' can be anything you like, but obviously it must not appear in the data ! (For the avoidance of doubt, it may be different for each file, but must be the same in the two places it appears for each one.)
      3. the marker at the end of each "file" must have a newline at the end of it. (No other trailing whitespace. End-of-file will not do -- hence the suggested #____ line at the end.
      4. NB: tabs may be translated to one or more spaces in the upload process. But ...
      5. before posting, you must ensure that your example code works (and illustrates the issue you have) with the files embedded.

      Update: removed spurious and erroneous & from sub &my_favourite_yum and sub &my_other_favourite. Thanks tinita. (Blushes deep crimson and wonders whether going back to bed and starting again is an option.)

        Good hint. I tried to use __DATA__ but for whatever reason my data was not showing properly in preview so I decided to go with readmore tag. Sorry if it caused any inconvenience.

        As per sub. if you replace

        &count_unique (@{$genes_number{$k}); with

        &count_unique (@genes_number);

        my code will work. But the simple question that I had to ask is that how can we print the unique elements of the most inner array of an array of array. Probably that makes life easier for you to be able to respond. Just a simple example will help me a lot.

        Thank you very much.

        Pedro