I have an array with the following elements:
my @array = ("\"Foo in Bar\" on Mon 09 Feb 2015 08:07:44 AM PST",
"\"Foo in Bar\" on Mon 09 Feb 2015 08:07:47 AM MST",
"\"Foo in Bar\" on Mon 09 Feb 2015 08:07:49 AM MST",
"\"Apple in Pie\" on Mon 09 Feb 2015 10:22:32 AM MST",
"\"Foo in Bar\" on Mon 09 Feb 2015 08:07:51 AM MST",
"\"Rock in Out\" on Mon 09 Feb 2015 11:17:41 AM PST")
I want to sort this array so that all elements with a repeated string (inside the "") will be removed. The reason why this is a little unique is because the time associated with each string is a little different, but not much.
Here is what I want the output to look like:
"\"Foo in Bar\" on Mon 09 Feb 2015 08:07:49 AM MST",
"\"Apple in Pie\" on Mon 09 Feb 2015 10:22:32 AM MST",
"\"Rock in Out\" on Mon 09 Feb 2015 11:17:41 AM PST"
I don't really care about sorting the time, just removing the repeats inside the "".
This was my thought process so far:
my @row;
foreach my $row (@array) {
my $name = $row;
$name =~ s/\son.*//;
next if (grep {$_ =~ /($name)/} @row);
push(@row,$row);
}
There has to be a better way to do this. Also, I am having issues with my method (the grep doesn't seem to be working as intended, it won't go to the next statement).