in reply to Re^2: Print Uniqe elements of arry of hash
in thread Print Uniqe elements of arry of hash

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.)

Replies are listed 'Best First'.
Re^4: Print Uniqe elements of arry of hash
by sesemin (Beadle) on Oct 15, 2008 at 19:34 UTC
    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