print("LA-1-00 LA-2-01 LA-03-2\n");
Sorry, but I don't see the pattern between your input and output. Did you mean to print out all those starting with LA-? If so, you missed LA-03-02. The following prints all the tokens starting with LA-
open(FILE, "< $filename")
or die("Can't open input file: $!\n");
my $text = do { local $/; <FILE> };
close(FILE);
print(join(' ', grep { /^LA-/ } split(/\s+/, $text)), "\n");
Update: Maybe LA-03-2 and LA-03-02 are considered duplicates, and you're trying to remove duplicates? If so, the following code should help:
open(FILE, "< $filename")
or die("Can't open input file: $!\n");
my $text = do { local $/; <FILE> };
close(FILE);
my %seen;
print(join(' ', grep {
if (/LA-(\d+)-(\d+)/) {
my $key = "LA-" . ($1+0) . "-" . ($2+0);
$seen{$key}++ ? 0 : 1;
} else {
0
}
} split(/\s+/, $text)), "\n");
|