Skip to content

Instantly share code, notes, and snippets.

@sashaphanes
Created October 15, 2012 20:09
Show Gist options
  • Save sashaphanes/3895028 to your computer and use it in GitHub Desktop.
Save sashaphanes/3895028 to your computer and use it in GitHub Desktop.
print all different strings found in a list once each, remove "
#!/usr/bin/perl -s
require "getopts.pl";
use vars qw ($opt_f $opt_d $opt_h $opt_H);
&Getopts('f:d:hH:');
my $executable = "printUniqueStrings.pl";
$| = 1;
my $usage = qq{
###################################################################
usage: $executable -f fileName
used for printing a list of strings, without duplications, as well as deleting user-specifed characters
# -f the file name of the array of genes of interest; stdin used if not otherwise speficied.
#
# -d what character the user would like to delete from output
# Example format: -d'"' will delete all '"'
#
# -hH print this
example: >$executable -f testInputFile -s S > output
####################################################################
\n};
my $input;
# H options:
if (length($opt_h) > 0 || length($opt_H) > 0 ) {die($usage);}
# f options
if (-s $opt_f) {$input = $opt_f; }
else {open FILE, <STDIN>; $input = <FILE>;};
my (@unique, %seen);
my @strings = ();
while (<>) {
push (@strings, $_);
}
close FILE;
my $i;
for ($i = 0; $i <= $#strings ; ){
splice @strings, --$i, 1
if $seen{$strings[$i++]}++;
}
foreach $string (@strings) {
$string =~ s/"//g;
}
print "@strings\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment