ASPLMQ User Guide v 1.00
© 2026 Bassem W. Jamaleddine
Since IBM MQ queue objects are regularly structured, they can be parsed efficiently using regular expressions. Filtering these queue objects is achieved with the Perl code shown in Figure 1.2.1.
The program reads STDIN into the scalar variable $s and splits the string into segments that start with DEFINE QLOCAL and end with REPLACE, converting each into an object reference $o. The object is constructed using the Perl map function, extracting each queue name with qn(). The bulk of the parsing work is done within this map statement; reading the expression from right to left details its functional transformation steps:
![]()
map{ $$o{ qn($_) } = qdef($_) } ($s =~ m{ DEFINE\s+QLOCAL (.*?) REPLACE$ }gxmsi);
Break the string into pieces where
each piece starts with DEFINE QLOCAL
and end with REPLACE.
Call qdef() on each piece
mapping a left attribue to
its right value
Aggregate each derived
queue name qn() into the
object $o and make the
$$o{ qn($_) points to its
derived structure
Listing 1.2.1 shows the filtermq-queues script. For clarity, this version spreads the regular expressions across multiple lines and expands the map function inside the qdef() routine into an explicit for loop.
1. #!/usr/bin/perl 2. use strict; 3. use Data::Dumper; 4. 5. my $s = join '', <STDIN>; 6. 7. my(@QL) = ($s =~ 8. m{ 9. DEFINE\s+QLOCAL 10. (.*?) 11. REPLACE$ 12. }gxmsi 13. ); 14. 15. my $o; 16. map{ $$o{ qn($_) } = qdef($_) } @QL; 17. print Dumper($o); 18. 19. sub qn { 20. my $s = shift; 21. $s =~ m{ 22. \s*\(' 23. (.*) 24. '\)\s*\+$ 25. }xm; 26. return $1; 27. } 28. 29. sub qdef { 30. my $s = shift; 31. my $rec; 32. 33. my (@A) = ( 34. $s =~ 35. m{ 36. (\w+)\s*\((.*?)\) 37. }xgs 38. ); 39. 40. for (my $i=0; $i<@A; $i+=2) { 41. my ($att,$v)=($A[$i],$A[$i+1]); 42. $v =~ s/^'\s*//; $v =~ s/\s*'$//; 43. $$rec{$att} = $v; 44. } 45. return $rec; 46. } 47.
The ACMECO queue manager configuration can be dumped using saveqmgr and piped to filtermq-queues to aggregate the queue objects into the $o object reference.
# ssh -q mqm@vavamq /home/mqm/mqtools/saveqmgr -m ACMECO -s -c 2>&1 | filtermq-queues
# cat ACMECO.saveqmgr | filtermq-queues
■ Printing Formatted Reports for IBM MQ Queues
Adding a formatting function allows the script to print the queues in a tabulated report. Listing 1.2.2 shows the updated filtermq-queues script with this function included.
1. #!/usr/bin/perl 2. use strict; 3. 4. my $s = join '', <STDIN>; 5. my(@QL) = ($s =~ 6. m{ 7. DEFINE\s+QLOCAL 8. (.*?) 9. REPLACE$ 10. }gxmsi 11. ); 12. 13. my $o; 14. map{ $$o{ qn($_) } = qdef($_) } @QL; 15. qout($o); 16. 17. sub qn { 18. my $s = shift; 19. $s =~ m{ 20. \s*\(' 21. (.*) 22. '\)\s*\+$ 23. }xm; 24. return $1; 25. } 26. 27. sub qdef { 28. my $s = shift; 29. my $rec; 30. 31. my @A = ( $s =~ m{ (\w+)\s*\((.*?)\) }xgs); 32. 33. for (my $i=0; $i<@A; $i+=2) { 34. my ($att,$v)=($A[$i],$A[$i+1]); 35. $v =~ s/^'//; $v =~ s/'$//; 36. $v =~ s/^\s+//; $v =~ s/\s+$//; 37. $$rec{$att} = $v; 38. } 39. return $rec; 40. } 41. 42. ##################### 43. sub qout { 44. my ($o) = @_; 45. my($qn,$maxdepth,$maxmsgl,$defpsist,$bothresh,$boqname,$cluster,$crdate,$altdate); 46. format STDOUT_TOP = 47. MQ QUEUES Page: @>>>>>>>>>>>>>> 48. $% 49. 50. QUEUENAME MAXDEPTH MAXMSGL DEFPSIST BOTHRESH CRTDATE ALTDATE 51. ------------------------------- ------------ ------------ -------- -------- ---------- ---------- 52. . 53. format STDOUT = 54. @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<< @<<<<<<<<<<< @<<<<<<<< @<<<<<<< @<<<<<<<<< @<<<<<<<<< 55. $qn,$maxdepth,$maxmsgl,$defpsist,$bothresh,$crdate,$altdate 56. . 57. $== 20; 58. $-= 0; 59. $^L= "\nQUEUES DEFINED ON QMGR\n\n"; 60. foreach my $qname (sort keys %$o) { 61. $qn = $qname; 62. ($maxdepth,$maxmsgl,$defpsist,$bothresh,$boqname,$crdate,$altdate) = 63. map($$o{$qn}{$_}, qw(MAXDEPTH MAXMSGL DEFPSIST BOTHRESH BOQNAME CRDATE ALTDATE)); 64. write; 65. } 66. $- = 0; 67. }
The resulting tabulated report displaying the queue configurations is illustrated in Figure 1.2.3.