in reply to Re: NON Common Elements between two columns
in thread NON Common Elements between two columns

Yes, I've seen; but since I'm a novice I think I do not completely understand what the faq suggests. Could you give me a hand, please?
  • Comment on Re^2: NON Common Elements between two columns

Replies are listed 'Best First'.
Re^3: NON Common Elements between two columns
by aitap (Curate) on Jul 17, 2012 at 10:17 UTC
    Can you show an example of file (a couple of lines will be enough)?
    Sorry if my advice was wrong.
      Thank you very much! Sorry for my deep ignorance, but what I need to write in the my @input = ({},{}) inside the graph ? Where is addressed the input file, for istance 'mytext.txt' that contains the two columns?

        my @input = ({},{}) just creates an array containing two empty hash references which are going to be filled later.

        The input data can be passed directory to STDIN of the script or stated as a command line argument (<> is a special case, input from <> comes either from standard input, or from each file listed on the command line. See I/O Operators).

        Sorry if my advice was wrong.
      Here are the two columns, The second is a sublist of the firs generated after an analys, I need to know what elements have not been reported. (The NON common elements) The columns are in the same file.
      >chr9:133738100-133738472_0 chr20:62159728-62161126_840 >chr9:133738100-133738472_60 chr2:215589720-215676478_59220 >chr9:133738100-133738472_120 chr2:215589720-215676478_59160 >chr9:133738100-133738472_180 chr15:99500240-99507809_0 >chr9:133738100-133738472_240 chr2:215589720-215676478_59100 >chr9:133738100-133738472_253 chr1:162745876-162746210_215 >chr9:133747466-133747650_0 chr5:108523084-108532592_960 >chr9:133747466-133747650_60 chr20:62159728-62161126_900 >chr9:133747466-133747650_65
        Try this code:
        #!/usr/bin/perl use warnings; use strict; # firstly, put all data in hashes because it's easier to look for data + in a hash my @input = ({},{}); # 2 hash references my @output; while (<>) { # this means: <STDIN> and/or filenames from @ARGV if (/^>([^\s]+)(\s+)?([^\s]+)?$/) { ++$input[0]->{$1}; # first match is an element of 1st +column defined $3 && ++$input[1]->{$3}; # third match might n +ot exist and belongs to 2nd column } } # secondly, loop over first hash searching for elements in second hash for (keys %{$input[0]}) { unless (exists ${$input[1]}{$_}) { push @output,$_; } } print join "\n",@output;
        Sorry if my advice was wrong.
      Ok thank you ! I've tried so: perl scriptyoumade.pl <> mytext.txt > output.txt But give me a blank file. So I'm afraid to not having understand what you said me in the last post.
        <> is a file descriptor reading operation and it is already inside the script, so you should run either perl script.pl mytext.txt >output.txt (passing filename as command line argument) or perl script.pl <mytext.txt >output.txt (passing file contents as STDIN).
        Sorry if my advice was wrong.