#!/usr/bin/perl -w use strict; use warnings; # I want to parse a string containing bug fix identifiers such that # it will take a list of comma separated bugs, or single bugs prefixed # with "bug[s:]" ignoring whitespace, sort them and pick out only # unique identifiers and put them into an array. # The printing is just for testing each stage. my $bug_fix_msg = "this 33,44 is a fix for mybug44,99 real \ bug 99 again bug33r bug1722,3 bUg:99, \ bugs:456, 17, 24 bugs 42,58 bug: 50,50"; my @filtered = (); while ($bug_fix_msg =~ m/\bbugs?:?([\s\d,]*)\b/ig) { push @filtered, $1; print $1; print "\n"; } print "filtered: @filtered"; s/\s//g for(@filtered); my @bug_array = (); foreach my $bug_line(@filtered) { my @items = split(',', $bug_line); push @bug_array, @items; } my %hash = map { $_ => 1 } @bug_array; my @unique = keys %hash; my @sorted = sort {$a <=> $b} @unique; print "\nunsorted: @bug_array"; print "\n unique: @unique"; print "\n sorted: @sorted\n"; #### 99 1722,3 99, 456, 17, 24 42,58 50,50 filtered: 99 1722,3 99, 456, 17, 24 42,58 50,50 unsorted: 99 1722 3 99 456 17 24 42 58 50 50 unique: 50 3 58 17 456 42 99 24 1722 sorted: 3 17 24 42 50 58 99 456 1722