http://qs321.pair.com?node_id=777694


in reply to LaTeX Abbreviations for Linguists

Apart from the problem cited in the first reply, you could accomplish the same goal with a lot fewer lines of code -- e.g. this:
if ( $abbr =~ s/([123][sdp])// ) { push(@abbr, $1); $abbr =~ s/\s//g; };
will replace 45 lines of OP code (the 5-line block that is repeated 9 times, for each combination of 1/2/3 with s/d/p).

A similar refactoring should be done on all those blocks that "do the nasty" with @inlist -- you should be able to reduce all of those blocks down to a single loop as well, and then you only have to fix the misuse of "push" on the one remaining instance of that problem.

(updated to fix wording in 1st paragraph)

Oh, and instead of this:

if ( $file[$i] =~ m/(\\gll|\\ag\.|\\bg\.|\\cg\.|\\dg\.|\\eg\.|\\fg\.|\ +\exg\.|\\exg)/ )
How about:
if ( $file[$i] =~ /(\\(?:gll|[abcdef]g\.|exg\.?))/ )
(updated last snippet to include a much-needed ":" after the first "?")