1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732
|
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>
<body>
<ul id="index">
<li><a href="#NAME">NAME</a></li>
<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
<li><a href="#EXAMPLES">EXAMPLES</a></li>
<li><a href="#OPTIONS---OVERVIEW">OPTIONS - OVERVIEW</a>
<ul>
<li><a href="#I-O-Control">I/O Control</a></li>
</ul>
</li>
<li><a href="#FORMATTING-OPTIONS">FORMATTING OPTIONS</a>
<ul>
<li><a href="#Basic-Options">Basic Options</a></li>
<li><a href="#Code-Indentation-Control">Code Indentation Control</a></li>
<li><a href="#Whitespace-Control">Whitespace Control</a></li>
<li><a href="#Comment-Controls">Comment Controls</a></li>
<li><a href="#Skipping-Selected-Sections-of-Code">Skipping Selected Sections of Code</a></li>
<li><a href="#Formatting-a-Limited-Range-of-Lines">Formatting a Limited Range of Lines</a></li>
<li><a href="#Line-Break-Control">Line Break Control</a></li>
<li><a href="#Controlling-Breaks-at-Braces-Parens-and-Square-Brackets">Controlling Breaks at Braces, Parens, and Square Brackets</a></li>
<li><a href="#Welding">Welding</a></li>
<li><a href="#Breaking-Before-or-After-Operators">Breaking Before or After Operators</a></li>
<li><a href="#Controlling-List-Formatting">Controlling List Formatting</a></li>
<li><a href="#Adding-and-Deleting-Commas">Adding and Deleting Commas</a></li>
<li><a href="#Adding-and-Deleting-Interbracket-Arrows">Adding and Deleting Interbracket Arrows</a></li>
<li><a href="#Missing-Else-Blocks">Missing Else Blocks</a></li>
<li><a href="#Retaining-or-Ignoring-Existing-Line-Breaks">Retaining or Ignoring Existing Line Breaks</a></li>
<li><a href="#Blank-Line-Control">Blank Line Control</a></li>
<li><a href="#Styles">Styles</a></li>
<li><a href="#One-Line-Blocks">One-Line Blocks</a></li>
<li><a href="#Controlling-Vertical-Alignment">Controlling Vertical Alignment</a></li>
<li><a href="#Extended-Syntax">Extended Syntax</a></li>
<li><a href="#Deleting-and-Extracting-Pod-or-Comments">Deleting and Extracting Pod or Comments</a></li>
<li><a href="#The-perltidyrc-file">The perltidyrc file</a></li>
<li><a href="#Debugging-perltidy-input">Debugging perltidy input</a></li>
<li><a href="#Analyzing-Code">Analyzing Code</a></li>
<li><a href="#Working-with-MakeMaker-AutoLoader-and-SelfLoader">Working with MakeMaker, AutoLoader and SelfLoader</a></li>
</ul>
</li>
<li><a href="#HTML-OPTIONS">HTML OPTIONS</a></li>
<li><a href="#SOME-COMMON-INPUT-CONVENTIONS">SOME COMMON INPUT CONVENTIONS</a>
<ul>
<li><a href="#Specifying-Block-Types">Specifying Block Types</a></li>
<li><a href="#Specifying-File-Extensions">Specifying File Extensions</a></li>
</ul>
</li>
<li><a href="#SWITCHES-WHICH-MAY-BE-NEGATED">SWITCHES WHICH MAY BE NEGATED</a></li>
<li><a href="#LIMITATIONS">LIMITATIONS</a></li>
<li><a href="#FILES">FILES</a></li>
<li><a href="#ERROR-HANDLING">ERROR HANDLING</a></li>
<li><a href="#SEE-ALSO">SEE ALSO</a></li>
<li><a href="#INSTALLATION">INSTALLATION</a></li>
<li><a href="#VERSION">VERSION</a></li>
<li><a href="#BUG-REPORTS">BUG REPORTS</a></li>
<li><a href="#COPYRIGHT">COPYRIGHT</a></li>
<li><a href="#LICENSE">LICENSE</a></li>
<li><a href="#DISCLAIMER">DISCLAIMER</a></li>
</ul>
<h1 id="NAME">NAME</h1>
<p>perltidy - a perl script indenter and reformatter</p>
<h1 id="SYNOPSIS">SYNOPSIS</h1>
<pre><code> perltidy [ options ] file1 file2 file3 ...
(output goes to file1.tdy, file2.tdy, file3.tdy, ...)
perltidy [ options ] file1 -o outfile
perltidy [ options ] file1 -st >outfile
perltidy [ options ] <infile >outfile</code></pre>
<h1 id="DESCRIPTION">DESCRIPTION</h1>
<p>Perltidy reads a perl script and writes an indented, reformatted script. The formatting process involves converting the script into a string of tokens, removing any non-essential whitespace, and then rewriting the string of tokens with whitespace using whatever rules are specified, or defaults. This happens in a series of operations which can be controlled with the parameters described in this document.</p>
<p>Perltidy is a commandline frontend to the module Perl::Tidy. For documentation describing how to call the Perl::Tidy module from other applications see the separate documentation for Perl::Tidy. It is the file Perl::Tidy.pod in the source distribution.</p>
<p>Many users will find enough information in <a href="#EXAMPLES">"EXAMPLES"</a> to get started. New users may benefit from the short tutorial which can be found at http://perltidy.sourceforge.net/tutorial.html</p>
<p>A convenient aid to systematically defining a set of style parameters can be found at http://perltidy.sourceforge.net/stylekey.html</p>
<p>Perltidy can produce output on either of two modes, depending on the existence of an <b>-html</b> flag. Without this flag, the output is passed through a formatter. The default formatting tries to follow the recommendations in perlstyle(1), but it can be controlled in detail with numerous input parameters, which are described in <a href="#FORMATTING-OPTIONS">"FORMATTING OPTIONS"</a>.</p>
<p>When the <b>-html</b> flag is given, the output is passed through an HTML formatter which is described in <a href="#HTML-OPTIONS">"HTML OPTIONS"</a>.</p>
<h1 id="EXAMPLES">EXAMPLES</h1>
<p>Here are some example perltidy commands followed by their meanings:</p>
<pre><code> perltidy somefile.pl</code></pre>
<p>This will produce a file <i>somefile.pl.tdy</i> containing the script reformatted using the default options, which approximate the style suggested in perlstyle(1). The source file <i>somefile.pl</i> is unchanged.</p>
<pre><code> perltidy *.pl</code></pre>
<p>Execute perltidy on all <i>.pl</i> files in the current directory with the default options. The output will be in files with an appended <i>.tdy</i> extension. For any file with an error, there will be a file with extension <i>.ERR</i>.</p>
<pre><code> perltidy -b file1.pl file2.pl</code></pre>
<p>Modify <i>file1.pl</i> and <i>file2.pl</i> in place, and backup the originals to <i>file1.pl.bak</i> and <i>file2.pl.bak</i>. If <i>file1.pl.bak</i> and/or <i>file2.pl.bak</i> already exist, they will be overwritten.</p>
<pre><code> perltidy -b -bext='/' file1.pl file2.pl</code></pre>
<p>Same as the previous example except that the backup files <i>file1.pl.bak</i> and <i>file2.pl.bak</i> will be deleted if there are no errors.</p>
<pre><code> perltidy -gnu somefile.pl</code></pre>
<p>Execute perltidy on file <i>somefile.pl</i> with a style which approximates the GNU Coding Standards for C programs. The output will be <i>somefile.pl.tdy</i>.</p>
<pre><code> perltidy -i=3 somefile.pl</code></pre>
<p>Execute perltidy on file <i>somefile.pl</i>, with 3 columns for each level of indentation (<b>-i=3</b>) instead of the default 4 columns. There will not be any tabs in the reformatted script, except for any which already exist in comments, pod documents, quotes, and here documents. Output will be <i>somefile.pl.tdy</i>.</p>
<pre><code> perltidy -i=3 -et=8 somefile.pl</code></pre>
<p>Same as the previous example, except that leading whitespace will be entabbed with one tab character per 8 spaces.</p>
<pre><code> perltidy -ce -l=72 somefile.pl</code></pre>
<p>Execute perltidy on file <i>somefile.pl</i> with all defaults except use "cuddled elses" (<b>-ce</b>) and a maximum line length of 72 columns (<b>-l=72</b>) instead of the default 80 columns.</p>
<pre><code> perltidy -g somefile.pl</code></pre>
<p>Execute perltidy on file <i>somefile.pl</i> and save a log file <i>somefile.pl.LOG</i> which shows the nesting of braces, parentheses, and square brackets at the start of every line.</p>
<pre><code> perltidy -dbs -dbl=10 somefile.pl >blocks.csv</code></pre>
<p>This will dump a table of comma-separated metrics for subroutines longer than 10 lines to <i>blocks.csv</i>.</p>
<pre><code> perltidy -duv somefile.pl >vars.txt</code></pre>
<p>This will dump a list of unused and reused lexical variable names to <i>vars.txt</i>.</p>
<pre><code> perltidy -html somefile.pl</code></pre>
<p>This will produce a file <i>somefile.pl.html</i> containing the script with html markup. The output file will contain an embedded style sheet in the <code><HEAD</code>> section which may be edited to change the appearance.</p>
<pre><code> perltidy -html -css=mystyle.css somefile.pl</code></pre>
<p>This will produce a file <i>somefile.pl.html</i> containing the script with html markup. This output file will contain a link to a separate style sheet file <i>mystyle.css</i>. If the file <i>mystyle.css</i> does not exist, it will be created. If it exists, it will not be overwritten.</p>
<pre><code> perltidy -html -pre somefile.pl</code></pre>
<p>Write an html snippet with only the <code><PRE</code>> section to <i>somefile.pl.html</i>. This is useful when code snippets are being formatted for inclusion in a larger web page. No style sheet will be written in this case.</p>
<pre><code> perltidy -html -ss >mystyle.css</code></pre>
<p>Write a style sheet to <i>mystyle.css</i> and exit.</p>
<pre><code> perltidy -html -frm mymodule.pm</code></pre>
<p>Write html with a frame holding a table of contents and the source code. The output files will be <i>mymodule.pm.html</i> (the frame), <i>mymodule.pm.toc.html</i> (the table of contents), and <i>mymodule.pm.src.html</i> (the source code).</p>
<h1 id="OPTIONS---OVERVIEW">OPTIONS - OVERVIEW</h1>
<p>The entire command line is scanned for options, and they are processed before any files are processed. As a result, it does not matter whether flags are before or after any filenames. However, the relative order of parameters is important, with later parameters overriding the values of earlier parameters.</p>
<p>For each parameter, there is a long name and a short name. The short names are convenient for keyboard input, while the long names are self-documenting and therefore useful in scripts. It is customary to use two leading dashes for long names, but one may be used.</p>
<p>Most parameters which serve as on/off flags can be negated with a leading "n" (for the short name) or a leading "no" or "no-" (for the long name). For example, the flag to outdent long quotes is <b>-olq</b> or <b>--outdent-long-quotes</b>. The flag to skip this is <b>-nolq</b> or <b>--nooutdent-long-quotes</b> or <b>--no-outdent-long-quotes</b>.</p>
<p>Options may not be bundled together. In other words, options <b>-q</b> and <b>-g</b> may NOT be entered as <b>-qg</b>.</p>
<p>Option names may be terminated early as long as they are uniquely identified. For example, instead of <b>--dump-token-types</b>, it would be sufficient to enter <b>--dump-tok</b>, or even <b>--dump-t</b>, to uniquely identify this command.</p>
<h2 id="I-O-Control">I/O Control</h2>
<p>The following parameters concern the files which are read and written.</p>
<dl>
<dt id="h---help"><b>-h</b>, <b>--help</b></dt>
<dd>
<p>Show summary of usage and exit.</p>
</dd>
<dt id="v---version"><b>-v</b>, <b>--version</b></dt>
<dd>
<p>Show perltidy VERSION number and exit.</p>
</dd>
<dt id="o-filename---outfile-filename"><b>-o</b>=filename, <b>--outfile</b>=filename</dt>
<dd>
<p>Name of the output file (only if a single input file is being processed). If no output file is specified, and output is not redirected to the standard output (see <b>-st</b>), the output will go to <i>filename.tdy</i>. [Note: - does not redirect to standard output. Use <b>-st</b> instead.]</p>
</dd>
<dt id="st---standard-output"><b>-st</b>, <b>--standard-output</b></dt>
<dd>
<p>Perltidy must be able to operate on an arbitrarily large number of files in a single run, with each output being directed to a different output file. Obviously this would conflict with outputting to the single standard output device, so a special flag, <b>-st</b>, is required to request outputting to the standard output. For example,</p>
<pre><code> perltidy somefile.pl -st >somefile.new.pl</code></pre>
<p>This option may only be used if there is just a single input file. The default is <b>-nst</b> or <b>--nostandard-output</b>.</p>
</dd>
<dt id="se---standard-error-output"><b>-se</b>, <b>--standard-error-output</b></dt>
<dd>
<p>If perltidy detects an error when processing file <i>somefile.pl</i>, its default behavior is to write error messages to file <i>somefile.pl.ERR</i>. Use <b>-se</b> to cause all error messages to be sent to the standard error output stream instead. This directive may be negated with <b>-nse</b>. Thus, you may place <b>-se</b> in a <i>.perltidyrc</i> and override it when desired with <b>-nse</b> on the command line.</p>
</dd>
<dt id="oext-ext---output-file-extension-ext"><b>-oext</b>=ext, <b>--output-file-extension</b>=ext</dt>
<dd>
<p>Change the extension of the output file to be <i>ext</i> instead of the default <i>tdy</i> (or <i>html</i> in case the -<b>-html</b> option is used). See <a href="#Specifying-File-Extensions">"Specifying File Extensions"</a>.</p>
</dd>
<dt id="opath-path---output-path-path"><b>-opath</b>=path, <b>--output-path</b>=path</dt>
<dd>
<p>When perltidy creates a filename for an output file, by default it merely appends an extension to the path and basename of the input file. This parameter causes the path to be changed to <i>path</i> instead.</p>
<p>The path should end in a valid path separator character, but perltidy will try to add one if it is missing.</p>
<p>For example</p>
<pre><code> perltidy somefile.pl -opath=/tmp/</code></pre>
<p>will produce <i>/tmp/somefile.pl.tdy</i>. Otherwise, <i>somefile.pl.tdy</i> will appear in whatever directory contains <i>somefile.pl</i>.</p>
<p>If the path contains spaces, it should be placed in quotes.</p>
<p>This parameter will be ignored if output is being directed to standard output, or if it is being specified explicitly with the <b>--outfile=s</b> parameter.</p>
</dd>
<dt id="b---backup-and-modify-in-place"><b>-b</b>, <b>--backup-and-modify-in-place</b></dt>
<dd>
<p>Modify the input file or files in-place and save the original with the extension <i>.bak</i>. Any existing <i>.bak</i> file will be deleted. See next item for changing the default backup extension, and for eliminating the backup file altogether.</p>
<p><b>Please Note</b>: Writing back to the input file increases the risk of data loss or corruption in the event of a software or hardware malfunction. Before using the <b>-b</b> parameter please be sure to have backups and verify that it works correctly in your environment and operating system.</p>
<p>A <b>-b</b> flag will be ignored if input is from standard input or goes to standard output, or if the <b>-html</b> flag is set.</p>
<p>In particular, if you want to use both the <b>-b</b> flag and the <b>--perl-best-practices</b> (<b>-pbp</b>) flag, then you must put a <b>--nostandard-output</b> (<b>-nst</b>) flag after the <b>-pbp</b> flag because it contains a <b>--standard-output</b> flag as one of its components, which means that output will go to the standard output stream.</p>
</dd>
<dt id="bext-ext---backup-file-extension-ext"><b>-bext</b>=ext, <b>--backup-file-extension</b>=ext</dt>
<dd>
<p>This parameter serves two purposes: (1) to change the extension of the backup file to be something other than the default <i>.bak</i>, and (2) to indicate that no backup file should be saved.</p>
<p>To change the default extension to something other than <i>.bak</i> see <a href="#Specifying-File-Extensions">"Specifying File Extensions"</a>.</p>
<p>A backup file of the source is always written, but you can request that it be deleted at the end of processing if there were no errors. This is risky unless the source code is being maintained with a source code control system.</p>
<p>To indicate that the backup should be deleted include one forward slash, <b>/</b>, in the extension. If any text remains after the slash is removed it will be used to define the backup file extension (which is always created and only deleted if there were no errors).</p>
<p>Here are some examples:</p>
<pre><code> Parameter Extension Backup File Treatment
-bext=bak .bak Keep (same as default behavior)
-bext='/' .bak Delete if no errors
-bext='/backup' .backup Delete if no errors
-bext='original/' .original Delete if no errors</code></pre>
</dd>
<dt id="bm-s---backup-method-s"><b>-bm=s</b>, <b>--backup-method=s</b></dt>
<dd>
<p>This parameter should not normally be used but is available in the event that problems arise as a transition is made from an older implementation of the backup logic to a newer implementation. The newer implementation is the default and is specified with <b>-bm='copy'</b>. The older implementation is specified with <b>-bm='move'</b>. The difference is that the older implementation made the backup by moving the input file to the backup file, and the newer implementation makes the backup by copying the input file. The newer implementation preserves the file system <b>inode</b> value. This may avoid problems with other software running simultaneously. This change was made as part of issue <b>git #103</b> at github.</p>
</dd>
<dt id="w---warning-output"><b>-w</b>, <b>--warning-output</b></dt>
<dd>
<p>Setting <b>-w</b> causes any non-critical warning messages to be reported as errors. These include messages about possible pod problems, possibly bad starting indentation level, and cautions about indirect object usage. The default, <b>-nw</b> or <b>--nowarning-output</b>, is not to include these warnings.</p>
</dd>
<dt id="q---quiet"><b>-q</b>, <b>--quiet</b></dt>
<dd>
<p>Deactivate error messages (for running under an editor).</p>
<p>For example, if you use a vi-style editor, such as vim, you may execute perltidy as a filter from within the editor using something like</p>
<pre><code> :n1,n2!perltidy -q</code></pre>
<p>where <code>n1,n2</code> represents the selected text. Without the <b>-q</b> flag, any error message may mess up your screen, so be prepared to use your "undo" key.</p>
</dd>
<dt id="log---logfile"><b>-log</b>, <b>--logfile</b></dt>
<dd>
<p>Save the <i>.LOG</i> file, which has many useful diagnostics. Perltidy always creates a <i>.LOG</i> file, but by default it is deleted unless a program bug is suspected. Setting the <b>-log</b> flag forces the log file to be saved.</p>
</dd>
<dt id="g-n---logfile-gap-n"><b>-g=n</b>, <b>--logfile-gap=n</b></dt>
<dd>
<p>Set maximum interval between input code lines in the logfile. This purpose of this flag is to assist in debugging nesting errors. The value of <code>n</code> is optional. If you set the flag <b>-g</b> without the value of <code>n</code>, it will be taken to be 1, meaning that every line will be written to the log file. This can be helpful if you are looking for a brace, paren, or bracket nesting error.</p>
<p>Setting <b>-g</b> also causes the logfile to be saved, so it is not necessary to also include <b>-log</b>.</p>
<p>If no <b>-g</b> flag is given, a value of 50 will be used, meaning that at least every 50th line will be recorded in the logfile. This helps prevent excessively long log files.</p>
<p>Setting a negative value of <code>n</code> is the same as not setting <b>-g</b> at all.</p>
</dd>
<dt id="npro---noprofile"><b>-npro</b> <b>--noprofile</b></dt>
<dd>
<p>Ignore any <i>.perltidyrc</i> command file. Normally, perltidy looks first in your current directory for a <i>.perltidyrc</i> file of parameters. (The format is described below). If it finds one, it applies those options to the initial default values, and then it applies any that have been defined on the command line. If no <i>.perltidyrc</i> file is found, it looks for one in your home directory.</p>
<p>If you set the <b>-npro</b> flag, perltidy will not look for this file.</p>
</dd>
<dt id="pro-filename-or---profile-filename"><b>-pro=filename</b> or <b>--profile=filename</b></dt>
<dd>
<p>To simplify testing and switching .perltidyrc files, this command may be used to specify a configuration file which will override the default name of <i>.perltidyrc</i>. There must not be a space on either side of the '=' sign. For example, the line</p>
<pre><code> perltidy -pro=testcfg</code></pre>
<p>would cause file <i>testcfg</i> to be used instead of the default <i>.perltidyrc</i>.</p>
<p>A pathname begins with three dots, e.g. ".../.perltidyrc", indicates that the file should be searched for starting in the current directory and working upwards. This makes it easier to have multiple projects each with their own .perltidyrc in their root directories.</p>
</dd>
<dt id="opt---show-options"><b>-opt</b>, <b>--show-options</b></dt>
<dd>
<p>Write a list of all options used to the <i>.LOG</i> file. Please see <b>--dump-options</b> for a simpler way to do this.</p>
</dd>
<dt id="f---force-read-binary"><b>-f</b>, <b>--force-read-binary</b></dt>
<dd>
<p>Force perltidy to process binary files. To avoid producing excessive error messages, perltidy skips files identified by the system as non-text. However, valid perl scripts containing binary data may sometimes be identified as non-text, and this flag forces perltidy to process them.</p>
</dd>
<dt id="ast---assert-tidy"><b>-ast</b>, <b>--assert-tidy</b></dt>
<dd>
<p>This flag asserts that the input and output code streams are identical, or in other words that the input code is already 'tidy' according to the formatting parameters. If this is not the case, an error message noting this is produced. This error message will cause the process to return a non-zero exit code. The test for this is made by comparing an MD5 hash value for the input and output code streams. This flag has no other effect on the functioning of perltidy. This might be useful for certain code maintenance operations. Note: you will not see this message if you have error messages turned off with the -quiet flag.</p>
</dd>
<dt id="asu---assert-untidy"><b>-asu</b>, <b>--assert-untidy</b></dt>
<dd>
<p>This flag asserts that the input and output code streams are different, or in other words that the input code is 'untidy' according to the formatting parameters. If this is not the case, an error message noting this is produced. This flag has no other effect on the functioning of perltidy.</p>
</dd>
<dt id="tos-n---timeout-in-seconds-n"><b>-tos=n</b>, <b>--timeout-in-seconds=n</b></dt>
<dd>
<p>When the standard input supplies the input stream, and the input has not been received within <b>n</b> seconds, perltidy will end with a timeout message. The intention is to catch a situation where perltidy is accidentally invoked without a file to process and therefore waits for input from the system standard input (stdin), which never arrives. The default is <b>n=10</b> seconds. This check can be turned off with <b>n=0</b>.</p>
</dd>
</dl>
<h1 id="FORMATTING-OPTIONS">FORMATTING OPTIONS</h1>
<h2 id="Basic-Options">Basic Options</h2>
<dl>
<dt id="fmt-s---format-s"><b>-fmt=s</b>, <b>--format=s</b></dt>
<dd>
<p>If <b>--format=tidy</b> (the default) then perltidy will reformat the input file, and if <b>--format=html</b> then perltidy will produce html output.</p>
<p>For convenience, the abbreviation <b>--tidy</b> is equivalent to <b>--format=tidy</b>, and <b>-html</b> is equivalent to <b>--format=html</b>.</p>
</dd>
<dt id="notidy"><b>--notidy</b></dt>
<dd>
<p>This flag disables all formatting and causes the input to be copied unchanged to the output except for possible changes in line ending characters and any pre- and post-filters. This can be useful in conjunction with a hierarchical set of <i>.perltidyrc</i> files to avoid unwanted code tidying. See also <a href="#Skipping-Selected-Sections-of-Code">"Skipping Selected Sections of Code"</a> for a way to avoid tidying specific sections of code.</p>
</dd>
<dt id="i-n---indent-columns-n"><b>-i=n</b>, <b>--indent-columns=n</b></dt>
<dd>
<p>Use n columns per indentation level (default n=4).</p>
</dd>
<dt id="l-n---maximum-line-length-n"><b>-l=n</b>, <b>--maximum-line-length=n</b></dt>
<dd>
<p>The default maximum line length is <b>n=80</b> characters. Perltidy will try to find line break points to keep lines below this length. However, long quotes and side comments may cause lines to exceed this length. And long lines may sometimes be broken at a length less than <b>n</b> characters because some of the line break decisions employ small tolerances to prevent formatting instabilities.</p>
<p>The default length of 80 comes from the past when this was the standard CRT screen width. Many programmers prefer to increase this to something like 120.</p>
<p>Setting <b>-l=0</b> is equivalent to setting <b>-l=(a very large number)</b>. But this is not recommended because, for example, a very long list will be formatted in a single long line.</p>
</dd>
<dt id="vmll---variable-maximum-line-length"><b>-vmll</b>, <b>--variable-maximum-line-length</b></dt>
<dd>
<p>A problem arises using a fixed maximum line length with very deeply nested code and data structures because eventually the amount of leading whitespace used for indicating indentation takes up most or all of the available line width, leaving little or no space for the actual code or data. One solution is to use a very long line length. Another solution is to use the <b>-vmll</b> flag, which basically tells perltidy to ignore leading whitespace when measuring the line length.</p>
<p>To be precise, when the <b>-vmll</b> parameter is set, the maximum line length of a line of code will be M+L*I, where</p>
<pre><code> M is the value of --maximum-line-length=M (-l=M), default 80,
I is the value of --indent-columns=I (-i=I), default 4,
L is the indentation level of the line of code</code></pre>
<p>When this flag is set, the choice of breakpoints for a block of code should be essentially independent of its nesting depth. However, the absolute line lengths, including leading whitespace, can still be arbitrarily large. This problem can be avoided by including the next parameter.</p>
<p>The default is not to do this (<b>-nvmll</b>).</p>
</dd>
<dt id="wc-n---whitespace-cycle-n"><b>-wc=n</b>, <b>--whitespace-cycle=n</b></dt>
<dd>
<p>This flag also addresses problems with very deeply nested code and data structures. When the nesting depth exceeds the value <b>n</b> the leading whitespace will be reduced and start at a depth of 1 again. The result is that blocks of code will shift back to the left rather than moving arbitrarily far to the right. This occurs cyclically to any depth.</p>
<p>For example if one level of indentation equals 4 spaces (<b>-i=4</b>, the default), and one uses <b>-wc=15</b>, then if the leading whitespace on a line exceeds about 4*15=60 spaces it will be reduced back to 4*1=4 spaces and continue increasing from there. If the whitespace never exceeds this limit the formatting remains unchanged.</p>
<p>The combination of <b>--variable-maximum-line-length</b> and <b>--whitespace-cycle=n</b> provides a solution to the problem of displaying arbitrarily deep data structures and code in a finite window, although <b>--whitespace-cycle=n</b> may of course be used without <b>--variable-maximum-line-length</b>.</p>
<p>The default is not to use this, which can also be indicated using <b>-wc=0</b>.</p>
</dd>
<dt id="Tabs"><b>Tabs</b></dt>
<dd>
<p>Using tab characters will almost certainly lead to future portability and maintenance problems, so the default and recommendation is not to use them. For those who prefer tabs, however, there are two different options.</p>
<p>Except for possibly introducing tab indentation characters, as outlined below, perltidy does not introduce any tab characters into your file, and it removes any tabs from the code (unless requested not to do so with <b>--freeze-whitespace</b>). If you have any tabs in your comments, quotes, or here-documents, they will remain.</p>
<dl>
<dt id="et-n---entab-leading-whitespace"><b>-et=n</b>, <b>--entab-leading-whitespace</b></dt>
<dd>
<p>This flag causes each <b>n</b> leading space characters produced by the formatting process to be replaced by one tab character. The formatting process itself works with space characters. The <b>-et=n</b> parameter is applied as a last step, after formatting is complete, to convert leading spaces into tabs. Before starting to use tabs, it is essential to first get the indentation controls set as desired without tabs, particularly the two parameters <b>--indent-columns=n</b> (or <b>-i=n</b>) and <b>--continuation-indentation=n</b> (or <b>-ci=n</b>).</p>
<p>The value of the integer <b>n</b> can be any value but can be coordinated with the number of spaces used for indentation. For example, <b>-et=4 -ci=4 -i=4</b> will produce one tab for each indentation level and and one for each continuation indentation level. You may want to coordinate the value of <b>n</b> with what your display software assumes for the spacing of a tab.</p>
<p>The default is not to use this, which can also be indicated using <b>-et=0</b>.</p>
</dd>
<dt id="t---tabs"><b>-t</b>, <b>--tabs</b></dt>
<dd>
<p>This flag causes one leading tab character to be inserted for each level of indentation. Certain other features are incompatible with this option, and if these options are also given, then a warning message will be issued and this flag will be unset. One example is the <b>--line-up-parentheses</b> option. This flag is retained for backwards compatibility, but if you use tabs, the <b>--entab-leading-whitespace=n</b> flag is recommended. If both <b>--tabs</b> and <b>--entab-leading-whitespace=n</b> are set, then <b>--entab-leading-whitespace=n</b> is used.</p>
</dd>
<dt id="dt-n---default-tabsize-n"><b>-dt=n</b>, <b>--default-tabsize=n</b></dt>
<dd>
<p>If the first line of code passed to perltidy contains leading tabs but no tab scheme is specified for the output stream then perltidy must guess how many spaces correspond to each leading tab. This number of spaces <b>n</b> corresponding to each leading tab of the input stream may be specified with <b>-dt=n</b>. The default is <b>n=8</b>.</p>
<p>This flag has no effect if a tab scheme is specified for the output stream, because then the input stream is assumed to use the same tab scheme and indentation spaces as for the output stream (any other assumption would lead to unstable editing).</p>
</dd>
</dl>
</dd>
<dt id="io---indent-only"><b>-io</b>, <b>--indent-only</b></dt>
<dd>
<p>This flag is used to deactivate all whitespace and line break changes within non-blank lines of code. When it is in effect, the only change to the script will be to the indentation and to the number of blank lines. And any flags controlling whitespace and newlines will be ignored. You might want to use this if you are perfectly happy with your whitespace and line breaks, and merely want perltidy to handle the indentation. (This also speeds up perltidy by well over a factor of two, so it might be useful when perltidy is merely being used to help find a brace error in a large script).</p>
<p>Setting this flag is equivalent to setting <b>--freeze-newlines</b> and <b>--freeze-whitespace</b>.</p>
<p>If you also want to keep your existing blank lines exactly as they are, you can add <b>--freeze-blank-lines</b>.</p>
<p>With this option perltidy is still free to modify the indenting (and outdenting) of code and comments as it normally would. If you also want to prevent long comment lines from being outdented, you can add either <b>--nooutdent-long-lines</b> (<b>-noll</b>) or <b>--maximum-line-length=0</b> (<b>l=0</b>).</p>
<p>Setting this flag will prevent perltidy from doing any special operations on closing side comments. You may still delete all side comments however when this flag is in effect.</p>
</dd>
<dt id="enc-s---character-encoding-s"><b>-enc=s</b>, <b>--character-encoding=s</b></dt>
<dd>
<p>This flag indicates if the input data stream uses a character encoding. Perltidy does not look for the encoding directives in the source stream, such as <b>use utf8</b>, and instead relies on this flag to determine the encoding. (This is because perltidy often works on snippets of code rather than complete files, so it cannot rely on <b>use utf8</b> directives). Consequently perltidy is likely to encounter problems formatting a file which is only partially encoded.</p>
<p>The possible values for <b>s</b> are:</p>
<pre><code> -enc=none if no encoding is used, or
-enc=utf8 for encoding in utf8
-enc=guess if perltidy should guess between these two possibilities.</code></pre>
<p>The value <b>none</b> causes the stream to be processed without special encoding assumptions. This is appropriate for files which are written in single-byte character encodings such as latin-1.</p>
<p>The value <b>utf8</b> causes the stream to be read and written as UTF-8. If the input stream cannot be decoded with this encoding then processing is not done.</p>
<p>The value <b>guess</b> tells perltidy to guess between either utf8 encoding or no encoding (meaning one character per byte). The <b>guess</b> option uses the Encode::Guess module which has been found to be reliable at detecting if a file is encoded in utf8 or not.</p>
<p>The current default is <b>guess</b>.</p>
<p>The abbreviations <b>-utf8</b> or <b>-UTF8</b> are equivalent to <b>-enc=utf8</b>, and the abbreviation <b>-guess</b> is equivalent to <b>-enc=guess</b>. So to process a file named <b>file.pl</b> which is encoded in UTF-8 you can use:</p>
<pre><code> perltidy -utf8 file.pl</code></pre>
<p>or</p>
<pre><code> perltidy -guess file.pl</code></pre>
<p>or simply</p>
<pre><code> perltidy file.pl</code></pre>
<p>since <b>-guess</b> is the default.</p>
<p>To process files with an encoding other than UTF-8, it would be necessary to write a short program which calls the Perl::Tidy module with some pre- and post-processing to handle decoding and encoding.</p>
</dd>
<dt id="eos-s---encode-output-strings-s"><b>-eos=s</b>, <b>--encode-output-strings=s</b></dt>
<dd>
<p>This flag was added to resolve an issue involving the interface between Perl::Tidy and calling programs, and in particular <b>Code::TidyAll (tidyall)</b>.</p>
<p>If you only run the <b>perltidy</b> binary this flag has no effect. If you run a program which calls the Perl::Tidy module and receives a string in return, then the meaning of the flag is as follows:</p>
<ul>
<li><p>The setting <b>-eos</b> means Perl::Tidy should encode any string which it decodes. This is the default because it makes perltidy behave well as a filter, and is the correct setting for most programs.</p>
</li>
<li><p>The setting <b>-neos</b> means that a string should remain decoded if it was decoded by Perl::Tidy. This is only appropriate if the calling program will handle any needed encoding before outputting the string.</p>
</li>
</ul>
<p>The default was changed from <b>-neos</b> to <b>-eos</b> in versions after 20220217. If this change causes a program to start running incorrectly on encoded files, an emergency fix might be to set <b>-neos</b>. Additional information can be found in the man pages for the <b>Perl::Tidy</b> module and also in <a href="https://github.com/perltidy/perltidy/blob/master/docs/eos_flag.md">https://github.com/perltidy/perltidy/blob/master/docs/eos_flag.md</a>.</p>
</dd>
<dt id="gcs---use-unicode-gcstring"><b>-gcs</b>, <b>--use-unicode-gcstring</b></dt>
<dd>
<p>This flag controls whether or not perltidy may use module Unicode::GCString to obtain accurate display widths of wide characters. The default is <b>--nouse-unicode-gcstring</b>.</p>
<p>If this flag is set, and text is encoded, perltidy will look for the module Unicode::GCString and, if found, will use it to obtain character display widths. This can improve displayed vertical alignment for files with wide characters. It is a nice feature but it is off by default to avoid conflicting formatting when there are multiple developers. Perltidy installation does not require Unicode::GCString, so users wanting to use this feature need set this flag and also to install Unicode::GCString separately.</p>
<p>If this flag is set and perltidy does not find module Unicode::GCString, a warning message will be produced and processing will continue but without the potential benefit provided by the module.</p>
<p>Also note that actual vertical alignment depends upon the fonts used by the text display software, so vertical alignment may not be optimal even when Unicode::GCString is used.</p>
</dd>
<dt id="ole-s---output-line-ending-s"><b>-ole=s</b>, <b>--output-line-ending=s</b></dt>
<dd>
<p>where s=<code>win</code>, <code>dos</code>, <code>unix</code>, or <code>mac</code>. This flag tells perltidy to output line endings for a specific system. Normally, perltidy writes files with the line separator character of the host system. The <code>win</code> and <code>dos</code> flags have an identical result.</p>
</dd>
<dt id="ple---preserve-line-endings"><b>-ple</b>, <b>--preserve-line-endings</b></dt>
<dd>
<p>This flag tells perltidy to write its output files with the same line endings as the input file, if possible. It should work for <b>dos</b>, <b>unix</b>, and <b>mac</b> line endings. It will only work if perltidy input comes from a filename (rather than stdin, for example). If perltidy has trouble determining the input file line ending, it will revert to the default behavior of using the line ending of the host system.</p>
</dd>
<dt id="atnl---add-terminal-newline"><b>-atnl</b>, <b>--add-terminal-newline</b></dt>
<dd>
<p>This flag, which is enabled by default, allows perltidy to terminate the last line of the output stream with a newline character, regardless of whether or not the input stream was terminated with a newline character. If this flag is negated, with <b>-natnl</b>, then perltidy will add a terminal newline to the the output stream only if the input stream is terminated with a newline.</p>
<p>Negating this flag may be useful for manipulating one-line scripts intended for use on a command line.</p>
</dd>
<dt id="it-n---iterations-n"><b>-it=n</b>, <b>--iterations=n</b></dt>
<dd>
<p>This flag causes perltidy to do <b>n</b> complete iterations. The reason for this flag is that code formatting is an iterative process and in some cases the output from perltidy can be different if it is applied a second time. For most purposes the default of <b>n=1</b> should be satisfactory. However <b>n=2</b> can be useful when a major style change is being made, or when code is being beautified on check-in to a source code control system. It has been found to be extremely rare for the output to change after 2 iterations. If a value <b>n</b> is greater than 2 is input then a convergence test will be used to stop the iterations as soon as possible, almost always after 2 iterations. See the next item for a simplified iteration control.</p>
<p>This flag has no effect when perltidy is used to generate html.</p>
</dd>
<dt id="conv---converge"><b>-conv</b>, <b>--converge</b></dt>
<dd>
<p>This flag is equivalent to <b>-it=4</b> and is included to simplify iteration control. Perltidy will check for convergence and stop iterating as soon as possible. The default is <b>-nconv</b> (no convergence check). Using <b>-conv</b> will approximately double run time since typically one extra iteration is required to verify convergence. No extra iterations are required if no new line breaks are made, and two extra iterations are occasionally needed when reformatting complex code structures, such as deeply nested ternary statements.</p>
</dd>
</dl>
<h2 id="Code-Indentation-Control">Code Indentation Control</h2>
<dl>
<dt id="ci-n---continuation-indentation-n"><b>-ci=n</b>, <b>--continuation-indentation=n</b></dt>
<dd>
<p>Continuation indentation is extra indentation spaces applied when a long line is broken. The default is n=2, illustrated here:</p>
<pre><code> my $level = # -ci=2
( $max_index_to_go >= 0 ) ? $levels_to_go[0] : $last_output_level;</code></pre>
<p>The same example, with n=0, is a little harder to read:</p>
<pre><code> my $level = # -ci=0
( $max_index_to_go >= 0 ) ? $levels_to_go[0] : $last_output_level;</code></pre>
<p>The value given to <b>-ci</b> is also used by some commands when a small space is required. Examples are commands for outdenting labels, <b>--outdent-labels</b> (<b>-ola</b>), and control keywords, <b>--outdent-keywords</b> (<b>-okw</b>).</p>
<p>When default values are not used, it is recommended that either</p>
<p>(1) the value <b>n</b> given with <b>-ci=n</b> be no more than about one-half of the number of spaces assigned to a full indentation level on the <b>-i=n</b> command, or</p>
<p>(2) the flag <b>--extended-continuation-indentation</b> is used (see next section).</p>
</dd>
<dt id="xci---extended-continuation-indentation"><b>-xci</b>, <b>--extended-continuation-indentation</b></dt>
<dd>
<p>This flag allows perltidy to use some improvements which have been made to its indentation model. One of the things it does is "extend" continuation indentation deeper into structures, hence the name. The improved indentation is particularly noticeable when the flags <b>-ci=n</b> and <b>-i=n</b> use the same value of <b>n</b>. There are no significant disadvantages to using this flag, but to avoid disturbing existing formatting the default is not to use it, <b>-nxci</b>.</p>
<p>Please see the section <a href="#pbp---perl-best-practices">"<b>-pbp</b>, <b>--perl-best-practices</b>"</a> for an example of how this flag can improve the formatting of ternary statements. It can also improve indentation of some multiline qw lists as shown below.</p>
<pre><code> # perltidy
foreach $color (
qw(
AntiqueWhite3 Bisque1 Bisque2 Bisque3 Bisque4
SlateBlue3 RoyalBlue1 SteelBlue2 DeepSkyBlue3
),
qw(
LightBlue1 DarkSlateGray1 Aquamarine2 DarkSeaGreen2
SeaGreen1 Yellow1 IndianRed1 IndianRed2 Tan1 Tan4
)
)
# perltidy -xci
foreach $color (
qw(
AntiqueWhite3 Bisque1 Bisque2 Bisque3 Bisque4
SlateBlue3 RoyalBlue1 SteelBlue2 DeepSkyBlue3
),
qw(
LightBlue1 DarkSlateGray1 Aquamarine2 DarkSeaGreen2
SeaGreen1 Yellow1 IndianRed1 IndianRed2 Tan1 Tan4
)
)</code></pre>
</dd>
<dt id="mci---minimize-continuation-indentation"><b>-mci</b>, <b>--minimize-continuation-indentation</b></dt>
<dd>
<p>This flag allows perltidy to remove continuation indentation in some special cases where it is not really unnecessary. For a simple example, the default formatting for the following snippet is:</p>
<pre><code> # perltidy -nmci
$self->blurt( "Error: No INPUT for type '$type', typekind '"
. $type->xstype
. "' found" );</code></pre>
<p>The second and third lines are one level deep in a container, and are also statement continuations, so they get indented by the sum of the full indentation <b>-i</b> value and the continuation indentation <b>-ci</b> value. If this flag is set, the indentation is reduced by <b>-ci</b> spaces, giving</p>
<pre><code> # perltidy -mci
$self->blurt( "Error: No INPUT for type '$type', typekind '"
. $type->xstype
. "' found" );</code></pre>
<p>This flag is off by default.</p>
</dd>
<dt id="sil-n---starting-indentation-level-n"><b>-sil=n</b> <b>--starting-indentation-level=n</b></dt>
<dd>
<p>By default, perltidy examines the input file and tries to determine the starting indentation level. While it is often zero, it may not be zero for a code snippet being sent from an editing session.</p>
<p>To guess the starting indentation level perltidy simply assumes that indentation scheme used to create the code snippet is the same as is being used for the current perltidy process. This is the only sensible guess that can be made. It should be correct if this is true, but otherwise it probably won't. For example, if the input script was written with <b>-i=2</b> and the current perltidy flags have <b>-i=4</b>, the wrong initial indentation will be guessed for a code snippet which has non-zero initial indentation. Likewise, if an entabbing scheme is used in the input script and not in the current process then the guessed indentation will be wrong.</p>
<p>If the default method does not work correctly, or you want to change the starting level, use <b>-sil=n</b>, to force the starting level to be n.</p>
</dd>
<dt id="List-indentation-using---line-up-parentheses--lp-or---extended--line-up-parentheses--xlp"><b>List indentation</b> using <b>--line-up-parentheses</b>, <b>-lp</b> or <b>--extended--line-up-parentheses</b> , <b>-xlp</b></dt>
<dd>
<p>These flags provide an alternative indentation method for list data. The original flag for this is <b>-lp</b>, but it has some limitations (explained below) which are avoided with the newer <b>-xlp</b> flag. So <b>-xlp</b> is probably the better choice for new work, but the <b>-lp</b> flag is retained to minimize changes to existing formatting. If you enter both <b>-lp</b> and <b>-xlp</b>, then <b>-xlp</b> will be used.</p>
<p>In the default indentation method perltidy indents lists with 4 spaces, or whatever value is specified with <b>-i=n</b>. Here is a small list formatted in this way:</p>
<pre><code> # perltidy (default)
@month_of_year = (
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
);</code></pre>
<p>The <b>-lp</b> or <b>-xlp</b> flags add extra indentation to cause the data to begin past the opening parentheses of a sub call or list, or opening square bracket of an anonymous array, or opening curly brace of an anonymous hash. With this option, the above list would become:</p>
<pre><code> # perltidy -lp or -xlp
@month_of_year = (
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
);</code></pre>
<p>If the available line length (see <b>-l=n</b> ) does not permit this much space, perltidy will use less. For alternate placement of the closing paren, see the next section.</p>
<p>These flags have no effect on code BLOCKS, such as if/then/else blocks, which always use whatever is specified with <b>-i=n</b>.</p>
<p>Some limitations on these flags are:</p>
<ul>
<li><p>A limitation on <b>-lp</b>, but not <b>-xlp</b>, occurs in situations where perltidy does not have complete freedom to choose line breaks. Then it may temporarily revert to its default indentation method. This can occur for example if there are blank lines, block comments, multiline quotes, or side comments between the opening and closing parens, braces, or brackets. It will also occur if a multiline anonymous sub occurs within a container since that will impose specific line breaks (such as line breaks after statements).</p>
</li>
<li><p>For both the <b>-lp</b> and <b>-xlp</b> flags, any parameter which significantly restricts the ability of perltidy to choose newlines will conflict with these flags and will cause them to be deactivated. These include <b>--indent-only</b>, <b>--freeze-newlines</b>, <b>--noadd-newlines</b>, and <b>--nodelete-old-newlines</b>.</p>
</li>
<li><p>The <b>-lp</b> and <b>-xlp</b> options may not be used together with the <b>-t</b> tabs option. They may, however, be used with the <b>-et=n</b> tab method</p>
</li>
</ul>
<p>There are some potential disadvantages of this indentation method compared to the default method that should be noted:</p>
<ul>
<li><p>The available line length can quickly be used up if variable names are long. This can cause deeply nested code to quickly reach the line length limit, and become badly formatted, much sooner than would occur with the default indentation method.</p>
</li>
<li><p>Since the indentation depends on the lengths of variable names, small changes in variable names can cause changes in indentation over many lines in a file. This means that minor name changes can produce significant file differences. This can be annoying and does not occur with the default indentation method.</p>
</li>
</ul>
<p>Some things that can be done to minimize these problems are:</p>
<ul>
<li><p>Increase <b>--maximum-line-length=n</b> above the default <b>n=80</b> characters if necessary.</p>
</li>
<li><p>If you use <b>-xlp</b> then long side comments can limit the indentation over multiple lines. Consider adding the flag <b>--ignore-side-comment-lengths</b> to prevent this, or minimizing the use of side comments.</p>
</li>
<li><p>Apply this style in a limited way. By default, it applies to all list containers (not just lists in parentheses). The next section describes how to limit this style to, for example, just function calls. The default indentation method will be applied elsewhere.</p>
</li>
</ul>
</dd>
<dt id="lpil-s---line-up-parentheses-inclusion-list-and--lpxl-s---line-up-parentheses-exclusion-list"><b>-lpil=s</b>, <b>--line-up-parentheses-inclusion-list</b> and <b>-lpxl=s</b>, <b>--line-up-parentheses-exclusion-list</b></dt>
<dd>
<p>The following discussion is written for <b>-lp</b> but applies equally to the newer <b>-xlp</b> version. By default, the <b>-lp</b> flag applies to as many containers as possible. The set of containers to which the <b>-lp</b> style applies can be reduced by either one of these two flags:</p>
<p>Use <b>--line-up-parentheses-inclusion-list=s</b> (<b>-lpil=s</b>) to specify the containers to which <b>-lp</b> applies, or</p>
<p>use <b>--line-up-parentheses-exclusion-list=s</b> (<b>-lpxl=s</b>) to specify the containers to which <b>-lp</b> does NOT apply.</p>
<p>Only one of these two flags may be used. Both flags can achieve the same result, but the <b>-lpil=s</b> flag is much easier to describe and use and is recommended. The <b>-lpxl=s</b> flag was the original implementation and is only retained for backwards compatibility.</p>
<p>This list <b>s</b> for these parameters is a string with space-separated items. Each item consists of up to three pieces of information in this order: (1) an optional letter code (2) a required container type, and (3) an optional numeric code.</p>
<p>The only required piece of information is a container type, which is one of '(', '[', or '{'. For example the string</p>
<pre><code> -lpil='('</code></pre>
<p>means use -lp formatting only on lists within parentheses, not lists in square-brackets or braces. The same thing could alternatively be specified with</p>
<pre><code> -lpxl = '[ {'</code></pre>
<p>which says to exclude lists within square-brackets and braces. So what remains is lists within parentheses.</p>
<p>A second optional item of information which can be given for parentheses is an alphanumeric letter which is used to limit the selection further depending on the type of token immediately before the paren. The possible letters are currently 'k', 'K', 'f', 'F', 'w', and 'W', with these meanings for matching whatever precedes an opening paren:</p>
<pre><code> 'k' matches if the previous nonblank token is a perl keyword
(such as 'if', 'while'),
'K' matches if 'k' does not: previous token is not a keyword
'f' matches if previous token is a function (not a keyword)
'F' matches if 'f' does not.
'w' matches if either 'k' or 'f' match.
'W' matches if 'w' does not.</code></pre>
<p>For example:</p>
<pre><code> -lpil = 'f('</code></pre>
<p>means only apply -lp to function calls, and</p>
<pre><code> -lpil = 'w('</code></pre>
<p>means only apply -lp to parenthesized lists which follow a function or a keyword.</p>
<p>This last example could alternatively be written using the <b>-lpxl=s</b> flag as</p>
<pre><code> -lpxl = '[ { W('</code></pre>
<p>which says exclude <b>-lp</b> for lists within square-brackets, braces, and parens NOT preceded by a keyword or function. Clearly, the <b>-lpil=s</b> method is easier to understand.</p>
<p>An optional numeric code may follow any of the container types to further refine the selection based on container contents. The numeric codes are:</p>
<pre><code> '0' or blank: no restriction is placed on container contents
'1' the container contents must be a simple list without sublists
'2' the container contents must be a simple list without sublists,
without code blocks, and without ternary operators</code></pre>
<p>For example,</p>
<pre><code> -lpil = 'f(2'</code></pre>
<p>means only apply -lp to function calls with simple lists (not containing any sublists, code blocks or ternary expressions).</p>
</dd>
<dt id="cti-n---closing-token-indentation"><b>-cti=n</b>, <b>--closing-token-indentation</b></dt>
<dd>
<p>The <b>-cti=n</b> flag controls the indentation of a line beginning with a <code>)</code>, <code>]</code>, or a non-block <code>}</code>. Such a line receives:</p>
<pre><code> -cti = 0 no extra indentation (default)
-cti = 1 extra indentation such that the closing token
aligns with its opening token.
-cti = 2 one extra indentation level if the line looks like:
); or ]; or };
-cti = 3 one extra indentation level always</code></pre>
<p>The flags <b>-cti=1</b> and <b>-cti=2</b> work well with the <b>--line-up-parentheses</b> (<b>-lp</b>) flag (previous section).</p>
<pre><code> # perltidy -lp -cti=1
@month_of_year = (
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
);
# perltidy -lp -cti=2
@month_of_year = (
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
);</code></pre>
<p>These flags are merely hints to the formatter and they may not always be followed. In particular, if -lp is not being used, the indentation for <b>cti=1</b> is constrained to be no more than one indentation level.</p>
<p>If desired, this control can be applied independently to each of the closing container token types. In fact, <b>-cti=n</b> is merely an abbreviation for <b>-cpi=n -csbi=n -cbi=n</b>, where: <b>-cpi</b> or <b>--closing-paren-indentation</b> controls <b>)</b>'s, <b>-csbi</b> or <b>--closing-square-bracket-indentation</b> controls <b>]</b>'s, <b>-cbi</b> or <b>--closing-brace-indentation</b> controls non-block <b>}</b>'s.</p>
</dd>
<dt id="icp---indent-closing-paren"><b>-icp</b>, <b>--indent-closing-paren</b></dt>
<dd>
<p>The <b>-icp</b> flag is equivalent to <b>-cti=2</b>, described in the previous section. The <b>-nicp</b> flag is equivalent <b>-cti=0</b>. They are included for backwards compatibility.</p>
</dd>
<dt id="icb---indent-closing-brace"><b>-icb</b>, <b>--indent-closing-brace</b></dt>
<dd>
<p>The <b>-icb</b> option gives one extra level of indentation to a brace which terminates a code block . For example,</p>
<pre><code> if ($task) {
yyy();
} # -icb
else {
zzz();
}</code></pre>
<p>The default is not to do this, indicated by <b>-nicb</b>.</p>
</dd>
<dt id="ils---indent-leading-semicolon"><b>-ils</b>, <b>--indent-leading-semicolon</b></dt>
<dd>
<p>A line which begins with a leading semicolon will, by default, have the extra number of indentation spaces defined by <b>--continuation-indentation=n</b>. This extra indentation can be removed by setting <b>-nils</b>.</p>
<pre><code> # default
$z = sqrt( $x**2 + $y**2 )
; # <-- indented by ci spaces
# -nils
$z = sqrt( $x**2 + $y**2 )
; # <-- not indented by ci spaces</code></pre>
<p>Note that leading semicolons do not normally occur unless requested with <b>--break-at-old-semicolon-breakpoints</b> or forced, for example by a blank line as in this example.</p>
</dd>
<dt id="nib---non-indenting-braces"><b>-nib</b>, <b>--non-indenting-braces</b></dt>
<dd>
<p>Normally, lines of code contained within a pair of block braces receive one additional level of indentation. This flag, which is enabled by default, causes perltidy to look for opening block braces which are followed by a special side comment. This special side comment is <b>#<<<</b> by default. If found, the code between this opening brace and its corresponding closing brace will not be given the normal extra indentation level. For example:</p>
<pre><code> { #<<< a closure to contain lexical vars
my $var; # this line does not get one level of indentation
...
}
# this line does not 'see' $var;</code></pre>
<p>This can be useful, for example, when combining code from different files. Different sections of code can be placed within braces to keep their lexical variables from being visible to the end of the file. To keep the new braces from causing all of their contained code to be indented if you run perltidy, and possibly introducing new line breaks in long lines, you can mark the opening braces with this special side comment.</p>
<p>Only the opening brace needs to be marked, since perltidy knows where the closing brace is. Braces contained within marked braces may also be marked as non-indenting.</p>
<p>If your code happens to have some opening braces followed by '#<<<', and you don't want this behavior, you can use <b>-nnib</b> to deactivate it. To make it easy to remember, the default string is the same as the string for starting a <b>format-skipping</b> section. There is no confusion because in that case it is for a block comment rather than a side-comment.</p>
<p>The special side comment can be changed with the next parameter.</p>
</dd>
<dt id="nibp-s---non-indenting-brace-prefix-s"><b>-nibp=s</b>, <b>--non-indenting-brace-prefix=s</b></dt>
<dd>
<p>The <b>-nibp=string</b> parameter may be used to change the marker for non-indenting braces. The default is equivalent to -nibp='#<<<'. The string that you enter must begin with a # and should be in quotes as necessary to get past the command shell of your system. This string is the leading text of a regex pattern that is constructed by prepending a '^' and appending a'\s', so you must also include backslashes for characters to be taken literally rather than as patterns.</p>
<p>For example, to match the side comment '#++', the parameter would be</p>
<pre><code> -nibp='#\+\+'</code></pre>
</dd>
<dt id="olq---outdent-long-quotes"><b>-olq</b>, <b>--outdent-long-quotes</b></dt>
<dd>
<p>When <b>-olq</b> is set, lines which is a quoted string longer than the value <b>maximum-line-length</b> will have their indentation removed to make them more readable. This is the default. To prevent such out-denting, use <b>-nolq</b>.</p>
</dd>
<dt id="oll---outdent-long-lines"><b>-oll</b>, <b>--outdent-long-lines</b></dt>
<dd>
<p>This command is equivalent to the combination <b>--outdent-long-quotes</b> and <b>--outdent-long-comments</b>, and it is included for compatibility with previous versions of perltidy. The negation of this also works, <b>-noll</b> or <b>--nooutdent-long-lines</b>, and is equivalent to setting <b>-nolq</b> and <b>-nolc</b>.</p>
</dd>
<dt id="Outdenting-Labels:--ola---outdent-labels"><b>Outdenting Labels:</b> <b>-ola</b>, <b>--outdent-labels</b></dt>
<dd>
<p>This command will cause labels to be outdented by the number of spaces defined by <b>--continuation-indentation=n</b>, if possible. This is the default. For example:</p>
<pre><code> my $i;
LOOP: while ( $i = <FOTOS> ) {
chomp($i);
next unless $i;
fixit($i);
}</code></pre>
<p>Use <b>-nola</b> to prevent this. To control line breaks after labels see <a href="#bal-n---break-after-labels-n">"-bal=n, --break-after-labels=n"</a>.</p>
</dd>
<dt id="Outdenting-Keywords"><b>Outdenting Keywords</b></dt>
<dd>
<dl>
<dt id="okw---outdent-keywords"><b>-okw</b>, <b>--outdent-keywords</b></dt>
<dd>
<p>The command <b>-okw</b> will cause certain leading control keywords to be outdented by the number of spaces defined by <b>--continuation-indentation=n</b>spaces, if possible. By default, these keywords are <code>redo</code>, <code>next</code>, <code>last</code>, <code>goto</code>, and <code>return</code>. The intention is to make these control keywords easier to see. To change this list of keywords being outdented, see the next section.</p>
<p>For example, using <code>perltidy -okw</code> on the previous example gives:</p>
<pre><code> my $i;
LOOP: while ( $i = <FOTOS> ) {
chomp($i);
next unless $i;
fixit($i);
}</code></pre>
<p>Notice that the keyword <b>next</b> has been outdented. The default is not to do this.</p>
</dd>
<dt id="Specifying-Outdented-Keywords:--okwl-string---outdent-keyword-list-string"><b>Specifying Outdented Keywords:</b> <b>-okwl=string</b>, <b>--outdent-keyword-list=string</b></dt>
<dd>
<p>This command can be used to change the keywords which are outdented with the <b>-okw</b> command. The parameter <b>string</b> is a required list of perl keywords, which should be placed in quotes if there are more than one. By itself, it does not cause any outdenting to occur, so the <b>-okw</b> command is still required.</p>
<p>For example, the commands <code>-okwl="next last redo goto" -okw</code> will cause those four keywords to be outdented.</p>
</dd>
</dl>
</dd>
</dl>
<h2 id="Whitespace-Control">Whitespace Control</h2>
<p>Whitespace refers to the blank space between variables, operators, and other code tokens.</p>
<dl>
<dt id="fws---freeze-whitespace"><b>-fws</b>, <b>--freeze-whitespace</b></dt>
<dd>
<p>This flag causes your original whitespace to remain unchanged, and causes the rest of the whitespace commands in this section, the Code Indentation section, and the Comment Control section to be ignored.</p>
</dd>
<dt id="Tightness-of-curly-braces-parentheses-and-square-brackets"><b>Tightness of curly braces, parentheses, and square brackets</b></dt>
<dd>
<p>Here the term "tightness" will mean the closeness with which pairs of enclosing tokens, such as parentheses, contain the quantities within. A numerical value of 0, 1, or 2 defines the tightness, with 0 being least tight and 2 being most tight. Spaces within containers are always symmetric, so if there is a space after a <code>(</code> then there will be a space before the corresponding <code>)</code>.</p>
<p>The <b>-pt=n</b> or <b>--paren-tightness=n</b> parameter controls the space within parens. The example below shows the effect of the three possible values, 0, 1, and 2:</p>
<pre><code> if ( ( my $len_tab = length( $tabstr ) ) > 0 ) { # -pt=0
if ( ( my $len_tab = length($tabstr) ) > 0 ) { # -pt=1 (default)
if ((my $len_tab = length($tabstr)) > 0) { # -pt=2</code></pre>
<p>When n is 0, there is always a space to the right of a '(' and to the left of a ')'. For n=2 there is never a space. For n=1, the default, there is a space unless the quantity within the parens is a single token, such as an identifier or quoted string.</p>
<p>Likewise, the parameter <b>-sbt=n</b> or <b>--square-bracket-tightness=n</b> controls the space within square brackets, as illustrated below.</p>
<pre><code> $width = $col[ $j + $k ] - $col[ $j ]; # -sbt=0
$width = $col[ $j + $k ] - $col[$j]; # -sbt=1 (default)
$width = $col[$j + $k] - $col[$j]; # -sbt=2</code></pre>
<p>Curly braces which do not contain code blocks are controlled by the parameter <b>-bt=n</b> or <b>--brace-tightness=n</b>.</p>
<pre><code> $obj->{ $parsed_sql->{ 'table' }[0] }; # -bt=0
$obj->{ $parsed_sql->{'table'}[0] }; # -bt=1 (default)
$obj->{$parsed_sql->{'table'}[0]}; # -bt=2</code></pre>
<p>And finally, curly braces which contain blocks of code are controlled by the parameter <b>-bbt=n</b> or <b>--block-brace-tightness=n</b> as illustrated in the example below (<b>-bbt=0</b> is the default).</p>
<pre><code> %bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # -bbt=0
%bf = map { $_ => -M $_ } grep {/\.deb$/} dirents '.'; # -bbt=1
%bf = map {$_ => -M $_} grep {/\.deb$/} dirents '.'; # -bbt=2</code></pre>
<p>To simplify input in the case that all of the tightness flags have the same value <b>n</b>, the parameter <b>-act=n</b> or <b>--all-containers-tightness=n</b> is an abbreviation for the combination <b>-pt=n -sbt=n -bt=n -bbt=n</b>.</p>
</dd>
<dt id="mutt-s---multiple-token-tightness-s"><b>-mutt=s</b>, <b>--multiple-token-tightness=s</b></dt>
<dd>
<p>To review, the tightness controls described in the previous section have three possible integer values: 0, 1, and 2, where <b>n=0</b> always adds a space, and <b>n=2</b> never adds a space.</p>
<p>The default value <b>n=1</b> adds space only if the container holds multiple tokens. Some perltidy tokens may be rather long, and it can be preferable to space some of them as if they were multple tokens. This can be done with this paramter.</p>
<p>For example, in the following expression the <code>qw</code> list is a single token and therefore there the default formatting does not put spaces within the square brackets:</p>
<pre><code> my $rlist = [qw(alpha beta gamma)];</code></pre>
<p>This can be changed with</p>
<pre><code> # perltidy -mutt='qw'
my $rlist = [ qw(alpha beta gamma) ];</code></pre>
<p>This tells perltidy to space a <code>qw</code>list as if it were multiple tokens when the default tightness is used.</p>
<p>The parameter <b>s</b> may contain any of the following perl operators:</p>
<pre><code> qw q qq qx qr s y tr m</code></pre>
<p>Other possible specifications are</p>
<pre><code> q* - all of the above operators
Q - all of the above plus any quoted text
h - a here-doc target, such as '<<EOT'
<<>> - the double-diamond operator</code></pre>
<p>A symbol may be negated by preceding it with a carat <b>^</b> symbol. The double-diamond operator is always included unless negated in this way.</p>
</dd>
<dt id="xbt---extended-block-tightness"><b>-xbt</b>, <b>--extended-block-tightness</b></dt>
<dd>
<p>There are two controls for spacing within curly braces, namely <b>--block-brace-tightness=n</b> for code block braces and <b>--brace-tightness=n</b> for all other braces.</p>
<p>There is a little fuzziness in this division of brace types though because the curly braces considered by perltidy to contain code blocks for formatting purposes, such as highlighting code structure, exclude some of the small code blocks used by Perl mainly for isolating terms. These include curly braces following a keyword where an indirect object might occur, or curly braces following a type symbol. For example, perltidy does not mark the following braces as code block braces:</p>
<pre><code> print {*STDERR} $message;
return ${$foo};</code></pre>
<p>Consequently, the spacing within these small braced containers by default follows the flag <b>--brace-tightness=n</b> rather than <b>--block-brace-tightness=n</b>, as one might expect.</p>
<p>If desired, small blocks such as these can be made to instead follow the spacing defined by the <b>--block-brace-tightness=n</b> flag by setting <b>--extended-block-tightness</b>. The specific types of small blocks to which this parameter applies is controlled by a companion control parameter, described in the next section.</p>
<p>Note that if the two flags <b>--block-brace-tightness=n</b> and <b>--brace-tightness=n</b> have the same value <b>n</b> then there would be no reason to set this flag.</p>
</dd>
<dt id="xbtl-s---extended-block-tightness-list-s"><b>-xbtl=s</b>, <b>--extended-block-tightness-list=s</b></dt>
<dd>
<p>The previous parameter <b>--extended-block-tightness</b> (<b>-xbt</b>) can be made to apply to curly braces preceded by any of the keywords</p>
<pre><code> print printf exec system say</code></pre>
<p>and/or the special symbols</p>
<pre><code> $ @ % & * $#</code></pre>
<p>The parameter string <b>s</b> may contain a selection of these keywords and symbols to indicate the brace types to which <b>--extended-block-tightness</b> applies. For convenience, all of the keywords can be selected with 'k', and all of the special symbols can be selected with 't'. The default is equivalent to <b>-xbtl='k'</b>, which selects all of the keywords.</p>
<p>Examples:</p>
<pre><code> -xbtl='k' # selects just the keywords [DEFAULT]
-xbtl="t" # selects just the special type symbols
-xbtl="k t" # selects all keywords and symbols, or simply
-xbtl="kt" # selects all keywords and symbols
-xbtl="print say" # selects just keywords B<print> and B<say>:</code></pre>
<p>Here are some formatting examples using the default values of <b>--brace-tightness=n</b> and <b>--block-brace-tightness=n</b>. Note that in these examples <b>$ref</b> is in block braces but <b>$key</b> is not.</p>
<pre><code> # default formatting
print {*STDERR} $message;
my $val = ${$ref}{$key};
# perltidy -xbt or
# perltidy -xbt -xbtl=k
print { *STDERR } $message;
my $val = ${$ref}{$key};
# perltidy -xbt -xbtl=t
print {*STDERR} $message;
my $val = ${ $ref }{$key};
# perltidy -xbt -xbtl=kt
print { *STDERR } $message;
my $val = ${ $ref }{$key};</code></pre>
<p>Finally, note that this parameter merely changes the way that the parameter <b>--extended-block-tightness</b> works. It has no effect unless <b>--extended-block-tightness</b> is actually set.</p>
</dd>
<dt id="tso---tight-secret-operators"><b>-tso</b>, <b>--tight-secret-operators</b></dt>
<dd>
<p>The flag <b>-tso</b> causes certain perl token sequences (secret operators) which might be considered to be a single operator to be formatted "tightly" (without spaces). The operators currently modified by this flag are:</p>
<pre><code> 0+ +0 ()x!! ~~<> ,=> =( )=</code></pre>
<p>For example the sequence <b>0 +</b>, which converts a string to a number, would be formatted without a space: <b>0+</b> when the <b>-tso</b> flag is set. This flag is off by default.</p>
</dd>
<dt id="sts---space-terminal-semicolon"><b>-sts</b>, <b>--space-terminal-semicolon</b></dt>
<dd>
<p>Some programmers prefer a space before all terminal semicolons. The default is for no such space, and is indicated with <b>-nsts</b> or <b>--nospace-terminal-semicolon</b>.</p>
<pre><code> $i = 1 ; # -sts
$i = 1; # -nsts (default)</code></pre>
</dd>
<dt id="sfs---space-for-semicolon"><b>-sfs</b>, <b>--space-for-semicolon</b></dt>
<dd>
<p>Semicolons within <b>for</b> loops may sometimes be hard to see, particularly when commas are also present. This option places spaces on both sides of these special semicolons, and is the default. Use <b>-nsfs</b> or <b>--nospace-for-semicolon</b> to deactivate it.</p>
<pre><code> for ( @a = @$ap, $u = shift @a ; @a ; $u = $v ) { # -sfs (default)
for ( @a = @$ap, $u = shift @a; @a; $u = $v ) { # -nsfs</code></pre>
</dd>
<dt id="asc---add-semicolons"><b>-asc</b>, <b>--add-semicolons</b></dt>
<dd>
<p>Setting <b>-asc</b> allows perltidy to add any missing optional semicolon at the end of a line which is followed by a closing curly brace on the next line. This is the default, and may be deactivated with <b>-nasc</b> or <b>--noadd-semicolons</b>.</p>
</dd>
<dt id="dsm---delete-semicolons"><b>-dsm</b>, <b>--delete-semicolons</b></dt>
<dd>
<p>Setting <b>-dsm</b> allows perltidy to delete extra semicolons which are simply empty statements. This is the default, and may be deactivated with <b>-ndsm</b> or <b>--nodelete-semicolons</b>. (Such semicolons are not deleted, however, if they would promote a side comment to a block comment).</p>
</dd>
<dt id="aws---add-whitespace"><b>-aws</b>, <b>--add-whitespace</b></dt>
<dd>
<p>Setting this option allows perltidy to add certain whitespace to improve code readability. This is the default. If you do not want any whitespace added, but are willing to have some whitespace deleted, use <b>-naws</b>. (Use <b>--freeze-whitespace</b> (<b>-fws</b>) to leave whitespace completely unchanged).</p>
</dd>
<dt id="dws---delete-old-whitespace"><b>-dws</b>, <b>--delete-old-whitespace</b></dt>
<dd>
<p>Setting this option allows perltidy to remove optional whitespace between characters in the input file. The default is to not to do this (<b>-nodelete-old-whitespace</b>). This parameter has little effect by itself. But in combination with <b>--noadd-whitespace</b> it will cause most of the whitespace in a file to be removed.</p>
</dd>
<dt id="Detailed-whitespace-controls-around-tokens"><b>Detailed whitespace controls around tokens</b></dt>
<dd>
<p>For those who want more detailed control over the whitespace around tokens, there are four parameters which can directly modify the default whitespace rules built into perltidy for any token. They are:</p>
<p><b>-wls=s</b> or <b>--want-left-space=s</b>,</p>
<p><b>-nwls=s</b> or <b>--nowant-left-space=s</b>,</p>
<p><b>-wrs=s</b> or <b>--want-right-space=s</b>,</p>
<p><b>-nwrs=s</b> or <b>--nowant-right-space=s</b>.</p>
<p>These parameters are each followed by a quoted string, <b>s</b>, containing a list of token types. No more than one of each of these parameters should be specified, because repeating a command-line parameter always overwrites the previous one before perltidy ever sees it.</p>
<p>To illustrate how these are used, suppose it is desired that there be no space on either side of the token types <b>= + - / *</b>. The following two parameters would specify this desire:</p>
<pre><code> -nwls="= + - / *" -nwrs="= + - / *"</code></pre>
<p>(Note that the token types are in quotes, and that they are separated by spaces). With these modified whitespace rules, the following line of math:</p>
<pre><code> $root = -$b + sqrt( $b * $b - 4. * $a * $c ) / ( 2. * $a );</code></pre>
<p>becomes this:</p>
<pre><code> $root=-$b+sqrt( $b*$b-4.*$a*$c )/( 2.*$a );</code></pre>
<p>These parameters should be considered to be hints to perltidy rather than fixed rules, because perltidy must try to resolve conflicts that arise between them and all of the other rules that it uses. One conflict that can arise is if, between two tokens, the left token wants a space and the right one doesn't. In this case, the token not wanting a space takes priority.</p>
<p>It is necessary to have a list of all token types in order to create this type of input. Such a list can be obtained by the command <b>--dump-token-types</b>. Also try the <b>-D</b> flag on a short snippet of code and look at the <i>.DEBUG</i> file to see the tokenization.</p>
<p>To illustrate, suppose we do not want a space after a colon which introduces a sub attribute. We need to know its type. It is not a colon because that is the type of a ternary operator. The output of <b>--dump-token-types</b> states that it is token type 'A'. To verify this, we can run <code>perltidy -D</code> on a short piece of code containing such a colon, such as</p>
<pre><code> sub foo : lvalue;</code></pre>
<p>This produces a <i>.DEBUG</i> file which contains</p>
<pre><code> 1: sub foo : lvalue;
1: SSSSSSSbAbwwwwww;</code></pre>
<p>The top line is the input, and the bottom line shows the token types. The 'A' beneath the colon verifies that it is type <b>A</b>.</p>
<p>So to prevent a space on the right of this colon we can use</p>
<pre><code> # perltidy -nwrs='A'
sub foo :lvalue;</code></pre>
<p><b>WARNING</b> Be sure to put these tokens in quotes to avoid having them misinterpreted by your command shell.</p>
</dd>
<dt id="Note1:-Perltidy-does-always-follow-whitespace-controls"><b>Note1: Perltidy does always follow whitespace controls</b></dt>
<dd>
<p>The various parameters controlling whitespace within a program are requests which perltidy follows as well as possible, but there are a number of situations where changing whitespace could change program behavior and is not done. Some of these are obvious; for example, we should not remove the space between the two plus symbols in '$x+ +$y' to avoid creating a '++' operator. Some are more subtle and involve the whitespace around bareword symbols and locations of possible filehandles. For example, consider the problem of formatting the following subroutine:</p>
<pre><code> sub print_div {
my ($x,$y)=@_;
print $x/$y;
}</code></pre>
<p>Suppose the user requests that / signs have a space to the left but not to the right. Perltidy will refuse to do this, but if this were done the result would be</p>
<pre><code> sub print_div {
my ($x,$y)=@_;
print $x /$y;
}</code></pre>
<p>If formatted in this way, the program will not run (at least with recent versions of perl) because the $x is taken to be a filehandle and / is assumed to start a quote. In a complex program, there might happen to be a / which terminates the multiline quote without a syntax error, allowing the program to run, but not as intended.</p>
<p>Related issues arise with other binary operator symbols, such as + and -, and in older versions of perl there could be problems with ternary operators. So to avoid changing program behavior, perltidy has the simple rule that whitespace around possible filehandles is left unchanged. Likewise, whitespace around unknown barewords is left unchanged. The reason is that if the barewords are defined in other modules, or in code that has not even been written yet, perltidy will not have seen their prototypes and must treat them cautiously.</p>
<p>In perltidy this is implemented in the tokenizer by marking token following a <b>print</b> keyword as a special type <b>Z</b>. When formatting is being done, whitespace following this token type is generally left unchanged as a precaution against changing program behavior. This is excessively conservative but simple and easy to implement. Keywords which are treated similarly to <b>print</b> include <b>printf</b>, <b>sort</b>, <b>exec</b>, <b>system</b>. Changes in spacing around parameters following these keywords may have to be made manually. For example, the space, or lack of space, after the parameter $foo in the following line will be unchanged in formatting.</p>
<pre><code> system($foo );
system($foo);</code></pre>
<p>To find if a token is of type <b>Z</b> you can use <b>perltidy -DEBUG</b>. For the first line above the result is</p>
<pre><code> 1: system($foo );
1: kkkkkk{ZZZZb};</code></pre>
<p>which shows that <b>system</b> is type <b>k</b> (keyword) and $foo is type <b>Z</b>.</p>
</dd>
<dt id="Note2:-Perltidys-whitespace-rules-are-not-perfect"><b>Note2: Perltidy's whitespace rules are not perfect</b></dt>
<dd>
<p>Despite these precautions, it is still possible to introduce syntax errors with some asymmetric whitespace rules, particularly when call parameters are not placed in containing parens or braces. For example, the following two lines will be parsed by perl without a syntax error:</p>
<pre><code> # original programming, syntax ok
my @newkeys = map $_-$nrecs+@data, @oldkeys;
# perltidy default, syntax ok
my @newkeys = map $_ - $nrecs + @data, @oldkeys;</code></pre>
<p>But the following will give a syntax error:</p>
<pre><code> # perltidy -nwrs='-'
my @newkeys = map $_ -$nrecs + @data, @oldkeys;</code></pre>
<p>For another example, the following two lines will be parsed without syntax error:</p>
<pre><code> # original programming, syntax ok
for my $severity ( reverse $LOWEST+1 .. $HIGHEST ) { ... }
# perltidy default, syntax ok
for my $severity ( reverse $LOWEST + 1 .. $HIGHEST ) { ... }</code></pre>
<p>But the following will give a syntax error:</p>
<pre><code> # perltidy -nwrs='+', syntax error:
for my $severity ( reverse $LOWEST +1 .. $HIGHEST ) { ... }</code></pre>
<p>To avoid subtle parsing problems like this, it is best to avoid spacing a binary operator asymmetrically with a space on the left but not on the right.</p>
</dd>
<dt id="Space-between-specific-keywords-and-opening-paren"><b>Space between specific keywords and opening paren</b></dt>
<dd>
<p>When an opening paren follows a Perl keyword, no space is introduced after the keyword, unless it is (by default) one of these:</p>
<pre><code> my local our state and or xor err eq ne if else elsif until unless
while for foreach return switch case given when catch</code></pre>
<p>These defaults can be modified with two commands:</p>
<p><b>-sak=s</b> or <b>--space-after-keyword=s</b> adds keywords.</p>
<p><b>-nsak=s</b> or <b>--nospace-after-keyword=s</b> removes keywords.</p>
<p>where <b>s</b> is a list of keywords (in quotes if necessary). For example,</p>
<pre><code> my ( $a, $b, $c ) = @_; # default
my( $a, $b, $c ) = @_; # -nsak="my local our"</code></pre>
<p>The abbreviation <b>-nsak='*'</b> is equivalent to including all of the keywords in the above list.</p>
<p>When both <b>-nsak=s</b> and <b>-sak=s</b> commands are included, the <b>-nsak=s</b> command is executed first. For example, to have space after only the keywords (my, local, our) you could use <b>-nsak="*" -sak="my local our"</b>.</p>
<p>To put a space after all keywords, see the next item.</p>
</dd>
<dt id="Space-between-all-keywords-and-opening-parens"><b>Space between all keywords and opening parens</b></dt>
<dd>
<p>When an opening paren follows a function or keyword, no space is introduced after the keyword except for the keywords noted in the previous item. To always put a space between a function or keyword and its opening paren, use the command:</p>
<p><b>-skp</b> or <b>--space-keyword-paren</b></p>
<p>You may also want to use the flag <b>-sfp</b> (next item) too.</p>
</dd>
<dt id="Space-between-all-function-names-and-opening-parens"><b>Space between all function names and opening parens</b></dt>
<dd>
<p>When an opening paren follows a function the default and recommended formatting is not to introduce a space. To cause a space to be introduced use:</p>
<p><b>-sfp</b> or <b>--space-function-paren</b></p>
<pre><code> myfunc( $a, $b, $c ); # default
myfunc ( $a, $b, $c ); # -sfp</code></pre>
<p>You will probably also want to use the flag <b>-skp</b> (previous item) too.</p>
<p>The parameter is not recommended because spacing a function paren can make a program vulnerable to parsing problems by Perl. For example, the following two-line program will run as written but will have a syntax error if reformatted with -sfp:</p>
<pre><code> if ( -e filename() ) { print "I'm here\n"; }
sub filename { return $0 }</code></pre>
<p>In this particular case the syntax error can be removed if the line order is reversed, so that Perl parses 'sub filename' first.</p>
</dd>
<dt id="fpva-or---function-paren-vertical-alignment"><b>-fpva</b> or <b>--function-paren-vertical-alignment</b></dt>
<dd>
<p>A side-effect of using the <b>-sfp</b> flag is that the parens may become vertically aligned. For example,</p>
<pre><code> # perltidy -sfp
myfun ( $aaa, $b, $cc );
mylongfun ( $a, $b, $c );</code></pre>
<p>This is the default behavior. To prevent this alignment use <b>-nfpva</b>:</p>
<pre><code> # perltidy -sfp -nfpva
myfun ( $aaa, $b, $cc );
mylongfun ( $a, $b, $c );</code></pre>
</dd>
<dt id="spp-n-or---space-prototype-paren-n"><b>-spp=n</b> or <b>--space-prototype-paren=n</b></dt>
<dd>
<p>This flag can be used to control whether a function prototype is preceded by a space. For example, the following prototype does not have a space.</p>
<pre><code> sub usage();</code></pre>
<p>This integer <b>n</b> may have the value 0, 1, or 2 as follows:</p>
<pre><code> -spp=0 means no space before the paren
-spp=1 means follow the example of the source code [DEFAULT]
-spp=2 means always put a space before the paren</code></pre>
<p>The default is <b>-spp=1</b>, meaning that a space will be used if and only if there is one in the source code. Given the above line of code, the result of applying the different options would be:</p>
<pre><code> sub usage(); # n=0 [no space]
sub usage(); # n=1 [default; follows input]
sub usage (); # n=2 [space]</code></pre>
</dd>
<dt id="ssp-n-or---space-signature-paren-n"><b>-ssp=n</b> or <b>--space-signature-paren=n</b></dt>
<dd>
<p>This flag is analogous to the previous except that it applies to the space before the opening paren of a sub <b>signature</b> rather than a sub <b>prototype</b>.</p>
<p>For example, consider the following line:</p>
<pre><code> sub circle( $xc, $yc, $rad )</code></pre>
<p>This space before the opening paren can be controlled with integer <b>n</b> which may have the value 0, 1, or 2 with these meanings:</p>
<pre><code> -ssp=0 means no space before the paren
-ssp=1 means follow the example of the source code [DEFAULT]
-ssp=2 means always put a space before the paren</code></pre>
<p>The default is <b>-ssp=1</b>, meaning that will be a space in the output if, and only if, there is one in the input. Given the above line of code, the result of applying the different options would be:</p>
<pre><code> sub circle( $xc, $yc, $rad ) # n=0 [no space]
sub circle( $xc, $yc, $rad ) # n=1 [default; same as input]
sub circle ( $xc, $yc, $rad ) # n=2 [space]</code></pre>
</dd>
<dt id="kpit-n-or---keyword-paren-inner-tightness-n"><b>-kpit=n</b> or <b>--keyword-paren-inner-tightness=n</b></dt>
<dd>
<p>The space inside of an opening paren, which itself follows a certain keyword, can be controlled by this parameter. The space on the inside of the corresponding closing paren will be treated in the same (balanced) manner. This parameter has precedence over any other paren spacing rules. The values of <b>n</b> are as follows:</p>
<pre><code> -kpit=0 means always put a space (not tight)
-kpit=1 means ignore this parameter [default]
-kpit=2 means never put a space (tight)</code></pre>
<p>To illustrate, the following snippet is shown formatted in three ways:</p>
<pre><code> if ( seek( DATA, 0, 0 ) ) { ... } # perltidy (default)
if (seek(DATA, 0, 0)) { ... } # perltidy -pt=2
if ( seek(DATA, 0, 0) ) { ... } # perltidy -pt=2 -kpit=0</code></pre>
<p>In the second case the -pt=2 parameter makes all of the parens tight. In the third case the -kpit=0 flag causes the space within the 'if' parens to have a space, since 'if' is one of the keywords to which the -kpit flag applies by default. The remaining parens are still tight because of the -pt=2 parameter.</p>
<p>The set of keywords to which this parameter applies are by default are:</p>
<pre><code> if elsif unless while until for foreach</code></pre>
<p>These can be changed with the parameter <b>-kpitl=s</b> described in the next section.</p>
</dd>
<dt id="kpitl-string-or---keyword-paren-inner-tightness-list-string"><b>-kpitl=string</b> or <b>--keyword-paren-inner-tightness-list=string</b></dt>
<dd>
<p>This command can be used to change the keywords to which the previous parameter, <b>-kpit=n</b>, applies. The parameter <b>string</b> is a required list either keywords or functions, which should be placed in quotes if there are more than one. By itself, this parameter does not cause any change in spacing, so the <b>-kpit=n</b> command is still required.</p>
<p>For example, the commands <code>-kpitl="if else while" -kpit=2</code> will cause the just the spaces inside parens following 'if', 'else', and 'while' keywords to follow the tightness value indicated by the <b>-kpit=2</b> flag.</p>
</dd>
<dt id="lop-or---logical-padding"><b>-lop</b> or <b>--logical-padding</b></dt>
<dd>
<p>In the following example some extra space has been inserted on the second line between the two open parens. This extra space is called "logical padding" and is intended to help align similar things vertically in some logical or ternary expressions.</p>
<pre><code> # perltidy [default formatting]
$same =
( ( $aP eq $bP )
&& ( $aS eq $bS )
&& ( $aT eq $bT )
&& ( $a->{'title'} eq $b->{'title'} )
&& ( $a->{'href'} eq $b->{'href'} ) );</code></pre>
<p>Note that this is considered to be a different operation from "vertical alignment" because space at just one line is being adjusted, whereas in "vertical alignment" the spaces at all lines are being adjusted. So it is sort of a local version of vertical alignment.</p>
<p>Here is an example involving a ternary operator:</p>
<pre><code> # perltidy [default formatting]
$bits =
$top > 0xffff ? 32
: $top > 0xff ? 16
: $top > 1 ? 8
: 1;</code></pre>
<p>This behavior is controlled with the flag <b>--logical-padding</b>, which is set 'on' by default. If it is not desired it can be turned off using <b>--nological-padding</b> or <b>-nlop</b>. The above two examples become, with <b>-nlop</b>:</p>
<pre><code> # perltidy -nlop
$same =
( ( $aP eq $bP )
&& ( $aS eq $bS )
&& ( $aT eq $bT )
&& ( $a->{'title'} eq $b->{'title'} )
&& ( $a->{'href'} eq $b->{'href'} ) );
# perltidy -nlop
$bits =
$top > 0xffff ? 32
: $top > 0xff ? 16
: $top > 1 ? 8
: 1;</code></pre>
</dd>
<dt id="Trimming-whitespace-around-qw-quotes"><b>Trimming whitespace around <code>qw</code> quotes</b></dt>
<dd>
<p><b>-tqw</b> or <b>--trim-qw</b> provide the default behavior of trimming spaces around multiline <code>qw</code> quotes and indenting them appropriately.</p>
<p><b>-ntqw</b> or <b>--notrim-qw</b> cause leading and trailing whitespace around multiline <code>qw</code> quotes to be left unchanged. This option will not normally be necessary, but was added for testing purposes, because in some versions of perl, trimming <code>qw</code> quotes changes the syntax tree.</p>
</dd>
<dt id="sbq-n-or---space-backslash-quote-n"><b>-sbq=n</b> or <b>--space-backslash-quote=n</b></dt>
<dd>
<p>lines like</p>
<pre><code> $str1=\"string1";
$str2=\'string2';</code></pre>
<p>can confuse syntax highlighters unless a space is included between the backslash and the single or double quotation mark.</p>
<p>this can be controlled with the value of <b>n</b> as follows:</p>
<pre><code> -sbq=0 means no space between the backslash and quote
-sbq=1 means follow the example of the source code
-sbq=2 means always put a space between the backslash and quote</code></pre>
<p>The default is <b>-sbq=1</b>, meaning that a space will be used if there is one in the source code.</p>
</dd>
<dt id="Trimming-trailing-whitespace-from-lines-of-POD"><b>Trimming trailing whitespace from lines of POD</b></dt>
<dd>
<p><b>-trp</b> or <b>--trim-pod</b> will remove trailing whitespace from lines of POD. The default is not to do this.</p>
</dd>
</dl>
<h2 id="Comment-Controls">Comment Controls</h2>
<p>Perltidy has a number of ways to control the appearance of both block comments and side comments. The term <b>block comment</b> here refers to a full-line comment, whereas <b>side comment</b> will refer to a comment which appears on a line to the right of some code.</p>
<p>Perltidy does not do any word wrapping of commented text to match a selected maximum line length. This is because there is no way to determine if this is appropriate for the given content. However, an interactive program named <b>perlcomment.pl</b> is available in the <b>examples</b> folder of the perltidy distribution which can assist in doing this.</p>
<dl>
<dt id="ibc---indent-block-comments"><b>-ibc</b>, <b>--indent-block-comments</b></dt>
<dd>
<p>Block comments normally look best when they are indented to the same level as the code which follows them. This is the default behavior, but you may use <b>-nibc</b> to keep block comments left-justified. Here is an example:</p>
<pre><code> # this comment is indented (-ibc, default)
if ($task) { yyy(); }</code></pre>
<p>The alternative is <b>-nibc</b>:</p>
<pre><code> # this comment is not indented (-nibc)
if ($task) { yyy(); }</code></pre>
<p>See also the next item, <b>-isbc</b>, as well as <b>-sbc</b>, for other ways to have some indented and some outdented block comments.</p>
</dd>
<dt id="isbc---indent-spaced-block-comments"><b>-isbc</b>, <b>--indent-spaced-block-comments</b></dt>
<dd>
<p>If there is no leading space on the line, then the comment will not be indented, and otherwise it may be.</p>
<p>If both <b>-ibc</b> and <b>-isbc</b> are set, then <b>-isbc</b> takes priority.</p>
</dd>
<dt id="olc---outdent-long-comments"><b>-olc</b>, <b>--outdent-long-comments</b></dt>
<dd>
<p>When <b>-olc</b> is set, lines which are full-line (block) comments longer than the value <b>maximum-line-length</b> will have their indentation removed. This is the default; use <b>-nolc</b> to prevent outdenting.</p>
</dd>
<dt id="msc-n---minimum-space-to-comment-n"><b>-msc=n</b>, <b>--minimum-space-to-comment=n</b></dt>
<dd>
<p>Side comments look best when lined up several spaces to the right of code. Perltidy will try to keep comments at least n spaces to the right. The default is n=4 spaces.</p>
</dd>
<dt id="fpsc-n---fixed-position-side-comment-n"><b>-fpsc=n</b>, <b>--fixed-position-side-comment=n</b></dt>
<dd>
<p>This parameter tells perltidy to line up side comments in column number <b>n</b> whenever possible. The default, n=0, will not do this.</p>
</dd>
<dt id="iscl---ignore-side-comment-lengths"><b>-iscl</b>, <b>--ignore-side-comment-lengths</b></dt>
<dd>
<p>This parameter causes perltidy to ignore the length of side comments when setting line breaks. The default, <b>-niscl</b>, is to include the length of side comments when breaking lines to stay within the length prescribed by the <b>-l=n</b> maximum line length parameter. For example, the following long single line would remain intact with -l=80 and -iscl:</p>
<pre><code> perltidy -l=80 -iscl
$vmsfile =~ s/;[\d\-]*$//; # Clip off version number; we can use a newer version</code></pre>
<p>whereas without the -iscl flag the line will be broken:</p>
<pre><code> perltidy -l=80
$vmsfile =~ s/;[\d\-]*$//
; # Clip off version number; we can use a newer version</code></pre>
</dd>
<dt id="ipc---ignore-perlcritic-comments"><b>-ipc</b>, <b>--ignore-perlcritic-comments</b></dt>
<dd>
<p>Perltidy, by default, will look for side comments beginning with <b>## no critic</b> and ignore their lengths when making line break decisions, even if the user has not set <b>-iscl</b>. The reason is that an unwanted line break can make these special comments ineffective in controlling <b>perlcritic</b>.</p>
<p>Setting <b>--ignore-perlcritic-comments</b> tells perltidy not to look for these <b>## no critic</b> comments.</p>
</dd>
<dt id="hsc---hanging-side-comments"><b>-hsc</b>, <b>--hanging-side-comments</b></dt>
<dd>
<p>By default, perltidy tries to identify and align "hanging side comments", which are something like this:</p>
<pre><code> my $IGNORE = 0; # This is a side comment
# This is a hanging side comment
# And so is this</code></pre>
<p>A comment is considered to be a hanging side comment if (1) it immediately follows a line with a side comment, or another hanging side comment, and (2) there is some leading whitespace on the line. To deactivate this feature, use <b>-nhsc</b> or <b>--nohanging-side-comments</b>. If block comments are preceded by a blank line, or have no leading whitespace, they will not be mistaken as hanging side comments.</p>
</dd>
<dt id="Closing-Side-Comments"><b>Closing Side Comments</b></dt>
<dd>
<p>A closing side comment is a special comment which perltidy can automatically create and place after the closing brace of a code block. They can be useful for code maintenance and debugging. The command <b>-csc</b> (or <b>--closing-side-comments</b>) adds or updates closing side comments. For example, here is a small code snippet</p>
<pre><code> sub message {
if ( !defined( $_[0] ) ) {
print("Hello, World\n");
}
else {
print( $_[0], "\n" );
}
}</code></pre>
<p>And here is the result of processing with <code>perltidy -csc</code>:</p>
<pre><code> sub message {
if ( !defined( $_[0] ) ) {
print("Hello, World\n");
}
else {
print( $_[0], "\n" );
}
} ## end sub message</code></pre>
<p>A closing side comment was added for <code>sub message</code> in this case, but not for the <code>if</code> and <code>else</code> blocks, because they were below the 6 line cutoff limit for adding closing side comments. This limit may be changed with the <b>-csci</b> command, described below.</p>
<p>The command <b>-dcsc</b> (or <b>--delete-closing-side-comments</b>) reverses this process and removes these comments.</p>
<p>Several commands are available to modify the behavior of these two basic commands, <b>-csc</b> and <b>-dcsc</b>:</p>
<dl>
<dt id="csci-n-or---closing-side-comment-interval-n"><b>-csci=n</b>, or <b>--closing-side-comment-interval=n</b></dt>
<dd>
<p>where <code>n</code> is the minimum number of lines that a block must have in order for a closing side comment to be added. The default value is <code>n=6</code>. To illustrate:</p>
<pre><code> # perltidy -csci=2 -csc
sub message {
if ( !defined( $_[0] ) ) {
print("Hello, World\n");
} ## end if ( !defined( $_[0] ))
else {
print( $_[0], "\n" );
} ## end else [ if ( !defined( $_[0] ))
} ## end sub message</code></pre>
<p>Now the <code>if</code> and <code>else</code> blocks are commented. However, now this has become very cluttered.</p>
</dd>
<dt id="cscp-string-or---closing-side-comment-prefix-string"><b>-cscp=string</b>, or <b>--closing-side-comment-prefix=string</b></dt>
<dd>
<p>where string is the prefix used before the name of the block type. The default prefix, shown above, is <code>## end</code>. This string will be added to closing side comments, and it will also be used to recognize them in order to update, delete, and format them. Any comment identified as a closing side comment will be placed just a single space to the right of its closing brace.</p>
</dd>
<dt id="cscl-string-or---closing-side-comment-list"><b>-cscl=string</b>, or <b>--closing-side-comment-list</b></dt>
<dd>
<p>where <code>string</code> is a list of block types to be tagged with closing side comments. By default, all code block types preceded by a keyword or label (such as <code>if</code>, <code>sub</code>, and so on) will be tagged. The <b>-cscl</b> command changes the default list to be any selected block types; see <a href="#Specifying-Block-Types">"Specifying Block Types"</a>. For example, the following command requests that only <code>sub</code>'s, labels, <code>BEGIN</code>, and <code>END</code> blocks be affected by operations which add (<b>-csc</b>) or delete (<b>-dcsc</b>) closing side comments:</p>
<pre><code> --closing-side-comment-list='sub : BEGIN END'</code></pre>
</dd>
<dt id="cscxl-string-or---closing-side-comment-exclusion-list"><b>-cscxl=string</b>, or <b>--closing-side-comment-exclusion-list</b></dt>
<dd>
<p>where <code>string</code> is a list of block types which should NOT be tagged with closing side comments. If a block type appears in both <b>-cscl</b> and <b>-cscxl</b>, then <b>-cscxl</b> has priority and the block will not be tagged.</p>
<p>For example, the following command requests that anonymous subs should not be affected by any <b>-csc</b> or <b>-dcsc</b> operation:</p>
<pre><code> --closing-side-comment-exclusion-list='asub'</code></pre>
<p>By default, no block types are excluded.</p>
</dd>
<dt id="csct-n-or---closing-side-comment-maximum-text-n"><b>-csct=n</b>, or <b>--closing-side-comment-maximum-text=n</b></dt>
<dd>
<p>The text appended to certain block types, such as an <code>if</code> block, is whatever lies between the keyword introducing the block, such as <code>if</code>, and the opening brace. Since this might be too much text for a side comment, there needs to be a limit, and that is the purpose of this parameter. The default value is <code>n=20</code>, meaning that no additional tokens will be appended to this text after its length reaches 20 characters. Omitted text is indicated with <code>...</code>. (Tokens, including sub names, are never truncated, however, so actual lengths may exceed this). To illustrate, in the above example, the appended text of the first block is <code> ( !defined( $_[0] )...</code>. The existing limit of <code>n=20</code> caused this text to be truncated, as indicated by the <code>...</code>. See the next flag for additional control of the abbreviated text.</p>
</dd>
<dt id="cscb-or---closing-side-comments-balanced"><b>-cscb</b>, or <b>--closing-side-comments-balanced</b></dt>
<dd>
<p>As discussed in the previous item, when the closing-side-comment-maximum-text limit is exceeded the comment text must be truncated. Older versions of perltidy terminated with three dots, and this can still be achieved with -ncscb:</p>
<pre><code> perltidy -csc -ncscb
} ## end foreach my $foo (sort { $b cmp $a ...</code></pre>
<p>However this causes a problem with editors which cannot recognize comments or are not configured to do so because they cannot "bounce" around in the text correctly. The <b>-cscb</b> flag has been added to help them by appending appropriate balancing structure:</p>
<pre><code> perltidy -csc -cscb
} ## end foreach my $foo (sort { $b cmp $a ... })</code></pre>
<p>The default is <b>-cscb</b>.</p>
</dd>
<dt id="csce-n-or---closing-side-comment-else-flag-n"><b>-csce=n</b>, or <b>--closing-side-comment-else-flag=n</b></dt>
<dd>
<p>The default, <b>n=0</b>, places the text of the opening <code>if</code> statement after any terminal <code>else</code>.</p>
<p>If <b>n=2</b> is used, then each <code>elsif</code> is also given the text of the opening <code>if</code> statement. Also, an <code>else</code> will include the text of a preceding <code>elsif</code> statement. Note that this may result some long closing side comments.</p>
<p>If <b>n=1</b> is used, the results will be the same as <b>n=2</b> whenever the resulting line length is less than the maximum allowed.</p>
</dd>
<dt id="cscb-or---closing-side-comments-balanced1"><b>-cscb</b>, or <b>--closing-side-comments-balanced</b></dt>
<dd>
<p>When using closing-side-comments, and the closing-side-comment-maximum-text limit is exceeded, then the comment text must be abbreviated. It is terminated with three dots if the <b>-cscb</b> flag is negated:</p>
<pre><code> perltidy -csc -ncscb
} ## end foreach my $foo (sort { $b cmp $a ...</code></pre>
<p>This causes a problem with older editors which do not recognize comments because they cannot "bounce" around in the text correctly. The <b>-cscb</b> flag tries to help them by appending appropriate terminal balancing structures:</p>
<pre><code> perltidy -csc -cscb
} ## end foreach my $foo (sort { $b cmp $a ... })</code></pre>
<p>The default is <b>-cscb</b>.</p>
</dd>
<dt id="cscw-or---closing-side-comment-warnings"><b>-cscw</b>, or <b>--closing-side-comment-warnings</b></dt>
<dd>
<p>This parameter is intended to help make the initial transition to the use of closing side comments. It causes two things to happen if a closing side comment replaces an existing, different closing side comment: first, an error message will be issued, and second, the original side comment will be placed alone on a new specially marked comment line for later attention.</p>
<p>The intent is to avoid clobbering existing hand-written side comments which happen to match the pattern of closing side comments. This flag should only be needed on the first run with <b>-csc</b>.</p>
</dd>
</dl>
<p><b>Important Notes on Closing Side Comments:</b></p>
<ul>
<li><p>Closing side comments are only placed on lines terminated with a closing brace. Certain closing styles, such as the use of cuddled elses (<b>-ce</b>), preclude the generation of some closing side comments.</p>
</li>
<li><p>Please note that adding or deleting of closing side comments takes place only through the commands <b>-csc</b> or <b>-dcsc</b>. The other commands, if used, merely modify the behavior of these two commands.</p>
</li>
<li><p>It is recommended that the <b>-cscw</b> flag be used along with <b>-csc</b> on the first use of perltidy on a given file. This will prevent loss of any existing side comment data which happens to have the csc prefix.</p>
</li>
<li><p>Once you use <b>-csc</b>, you should continue to use it so that any closing side comments remain correct as code changes. Otherwise, these comments will become incorrect as the code is updated.</p>
</li>
<li><p>If you edit the closing side comments generated by perltidy, you must also change the prefix to be different from the closing side comment prefix. Otherwise, your edits will be lost when you rerun perltidy with <b>-csc</b>. For example, you could simply change <code>## end</code> to be <code>## End</code>, since the test is case sensitive. You may also want to use the <b>-ssc</b> flag to keep these modified closing side comments spaced the same as actual closing side comments.</p>
</li>
<li><p>Temporarily generating closing side comments is a useful technique for exploring and/or debugging a perl script, especially one written by someone else. You can always remove them with <b>-dcsc</b>.</p>
</li>
</ul>
</dd>
<dt id="Static-Block-Comments"><b>Static Block Comments</b></dt>
<dd>
<p>Static block comments are block comments with a special leading pattern, <code>##</code> by default, which will be treated slightly differently from other block comments. They effectively behave as if they had glue along their left and top edges, because they stick to the left edge and previous line when there is no blank spaces in those places. This option is particularly useful for controlling how commented code is displayed.</p>
<dl>
<dt id="sbc---static-block-comments"><b>-sbc</b>, <b>--static-block-comments</b></dt>
<dd>
<p>When <b>-sbc</b> is used, a block comment with a special leading pattern, <code>##</code> by default, will be treated specially.</p>
<p>Comments so identified are treated as follows:</p>
<ul>
<li><p>If there is no leading space on the line, then the comment will not be indented, and otherwise it may be,</p>
</li>
<li><p>no new blank line will be inserted before such a comment, and</p>
</li>
<li><p>such a comment will never become a hanging side comment.</p>
</li>
</ul>
<p>For example, assuming <code>@month_of_year</code> is left-adjusted:</p>
<pre><code> @month_of_year = ( # -sbc (default)
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
## 'Dec', 'Nov'
'Nov', 'Dec');</code></pre>
<p>Without this convention, the above code would become</p>
<pre><code> @month_of_year = ( # -nsbc
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
## 'Dec', 'Nov'
'Nov', 'Dec'
);</code></pre>
<p>which is not as clear. The default is to use <b>-sbc</b>. This may be deactivated with <b>-nsbc</b>.</p>
</dd>
<dt id="sbcp-string---static-block-comment-prefix-string"><b>-sbcp=string</b>, <b>--static-block-comment-prefix=string</b></dt>
<dd>
<p>This parameter defines the prefix used to identify static block comments when the <b>-sbc</b> parameter is set. The default prefix is <code>##</code>, corresponding to <code>-sbcp=##</code>. The prefix is actually part of a perl pattern used to match lines and it must either begin with <code>#</code> or <code>^#</code>. In the first case a prefix ^\s* will be added to match any leading whitespace, while in the second case the pattern will match only comments with no leading whitespace. For example, to identify all comments as static block comments, one would use <code>-sbcp=#</code>. To identify all left-adjusted comments as static block comments, use <code>-sbcp='^#'</code>.</p>
<p>Please note that <b>-sbcp</b> merely defines the pattern used to identify static block comments; it will not be used unless the switch <b>-sbc</b> is set. Also, please be aware that since this string is used in a perl regular expression which identifies these comments, it must enable a valid regular expression to be formed.</p>
<p>A pattern which can be useful is:</p>
<pre><code> -sbcp=^#{2,}[^\s#]</code></pre>
<p>This pattern requires a static block comment to have at least one character which is neither a # nor a space. It allows a line containing only '#' characters to be rejected as a static block comment. Such lines are often used at the start and end of header information in subroutines and should not be separated from the intervening comments, which typically begin with just a single '#'.</p>
</dd>
<dt id="osbc---outdent-static-block-comments"><b>-osbc</b>, <b>--outdent-static-block-comments</b></dt>
<dd>
<p>The command <b>-osbc</b> will cause static block comments to be outdented by the number of <b>--continuation-spaces=n</b>, if possible.</p>
</dd>
</dl>
</dd>
<dt id="Static-Side-Comments"><b>Static Side Comments</b></dt>
<dd>
<p>Static side comments are side comments with a special leading pattern. This option can be useful for controlling how commented code is displayed when it is a side comment.</p>
<dl>
<dt id="ssc---static-side-comments"><b>-ssc</b>, <b>--static-side-comments</b></dt>
<dd>
<p>When <b>-ssc</b> is used, a side comment with a static leading pattern, which is <code>##</code> by default, will be spaced only a single space from previous character, and it will not be vertically aligned with other side comments.</p>
<p>The default is <b>-nssc</b>.</p>
</dd>
<dt id="sscp-string---static-side-comment-prefix-string"><b>-sscp=string</b>, <b>--static-side-comment-prefix=string</b></dt>
<dd>
<p>This parameter defines the prefix used to identify static side comments when the <b>-ssc</b> parameter is set. The default prefix is <code>##</code>, corresponding to <code>-sscp=##</code>.</p>
<p>Please note that <b>-sscp</b> merely defines the pattern used to identify static side comments; it will not be used unless the switch <b>-ssc</b> is set. Also, note that this string is used in a perl regular expression which identifies these comments, so it must enable a valid regular expression to be formed.</p>
</dd>
</dl>
</dd>
</dl>
<h2 id="Skipping-Selected-Sections-of-Code">Skipping Selected Sections of Code</h2>
<p>Selected lines of code may be passed verbatim to the output without any formatting by marking the starting and ending lines with special comments. There are two options for doing this. The first option is called <b>--format-skipping</b> or <b>-fs</b>, and the second option is called <b>--code-skipping</b> or <b>-cs</b>.</p>
<p>In both cases the lines of code will be output without any changes. The difference is that in <b>--format-skipping</b> perltidy will still parse the marked lines of code and check for errors, whereas in <b>--code-skipping</b> perltidy will simply pass the lines to the output without any checking.</p>
<p>Both of these features are enabled by default and are invoked with special comment markers. <b>--format-skipping</b> uses starting and ending markers '#<<<' and '#>>>', like this:</p>
<pre><code> #<<< format skipping: do not let perltidy change my nice formatting
my @list = (1,
1, 1,
1, 2, 1,
1, 3, 3, 1,
1, 4, 6, 4, 1,);
#>>></code></pre>
<p><b>--code-skipping</b> uses starting and ending markers '#<<V' and '#>>V', like this:</p>
<pre><code> #<<V code skipping: perltidy passes this verbatim, no error checking
token ident_digit {
[ [ <?word> | _ | <?digit> ] <?ident_digit>
| <''>
]
};
#>>V</code></pre>
<p>(The last character V is like a < or > rotated 90 degrees). Additional text may appear on the special comment lines provided that it is separated from the marker by at least one space to highlight the sign, as in the above examples.</p>
<p>Any number of code-skipping or format-skipping sections may appear in a file. If an opening code-skipping or format-skipping comment is not followed by a corresponding closing comment, then skipping continues to the end of the file. If a closing code-skipping or format-skipping comment appears in a file but does not follow a corresponding opening comment, then it is treated as an ordinary comment without any special meaning.</p>
<p>It is recommended to use <b>--code-skipping</b> only if you need to hide a block of an extended syntax which would produce errors if parsed by perltidy, and use <b>--format-skipping</b> otherwise. This is because the <b>--format-skipping</b> option provides the benefits of error checking, and there are essentially no limitations on which lines to which it can be applied. The <b>--code-skipping</b> option, on the other hand, does not do error checking and its use is more restrictive because the code which remains, after skipping the marked lines, must be syntactically correct code with balanced containers.</p>
<p>These features should be used sparingly to avoid littering code with markers, but they can be helpful for working around occasional problems.</p>
<p>Note that it may be possible to avoid the use of <b>--format-skipping</b> for the specific case of a comma-separated list of values, as in the above example, by simply inserting a blank or comment somewhere between the opening and closing parens. See the section <a href="#Controlling-List-Formatting">"Controlling List Formatting"</a>.</p>
<p>The following sections describe the available controls for these options. They should not normally be needed.</p>
<dl>
<dt id="fs---format-skipping"><b>-fs</b>, <b>--format-skipping</b></dt>
<dd>
<p>As explained above, this flag, which is enabled by default, causes any code between special beginning and ending comment markers to be passed to the output without formatting. The code between the comments is still checked for errors however. The default beginning marker is #<<< and the default ending marker is #>>>.</p>
<p>Format skipping begins when a format skipping beginning comment is seen and continues until a format-skipping ending comment is found.</p>
<p>This feature can be disabled with <b>-nfs</b>. This should not normally be necessary.</p>
</dd>
<dt id="fsb-string---format-skipping-begin-string"><b>-fsb=string</b>, <b>--format-skipping-begin=string</b></dt>
<dd>
<p>This and the next parameter allow the special beginning and ending comments to be changed. However, it is recommended that they only be changed if there is a conflict between the default values and some other use. If they are used, it is recommended that they only be entered in a <b>.perltidyrc</b> file, rather than on a command line. This is because properly escaping these parameters on a command line can be difficult.</p>
<p>If changed comment markers do not appear to be working, use the <b>-log</b> flag and examine the <i>.LOG</i> file to see if and where they are being detected.</p>
<p>The <b>-fsb=string</b> parameter may be used to change the beginning marker for format skipping. The default is equivalent to -fsb='#<<<'. The string that you enter must begin with a # and should be in quotes as necessary to get past the command shell of your system. It is actually the leading text of a pattern that is constructed by appending a '\s', so you must also include backslashes for characters to be taken literally rather than as patterns.</p>
<p>Some examples show how example strings become patterns:</p>
<pre><code> -fsb='#\{\{\{' becomes /^#\{\{\{\s/ which matches #{{{ but not #{{{{
-fsb='#\*\*' becomes /^#\*\*\s/ which matches #** but not #***
-fsb='#\*{2,}' becomes /^#\*{2,}\s/ which matches #** and #*****</code></pre>
</dd>
<dt id="fse-string---format-skipping-end-string"><b>-fse=string</b>, <b>--format-skipping-end=string</b></dt>
<dd>
<p>The <b>-fse=string</b> is the corresponding parameter used to change the ending marker for format skipping. The default is equivalent to -fse='#<<<'.</p>
<p>The beginning and ending strings may be the same, but it is preferable to make them different for clarity.</p>
</dd>
<dt id="cs---code-skipping"><b>-cs</b>, <b>--code-skipping</b></dt>
<dd>
<p>As explained above, this flag, which is enabled by default, causes any code between special beginning and ending comment markers to be directly passed to the output without any error checking or formatting. Essentially, perltidy treats it as if it were a block of arbitrary text. The default beginning marker is #<<V and the default ending marker is #>>V.</p>
<p>This feature can be disabled with <b>-ncs</b>. This should not normally be necessary.</p>
</dd>
<dt id="csb-string---code-skipping-begin-string"><b>-csb=string</b>, <b>--code-skipping-begin=string</b></dt>
<dd>
<p>This may be used to change the beginning comment for a <b>--code-skipping</b> section, and its use is similar to the <b>-fsb=string</b>. The default is equivalent to -csb='#<<V'.</p>
</dd>
<dt id="cse-string---code-skipping-end-string"><b>-cse=string</b>, <b>--code-skipping-end=string</b></dt>
<dd>
<p>This may be used to change the ending comment for a <b>--code-skipping</b> section, and its use is similar to the <b>-fse=string</b>. The default is equivalent to -cse='#>>V'.</p>
</dd>
</dl>
<h2 id="Formatting-a-Limited-Range-of-Lines">Formatting a Limited Range of Lines</h2>
<p>A command <b>--line-range-tidy=n1:n2</b> is available to process just a selected range of lines of an input stream with perltidy. This command is mainly of interest for programming interactive code editors. When it is used, the entire input stream is read but just the selected range of lines of the input file are processed by the perltidy tokenizer and formatter, and then the stream is reassembled for output. The selected lines need to contain a complete statement or balanced container. Otherwise, a syntax error will occur and the code will not be tidied. There are a couple of limitations on the use of this command: (1) it may not be applied to multiple files, and (2) it only applies to code tidying and not, for example, html formatting.</p>
<dl>
<dt id="lrt-n1:n2---line-range-tidy-n1:n2"><b>-lrt=n1:n2</b>, <b>--line-range-tidy=n1:n2</b></dt>
<dd>
<p>The range of lines is specified by integers <b>n1</b> and <b>n2</b>, where <b>n1</b> is the first line number to be formatted (start counting with 1) and <b>n2</b> is the last line number to be formatted. If <b>n2</b> is not given, or exceeds the actual number of lines, then formatting continues to the end of the file.</p>
<p>Examples:</p>
<pre><code> --line-range-tidy=43:109 # tidy lines 43 through 109
--line-range-tidy=' 43 : 109' # tidy lines 43 through 109
--line-range-tidy=1: # tidy all lines
--line-range-tidy=0:90 # ERROR (n1 must be >= 1)</code></pre>
<p>The second example shows that spaces are okay if placed in quotes.</p>
</dd>
</dl>
<h2 id="Line-Break-Control">Line Break Control</h2>
<p>The parameters in this and the next sections control breaks after non-blank lines of code. Blank lines are controlled separately by parameters in the section <a href="#Blank-Line-Control">"Blank Line Control"</a>.</p>
<dl>
<dt id="dnl---delete-old-newlines"><b>-dnl</b>, <b>--delete-old-newlines</b></dt>
<dd>
<p>By default, perltidy first deletes all old line break locations, and then it looks for good break points to match the desired line length. Use <b>-ndnl</b> or <b>--nodelete-old-newlines</b> to force perltidy to retain all old line break points.</p>
</dd>
<dt id="anl---add-newlines"><b>-anl</b>, <b>--add-newlines</b></dt>
<dd>
<p>By default, perltidy will add line breaks when necessary to create continuations of long lines and to improve the script appearance. Use <b>-nanl</b> or <b>--noadd-newlines</b> to prevent any new line breaks.</p>
<p>This flag does not prevent perltidy from eliminating existing line breaks; see <b>--freeze-newlines</b> to completely prevent changes to line break points.</p>
</dd>
<dt id="fnl---freeze-newlines"><b>-fnl</b>, <b>--freeze-newlines</b></dt>
<dd>
<p>If you do not want any changes to the line breaks within lines of code in your script, set <b>-fnl</b>, and they will remain fixed, and the rest of the commands in this section and sections <a href="#Controlling-List-Formatting">"Controlling List Formatting"</a>, <a href="#Retaining-or-Ignoring-Existing-Line-Breaks">"Retaining or Ignoring Existing Line Breaks"</a>. You may want to use <b>--nooutdent-long-lines</b> with this.</p>
<p>Note: If you also want to keep your blank lines exactly as they are, you can use the <b>--freeze-blank-lines</b> flag which is described in the section <a href="#Blank-Line-Control">"Blank Line Control"</a>.</p>
</dd>
</dl>
<h2 id="Controlling-Breaks-at-Braces-Parens-and-Square-Brackets">Controlling Breaks at Braces, Parens, and Square Brackets</h2>
<dl>
<dt id="ce---cuddled-else"><b>-ce</b>, <b>--cuddled-else</b></dt>
<dd>
<p>Enable the "cuddled else" style, in which <code>else</code> and <code>elsif</code> are follow immediately after the curly brace closing the previous block. The default is not to use cuddled elses, and is indicated with the flag <b>-nce</b> or <b>--nocuddled-else</b>. Here is a comparison of the alternatives:</p>
<pre><code> # -ce
if ($task) {
yyy();
} else {
zzz();
}
# -nce (default)
if ($task) {
yyy();
}
else {
zzz();
}</code></pre>
<p>In this example the keyword <b>else</b> is placed on the same line which begins with the preceding closing block brace and is followed by its own opening block brace on the same line. Other keywords and function names which are formatted with this "cuddled" style are <b>elsif</b>, <b>continue</b>, <b>catch</b>, <b>finally</b>.</p>
<p>Other block types can be formatted by specifying their names on a separate parameter <b>--cuddled-block-list</b>, described in a later section.</p>
<p>Cuddling between a pair of code blocks requires that the closing brace of the first block start a new line. If this block is entirely on one line in the input file, it is necessary to decide if it should be broken to allow cuddling. This decision is controlled by the flag <b>--cuddled-break-options=n</b> (<b>-cbo=n</b>) discussed below. The default and recommended value of <b>-cbo=1</b> bases this decision on the first block in the chain. If it spans multiple lines then cuddling is made and continues along the chain, regardless of the sizes of subsequent blocks. Otherwise, short lines remain intact.</p>
<p>So for example, the <b>--cuddled-else</b> flag would not have any effect if the above snippet is rewritten as</p>
<pre><code> if ($task) { yyy() }
else { zzz() }</code></pre>
<p>If the first block spans multiple lines, then cuddling can be done and will continue for the subsequent blocks in the chain, as illustrated in the previous snippet.</p>
<p>If there are blank lines between cuddled blocks they will be eliminated. If there are comments after the closing brace where cuddling would occur then cuddling will be prevented. If this occurs, cuddling will restart later in the chain if possible.</p>
</dd>
<dt id="cb---cuddled-blocks"><b>-cb</b>, <b>--cuddled-blocks</b></dt>
<dd>
<p>This flag is equivalent to <b>--cuddled-else</b> (<b>-ce</b>).</p>
</dd>
<dt id="cbl---cuddled-block-list"><b>-cbl</b>, <b>--cuddled-block-list</b></dt>
<dd>
<p>The built-in default cuddled block types are <b>else, elsif, continue, catch, finally</b>.</p>
<p>Additional block types to which the <b>--cuddled-blocks</b> style applies can be defined by this parameter. This parameter is a character string, giving a list of block types separated by commas or spaces. For example, to cuddle code blocks of type sort, map and grep, in addition to the default types, the string could be set to</p>
<pre><code> -cbl="sort map grep"</code></pre>
<p>or equivalently</p>
<pre><code> -cbl=sort,map,grep</code></pre>
<p>Note however that these particular block types are typically short so there might not be much opportunity for the cuddled format style.</p>
<p>Using commas avoids the need to protect spaces with quotes.</p>
<p>As a diagnostic check, the flag <b>--dump-cuddled-block-list</b> or <b>-dcbl</b> can be used to view the hash of values that are generated by this flag.</p>
<p>Finally, note that the <b>--cuddled-block-list</b> parameter by itself merely specifies which blocks are formatted with the cuddled format. It has no effect unless this formatting style is activated with <b>--cuddled-else</b>.</p>
</dd>
<dt id="cblx---cuddled-block-list-exclusive"><b>-cblx</b>, <b>--cuddled-block-list-exclusive</b></dt>
<dd>
<p>When cuddled else formatting is selected with <b>--cuddled-else</b>, setting this flag causes perltidy to ignore its built-in defaults and rely exclusively on the block types specified on the <b>--cuddled-block-list</b> flag described in the previous section. For example, to avoid using cuddled <b>catch</b> and <b>finally</b>, which are among the defaults, the following set of parameters could be used:</p>
<pre><code> perltidy -ce -cbl='else elsif continue' -cblx</code></pre>
</dd>
<dt id="cbo-n---cuddled-break-option-n"><b>-cbo=n</b>, <b>--cuddled-break-option=n</b></dt>
<dd>
<p>Cuddled formatting is only possible between a pair of code blocks if the closing brace of the first block starts a new line. If a block is encountered which is entirely on a single line, and cuddled formatting is selected, it is necessary to make a decision as to whether or not to "break" the block, meaning to cause it to span multiple lines. This parameter controls that decision. The options are:</p>
<pre><code> cbo=0 Never force a short block to break.
cbo=1 If the first of a pair of blocks is broken in the input
file, then break the second [DEFAULT].
cbo=2 Break open all blocks for maximal cuddled formatting.</code></pre>
<p>The default and recommended value is <b>cbo=1</b>. With this value, if the starting block of a chain spans multiple lines, then a cascade of breaks will occur for remaining blocks causing the entire chain to be cuddled.</p>
<p>The option <b>cbo=0</b> can produce erratic cuddling if there are numerous one-line blocks.</p>
<p>The option <b>cbo=2</b> produces maximal cuddling but will not allow any short blocks.</p>
</dd>
<dt id="bl---opening-brace-on-new-line-or---brace-left"><b>-bl</b>, <b>--opening-brace-on-new-line</b>, or <b>--brace-left</b></dt>
<dd>
<p>Use the flag <b>-bl</b> to place an opening block brace on a new line:</p>
<pre><code> if ( $input_file eq '-' )
{
...
}</code></pre>
<p>By default it applies to all structural blocks except <b>sort map grep eval</b> and anonymous subs.</p>
<p>The default is <b>-nbl</b> which places an opening brace on the same line as the keyword introducing it if possible. For example,</p>
<pre><code> # default
if ( $input_file eq '-' ) {
...
}</code></pre>
<p>When <b>-bl</b> is set, the blocks to which this applies can be controlled with the parameters <b>--brace-left-list</b> and <b>--brace-left-exclusion-list</b> described in the next sections.</p>
</dd>
<dt id="bll-s---brace-left-list-s"><b>-bll=s</b>, <b>--brace-left-list=s</b></dt>
<dd>
<p>Use this parameter to change the types of block braces for which the <b>-bl</b> flag applies; see <a href="#Specifying-Block-Types">"Specifying Block Types"</a>. For example, <b>-bll='if elsif else sub'</b> would apply it to only <code>if/elsif/else</code> and named sub blocks. The default is all blocks, <b>-bll='*'</b>.</p>
</dd>
<dt id="blxl-s---brace-left-exclusion-list-s"><b>-blxl=s</b>, <b>--brace-left-exclusion-list=s</b></dt>
<dd>
<p>Use this parameter to exclude types of block braces for which the <b>-bl</b> flag applies; see <a href="#Specifying-Block-Types">"Specifying Block Types"</a>. For example, the default settings <b>-bll='*'</b> and <b>-blxl='sort map grep eval asub'</b> mean all blocks except <b>sort map grep eval</b> and anonymous sub blocks.</p>
<p>Note that the lists <b>-bll=s</b> and <b>-blxl=s</b> control the behavior of the <b>-bl</b> flag but have no effect unless the <b>-bl</b> flag is set. These two lists provide complete control for this flag, but two shortcut flags are available and described in the next sections.</p>
</dd>
<dt id="sbl---opening-sub-brace-on-new-line"><b>-sbl</b>, <b>--opening-sub-brace-on-new-line</b></dt>
<dd>
<p>The flag <b>-sbl</b> provides a shortcut way to turn on <b>-bl</b> just for named subs. The same effect can be achieved by turning on <b>-bl</b> with the block list set as <b>-bll='sub'</b>. To avoid conflicts, it is recommended to either use the more general list method described above to control <b>-bl</b>, or this shortcut method, but not both.</p>
<p>For example,</p>
<pre><code> perltidy -sbl</code></pre>
<p>produces this result:</p>
<pre><code> sub message
{
if (!defined($_[0])) {
print("Hello, World\n");
}
else {
print($_[0], "\n");
}
}</code></pre>
<p>This negative version of this flag, <b>-nsbl</b>, turns off <b>-bl</b> for named subs. The same effect can be achieved with the exclusion list method, <b>-blxl=sub</b>.</p>
</dd>
<dt id="asbl---opening-anonymous-sub-brace-on-new-line"><b>-asbl</b>, <b>--opening-anonymous-sub-brace-on-new-line</b></dt>
<dd>
<p>The flag <b>-asbl</b> is like the <b>-sbl</b> flag except that it applies to anonymous sub's instead of named subs. The same effect can be achieved by turning on <b>-bl</b> with the block list set to include <b>-bll='asub'</b>.</p>
<p>For example</p>
<pre><code> perltidy -asbl</code></pre>
<p>produces this result:</p>
<pre><code> $a = sub
{
if ( !defined( $_[0] ) ) {
print("Hello, World\n");
}
else {
print( $_[0], "\n" );
}
};</code></pre>
<p>This negative version of this flag, <b>-nasbl</b>, turns off <b>-bl</b> for anonymous subs.</p>
</dd>
<dt id="bli---brace-left-and-indent"><b>-bli</b>, <b>--brace-left-and-indent</b></dt>
<dd>
<p>The flag <b>-bli</b> is similar to the <b>-bl</b> flag but in addition it causes one unit of continuation indentation ( see <b>--continuation-indentation</b> ) to be placed before an opening and closing block braces.</p>
<p>For example</p>
<pre><code> # perltidy -bli
if ( $input_file eq '-' )
{
important_function();
}</code></pre>
<p>By default, this extra indentation occurs for block types: <b>if</b>, <b>elsif</b>, <b>else</b>, <b>unless</b>, <b>while</b>, <b>for</b>, <b>foreach</b>, <b>do</b>, and also <b>named subs</b> and blocks preceded by a <b>label</b>. The next item shows how to change this.</p>
<p><b>Note</b>: The <b>-bli</b> flag is similar to the <b>-bl</b> flag, with the difference being that braces get indented. But these two flags are implemented independently, and have different default settings for historical reasons. If desired, a mixture of effects can be achieved if desired by turning them both on with different <b>-list</b> settings. In the event that both settings are selected for a certain block type, the <b>-bli</b> style has priority.</p>
</dd>
<dt id="blil-s---brace-left-and-indent-list-s"><b>-blil=s</b>, <b>--brace-left-and-indent-list=s</b></dt>
<dd>
<p>Use this parameter to change the types of block braces for which the <b>-bli</b> flag applies; see <a href="#Specifying-Block-Types">"Specifying Block Types"</a>.</p>
<p>The default is <b>-blil='if else elsif unless while for foreach do : sub'</b>.</p>
</dd>
<dt id="blixl-s---brace-left-and-indent-exclusion-list-s"><b>-blixl=s</b>, <b>--brace-left-and-indent-exclusion-list=s</b></dt>
<dd>
<p>Use this parameter to exclude types of block braces for which the <b>-bli</b> flag applies; see <a href="#Specifying-Block-Types">"Specifying Block Types"</a>.</p>
<p>This might be useful in conjunction with selecting all blocks <b>-blil='*'</b>. The default setting is <b>-blixl=' '</b>, which does not exclude any blocks.</p>
<p>Note that the two parameters <b>-blil</b> and <b>-blixl</b> control the behavior of the <b>-bli</b> flag but have no effect unless the <b>-bli</b> flag is set.</p>
</dd>
<dt id="bar---opening-brace-always-on-right"><b>-bar</b>, <b>--opening-brace-always-on-right</b></dt>
<dd>
<p>The default style, <b>-nbl</b> places the opening code block brace on a new line if it does not fit on the same line as the opening keyword, like this:</p>
<pre><code> if ( $bigwasteofspace1 && $bigwasteofspace2
|| $bigwasteofspace3 && $bigwasteofspace4 )
{
big_waste_of_time();
}</code></pre>
<p>To force the opening brace to always be on the right, use the <b>-bar</b> flag. In this case, the above example becomes</p>
<pre><code> if ( $bigwasteofspace1 && $bigwasteofspace2
|| $bigwasteofspace3 && $bigwasteofspace4 ) {
big_waste_of_time();
}</code></pre>
<p>A conflict occurs if both <b>--opening-brace-on_new-line</b> (<b>-bl</b>) and <b>-bar</b> are specified.</p>
</dd>
<dt id="cpb---cuddled-paren-brace"><b>-cpb</b>, <b>--cuddled-paren-brace</b></dt>
<dd>
<p>A related parameter, <b>--cuddled-paren-brace</b>, causes perltidy to join two lines which otherwise would be</p>
<pre><code> )
{</code></pre>
<p>to be</p>
<pre><code> ) {</code></pre>
<p>For example:</p>
<pre><code> # default
foreach my $dir (
'05_lexer', '07_token', '08_regression', '11_util',
'13_data', '15_transform'
)
{
...
}
# perltidy -cpb
foreach my $dir (
'05_lexer', '07_token', '08_regression', '11_util',
'13_data', '15_transform'
) {
...;
}</code></pre>
</dd>
<dt id="otr---opening-token-right-and-related-flags"><b>-otr</b>, <b>--opening-token-right</b> and related flags</dt>
<dd>
<p>The <b>-otr</b> flag is a hint that perltidy should not place a break between a comma and an opening token. For example:</p>
<pre><code> # default formatting
push @{ $self->{$module}{$key} },
{
accno => $ref->{accno},
description => $ref->{description}
};
# perltidy -otr
push @{ $self->{$module}{$key} }, {
accno => $ref->{accno},
description => $ref->{description}
};</code></pre>
<p>The flag <b>-otr</b> is actually an abbreviation for three other flags which can be used to control parens, hash braces, and square brackets separately if desired:</p>
<pre><code> -opr or --opening-paren-right
-ohbr or --opening-hash-brace-right
-osbr or --opening-square-bracket-right</code></pre>
</dd>
<dt id="bbhb-n---break-before-hash-brace-n-and-related-flags"><b>-bbhb=n</b>, <b>--break-before-hash-brace=n</b> and related flags</dt>
<dd>
<p>When a list of items spans multiple lines, the default formatting is to place the opening brace (or other container token) at the end of the starting line, like this:</p>
<pre><code> $romanNumerals = {
one => 'I',
two => 'II',
three => 'III',
four => 'IV',
};</code></pre>
<p>This flag can change the default behavior to cause a line break to be placed before the opening brace according to the value given to the integer <b>n</b>:</p>
<pre><code> -bbhb=0 never break [default]
-bbhb=1 stable: break if the input script had a break
-bbhb=2 break if list is 'complex' (see note below)
-bbhb=3 always break</code></pre>
<p>For example,</p>
<pre><code> # perltidy -bbhb=3
$romanNumerals =
{
one => 'I',
two => 'II',
three => 'III',
four => 'IV',
};</code></pre>
<p>There are several points to note about this flag:</p>
<ul>
<li><p>This parameter only applies if the opening brace is preceded by an '=' or '=>'.</p>
</li>
<li><p>This parameter only applies if the contents of the container looks like a list. The contents need to contain some commas or '=>'s at the next interior level to be considered a list.</p>
</li>
<li><p>For the <b>n=2</b> option, a list is considered 'complex' if it is part of a nested list structure which spans multiple lines in the input file.</p>
</li>
<li><p>If multiple opening tokens have been 'welded' together with the <b>-wn</b> parameter, then this parameter has no effect.</p>
</li>
<li><p>The indentation of the braces will normally be one level of continuation indentation by default. This can be changed with the parameter <b>-bbhbi=n</b> in the next section.</p>
</li>
<li><p>Similar flags for controlling parens and square brackets are given in the subsequent section.</p>
</li>
</ul>
</dd>
<dt id="bbhbi-n---break-before-hash-brace-and-indent-n"><b>-bbhbi=n</b>, <b>--break-before-hash-brace-and-indent=n</b></dt>
<dd>
<p>This flag is a companion to <b>-bbhb=n</b> for controlling the indentation of an opening hash brace which is placed on a new line by that parameter. The indentation is as follows:</p>
<pre><code> -bbhbi=0 one continuation level [default]
-bbhbi=1 outdent by one continuation level
-bbhbi=2 indent one full indentation level</code></pre>
<p>For example:</p>
<pre><code> # perltidy -bbhb=3 -bbhbi=1
$romanNumerals =
{
one => 'I',
two => 'II',
three => 'III',
four => 'IV',
};
# perltidy -bbhb=3 -bbhbi=2
$romanNumerals =
{
one => 'I',
two => 'II',
three => 'III',
four => 'IV',
};</code></pre>
<p>Note that this parameter has no effect unless <b>-bbhb=n</b> is also set.</p>
</dd>
<dt id="bbsb-n---break-before-square-bracket-n"><b>-bbsb=n</b>, <b>--break-before-square-bracket=n</b></dt>
<dd>
<p>This flag is similar to the flag described above, except it applies to lists contained within square brackets.</p>
<pre><code> -bbsb=0 never break [default]
-bbsb=1 stable: break if the input script had a break
-bbsb=2 break if list is 'complex' (part of nested list structure)
-bbsb=3 always break</code></pre>
</dd>
<dt id="bbsbi-n---break-before-square-bracket-and-indent-n"><b>-bbsbi=n</b>, <b>--break-before-square-bracket-and-indent=n</b></dt>
<dd>
<p>This flag is a companion to <b>-bbsb=n</b> for controlling the indentation of an opening square bracket which is placed on a new line by that parameter. The indentation is as follows:</p>
<pre><code> -bbsbi=0 one continuation level [default]
-bbsbi=1 outdent by one continuation level
-bbsbi=2 indent one full indentation level</code></pre>
</dd>
<dt id="bbp-n---break-before-paren-n"><b>-bbp=n</b>, <b>--break-before-paren=n</b></dt>
<dd>
<p>This flag is similar to <b>-bbhb=n</b>, described above, except it applies to lists contained within parens.</p>
<pre><code> -bbp=0 never break [default]
-bbp=1 stable: break if the input script had a break
-bpb=2 break if list is 'complex' (part of nested list structure)
-bbp=3 always break</code></pre>
</dd>
<dt id="bbpi-n---break-before-paren-and-indent-n"><b>-bbpi=n</b>, <b>--break-before-paren-and-indent=n</b></dt>
<dd>
<p>This flag is a companion to <b>-bbp=n</b> for controlling the indentation of an opening paren which is placed on a new line by that parameter. The indentation is as follows:</p>
<pre><code> -bbpi=0 one continuation level [default]
-bbpi=1 outdent by one continuation level
-bbpi=2 indent one full indentation level</code></pre>
</dd>
<dt id="bfvt-n---brace-follower-vertical-tightness-n"><b>-bfvt=n</b>, <b>--brace-follower-vertical-tightness=n</b></dt>
<dd>
<p>Some types of closing block braces, such as <b>eval</b>, may be followed by additional code. A line break may be inserted between such a closing brace and the following code depending on the parameter <b>n</b> and the length of the trailing code, as follows:</p>
<p>If the trailing code fits on a single line, then</p>
<pre><code> -bfvt=0 Follow the input style regarding break/no-break
-bfvt=1 Follow the input style regarding break/no-break [Default]
-bfvt=2 Do not insert a line break</code></pre>
<p>If the trailing code requires multiple lines, then</p>
<pre><code> -bfvt=0 Insert a line break
-bfvt=1 Insert a line break except for a cuddled block chain
-bfvt=2 Do not insert a line break</code></pre>
<p>The default is <b>-bfvt=1</b>. The most compact code is achieved with <b>-bfvt=2</b>.</p>
<p>Example (non-cuddled, multiple lines ):</p>
<pre><code> # -bfvt=0 or -bvft=1 [DEFAULT]
eval {
( $line, $cond ) = $self->_normalize_if_elif($line);
1;
}
or die sprintf "Error at line %d\nLine %d: %s\n%s",
( $line_info->start_line_num() ) x 2, $line, $@;
# -bfvt=2
eval {
( $line, $cond ) = $self->_normalize_if_elif($line);
1;
} or die sprintf "Error at line %d\nLine %d: %s\n%s",
( $line_info->start_line_num() ) x 2, $line, $@;</code></pre>
<p>Example (cuddled, multiple lines):</p>
<pre><code> # -bfvt=0
eval {
#STUFF;
1; # return true
}
or do {
##handle error
};
# -bfvt=1 [DEFAULT] or -bfvt=2
eval {
#STUFF;
1; # return true
} or do {
##handle error
};</code></pre>
</dd>
</dl>
<h2 id="Welding">Welding</h2>
<dl>
<dt id="wn---weld-nested-containers"><b>-wn</b>, <b>--weld-nested-containers</b></dt>
<dd>
<p>The <b>-wn</b> flag causes closely nested pairs of opening and closing container symbols (curly braces, brackets, or parens) to be "welded" together, meaning that they are treated as if combined into a single unit, with the indentation of the innermost code reduced to be as if there were just a single container symbol.</p>
<p>For example:</p>
<pre><code> # default formatting
do {
{
next if $x == $y;
}
} until $x++ > $z;
# perltidy -wn
do { {
next if $x == $y;
} } until $x++ > $z;</code></pre>
<p>When this flag is set perltidy makes a preliminary pass through the file and identifies all nested pairs of containers. To qualify as a nested pair, the closing container symbols must be immediately adjacent and the opening symbols must either (1) be adjacent as in the above example, or (2) have an anonymous sub declaration following an outer opening container symbol which is not a code block brace, or (3) have an outer opening paren separated from the inner opening symbol by any single non-container symbol or something that looks like a function evaluation, as illustrated in the next examples. An additional option (4) which can be turned on with the flag <b>--weld-fat-comma</b> is when the opening container symbols are separated by a hash key and fat comma (=>).</p>
<p>Any container symbol may serve as both the inner container of one pair and as the outer container of an adjacent pair. Consequently, any number of adjacent opening or closing symbols may join together in weld. For example, here are three levels of wrapped function calls:</p>
<pre><code> # default formatting
my (@date_time) = Localtime(
Date_to_Time(
Add_Delta_DHMS(
$year, $month, $day, $hour, $minute, $second,
'0', $offset, '0', '0'
)
)
);
# perltidy -wn
my (@date_time) = Localtime( Date_to_Time( Add_Delta_DHMS(
$year, $month, $day, $hour, $minute, $second,
'0', $offset, '0', '0'
) ) );</code></pre>
<p>Notice how the indentation of the inner lines are reduced by two levels in this case. This example also shows the typical result of this formatting, namely it is a sandwich consisting of an initial opening layer, a central section of any complexity forming the "meat" of the sandwich, and a final closing layer. This predictable structure helps keep the compacted structure readable.</p>
<p>The inner sandwich layer is required to be at least one line thick. If this cannot be achieved, welding does not occur. This constraint can cause formatting to take a couple of iterations to stabilize when it is first applied to a script. The <b>--converge</b> flag can be used to insure that the final format is achieved in a single run.</p>
<p>Here is an example illustrating a welded container within a welded containers:</p>
<pre><code> # default formatting
$x->badd(
bmul(
$class->new(
abs(
$sx * int( $xr->num() ) & $sy * int( $yr->num() )
)
),
$m
)
);
# perltidy -wn
$x->badd( bmul(
$class->new( abs(
$sx * int( $xr->num() ) & $sy * int( $yr->num() )
) ),
$m
) );</code></pre>
<p>The welded closing tokens are by default on a separate line but this can be modified with the <b>--vertical-tightness-closing=n</b> (<b>-vtc=n</b>) flag (described in the next section). For example, the same example adding <b>-vtc=2</b> is</p>
<pre><code> # perltidy -wn -vtc=2
$x->badd( bmul(
$class->new( abs(
$sx * int( $xr->num() ) & $sy * int( $yr->num() ) ) ),
$m ) );</code></pre>
<p>This format option is quite general but there are some limitations.</p>
<p>One limitation is that any line length limit still applies and can cause long welded sections to be broken into multiple lines.</p>
<p>Also, the stacking of containers defined by this flag have priority over any other container stacking flags. This is because any welding is done first.</p>
</dd>
<dt id="wfc---weld-fat-comma"><b>-wfc</b>, <b>--weld-fat-comma </b></dt>
<dd>
<p>When the <b>-wfc</b> flag is set, along with <b>-wn</b> (<b>--weld-nested-containers</b>), perltidy is allowed to weld an opening paren to an inner opening container when they are separated by a hash key and fat comma (=>). for example</p>
<pre><code> # perltidy -wn -wfc
elf->call_method( method_name_foo => {
some_arg1 => $foo,
some_other_arg3 => $bar->{'baz'},
} );</code></pre>
<p>This option is off by default.</p>
</dd>
<dt id="wnxl-s---weld-nested-exclusion-list"><b>-wnxl=s</b>, <b>--weld-nested-exclusion-list</b></dt>
<dd>
<p>The <b>-wnxl=s</b> flag provides some control over the types of containers which can be welded. The <b>-wn</b> flag by default is "greedy" in welding adjacent containers. If it welds more types of containers than desired, this flag provides a capability to reduce the amount of welding by specifying a list of things which should <b>not</b> be welded.</p>
<p>The logic in perltidy to apply this is straightforward. As each container token is being considered for joining a weld, any exclusion rules are consulted and used to reject the weld if necessary.</p>
<p>This list is a string with space-separated items. Each item consists of up to three pieces of information: (1) an optional position, (2) an optional preceding type, and (3) a container type.</p>
<p>The only required piece of information is a container type, which is one of '(', '[', '{' or 'q'. The first three of these are container tokens and the last represents a quoted list. For example the string</p>
<pre><code> -wnxl='[ { q'</code></pre>
<p>means do <b>NOT</b> include square-brackets, braces, or quotes in any welds. The only unspecified container is '(', so this string means that only welds involving parens will be made.</p>
<p>To illustrate, following welded snippet consists of a chain of three welded containers with types '(' '[' and 'q':</p>
<pre><code> # perltidy -wn
skip_symbols( [ qw(
Perl_dump_fds
Perl_ErrorNo
Perl_GetVars
PL_sys_intern
) ] );</code></pre>
<p>Even though the qw term uses parens as the quote delimiter, it has a special type 'q' here. If it appears in a weld it always appears at the end of the welded chain.</p>
<p>Any of the container types '[', '{', and '(' may be prefixed with a position indicator which is either '^', to indicate the first token of a welded sequence, or '.', to indicate an interior token of a welded sequence. (Since a quoted string 'q' always ends a chain it does need a position indicator).</p>
<p>For example, if we do not want a sequence of welded containers to start with a square bracket we could use</p>
<pre><code> -wnxl='^['</code></pre>
<p>In the above snippet, there is a square bracket but it does not start the chain, so the formatting would be unchanged if it were formatted with this restriction.</p>
<p>A third optional item of information which can be given is an alphanumeric letter which is used to limit the selection further depending on the type of token immediately before the container. If given, it goes just before the container symbol. The possible letters are currently 'k', 'K', 'f', 'F', 'w', and 'W', with these meanings:</p>
<pre><code> 'k' matches if the previous nonblank token is a perl keyword
(such as 'if', 'while'),
'K' matches if 'k' does not: previous token is not a keyword
'f' matches if previous token is a function (not a keyword)
'F' matches if 'f' does not
'w' matches if either 'k' or 'f' match
'W' matches if 'w' does not</code></pre>
<p>For example, compare</p>
<pre><code> # perltidy -wn
if ( defined( $_Cgi_Query{
$Config{'methods'}{'auth'}{'remote'}{'cgi'}{'username'}
} ) )</code></pre>
<p>with</p>
<pre><code> # perltidy -wn -wnxl='^K( {'
if ( defined(
$_Cgi_Query{ $Config{'methods'}{'auth'}{'remote'}{'cgi'}
{'username'} }
) )</code></pre>
<p>The first case does maximum welding. In the second case the leading paren is retained by the rule (it would have been rejected if preceded by a non-keyword) but the curly brace is rejected by the rule.</p>
<p>Here are some additional example strings and their meanings:</p>
<pre><code> '^(' - the weld must not start with a paren
'.(' - second and later tokens may not be parens
'.w(' - second and later tokens may not be a keyword or call parens
'(' - no parens in a weld
'^K(' - exclude a leading paren preceded by a non-keyword
'.k(' - exclude a secondary paren preceded by a keyword
'[ {' - exclude all brackets and braces
'[ ( ^K{' - exclude all except nested structures like do {{ ... }}</code></pre>
</dd>
<dt id="Vertical-tightness-of-non-block-curly-braces-parentheses-and-square-brackets"><b>Vertical tightness</b> of non-block curly braces, parentheses, and square brackets.</dt>
<dd>
<p>These parameters control what shall be called vertical tightness. Here are the main points:</p>
<ul>
<li><p>Opening tokens (except for block braces) are controlled by <b>-vt=n</b>, or <b>--vertical-tightness=n</b>, where</p>
<pre><code> -vt=0 always break a line after opening token (default).
-vt=1 do not break unless this would produce more than one
step in indentation in a line.
-vt=2 never break a line after opening token</code></pre>
</li>
<li><p>You must also use the <b>-lp</b> (<b>--line-up-parentheses</b>) flag when you use the <b>-vt</b> flag; the reason is explained below.</p>
</li>
<li><p>Closing tokens (except for block braces) are controlled by <b>-vtc=n</b>, or <b>--vertical-tightness-closing=n</b>, where</p>
<pre><code> -vtc=0 always break a line before a closing token (default),
-vtc=1 do not break before a closing token which is followed
by a semicolon or another closing token, and is not in
a list environment.
-vtc=2 never break before a closing token.
-vtc=3 Like -vtc=1 except always break before a closing token
if the corresponding opening token follows an = or =>.</code></pre>
<p>The rules for <b>-vtc=1</b> and <b>-vtc=3</b> are designed to maintain a reasonable balance between tightness and readability in complex lists.</p>
</li>
<li><p>Different controls may be applied to different token types, and it is also possible to control block braces; see below.</p>
</li>
<li><p>Finally, please note that these vertical tightness flags are merely hints to the formatter, and it cannot always follow them. Things which make it difficult or impossible include comments, blank lines, blocks of code within a list, and possibly the lack of the <b>--line-up-parentheses</b> parameter. Also, these flags may be ignored for very small lists (2 or 3 lines in length).</p>
</li>
</ul>
<p>Here are some examples:</p>
<pre><code> # perltidy -lp -vt=0 -vtc=0
%romanNumerals = (
one => 'I',
two => 'II',
three => 'III',
four => 'IV',
);
# perltidy -lp -vt=1 -vtc=0
%romanNumerals = ( one => 'I',
two => 'II',
three => 'III',
four => 'IV',
);
# perltidy -lp -vt=1 -vtc=1
%romanNumerals = ( one => 'I',
two => 'II',
three => 'III',
four => 'IV', );
# perltidy -vtc=3
my_function(
one => 'I',
two => 'II',
three => 'III',
four => 'IV', );
# perltidy -vtc=3
%romanNumerals = (
one => 'I',
two => 'II',
three => 'III',
four => 'IV',
);</code></pre>
<p>In the last example for <b>-vtc=3</b>, the opening paren is preceded by an equals so the closing paren is placed on a new line.</p>
<p>The difference between <b>-vt=1</b> and <b>-vt=2</b> is shown here:</p>
<pre><code> # perltidy -lp -vt=1
$init->add(
mysprintf( "(void)find_threadsv(%s);",
cstring( $threadsv_names[ $op->targ ] )
)
);
# perltidy -lp -vt=2
$init->add( mysprintf( "(void)find_threadsv(%s);",
cstring( $threadsv_names[ $op->targ ] )
)
);</code></pre>
<p>With <b>-vt=1</b>, the line ending in <code>add(</code> does not combine with the next line because the next line is not balanced. This can help with readability, but <b>-vt=2</b> can be used to ignore this rule.</p>
<p>The tightest, and least readable, code is produced with both <code>-vt=2</code> and <code>-vtc=2</code>:</p>
<pre><code> # perltidy -lp -vt=2 -vtc=2
$init->add( mysprintf( "(void)find_threadsv(%s);",
cstring( $threadsv_names[ $op->targ ] ) ) );</code></pre>
<p>Notice how the code in all of these examples collapses vertically as <b>-vt</b> increases, but the indentation remains unchanged. This is because perltidy implements the <b>-vt</b> parameter by first formatting as if <b>-vt=0</b>, and then simply overwriting one output line on top of the next, if possible, to achieve the desired vertical tightness. The <b>-lp</b> (<b>--line-up-parentheses</b>) indentation style has been designed to allow this vertical collapse to occur, which is why it is required for the <b>-vt</b> parameter.</p>
<p>The <b>-vt=n</b> and <b>-vtc=n</b> parameters apply to each type of container token. If desired, vertical tightness controls can be applied independently to each of the closing container token types.</p>
<p>The parameters for controlling parentheses are <b>-pvt=n</b> or <b>--paren-vertical-tightness=n</b>, and <b>-pvtc=n</b> or <b>--paren-vertical-tightness-closing=n</b>.</p>
<p>Likewise, the parameters for square brackets are <b>-sbvt=n</b> or <b>--square-bracket-vertical-tightness=n</b>, and <b>-sbvtc=n</b> or <b>--square-bracket-vertical-tightness-closing=n</b>.</p>
<p>Finally, the parameters for controlling non-code block braces are <b>-bvt=n</b> or <b>--brace-vertical-tightness=n</b>, and <b>-bvtc=n</b> or <b>--brace-vertical-tightness-closing=n</b>.</p>
<p>In fact, the parameter <b>-vt=n</b> is actually just an abbreviation for <b>-pvt=n -bvt=n sbvt=n</b>, and likewise <b>-vtc=n</b> is an abbreviation for <b>-pvtc=n -bvtc=n -sbvtc=n</b>.</p>
</dd>
<dt id="bbvt-n-or---block-brace-vertical-tightness-n"><b>-bbvt=n</b> or <b>--block-brace-vertical-tightness=n</b></dt>
<dd>
<p>The <b>-bbvt=n</b> flag is just like the <b>-vt=n</b> flag but applies to opening code block braces.</p>
<pre><code> -bbvt=0 break after opening block brace (default).
-bbvt=1 do not break unless this would produce more than one
step in indentation in a line.
-bbvt=2 do not break after opening block brace.</code></pre>
<p>It is necessary to also use either <b>-bl</b> or <b>-bli</b> for this to work, because, as with other vertical tightness controls, it is implemented by simply overwriting a line ending with an opening block brace with the subsequent line. For example:</p>
<pre><code> # perltidy -bli -bbvt=0
if ( open( FILE, "< $File" ) )
{
while ( $File = <FILE> )
{
$In .= $File;
$count++;
}
close(FILE);
}
# perltidy -bli -bbvt=1
if ( open( FILE, "< $File" ) )
{ while ( $File = <FILE> )
{ $In .= $File;
$count++;
}
close(FILE);
}</code></pre>
<p>By default this applies to blocks associated with keywords <b>if</b>, <b>elsif</b>, <b>else</b>, <b>unless</b>, <b>for</b>, <b>foreach</b>, <b>sub</b>, <b>while</b>, <b>until</b>, and also with a preceding label. This can be changed with the parameter <b>-bbvtl=string</b>, or <b>--block-brace-vertical-tightness-list=string</b>, where <b>string</b> is a space-separated list of block types. For more information on the possible values of this string, see <a href="#Specifying-Block-Types">"Specifying Block Types"</a></p>
<p>For example, if we want to just apply this style to <code>if</code>, <code>elsif</code>, and <code>else</code> blocks, we could use <code>perltidy -bli -bbvt=1 -bbvtl='if elsif else'</code>.</p>
<p>There is no vertical tightness control for closing block braces; with one exception they will be placed on separate lines. The exception is that a cascade of closing block braces may be stacked on a single line. See <b>--stack-closing-block-brace</b>.</p>
</dd>
<dt id="sot---stack-opening-tokens-and-related-flags"><b>-sot</b>, <b>--stack-opening-tokens</b> and related flags</dt>
<dd>
<p>The <b>-sot</b> flag tells perltidy to "stack" opening tokens when possible to avoid lines with isolated opening tokens.</p>
<p>For example:</p>
<pre><code> # default
$opt_c = Text::CSV_XS->new(
{
binary => 1,
sep_char => $opt_c,
always_quote => 1,
}
);
# -sot
$opt_c = Text::CSV_XS->new( {
binary => 1,
sep_char => $opt_c,
always_quote => 1,
}
);</code></pre>
<p>For detailed control of individual closing tokens the following controls can be used:</p>
<pre><code> -sop or --stack-opening-paren
-sohb or --stack-opening-hash-brace
-sosb or --stack-opening-square-bracket
-sobb or --stack-opening-block-brace</code></pre>
<p>The flag <b>-sot</b> is an abbreviation for <b>-sop -sohb -sosb</b>.</p>
<p>The flag <b>-sobb</b> is an abbreviation for <b>-bbvt=2 -bbvtl='*'</b>. This will case a cascade of opening block braces to appear on a single line, although this an uncommon occurrence except in test scripts.</p>
</dd>
<dt id="sct---stack-closing-tokens-and-related-flags"><b>-sct</b>, <b>--stack-closing-tokens</b> and related flags</dt>
<dd>
<p>The <b>-sct</b> flag tells perltidy to "stack" closing tokens when possible to avoid lines with isolated closing tokens.</p>
<p>For example:</p>
<pre><code> # default
$opt_c = Text::CSV_XS->new(
{
binary => 1,
sep_char => $opt_c,
always_quote => 1,
}
);
# -sct
$opt_c = Text::CSV_XS->new(
{
binary => 1,
sep_char => $opt_c,
always_quote => 1,
} );</code></pre>
<p>The <b>-sct</b> flag is somewhat similar to the <b>-vtc</b> (<b>--vertical-tightness-closing</b> flags, and in some cases it can give a similar result. The difference is that the <b>-vtc</b> flags try to avoid lines with leading opening tokens by "hiding" them at the end of a previous line, whereas the <b>-sct</b> flag merely tries to reduce the number of lines with isolated closing tokens by stacking them but does not try to hide them. For example:</p>
<pre><code> # -vtc=2
$opt_c = Text::CSV_XS->new(
{
binary => 1,
sep_char => $opt_c,
always_quote => 1, } );</code></pre>
<p>For detailed control of the stacking of individual closing tokens the following controls can be used:</p>
<pre><code> -scp or --stack-closing-paren
-schb or --stack-closing-hash-brace
-scsb or --stack-closing-square-bracket
-scbb or --stack-closing-block-brace</code></pre>
<p>The flag <b>-sct</b> is an abbreviation for stacking the non-block closing tokens, <b>-scp -schb -scsb</b>.</p>
<p>Stacking of closing block braces, <b>-scbb</b>, causes a cascade of isolated closing block braces to be combined into a single line as in the following example:</p>
<pre><code> # -scbb:
for $w1 (@w1) {
for $w2 (@w2) {
for $w3 (@w3) {
for $w4 (@w4) {
push( @lines, "$w1 $w2 $w3 $w4\n" );
} } } }</code></pre>
<p>To simplify input even further for the case in which both opening and closing non-block containers are stacked, the flag <b>-sac</b> or <b>--stack-all-containers</b> is an abbreviation for <b>--stack-opening-tokens --stack-closing-tokens</b>.</p>
<p>Please note that if both opening and closing tokens are to be stacked, then the newer flag <b>--weld-nested-containers</b> may be preferable because it insures that stacking is always done symmetrically. It also removes an extra level of unnecessary indentation within welded containers. It is able to do this because it works on formatting globally rather than locally, as the <b>--stack-opening-tokens</b> and <b>--stack-closing-tokens</b> flags do.</p>
</dd>
</dl>
<h2 id="Breaking-Before-or-After-Operators">Breaking Before or After Operators</h2>
<p>Four command line parameters provide some control over whether a line break should be before or after specific token types. Two parameters give detailed control:</p>
<p><b>-wba=s</b> or <b>--want-break-after=s</b>, and</p>
<p><b>-wbb=s</b> or <b>--want-break-before=s</b>.</p>
<p>These parameters are each followed by a quoted string, <b>s</b>, containing a list of token types (separated only by spaces). No more than one of each of these parameters should be specified, because repeating a command-line parameter always overwrites the previous one before perltidy ever sees it.</p>
<p>By default, perltidy breaks <b>after</b> these token types: % + - * / x != == >= <= =~ !~ < > | & = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=</p>
<p>And perltidy breaks <b>before</b> these token types by default: . << >> -> && || //</p>
<p>To illustrate, to cause a break after a concatenation operator, <code>'.'</code>, rather than before it, the command line would be</p>
<pre><code> -wba="."</code></pre>
<p>As another example, the following command would cause a break before math operators <code>'+'</code>, <code>'-'</code>, <code>'/'</code>, and <code>'*'</code>:</p>
<pre><code> -wbb="+ - / *"</code></pre>
<p>These commands should work well for most of the token types that perltidy uses (use <b>--dump-token-types</b> for a list). Also try the <b>-D</b> flag on a short snippet of code and look at the .DEBUG file to see the tokenization. However, for a few token types there may be conflicts with hardwired logic which cause unexpected results. One example is curly braces, which should be controlled with the parameter <b>--opening-brace-on-new-line</b> provided for that purpose.</p>
<p><b>WARNING</b> Be sure to put these tokens in quotes to avoid having them misinterpreted by your command shell.</p>
<p>Two additional parameters are available which, though they provide no further capability, can simplify input are:</p>
<p><b>-baao</b> or <b>--break-after-all-operators</b>,</p>
<p><b>-bbao</b> or <b>--break-before-all-operators</b>.</p>
<p>The -baao sets the default to be to break after all of the following operators:</p>
<pre><code> % + - * / x != == >= <= =~ !~ < > | &
= **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=
. : ? && || and or err xor</code></pre>
<p>and the <b>-bbao</b> flag sets the default to break before all of these operators. These can be used to define an initial break preference which can be fine-tuned with the <b>--want-break-after</b> and <b>--want-break-before</b> flags. For example, to break before all operators except an <b>=</b> one could use <code>-bbao -wba='='</code> rather than listing every single perl operator except <b>=</b> on a <b>-wbb</b> flag.</p>
<dl>
<dt id="bal-n---break-after-labels-n"><b>-bal=n, --break-after-labels=n</b></dt>
<dd>
<p>This flag controls whether or not a line break occurs after a label. There are three possible values for <b>n</b>:</p>
<pre><code> -bal=0 break if there is a break in the input [DEFAULT]
-bal=1 always break after a label
-bal=2 never break after a label</code></pre>
<p>For example,</p>
<pre><code> # perltidy -bal=1
RETURN:
return;
# perltidy -bal=2
RETURN: return;</code></pre>
</dd>
</dl>
<h2 id="Controlling-List-Formatting">Controlling List Formatting</h2>
<p>Perltidy attempts to format lists of comma-separated values in tables which look good. Its default algorithms usually work well, but sometimes they don't. In this case, there are several methods available to control list formatting.</p>
<p>A very simple way to prevent perltidy from changing the line breaks within a comma-separated list of values is to insert a blank line, comment, or side-comment anywhere between the opening and closing parens (or braces or brackets). This causes perltidy to skip over its list formatting logic. (The reason is that any of these items put a constraint on line breaks, and perltidy needs complete control over line breaks within a container to adjust a list layout). For example, let us consider</p>
<pre><code> my @list = (1,
1, 1,
1, 2, 1,
1, 3, 3, 1,
1, 4, 6, 4, 1,);</code></pre>
<p>The default formatting, which allows a maximum line length of 80, will flatten this down to one line:</p>
<pre><code> # perltidy (default)
my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, );</code></pre>
<p>This formatting loses the nice structure. The original line breaks can be retained by adding comment or a blank line somewhere between the two parens. For example,</p>
<pre><code> my @list = (
1, # a side comment forces the original breakpoints to be kept
1, 1,
1, 2, 1,
1, 3, 3, 1,
1, 4, 6, 4, 1,
);</code></pre>
<p>We could achieve the same result with a blank line or full comment anywhere between the opening and closing parens. Vertical alignment of the list items will still occur if possible. The blank line method is shown here:</p>
<pre><code> my @list = (
1,
1, 1,
1, 2, 1,
1, 3, 3, 1,
1, 4, 6, 4, 1,
);</code></pre>
<p>For another possibility see the -fs flag in <a href="#Skipping-Selected-Sections-of-Code">"Skipping Selected Sections of Code"</a>.</p>
<dl>
<dt id="boc---break-at-old-comma-breakpoints"><b>-boc</b>, <b>--break-at-old-comma-breakpoints</b></dt>
<dd>
<p>The <b>-boc</b> flag is another way to prevent comma-separated lists from being reformatted. Using <b>-boc</b> on the above example, plus additional flags to retain the original style, yields</p>
<pre><code> # perltidy -boc -lp -pt=2 -vt=1 -vtc=1
my @list = (1,
1, 1,
1, 2, 1,
1, 3, 3, 1,
1, 4, 6, 4, 1,);</code></pre>
<p>A disadvantage of this flag compared to the methods discussed above is that all tables in the file must already be nicely formatted.</p>
</dd>
<dt id="btct-s---break-at-trailing-comma-types-s"><b>-btct=s</b>, <b>--break-at-trailing-comma-types=s</b></dt>
<dd>
<p>A <b>trailing comma</b> is an optional comma following the last item of a list. The <b>-btct=s</b> tells perltidy to end a line at selected trailing commas. The string <b>s</b> selects the trailing commas, as follows:</p>
<pre><code> s=1 or '*' : every trailing comma
s=m a trailing comma in a multiline list
s=b a bare trailing comma
s=0 none</code></pre>
<p>For example, given the following input</p>
<pre><code> $w->bind(
'<Page_Down>' => xx,
);</code></pre>
<p>The default formatting would flatten this into a single line. But the container can be kept open with</p>
<pre><code> # perltidy -btct='b'
$w->bind(
'<Page_Down>' => xx,
);</code></pre>
<p>This can be particularly useful for short function calls like this, where the default perltidy formatting does not keep the container open.</p>
<p>The options <b>s=m</b> and <b>s=1</b> can be used to open up containers with non-bare trailing commas. For example, given this input</p>
<pre><code> $w->bind( '<Page_Down>' => xx, );</code></pre>
<p>we can break it open with</p>
<pre><code> # perltidy -btct=1
$w->bind(
'<Page_Down>' => xx,
);</code></pre>
<p>Afterwards, we could switch to <b>-btct='b'</b> since the trailing comma is now bare. But the <b>-btct</b> parameter must be retained in this case because otherwise this small list will be flattened the next time it is formatted.</p>
<p>This logic can be restricted to specific container types by including an opening token ahead of the letter in the above table. For example</p>
<pre><code> -btct='(b'</code></pre>
<p>means that this operation should only apply to bare trailing commas within parentheses.</p>
<p>For parentheses, an additional item of information which can be given is an alphanumeric letter which is used to limit the selection further depending on the type of token immediately before the opening paren. The possible letters are currently 'k', 'K', 'f', 'F', 'w', and 'W', with these meanings for matching whatever precedes an opening paren:</p>
<pre><code> 'k' matches if the previous nonblank token is a perl keyword
(such as 'if', 'while'),
'K' matches if 'k' does not: previous token is not a keyword
'f' matches if previous token is a function (not a keyword)
'F' matches if 'f' does not.
'w' matches if either 'k' or 'f' match.
'W' matches if 'w' does not.</code></pre>
<p>These are the same codes used for <b>--line-up-parentheses-inclusion-list</b>. For example,</p>
<pre><code> -btct='f(b'</code></pre>
<p>means that bare trailing commas in function call lists in the input stream should be followed by line breaks in the formatted output stream.</p>
<p>The section <a href="#Adding-and-Deleting-Commas">"Adding and Deleting Commas"</a> describes additional controls for working with trailing commas. These can be combined with the <b>-break-trailing-comma-types</b> parameter for additional control of list formatting.</p>
</dd>
<dt id="mft-n---maximum-fields-per-table-n"><b>-mft=n</b>, <b>--maximum-fields-per-table=n</b></dt>
<dd>
<p>If <b>n</b> is a positive number, and the computed number of fields for any table exceeds <b>n</b>, then it will be reduced to <b>n</b>. This parameter might be used on a small section of code to force a list to have a particular number of fields per line, and then either the <b>-boc</b> flag could be used to retain this formatting, or a blank line or comment could be introduced somewhere to freeze the formatting in future applications of perltidy. For example</p>
<pre><code> # perltidy -mft=2
@month_of_year = (
'Jan', 'Feb',
'Mar', 'Apr',
'May', 'Jun',
'Jul', 'Aug',
'Sep', 'Oct',
'Nov', 'Dec'
);</code></pre>
<p>The default value is <b>n=0</b>, which does not place a limit on the number of fields in a table.</p>
</dd>
<dt id="cab-n---comma-arrow-breakpoints-n"><b>-cab=n</b>, <b>--comma-arrow-breakpoints=n</b></dt>
<dd>
<p>A comma which follows a comma arrow, '=>', is given special consideration. In a long list, it is common to break at all such commas. This parameter can be used to control how perltidy breaks at these commas. (However, it will have no effect if old comma breaks are being forced because <b>-boc</b> is used). The possible values of <b>n</b> are:</p>
<pre><code> n=0 break at all commas after =>
n=1 stable: break at all commas after => if container is open,
EXCEPT FOR one-line containers
n=2 break at all commas after =>, BUT try to form the maximum
one-line container lengths
n=3 do not treat commas after => specially at all
n=4 break everything: like n=0 but ALSO break a short container with
a => not followed by a comma when -vt=0 is used
n=5 stable: like n=1 but ALSO break at open one-line containers when
-vt=0 is used (default)</code></pre>
<p>For example, given the following single line, perltidy by default will not add any line breaks because it would break the existing one-line container:</p>
<pre><code> bless { B => $B, Root => $Root } => $package;</code></pre>
<p>Using <b>-cab=0</b> will force a break after each comma-arrow item:</p>
<pre><code> # perltidy -cab=0:
bless {
B => $B,
Root => $Root
} => $package;</code></pre>
<p>If perltidy is subsequently run with this container broken, then by default it will break after each '=>' because the container is now broken. To reform a one-line container, the parameter <b>-cab=2</b> could be used.</p>
<p>The flag <b>-cab=3</b> can be used to prevent these commas from being treated specially. In this case, an item such as "01" => 31 is treated as a single item in a table. The number of fields in this table will be determined by the same rules that are used for any other table. Here is an example.</p>
<pre><code> # perltidy -cab=3
my %last_day = (
"01" => 31, "02" => 29, "03" => 31, "04" => 30,
"05" => 31, "06" => 30, "07" => 31, "08" => 31,
"09" => 30, "10" => 31, "11" => 30, "12" => 31
);</code></pre>
</dd>
<dt id="qwaf---qw-as-function"><b>-qwaf</b>, <b>--qw-as-function</b></dt>
<dd>
<p>This option tells perltidy to format a <b>qw</b> list which is delimited with parentheses as if it were a function call whose call args are a list of quoted items. Normally, a <b>qw</b> list is output verbatim except for an adjustment of leading whitespace to indicate the indentation level. For example, here is an example of the default formatting of a poorly formatted <b>qw</b> list:</p>
<pre><code> # perltidy
@fields = qw( $st_dev $st_ino $st_mode $st_nlink $st_uid
$st_gid $st_rdev $st_size $st_atime $st_mtime $st_ctime
$st_blksize $st_blocks);</code></pre>
<p>If we format with <b>-qwaf</b> then the result will be:</p>
<pre><code> # perltidy -qwaf
@fields = qw(
$st_dev $st_ino $st_mode $st_nlink
$st_uid $st_gid $st_rdev $st_size
$st_atime $st_mtime $st_ctime $st_blksize
$st_blocks
);</code></pre>
<p>The way this works is that just before formatting begins, the tokens of the <b>qw</b> text are replaced with the tokens of an equivalent function call with a comma-separated list of quoted items as call args. Then it is formatted like any other list. Special comma tokens are employed which have no display text, so when the code is eventually displayed it remains a valid <b>qw</b> quote.</p>
<p>Some things to note are:</p>
<ul>
<li><p>This only works for <b>qw</b> quotes which begin with <b>qw(</b>, with no space before the paren.</p>
</li>
<li><p>If the option <b>--space-function-paren</b> is employed, it is ignored for these special function calls because it would deactivate them.</p>
</li>
<li><p>Otherwise the various formatting control flags operate on these lists the same as for other comma-separated lists. In particular, note that if <b>--break-at-old-comma-breakpoints</b>, or <b>-boc</b>, is set, then the old line break locations will be retained. And old line breaks will be retained if there are any blank lines between the opening and closing parens.</p>
</li>
<li><p>Before using this option for the first time, it is a good idea to scan the code and decide if any lists have a special order which should be retained. This can be accomplished for example by changing the quote delimiters to something other than parens, or by inserting a blank line as discussed at the start of this section.</p>
</li>
</ul>
</dd>
</dl>
<h2 id="Adding-and-Deleting-Commas">Adding and Deleting Commas</h2>
<dl>
<dt id="drc---delete-repeated-commas"><b>-drc</b>, <b>--delete-repeated-commas</b></dt>
<dd>
<p>This option causes repeated commas to be removed. For example, given this list with a repeated comma</p>
<pre><code> ignoreSpec( $file, "file",, \%spec, \%Rspec );</code></pre>
<p>we can remove it with -drc</p>
<pre><code> # perltidy -drc:
ignoreSpec( $file, "file", \%spec, \%Rspec );</code></pre>
<p>This parameter also deletes repeated fat commas, '=>'. The complete list of actions taken when this flag is set are as follows:</p>
<ul>
<li><p>Repeated commas like ',,' are removed with a warning.</p>
</li>
<li><p>Repeated fat commas like '=> =>' are removed with a warning.</p>
</li>
<li><p>The combination '=>,' produces a warning but is not changed (it is likely an error but only its author would know how to fix it).</p>
</li>
<li><p>The remaining combination ',=>' (sometimes called a 'winking fat comma') is ignored by this parameter.</p>
</li>
<li><p>These warnings are only output if the <b>--warning-output</b>, or <b>-w</b>, flag is set.</p>
</li>
</ul>
<p>This option is on by default. Use <b>-ndrc</b> to turn it off.</p>
</dd>
<dt id="Adding-and-Deleting-Trailing-Commas"><b>Adding and Deleting Trailing Commas</b></dt>
<dd>
<p>A <b>trailing comma</b> is a comma following the last item of a list. Perl allows trailing commas but they are not required. Including them can sometimes simplify the maintenance of large or complex lists, and help display structure. But they may not be appropriate in all lists, for example in a list which always has just one term. By default, perltidy does not add or delete trailing commas, but it is possible to manipulate them with the following set of related parameters:</p>
<ul>
<li><p><b>--want-trailing-commas=s, -wtc=s</b> - defines where trailing commas are wanted (the style)</p>
</li>
<li><p><b>--add-trailing-commas, -atc</b> - gives permission to add trailing commas to match the style wanted</p>
</li>
<li><p><b>--delete-trailing-commas, -dtc</b> - gives permission to delete trailing commas which do not match the style wanted</p>
</li>
</ul>
<p>The parameter <b>--want-trailing-commas=s</b>, or <b>-wtc=s</b>, defines a preferred style. The string <b>s</b> indicates which lists should get trailing commas, as follows:</p>
<pre><code> s=1 or '*' : every list
s=m a multiline list
s=b a multiline list, bare trailing comma
s=i a multiline list, bare trailing comma, about one comma per line
s=h a multiline list, bare trailing comma, about one key=>value
pair per line
s=0 : no list
s=' ' or not defined : leave trailing commas unchanged [DEFAULT]</code></pre>
<p>where:</p>
<ul>
<li><p>A <b>list</b> here is basically taken to be a container of items (parens, square brackets, or braces), which is not a code block, which contains one or more commas or fat commas. These parameters only apply to something that fits this definition of a list.</p>
<p>A paren-less list of parameters is not a list by this definition, so these parameters do not apply to a paren-less list.</p>
</li>
<li><p>A <b>multiline list</b> is a list for which the opening and closing brackets on different lines.</p>
</li>
<li><p>A <b>bare trailing comma</b> is a comma which is at the end of a line. That is, the closing container token follows on a different line. So a list with a bare trailing comma is a special case of a multiline list.</p>
</li>
<li><p>In fact the above options for trailing commas can be seen as a hierarchy of nesting sets which can be expressed as</p>
<pre><code> 1 > m > b > i > h > 0</code></pre>
<p>This indicates that multiline trailing commas <b>m</b> are a subset of all trailing commas, and bare trailing commas <b>b</b> are a subset of all multiline trailing commas, and so on.</p>
</li>
</ul>
<p>This parameter by itself only indicates where trailing commas are wanted. Perltidy only adds these trailing commas if permission is granted by setting the flag <b>--add-trailing-commas</b>, or <b>-atc</b>. And perltidy only removes unwanted trailing commas if the flag <b>--delete-trailing-commas</b>, or <b>-dtc</b> is set.</p>
<p>Here are some example parameter combinations and their meanings</p>
<pre><code> -wtc=0 -dtc : delete all trailing commas
-wtc=1 -atc : add trailing commas to all lists
-wtc=m -atc : add trailing commas to all multiline lists
(single line lists remain unchanged)
-wtc=b -atc : add commas so that all lists whose closing
bracket starts a new line have trailing commas
-wtc=b -dtc : all trailing commas which are not bare
(not followed by a newline) get deleted.
-wtc=b -atc -dtc : do both of the above operations so that
all trailing commas are bare</code></pre>
<p>For example, given the following input</p>
<pre><code> $wine_list = $top->Box(
"-length" => 5,
"-width" => 3
)->select( "red", "white", "gold", );</code></pre>
<p>we have</p>
<pre><code> # perltidy -wtc=b -atc -dtc
$wine_list = $top->Box(
"-length" => 5,
"-width" => 3,
)->select( "red", "white", "gold" );</code></pre>
<p>A comma was added after the <code>3</code>, since it is bare, and a comma was removed after <code>"gold"</code>, since it not bare.</p>
<p>It is possible to apply a different style to each type of container token by including an opening token ahead of the style character in the above table. For example</p>
<pre><code> -wtc='(m [b'</code></pre>
<p>means that lists within parens should have multiline trailing commas, and that lists within square brackets have bare trailing commas. Since there is no specification for curly braces in this example, their trailing commas would remain unchanged.</p>
<p>For parentheses, an additional item of information which can be given is an alphanumeric letter which is used to limit the selection further depending on the type of token immediately before the opening paren. The possible letters are currently 'k', 'K', 'f', 'F', 'w', and 'W', with these meanings for matching whatever precedes an opening paren:</p>
<pre><code> 'k' matches if the previous nonblank token is a perl keyword
(such as 'if', 'while'),
'K' matches if 'k' does not: previous token is not a keyword
'f' matches if previous token is a function (not a keyword)
'F' matches if 'f' does not.
'w' matches if either 'k' or 'f' match.
'W' matches if 'w' does not.</code></pre>
<p>These are the same codes used for <b>--line-up-parentheses-inclusion-list</b>. For example,</p>
<pre><code> -wtc='w(m'</code></pre>
<p>means that trailing commas are wanted for multiline parenthesized lists following a function call or keyword.</p>
<p>Finally, a leading <b>+</b> can be placed on any term to indicate that it only applies when adding commas. A leading <b>-</b> indicates that it only applies when deleting commas. For example,</p>
<pre><code> -wtc='+h -b' -atc -dtc</code></pre>
<p>means that missing trailing commas should be added to lists of key => value pairs, and trailing commas which are not bare should be removed. No other changes are made. When both plus and minus terms are used like this, they must not be in conflict. There is no conflict in this example because the trailing comma locations of the key=>value pairs selected by the <b>+h</b> term are a subset of all bare trailing commas, and thus will not be deleted by the <b>-b</b> term. The general rule is that the letter of the plus term should occur after the letter of the minus term in the hierarchical nesting order, <b>1 > m > b > i > h > 0</b>.</p>
<p><b>Some points to note</b> regarding adding and deleting trailing commas:</p>
<ul>
<li><p>It is recommended to also use the <b>--converge</b> parameter when adding and/or deleting trailing commas, especially if the formatter may be making other line break changes at the same time. The reason is that the decision regarding whether or not a list is multiline or bare is made based on the <b>input</b> stream if only one iteration is made, which is the default.</p>
<p>When iterations are requested with the <b>--converge</b> parameter, any comma deletion operations are postponed until the start of the <b>second iteration</b>, after most changes in line breaks have been made.</p>
<p>To illustrate, if we start with</p>
<pre><code> f(
a => 1,
b => 2, );</code></pre>
<p>and attempt to delete non-bare commas,</p>
<pre><code> # perltidy -wtc=b -dtc
f(
a => 1,
b => 2
);</code></pre>
<p>we delete a comma which has become bare, which is not what is wanted. This happened because the change was based on the starting rather than the final line breaks. Running with <b>--converge</b> gives the desired result:</p>
<pre><code> # perltidy -wtc=b -dtc --converge
f(
a => 1,
b => 2,
);</code></pre>
<p>because comma changes are based on the line breaks after the first iteration.</p>
<p>A parameter <b>--delay-trailing-comma-operations</b>, or <b>-dtco</b>, is available to control this behavior if desired. Negating this parameter, with <b>-ndtco</b>, tells perltidy to always use the starting state to make decisions regarding comma addition and deletion, even when iterations are requested. This should not normally be necessary.</p>
</li>
<li><p>Perltidy does not add a trailing comma in some <b>edge cases</b> which appear to be near a stability limit. So if a comma is unexpectedly not added, this is probably the reason.</p>
</li>
<li><p>If the parameter <b>--break-at-trailing-comma-types</b>, or <b>-btct</b>. is also employed, it operates on the state after any adding or deleting of commas. And it will allow trailing commas to be added in most edge cases. For example, given the following input text</p>
<pre><code> plot(
'g', Canvas => $overview_canvas
);</code></pre>
<p>formatting with <code>-wtc=f(b) -atc</code> will not add a trailing comma because the list will be flattened and the comma will not remain bare. But we can add a trailing comma, and keep the container open, with</p>
<pre><code> # perltidy -wtc='f(b' -atc -btct='f(b'
plot(
'g', Canvas => $overview_canvas,
);</code></pre>
<p>As another example, given the same text on a single line without a trailing comma</p>
<pre><code> plot( 'g', Canvas => $overview_canvas );</code></pre>
<p>we can add a trailing comma and break the container open with</p>
<pre><code> # perltidy -wtc=1 -atc -btct=1
plot(
'g', Canvas => $overview_canvas,
);</code></pre>
<p>After that, we could use <code>-btct='f(b'</code> to keep the container open.</p>
</li>
<li><p>When using these parameters for the first time it is a good idea to practice on some test scripts and verify that the results are as expected.</p>
</li>
</ul>
<p><b>Special Considerations for Lone Trailing Commas</b></p>
<p>Adding or deleting the only comma in a list can have some implications which need to be explained and possibly controlled. Two additional controls are available for these lone commas:</p>
<ul>
<li><p><b>--add-lone-trailing-commas, -altc</b> - gives permission to add a comma if it will be the only comma. This is on by default and explained below.</p>
</li>
<li><p><b>--delete-lone-trailing-commas, -dltc</b> - gives permission to delete the only comma in a list. This is on by default and explained below.</p>
</li>
</ul>
<p>One issue with deleting a lone comma is that if it is deleted, then it might not be possible add it back automatically since perltidy uses the existence of commas to help locate containers where commas are appropriate. For example, given</p>
<pre><code> my ( $self, ) = @_;</code></pre>
<p>and if we remove the comma with</p>
<pre><code> # perltidy -wtc=m -dtc
my ( $self ) = @_;</code></pre>
<p>then we cannot use the trailing comma controls to add this comma back. The parameter <b>--delete-lone-trailing-commas</b> allows such a comma to be deleted, and is on by default, but can be turned off to prevent this. This might be useful if one is experimenting with formatting options and wants to restrict testing to operations which are reversible. Note that this parameter is a fine-tuning control for <b>--delete-trailing-commas</b> which must also be set for it to have any effect.</p>
<p>However, if a single item in a list is itself is a list with multiple lines, such as the item in braces here</p>
<pre><code> $self->make_grammar(
{
iterator => $self->_iterator,
parser => $self,
}
);</code></pre>
<p>then perltidy can add and/or delete a lone comma:</p>
<pre><code> # perltidy -atc -wtc=b
$self->make_grammar(
{
iterator => $self->_iterator,
parser => $self,
},
);</code></pre>
<p>But it turns out that these cases usually coincide with situations where the <b>--weld-nested-containers</b>, or <b>-wn</b>, parameter would apply, and adding such commas can block welding. For example, the <b>-wn</b> parameter would succeed on the first of the above snippets, but it would fail on the second because of the added trailing comma.</p>
<p>The parameter <b>--add-lone-trailing-commas</b>, or <b>-altc</b> allows these commas to be added, provide that <b>--add-trailing-commas</b> is also set. It is on by default. Users of <b>-wn</b> may want to turn it off with <b>--noadd-lone-trailing-commas</b>, <b>-naltc</b> to prevent such commas from being added.</p>
<p>If such commas do get added, then can be removed to allow welding with the control described in the next section.</p>
</dd>
<dt id="dwic---delete-weld-interfering-commas"><b>-dwic</b>, <b>--delete-weld-interfering-commas</b></dt>
<dd>
<p>If the closing tokens of two nested containers are separated by a comma, then welding requested with <b>--weld-nested-containers</b> cannot occur. Any commas in this situation are optional trailing commas and can be removed with <b>-dwic</b>. For example, a comma in this script prevents welding:</p>
<pre><code> # perltidy -wn
$self->make_grammar(
{
iterator => $self->_iterator,
parser => $self,
},
);</code></pre>
<p>Adding <b>-dwic</b> removes the comma and allows welding:</p>
<pre><code> # perltidy -wn -dwic
$self->make_grammar( {
iterator => $self->_iterator,
parser => $self,
} );</code></pre>
<p>This feature is off by default. Here are some points to note about the <b>-dwic</b> parameter</p>
<ul>
<li><p>This operation is not always reversible, so please check results of using this parameter carefully.</p>
</li>
<li><p>Removing this type of isolated trailing comma is necessary for welding to be possible, but not sufficient. So welding will not always occur where these commas are removed.</p>
</li>
<li><p>This operation is independent of <b>--add-trailing-commas</b> and <b>--delete-trailing-commas</b>. If it conflicts with any of those settings, it has priority.</p>
</li>
</ul>
</dd>
</dl>
<h2 id="Adding-and-Deleting-Interbracket-Arrows">Adding and Deleting Interbracket Arrows</h2>
<p>In the following expression, the arrow operator '->' between the closing and opening brackets of hash keys and array indexes are optional:</p>
<pre><code> return $self->{'commandline'}->{'args'}->[0]->[0]->{'hgroups'};</code></pre>
<p>These will be called <b>interbracket arrows</b> here, for lack of a better term. Perltidy will not change them by default, but they can be added or removed with the following parameters.</p>
<dl>
<dt id="dia---delete-interbracket-arrows"><b>-dia</b>, <b>--delete-interbracket-arrows</b></dt>
<dd>
<p>This parameter deletes interbracket arrows. Applied to the above example we have</p>
<pre><code> # perltidy -dia
return $self->{'commandline'}{'args'}[0][0]{'hgroups'};</code></pre>
<p>By default this applies to all interbracket arrows, but selective deletion is possible with controls described below.</p>
</dd>
<dt id="aia---add-interbracket-arrows"><b>-aia</b>, <b>--add-interbracket-arrows</b></dt>
<dd>
<p>This parameter adds interbracket arrows. Applied to the line of code above, we get back the original line.</p>
<pre><code> # perltidy -aia
return $self->{'commandline'}->{'args'}->[0]->[0]->{'hgroups'};</code></pre>
<p>Selective changes can be made with controls described below.</p>
</dd>
<dt id="ias-s---interbracket-arrow-style-s"><b>-ias=s</b>, <b>--interbracket-arrow-style=s</b></dt>
<dd>
<p>By default the <b>-add-</b> and <b>-delete-</b> parameters apply to all interbracket arrows.</p>
<p>An optional style can be specified with this parameter string <b>s</b>. In that case the parameters <b>--add-interbracket-arrows</b> and <b>--delete-interbracket-arrows</b> only apply where they would bring the formatting into agreement with the specified style. They may both be used in a single run if a mixed style is specified since there is no conflict.</p>
<p>The style string <b>s</b> gives a graphical description of the desired style. It lists up to four possible pairs of bracket types with an optional arrow between them. For example:</p>
<pre><code> -ias='][ }->{'</code></pre>
<p>This means no arrows are wanted between '][' but arrows should be between '}{'. And it means that the unlisted pairs ']{' and '}[' should remain unchanged, either with or without arrows.</p>
<p>In this particular example, if the parameter <b>--delete-interbracket-arrows</b> is used, then only arrows like ']->[' will be deleted, since they are the only ones which disagree with the style.</p>
<p>And likewise, if <b>--add-interbracket-arrows</b> is used, then arrows will only be inserted between brackets like '}{' to bring the formatting into conformity with the style in this example.</p>
<p>Spaces in the string <b>s</b> are optional. They are ignored when the expression is parsed.</p>
<p>The style corresponding to all possible arrows is</p>
<pre><code> -ias=']->[ ]->{ }->[ }->{'</code></pre>
<p>For convenience, this may also be requested with <b>-ias=1</b> or <b>-ias='*'</b>.</p>
<p>The style corresponding to no interbracket arrows is</p>
<pre><code> -ias='] [ ] { } [ } {'</code></pre>
<p>which may also be requested with <b>-ias=0</b>.</p>
</dd>
<dt id="wia---warn-interbracket-arrows"><b>-wia</b>, <b>--warn-interbracket-arrows</b></dt>
<dd>
<p>If this parameter is set, then a message is written to the error file in the following cases:</p>
<ul>
<li><p>If an arrow is added or deleted by an add or delete command.</p>
</li>
<li><p>If a style is defined and an arrow would have been added or deleted if requested. So for example, the command</p>
<pre><code> perltidy -wia -ias=']['</code></pre>
<p>will show where a file has arrows like ]->[' since they do not match the style, but no changes will be made because the delete command <b>-dia</b> has not been given. And</p>
<pre><code> perltidy -wia -ias=0</code></pre>
<p>will warn if any arrows exist, since the flag -ias=0 means that no arrows are wanted.</p>
</li>
</ul>
</dd>
<dt id="iac-n---interbracket-arrow-complexity-n"><b>-iac=n</b>, <b>--interbracket-arrow-complexity=n</b></dt>
<dd>
<p>This parameter makes it possible to skip adding or deleting arrows following a container which is complex in some sense. Three levels of complexity can be specified with the integer <b>n</b>, as follows:</p>
<pre><code> n=0 the left container must contain be a single thing (token)
n=1 the left container must not contain other containers [DEFAULT]
n=2 the left container may contain anything</code></pre>
<p>Some examples:</p>
<pre><code> # Container complexity
{'commandline'} 0 single token OK by default
{ $type . $name } 1 multiple tokens OK by default
[ $plot{'x-axis'} - 1 ] 2 contains a container SKIPPED by default</code></pre>
<p>So, with the default complexity level of 1, an arrow could be added or deleted following the first two of these containers but not the third.</p>
</dd>
</dl>
<p><b>Some points to consider</b> when working with these parameters are:</p>
<ul>
<li><p>There are no known bugs, but this is a relatively new feature. So please carefully check file differences and run tests when interbracket arrows are added or removed.</p>
</li>
<li><p>For some unusual spacing parameters, it could take an extra iteration for the spaces between brackets to reach their final state after arrows are added or deleted.</p>
</li>
<li><p>Any comments between brackets will prevent the adding and deleting of arrows.</p>
</li>
</ul>
<h2 id="Missing-Else-Blocks">Missing Else Blocks</h2>
<p>A defensive programming technique is to require that every <b>if-elsif-</b> chain be terminated with an <b>else</b> block, even though it is not strictly required. This helps insure that there are no holes in the logic.</p>
<p>For example, consider the following snippet:</p>
<pre><code> my $type = get_cards();
if ( $type = 1 ) { action("hold 'em") }
elsif ( $type = 2 ) { action("fold 'em") }
elsif ( $type = 3 ) { action("walk away") }</code></pre>
<p>What if the variable <b>$type</b> is some other value? It might have been obvious that this was okay when the code was first written, but it might not be so clear when the code is reviewed a few years later. A terminal <b>else</b> block with a comment would help clarify things.</p>
<p>The parameters in this section can help by either issuing a warning if an <b>else</b> is missing, or even inserting an empty <b>else</b> block where one is missing, or both.</p>
<dl>
<dt id="wme---warn-missing-else"><b>-wme</b>, <b>--warn-missing-else</b></dt>
<dd>
<p>This flag tells perltidy to issue a warning if a program is missing a terminal <b>else</b> block. The default is not to issue such a warning.</p>
</dd>
<dt id="ame---add-missing-else"><b>-ame</b>, <b>--add-missing-else</b></dt>
<dd>
<p>This flag tells perltidy to output an empty else block wherever a program is missing a terminal <b>else</b> block. To get a warning when this is done you should also set <b>-wme</b>. The default is not to add missing else blocks.</p>
</dd>
<dt id="amec-s---add-missing-else-comment-s"><b>-amec=s</b>, <b>--add-missing-else-comment=s</b></dt>
<dd>
<p>This string is a side comment which will be written to highlight a new empty else block. The default is:</p>
<pre><code> -amec='##FIXME - added with perltidy -ame'</code></pre>
</dd>
</dl>
<p>For example, on the above example we can add a missing else and also get a warning notice with:</p>
<pre><code> # perltidy -ame -wme
my $type = get_cards();
if ( $type == 1 ) { action("hold 'em") }
elsif ( $type == 2 ) { action("fold 'em") }
elsif ( $type == 3 ) { action("walk away") }
else {
##FIXME - added with perltidy -ame
}</code></pre>
<p>Any <b>##FIXME</b> comments created in this way should be reviewed and changed appropriately. For example, one might decide that the code fine as is, and just change the comment to indicate that nothing has been overlooked:</p>
<pre><code> my $type = get_cards();
if ( $type == 1 ) { action("hold 'em") }
elsif ( $type == 2 ) { action("fold 'em") }
elsif ( $type == 3 ) { action("walk away") }
else {
# ok - no worries
}</code></pre>
<p>Or maybe a deeper analysis reveals that something was missed:</p>
<pre><code> my $type = get_cards();
if ( $type == 1 ) { action("hold 'em") }
elsif ( $type == 2 ) { action("fold 'em") }
elsif ( $type == 3 ) { action("walk away") }
else { action("run") }</code></pre>
<p>Sometimes it turns out that the else block should not reachable, in which case an error exit might be appropriate. In any case, having the <b>else</b> block can improve code maintainability.</p>
<h2 id="Retaining-or-Ignoring-Existing-Line-Breaks">Retaining or Ignoring Existing Line Breaks</h2>
<p>Several additional parameters are available for controlling the extent to which line breaks in the input script influence the output script. In most cases, the default parameter values are set so that, if a choice is possible, the output style follows the input style. For example, if a short logical container is broken in the input script, then the default behavior is for it to remain broken in the output script.</p>
<p>Most of the parameters in this section would only be required for a one-time conversion of a script from short container lengths to longer container lengths. The opposite effect, of converting long container lengths to shorter lengths, can be obtained by temporarily using a short maximum line length.</p>
<dl>
<dt id="bol---break-at-old-logical-breakpoints"><b>-bol</b>, <b>--break-at-old-logical-breakpoints</b></dt>
<dd>
<p>By default, if a logical expression is broken at a <code>&&</code>, <code>||</code>, <code>and</code>, or <code>or</code>, then the container will remain broken. Also, breaks at internal keywords <code>if</code> and <code>unless</code> will normally be retained. To prevent this, and thus form longer lines, use <b>-nbol</b>.</p>
<p>Please note that this flag does not duplicate old logical breakpoints. They are merely used as a hint with this flag that a statement should remain broken. Without this flag, perltidy will normally try to combine relatively short expressions into a single line.</p>
<p>For example, given this snippet:</p>
<pre><code> return unless $cmd = $cmd || ($dot
&& $Last) || &prompt('|');
# perltidy -bol [default]
return
unless $cmd = $cmd
|| ( $dot
&& $Last )
|| &prompt('|');
# perltidy -nbol
return unless $cmd = $cmd || ( $dot && $Last ) || &prompt('|');</code></pre>
</dd>
<dt id="bom---break-at-old-method-breakpoints"><b>-bom</b>, <b>--break-at-old-method-breakpoints</b></dt>
<dd>
<p>By default, a method call arrow <code>-></code> is considered a candidate for a breakpoint, but method chains will fill to the line width before a break is considered. With <b>-bom</b>, breaks before the arrow are preserved, so if you have pre-formatted a method chain:</p>
<pre><code> # perltidy -bom
$Document
->schild(0)
->schildren();</code></pre>
<p>the flag <b>-bom</b> will <b>keep</b> these line breaks, rather than become this:</p>
<pre><code> # perltidy [DEFAULT]
$Document->schild(0)->schildren();</code></pre>
<p>This flag will also look for and keep a 'cuddled' style of calls, in which lines begin with a closing paren followed by a call arrow, as in this example:</p>
<pre><code> # perltidy -bom
my $q = $rs->related_resultset(
'CDs'
)->related_resultset(
'Tracks'
)->search(
{
'track.id' => { -ident => 'none_search.id' },
}
)->as_query;</code></pre>
</dd>
<dt id="bos---break-at-old-semicolon-breakpoints"><b>-bos</b>, <b>--break-at-old-semicolon-breakpoints</b></dt>
<dd>
<p>Semicolons are normally placed at the end of a statement. This means that formatted lines do not normally begin with semicolons. If the input stream has some lines which begin with semicolons, these can be retained by setting this flag. For example, consider the following two-line input snippet:</p>
<pre><code> $z = sqrt($x**2 + $y**2)
;</code></pre>
<p>The default formatting will be:</p>
<pre><code> $z = sqrt( $x**2 + $y**2 );</code></pre>
<p>Using the <b>-bos</b> flag keeps the isolated semicolon:</p>
<pre><code> # perltidy -bos
$z = sqrt( $x**2 + $y**2 )
;</code></pre>
<p>The extra continuation indentation spaces on the semicolon can be removed by also setting <b>--noindent-leading-semicolon</b>.</p>
<pre><code> # perltidy -bos -nils
$z = sqrt( $x**2 + $y**2 )
;</code></pre>
<p>The default is not to do this, <b>-nbos</b>.</p>
</dd>
<dt id="bok---break-at-old-keyword-breakpoints"><b>-bok</b>, <b>--break-at-old-keyword-breakpoints</b></dt>
<dd>
<p>By default, perltidy will retain a breakpoint before keywords which may return lists, such as <code>sort</code> and <code>map</code>. This allows chains of these operators to be displayed one per line. Use <b>-nbok</b> to prevent retaining these breakpoints.</p>
</dd>
<dt id="bot---break-at-old-ternary-breakpoints"><b>-bot</b>, <b>--break-at-old-ternary-breakpoints</b></dt>
<dd>
<p>By default, if a conditional (ternary) operator is broken at a <code>:</code>, then it will remain broken. To prevent this, and thereby form longer lines, use <b>-nbot</b>.</p>
</dd>
<dt id="boa---break-at-old-attribute-breakpoints"><b>-boa</b>, <b>--break-at-old-attribute-breakpoints</b></dt>
<dd>
<p>By default, if an attribute list is broken at a <code>:</code> in the source file, then it will remain broken. For example, given the following code, the line breaks at the ':'s will be retained:</p>
<pre><code> my @field
: field
: Default(1)
: Get('Name' => 'foo') : Set('Name');</code></pre>
<p>If the attributes are on a single line in the source code then they will remain on a single line if possible.</p>
<p>To prevent this, and thereby always form longer lines, use <b>-nboa</b>.</p>
</dd>
<dt id="Keeping-old-breakpoints-at-specific-token-types"><b>Keeping old breakpoints at specific token types</b></dt>
<dd>
<p>It is possible to override the choice of line breaks made by perltidy, and force it to follow certain line breaks in the input stream, with these two parameters:</p>
<p><b>-kbb=s</b> or <b>--keep-old-breakpoints-before=s</b>, and</p>
<p><b>-kba=s</b> or <b>--keep-old-breakpoints-after=s</b></p>
<p>These parameters are each followed by a quoted string, <b>s</b>, containing a list of token types (separated only by spaces). No more than one of each of these parameters should be specified, because repeating a command-line parameter always overwrites the previous one before perltidy ever sees it.</p>
<p>For example, -kbb='=>' means that if an input line begins with a '=>' then the output script should also have a line break before that token.</p>
<p>For example, given the script:</p>
<pre><code> method 'foo'
=> [ Int, Int ]
=> sub {
my ( $self, $x, $y ) = ( shift, @_ );
...;
};
# perltidy [default]
method 'foo' => [ Int, Int ] => sub {
my ( $self, $x, $y ) = ( shift, @_ );
...;
};
# perltidy -kbb='=>'
method 'foo'
=> [ Int, Int ]
=> sub {
my ( $self, $x, $y ) = ( shift, @_ );
...;
};</code></pre>
<p>For the container tokens '{', '[' and '(' and, their closing counterparts, use the token symbol. Thus, the command to keep a break after all opening parens is:</p>
<pre><code> perltidy -kba='('</code></pre>
<p>It is possible to be more specific in matching parentheses by preceding them with a letter. The possible letters are 'k', 'K', 'f', 'F', 'w', and 'W', with these meanings (these are the same as used in the <b>--weld-nested-exclusion-list</b> and <b>--line-up-parentheses-exclusion-list</b> parameters):</p>
<pre><code> 'k' matches if the previous nonblank token is a perl keyword
(such as 'if', 'while'),
'K' matches if 'k' does not: previous token is not a keyword
'f' matches if previous token is a function (not a keyword)
'F' matches if 'f' does not.
'w' matches if either 'k' or 'f' match.
'W' matches if 'w' does not.</code></pre>
<p>So for example the the following parameter will keep breaks after opening function call parens:</p>
<pre><code> perltidy -kba='f('</code></pre>
<p><b>NOTE</b>: A request to break before an opening container, such as <b>-kbb='('</b>, will be silently ignored because it can lead to formatting instability. Likewise, a request to break after a closing container, such as <b>-kba</b>=')', will also be silently ignored.</p>
</dd>
<dt id="iob---ignore-old-breakpoints"><b>-iob</b>, <b>--ignore-old-breakpoints</b></dt>
<dd>
<p>Use this flag to tell perltidy to ignore existing line breaks to the maximum extent possible. This will tend to produce the longest possible containers, regardless of type, which do not exceed the line length limit. But please note that this parameter has priority over all other parameters requesting that certain old breakpoints be kept.</p>
<p>To illustrate, consider the following input text:</p>
<pre><code> has subcmds => (
is => 'ro',
default => sub { [] },
);</code></pre>
<p>The default formatting will keep the container broken, giving</p>
<pre><code> # perltidy [default]
has subcmds => (
is => 'ro',
default => sub { [] },
);</code></pre>
<p>If old breakpoints are ignored, the list will be flattened:</p>
<pre><code> # perltidy -iob
has subcmds => ( is => 'ro', default => sub { [] }, );</code></pre>
<p>Besides flattening lists, this parameter also applies to lines broken at certain logical breakpoints such as 'if' and 'or'.</p>
<p>Even if this is parameter is not used globally, it provides a convenient way to flatten selected lists from within an editor.</p>
</dd>
<dt id="kis---keep-interior-semicolons"><b>-kis</b>, <b>--keep-interior-semicolons</b></dt>
<dd>
<p>Use the <b>-kis</b> flag to prevent breaking at a semicolon if there was no break there in the input file. Normally perltidy places a newline after each semicolon which terminates a statement unless several statements are contained within a one-line brace block. To illustrate, consider the following input lines:</p>
<pre><code> dbmclose(%verb_delim); undef %verb_delim;
dbmclose(%expanded); undef %expanded;</code></pre>
<p>The default is to break after each statement, giving</p>
<pre><code> dbmclose(%verb_delim);
undef %verb_delim;
dbmclose(%expanded);
undef %expanded;</code></pre>
<p>With <b>perltidy -kis</b> the multiple statements are retained:</p>
<pre><code> dbmclose(%verb_delim); undef %verb_delim;
dbmclose(%expanded); undef %expanded;</code></pre>
<p>The statements are still subject to the specified value of <b>maximum-line-length</b> and will be broken if this maximum is exceeded.</p>
</dd>
</dl>
<h2 id="Blank-Line-Control">Blank Line Control</h2>
<p>Blank lines can improve the readability of a script if they are carefully placed. Perltidy has several commands for controlling the insertion, retention, and removal of blank lines.</p>
<dl>
<dt id="fbl---freeze-blank-lines"><b>-fbl</b>, <b>--freeze-blank-lines</b></dt>
<dd>
<p>Set <b>-fbl</b> if you want to the blank lines in your script to remain exactly as they are. The rest of the parameters in this section may then be ignored. (Note: setting the <b>-fbl</b> flag is equivalent to setting <b>-mbl=0</b> and <b>-kbl=2</b>).</p>
</dd>
<dt id="bbc---blanks-before-comments"><b>-bbc</b>, <b>--blanks-before-comments</b></dt>
<dd>
<p>A blank line will be introduced before a full-line comment. This is the default. Use <b>-nbbc</b> or <b>--noblanks-before-comments</b> to prevent such blank lines from being introduced.</p>
</dd>
<dt id="blbs-n---blank-lines-before-subs-n"><b>-blbs=n</b>, <b>--blank-lines-before-subs=n</b></dt>
<dd>
<p>The parameter <b>-blbs=n</b> requests that least <b>n</b> blank lines precede a sub definition which does not follow a comment and which is more than one-line long. The default is <b>-blbs=1</b>. <b>BEGIN</b> and <b>END</b> blocks are included.</p>
<p>The requested number of blanks statement will be inserted regardless of the value of <b>--maximum-consecutive-blank-lines=n</b> (<b>-mbl=n</b>) with the exception that if <b>-mbl=0</b> then no blanks will be output.</p>
<p>This parameter interacts with the value <b>k</b> of the parameter <b>--maximum-consecutive-blank-lines=k</b> (<b>-mbl=k</b>) as follows:</p>
<p>1. If <b>-mbl=0</b> then no blanks will be output. This allows all blanks to be suppressed with a single parameter. Otherwise,</p>
<p>2. If the number of old blank lines in the script is less than <b>n</b> then additional blanks will be inserted to make the total <b>n</b> regardless of the value of <b>-mbl=k</b>.</p>
<p>3. If the number of old blank lines in the script equals or exceeds <b>n</b> then this parameter has no effect, however the total will not exceed value specified on the <b>-mbl=k</b> flag.</p>
</dd>
<dt id="blbp-n---blank-lines-before-packages-n"><b>-blbp=n</b>, <b>--blank-lines-before-packages=n</b></dt>
<dd>
<p>The parameter <b>-blbp=n</b> requests that least <b>n</b> blank lines precede a package which does not follow a comment. The default is <b>-blbp=1</b>.</p>
<p>This parameter interacts with the value <b>k</b> of the parameter <b>--maximum-consecutive-blank-lines=k</b> (<b>-mbl=k</b>) in the same way as described for the previous item <b>-blbs=n</b>.</p>
</dd>
<dt id="bbs---blanks-before-subs"><b>-bbs</b>, <b>--blanks-before-subs</b></dt>
<dd>
<p>For compatibility with previous versions, <b>-bbs</b> or <b>--blanks-before-subs</b> is equivalent to <b>-blbp=1</b> and <b>-blbs=1</b>.</p>
<p>Likewise, <b>-nbbs</b> or <b>--noblanks-before-subs</b> is equivalent to <b>-blbp=0</b> and <b>-blbs=0</b>.</p>
</dd>
<dt id="bbb---blanks-before-blocks"><b>-bbb</b>, <b>--blanks-before-blocks</b></dt>
<dd>
<p>A blank line will be introduced before blocks of coding delimited by <b>for</b>, <b>foreach</b>, <b>while</b>, <b>until</b>, and <b>if</b>, <b>unless</b>, in the following circumstances:</p>
<ul>
<li><p>The block is not preceded by a comment.</p>
</li>
<li><p>The block is not a one-line block.</p>
</li>
<li><p>The number of consecutive non-blank lines at the current indentation depth is at least <b>-lbl</b> (see next section).</p>
</li>
</ul>
<p>This is the default. The intention of this option is to introduce some space within dense coding. This is negated with <b>-nbbb</b> or <b>--noblanks-before-blocks</b>.</p>
</dd>
<dt id="lbl-n---long-block-line-count-n"><b>-lbl=n</b> <b>--long-block-line-count=n</b></dt>
<dd>
<p>This controls how often perltidy is allowed to add blank lines before certain block types (see previous section). The default is 8. Entering a value of <b>0</b> is equivalent to entering a very large number.</p>
</dd>
<dt id="blao-i-or---blank-lines-after-opening-block-i"><b>-blao=i</b> or <b>--blank-lines-after-opening-block=i</b></dt>
<dd>
<p>This control places a minimum of <b>i</b> blank lines <b>after</b> a line which <b>ends</b> with an opening block brace of a specified type. By default, this only applies to the block of a named <b>sub</b>, but this can be changed (see <b>-blaol</b> below). The default is not to do this (<b>i=0</b>).</p>
<p>Please see the note below on using the <b>-blao</b> and <b>-blbc</b> options.</p>
</dd>
<dt id="blbc-i-or---blank-lines-before-closing-block-i"><b>-blbc=i</b> or <b>--blank-lines-before-closing-block=i</b></dt>
<dd>
<p>This control places a minimum of <b>i</b> blank lines <b>before</b> a line which <b>begins</b> with a closing block brace of a specified type. By default, this only applies to the block of a named <b>sub</b>, but this can be changed (see <b>-blbcl</b> below). The default is not to do this (<b>i=0</b>).</p>
</dd>
<dt id="blaol-s-or---blank-lines-after-opening-block-list-s"><b>-blaol=s</b> or <b>--blank-lines-after-opening-block-list=s</b></dt>
<dd>
<p>The parameter <b>s</b> is a list of block type keywords to which the flag <b>-blao</b> should apply. The section <a href="#Specifying-Block-Types">"Specifying Block Types"</a> explains how to list block types.</p>
</dd>
<dt id="blbcl-s-or---blank-lines-before-closing-block-list-s"><b>-blbcl=s</b> or <b>--blank-lines-before-closing-block-list=s</b></dt>
<dd>
<p>This parameter is a list of block type keywords to which the flag <b>-blbc</b> should apply. The section <a href="#Specifying-Block-Types">"Specifying Block Types"</a> explains how to list block types.</p>
</dd>
<dt id="Note-on-using-the--blao-and--blbc-options"><b>Note on using the</b> <b>-blao</b> and <b>-blbc</b> options.</dt>
<dd>
<p>These blank line controls introduce a certain minimum number of blank lines in the text, but the final number of blank lines may be greater, depending on values of the other blank line controls and the number of old blank lines. A consequence is that introducing blank lines with these and other controls cannot be exactly undone, so some experimentation with these controls is recommended before using them.</p>
<p>For example, suppose that for some reason we decide to introduce one blank space at the beginning and ending of all blocks. We could do this using</p>
<pre><code> perltidy -blao=2 -blbc=2 -blaol='*' -blbcl='*' filename</code></pre>
<p>Now suppose the script continues to be developed, but at some later date we decide we don't want these spaces after all. We might expect that running with the flags <b>-blao=0</b> and <b>-blbc=0</b> will undo them. However, by default perltidy retains single blank lines, so the blank lines remain.</p>
<p>We can easily fix this by telling perltidy to ignore old blank lines by including the added parameter <b>--keep-old-blank-lines=0</b> and rerunning. Then the unwanted blank lines will be gone. However, this will cause all old blank lines to be ignored, perhaps even some that were added by hand to improve formatting. So please be cautious when using these parameters.</p>
</dd>
<dt id="mbl-n---maximum-consecutive-blank-lines-n"><b>-mbl=n</b> <b>--maximum-consecutive-blank-lines=n</b></dt>
<dd>
<p>This parameter specifies the maximum number of consecutive blank lines which will be output within code sections of a script. The default is n=1. If the input file has more than n consecutive blank lines, the number will be reduced to <b>n</b> except as noted above for the <b>--blank-lines-before-subs</b> and <b>--blank-lines-before-subs</b> parameters. If <b>n=0</b> then no blank lines will be output (unless all old blank lines are retained with the <b>--keep-old-blank-lines=2</b> flag of the next section).</p>
<p>This flag obviously does not apply to pod sections, here-documents, and quotes.</p>
</dd>
<dt id="kbl-n---keep-old-blank-lines-n"><b>-kbl=n</b>, <b>--keep-old-blank-lines=n</b></dt>
<dd>
<p>The <b>-kbl=n</b> flag gives you control over how your existing blank lines are treated.</p>
<p>The possible values of <b>n</b> are:</p>
<pre><code> n=0 ignore all old blank lines
n=1 stable: keep old blanks, but limited by the B<-mbl=n> flag
n=2 keep all old blank lines, regardless of the B<-mbl=n> flag</code></pre>
<p>The default is <b>n=1</b>.</p>
</dd>
<dt id="sob---swallow-optional-blank-lines"><b>-sob</b>, <b>--swallow-optional-blank-lines</b></dt>
<dd>
<p>This is equivalent to <b>--keep-old-blank-lines=0</b> and is included for compatibility with previous versions.</p>
</dd>
<dt id="nsob---noswallow-optional-blank-lines"><b>-nsob</b>, <b>--noswallow-optional-blank-lines</b></dt>
<dd>
<p>This is equivalent to <b>--keep-old-blank-lines=1</b> and is included for compatibility with previous versions.</p>
</dd>
</dl>
<p><b>Controls for blank lines around lines of consecutive keywords</b></p>
<p>The parameters in this section provide some control over the placement of blank lines within and around groups of statements beginning with selected keywords. These blank lines are called here <b>keyword group blanks</b>, and all of the parameters begin with <b>--keyword-group-blanks*</b>, or <b>-kgb*</b> for short. The default settings do not employ these controls but they can be enabled with the following parameters:</p>
<p><b>-kgbl=s</b> or <b>--keyword-group-blanks-list=s</b>; <b>s</b> is a quoted string of keywords</p>
<p><b>-kgbs=s</b> or <b>--keyword-group-blanks-size=s</b>; <b>s</b> gives the number of keywords required to form a group.</p>
<p><b>-kgbb=n</b> or <b>--keyword-group-blanks-before=n</b>; <b>n</b> = (0, 1, or 2) controls a leading blank</p>
<p><b>-kgba=n</b> or <b>--keyword-group-blanks-after=n</b>; <b>n</b> = (0, 1, or 2) controls a trailing blank</p>
<p><b>-kgbi</b> or <b>--keyword-group-blanks-inside</b> is a switch for adding blanks between subgroups</p>
<p><b>-kgbd</b> or <b>--keyword-group-blanks-delete</b> is a switch for removing initial blank lines between keywords</p>
<p><b>-kgbr=n</b> or <b>--keyword-group-blanks-repeat-count=n</b> can limit the number of times this logic is applied</p>
<p>In addition, the following abbreviations are available to for simplified usage:</p>
<p><b>-kgb</b> or <b>--keyword-group-blanks</b> is short for <b>-kgbb=2 -kgba=2 kgbi</b></p>
<p><b>-nkgb</b> or <b>--nokeyword-group-blanks</b>, is short for <b>-kgbb=1 -kgba=1 nkgbi</b></p>
<p>Before describing the meaning of the parameters in detail let us look at an example which is formatted with default parameter settings.</p>
<pre><code> print "Entering test 2\n";
use Test;
use Encode qw(from_to encode decode
encode_utf8 decode_utf8
find_encoding is_utf8);
use charnames qw(greek);
my @encodings = grep( /iso-?8859/, Encode::encodings() );
my @character_set = ( '0' .. '9', 'A' .. 'Z', 'a' .. 'z' );
my @source = qw(ascii iso8859-1 cp1250);
my @destiny = qw(cp1047 cp37 posix-bc);
my @ebcdic_sets = qw(cp1047 cp37 posix-bc);
my $str = join( '', map( chr($_), 0x20 .. 0x7E ) );
return unless ($str);</code></pre>
<p>using <b>perltidy -kgb</b> gives:</p>
<pre><code> print "Entering test 2\n";
<----------this blank controlled by -kgbb
use Test;
use Encode qw(from_to encode decode
encode_utf8 decode_utf8
find_encoding is_utf8);
use charnames qw(greek);
<---------this blank controlled by -kgbi
my @encodings = grep( /iso-?8859/, Encode::encodings() );
my @character_set = ( '0' .. '9', 'A' .. 'Z', 'a' .. 'z' );
my @source = qw(ascii iso8859-1 cp1250);
my @destiny = qw(cp1047 cp37 posix-bc);
my @ebcdic_sets = qw(cp1047 cp37 posix-bc);
my $str = join( '', map( chr($_), 0x20 .. 0x7E ) );
<----------this blank controlled by -kgba
return unless ($str);</code></pre>
<p>Blank lines have been introduced around the <b>my</b> and <b>use</b> sequences. What happened is that the default keyword list includes <b>my</b> and <b>use</b> but not <b>print</b> and <b>return</b>. So a continuous sequence of nine <b>my</b> and <b>use</b> statements was located. This number exceeds the default threshold of five, so blanks were placed before and after the entire group. Then, since there was also a subsequence of six <b>my</b> lines, a blank line was introduced to separate them.</p>
<p>Finer control over blank placement can be achieved by using the individual parameters rather than the <b>-kgb</b> flag. The individual controls are as follows.</p>
<p><b>-kgbl=s</b> or <b>--keyword-group-blanks-list=s</b>, where <b>s</b> is a quoted string, defines the set of keywords which will be formed into groups. The string is a space separated list of keywords. The default set is <b>s="use require local our my"</b>, but any list of keywords may be used. Comment lines may also be included in a keyword group, even though they are not keywords. To include ordinary block comments, include the symbol <b>BC</b>. To include static block comments (which normally begin with '##'), include the symbol <b>SBC</b>.</p>
<p><b>-kgbs=s</b> or <b>--keyword-group-blanks-size=s</b>, where <b>s</b> is a string describing the number of consecutive keyword statements forming a group (Note: statements separated by blank lines in the input file are considered consecutive for purposes of this count). If <b>s</b> is an integer then it is the minimum number required for a group. A maximum value may also be given with the format <b>s=min.max</b>, where <b>min</b> is the minimum number and <b>max</b> is the maximum number, and the min and max values are separated by one or more dots. No groups will be found if the maximum is less than the minimum. The maximum is unlimited if not given. The default is <b>s=5</b>. Some examples:</p>
<pre><code> s min max number for group
3 3 unlimited 3 or more
1.1 1 1 1
1..3 1 3 1 to 3
1.0 1 0 (no match)</code></pre>
<p>There is no really good default value for this parameter. If it is set too small, then an excessive number of blank lines may be generated. However, some users may prefer reducing the value somewhat below the default, perhaps to <b>s=3</b>.</p>
<p><b>-kgbb=n</b> or <b>--keyword-group-blanks-before=n</b> specifies whether a blank should appear before the first line of the group, as follows:</p>
<pre><code> n=0 => (delete) an existing blank line will be removed
n=1 => (stable) no change to the input file is made [DEFAULT]
n=2 => (insert) a blank line is introduced if possible</code></pre>
<p><b>-kgba=n</b> or <b>--keyword-group-blanks-after=n</b> likewise specifies whether a blank should appear after the last line of the group, using the same scheme (0=delete, 1=stable, 2=insert).</p>
<p><b>-kgbi</b> or <b>--keyword-group-blanks-inside</b> controls the insertion of blank lines between the first and last statement of the entire group. If there is a continuous run of a single statement type with more than the minimum threshold number (as specified with <b>-kgbs=s</b>) then this switch causes a blank line be inserted between this subgroup and the others. In the example above this happened between the <b>use</b> and <b>my</b> statements.</p>
<p><b>-kgbd</b> or <b>--keyword-group-blanks-delete</b> controls the deletion of any blank lines that exist in the the group when it is first scanned. When statements are initially scanned, any existing blank lines are included in the collection. Any such original blank lines will be deleted before any other insertions are made when the parameter <b>-kgbd</b> is set. The default is not to do this, <b>-nkgbd</b>.</p>
<p><b>-kgbr=n</b> or <b>--keyword-group-blanks-repeat-count=n</b> specifies <b>n</b>, the maximum number of times this logic will be applied to any file. The special value <b>n=0</b> is the same as n=infinity which means it will be applied to an entire script [Default]. A value <b>n=1</b> could be used to make it apply just one time for example. This might be useful for adjusting just the <b>use</b> statements in the top part of a module for example.</p>
<p><b>-kgb</b> or <b>--keyword-group-blanks</b> is an abbreviation equivalent to setting <b>-kgbb=1 -kgba=1 -kgbi</b>. This turns on keyword group formatting with a set of default values.</p>
<p><b>-nkgb</b> or <b>--nokeyword-group-blanks</b> is equivalent to <b>-kgbb=0 -kgba nkgbi</b>. This flag turns off keyword group blank lines and is the default setting.</p>
<p>Here are a few notes about the functioning of this technique.</p>
<ul>
<li><p>These parameters are probably more useful as part of a major code reformatting operation rather than as a routine formatting operation.</p>
<p>In particular, note that deleting old blank lines with <b>-kgbd</b> is an irreversible operation so it should be applied with care. Existing blank lines may be serving an important role in controlling vertical alignment.</p>
</li>
<li><p>Conflicts which arise among these <b>kgb*</b> parameters and other blank line controls are generally resolved by producing the maximum number of blank lines implied by any parameter.</p>
<p>For example, if the flags <b>--freeze-blank-lines</b>, or <b>--keep-old-blank-lines=2</b>, are set, then they have priority over any blank line deletion implied by the <b>-kgb</b> flags of this section, so no blank lines will be deleted.</p>
<p>For another example, if a keyword group ends at a <b>sub</b> and the flag <b>kgba=0</b> requests no blank line there, but we also have <b>--blank-lines-before-subs=2</b>, then two blank lines will still be introduced before the sub.</p>
</li>
<li><p>The introduction of blank lines does not occur if it would conflict with other input controls or code validity. For example, a blank line will not be placed within a here-doc or within a section of code marked with format skipping comments. And in general, a blank line will only be introduced at the end of a group if the next statement is a line of code.</p>
</li>
<li><p>The count which is used to determine the group size is not the number of lines but rather the total number of keywords which are found. Individual statements with a certain leading keyword may continue on multiple lines, but if any of these lines is nested more than one level deep then that group will be ended.</p>
</li>
<li><p>The search for groups of lines with similar leading keywords is based on the input source, not the final formatted source. Consequently, if the source code is badly formatted, it would be best to make a first formatting pass without these options.</p>
</li>
</ul>
<h2 id="Styles">Styles</h2>
<p>A style refers to a convenient collection of existing parameters.</p>
<dl>
<dt id="gnu---gnu-style"><b>-gnu</b>, <b>--gnu-style</b></dt>
<dd>
<p><b>-gnu</b> gives an approximation to the GNU Coding Standards (which do not apply to perl) as they are sometimes implemented. At present, this style overrides the default style with the following parameters:</p>
<pre><code> -lp -bl -noll -pt=2 -bt=2 -sbt=2 -icp</code></pre>
<p>To use this style with <b>-xlp</b> (<b>--extended-line-up-parentheses</b>) instead of <b>-lp</b> (<b>--line-up-parentheses</b>) use <b>-gnu -xlp</b>.</p>
</dd>
<dt id="pbp---perl-best-practices"><b>-pbp</b>, <b>--perl-best-practices</b></dt>
<dd>
<p><b>-pbp</b> is an abbreviation for the parameters in the book <b>Perl Best Practices</b> by Damian Conway:</p>
<pre><code> -l=78 -i=4 -ci=4 -st -se -vt=2 -cti=0 -pt=1 -bt=1 -sbt=1 -bbt=1
-nsfs -nolq
-wbb="% + - * / x != == >= <= =~ !~ < > | & =
**= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x="</code></pre>
<p>Please note that this parameter set includes <b>-st</b> (<b>--standard-output</b>) and <b>-se</b> (<b>--standard-error-output</b>) flags, which make perltidy act as a filter on one file only. These can be overridden by placing <b>-nst</b> and/or <b>-nse</b> after the -pbp parameter.</p>
<p>Also note that the value of continuation indentation, <b>-ci=4</b>, is equal to the value of the full indentation, <b>-i=4</b>. It is recommended that the either (1) the parameter <b>-ci=2</b> be used instead, or (2) the flag <b>-xci</b> be set. This will help show structure, particularly when there are ternary statements. The following snippet illustrates these options.</p>
<pre><code> # perltidy -pbp
$self->{_text} = (
!$section ? ''
: $type eq 'item' ? "the $section entry"
: "the section on $section"
)
. (
$page
? ( $section ? ' in ' : '' ) . "the $page_ext manpage"
: ' elsewhere in this document'
);
# perltidy -pbp -ci=2
$self->{_text} = (
!$section ? ''
: $type eq 'item' ? "the $section entry"
: "the section on $section"
)
. (
$page
? ( $section ? ' in ' : '' ) . "the $page_ext manpage"
: ' elsewhere in this document'
);
# perltidy -pbp -xci
$self->{_text} = (
!$section ? ''
: $type eq 'item' ? "the $section entry"
: "the section on $section"
)
. ( $page
? ( $section ? ' in ' : '' ) . "the $page_ext manpage"
: ' elsewhere in this document'
);</code></pre>
<p>The <b>-xci</b> flag was developed after the <b>-pbp</b> parameters were published so you need to include it separately.</p>
</dd>
<dt id="Making-a-file-unreadable"><b>Making a file unreadable</b></dt>
<dd>
<p>The goal of perltidy is to improve the readability of files, but there are two commands which have the opposite effect, <b>--mangle</b> and <b>--extrude</b>. They are actually merely aliases for combinations of other parameters. Both of these strip all possible whitespace, but leave comments and pod documents, so that they are essentially reversible. The difference between these is that <b>--mangle</b> puts the fewest possible line breaks in a script while <b>--extrude</b> puts the maximum possible. Note that these options do not provided any meaningful obfuscation, because perltidy can be used to reformat the files. They were originally developed to help test the tokenization logic of perltidy, but they have other uses. One use for <b>--mangle</b> is the following:</p>
<pre><code> perltidy --mangle myfile.pl -st | perltidy -o myfile.pl.new</code></pre>
<p>This will form the maximum possible number of one-line blocks (see next section), and can sometimes help clean up a badly formatted script.</p>
<p>A similar technique can be used with <b>--extrude</b> instead of <b>--mangle</b> to make the minimum number of one-line blocks.</p>
<p>Another use for <b>--mangle</b> is to combine it with <b>--delete-all-comments (-dac)</b> to reduce the file size of a perl script.</p>
</dd>
</dl>
<h2 id="One-Line-Blocks">One-Line Blocks</h2>
<p>A one-line block is a block of code where the contents within the curly braces is short enough to fit on a single line. For example,</p>
<pre><code> if ( -e $file ) { print "'$file' exists\n" }</code></pre>
<p>The alternative, a block which spans multiple lines, is said to be a broken block. With few exceptions, perltidy retains existing one-line blocks, if it is possible within the line-length constraint, but it does not attempt to form new ones. In other words, perltidy will try to follow the input file regarding broken and unbroken blocks.</p>
<p>The main exception to this rule is that perltidy will attempt to form new one-line blocks following the keywords <code>map</code>, <code>eval</code>, and <code>sort</code>, <code>eval</code>, because these code blocks are often small and most clearly displayed in a single line. This behavior can be controlled with the flag <b>--one-line-block-exclusion-list</b> described below.</p>
<p>When the <b>cuddled-else</b> style is used, the default treatment of one-line blocks may interfere with the cuddled style. In this case, the default behavior may be changed with the flag <b>--cuddled-break-option=n</b> described elsewhere.</p>
<p>When an existing one-line block is longer than the maximum line length, and must therefore be broken into multiple lines, perltidy checks for and adds any optional terminating semicolon (unless the <b>-nasc</b> option is used) if the block is a code block.</p>
<dl>
<dt id="olbxl-s---one-line-block-exclusion-list-s"><b>-olbxl=s</b>, <b>--one-line-block-exclusion-list=s</b></dt>
<dd>
<p>As noted above, perltidy will, by default, attempt to create new one-line blocks for certain block types. This flag allows the user to prevent this behavior for the block types listed in the string <b>s</b>. The list <b>s</b> may include any of the words <code>sort</code>, <code>map</code>, <code>grep</code>, <code>eval</code>, or it may be <code>*</code> to indicate all of these.</p>
<p>So for example to prevent multiline <b>eval</b> blocks from becoming one-line blocks, the command would be <b>-olbxl='eval'</b>. In this case, existing one-line <b>eval</b> blocks will remain on one-line if possible, and existing multiline <b>eval</b> blocks will remain multiline blocks.</p>
</dd>
<dt id="olbn-n---one-line-block-nesting-n"><b>-olbn=n</b>, <b>--one-line-block-nesting=n</b></dt>
<dd>
<p>Nested one-line blocks are lines with code blocks which themselves contain code blocks. For example, the following line is a nested one-line block.</p>
<pre><code> foreach (@list) { if ($_ eq $asked_for) { last } ++$found }</code></pre>
<p>The default behavior is to break such lines into multiple lines, but this behavior can be controlled with this flag. The values of n are:</p>
<pre><code> n=0 break nested one-line blocks into multiple lines [DEFAULT]
n=1 stable: keep existing nested-one line blocks intact</code></pre>
<p>For the above example, the default formatting (<b>-olbn=0</b>) is</p>
<pre><code> foreach (@list) {
if ( $_ eq $asked_for ) { last }
++$found;
}</code></pre>
<p>If the parameter <b>-olbn=1</b> is given, then the line will be left intact if it is a single line in the source, or it will be broken into multiple lines if it is broken in multiple lines in the source.</p>
</dd>
<dt id="olbs-n---one-line-block-semicolons-n"><b>-olbs=n</b>, <b>--one-line-block-semicolons=n</b></dt>
<dd>
<p>This flag controls the placement of semicolons at the end of one-line blocks. Semicolons are optional before a closing block brace, and frequently they are omitted at the end of a one-line block containing just a single statement. By default, perltidy follows the input file regarding these semicolons, but this behavior can be controlled by this flag. The values of n are:</p>
<pre><code> n=0 remove terminal semicolons in single-statement one-line blocks
n=1 stable; keep input terminal semicolons [DEFAULT ]
n=2 add terminal semicolons in all one-line blocks</code></pre>
<p>Note that the <b>n=2</b> option has no effect if adding semicolons is prohibited with the <b>-nasc</b> flag. Also not that while <b>n=2</b> adds missing semicolons to all one-line blocks, regardless of complexity, the <b>n=0</b> option only removes ending semicolons which terminate one-line blocks containing just one semicolon. So these two options are not exact inverses.</p>
</dd>
<dt id="Forming-new-one-line-blocks"><b>Forming new one-line blocks</b></dt>
<dd>
<p>Sometimes it might be desirable to convert a script to have one-line blocks whenever possible. Although there is currently no flag for this, a simple workaround is to execute perltidy twice, once with the flag <b>--noadd-newlines</b> and then once again with normal parameters, like this:</p>
<pre><code> cat infile | perltidy -nanl | perltidy >outfile</code></pre>
<p>When executed on this snippet</p>
<pre><code> if ( $? == -1 ) {
die "failed to execute: $!\n";
}
if ( $? == -1 ) {
print "Had enough.\n";
die "failed to execute: $!\n";
}</code></pre>
<p>the result is</p>
<pre><code> if ( $? == -1 ) { die "failed to execute: $!\n"; }
if ( $? == -1 ) {
print "Had enough.\n";
die "failed to execute: $!\n";
}</code></pre>
<p>This shows that blocks with a single statement become one-line blocks.</p>
</dd>
<dt id="Breaking-existing-one-line-blocks"><b>Breaking existing one-line blocks</b></dt>
<dd>
<p>There is no automatic way to break existing long one-line blocks into multiple lines, but this can be accomplished by processing a script, or section of a script, with a short value of the parameter <b>maximum-line-length=n</b>. Then, when the script is reformatted again with the normal parameters, the blocks which were broken will remain broken (with the exceptions noted above).</p>
<p>Another trick for doing this for certain block types is to format one time with the <b>--cuddled-else</b> flag and <b>--cuddled-break-option=2</b>. Then format again with the normal parameters. This will break any one-line blocks which are involved in a cuddled-else style.</p>
</dd>
</dl>
<h2 id="Controlling-Vertical-Alignment">Controlling Vertical Alignment</h2>
<p>Vertical alignment refers to lining up certain symbols in a list of consecutive similar lines to improve readability. For example, the "fat commas" are aligned in the following statement:</p>
<pre><code> $data = $pkg->new(
PeerAddr => join( ".", @port[ 0 .. 3 ] ),
PeerPort => $port[4] * 256 + $port[5],
Proto => 'tcp'
);</code></pre>
<p>Vertical alignment can be completely turned off using the <b>-novalign</b> flag mentioned below. However, vertical alignment can be forced to stop and restart by selectively introducing blank lines. For example, a blank has been inserted in the following code to keep somewhat similar things aligned.</p>
<pre><code> %option_range = (
'format' => [ 'tidy', 'html', 'user' ],
'output-line-ending' => [ 'dos', 'win', 'mac', 'unix' ],
'character-encoding' => [ 'none', 'utf8' ],
'block-brace-tightness' => [ 0, 2 ],
'brace-tightness' => [ 0, 2 ],
'paren-tightness' => [ 0, 2 ],
'square-bracket-tightness' => [ 0, 2 ],
);</code></pre>
<p>Vertical alignment is implemented by locally increasing an existing blank space to produce alignment with an adjacent line. It cannot occur if there is no blank space to increase. So if a particular space is removed by one of the existing controls then vertical alignment cannot occur. Likewise, if a space is added with one of the controls, then vertical alignment might occur.</p>
<p>For example,</p>
<pre><code> # perltidy -nwls='=>'
$data = $pkg->new(
PeerAddr=> join( ".", @port[ 0 .. 3 ] ),
PeerPort=> $port[4] * 256 + $port[5],
Proto=> 'tcp'
);</code></pre>
<dl>
<dt id="Completely-turning-off-vertical-alignment-with--novalign"><b>Completely turning off vertical alignment with -novalign</b></dt>
<dd>
<p>The default is to use vertical alignment, but vertical alignment can be completely turned of with the <b>-novalign</b> flag.</p>
<p>A lower level of control of vertical alignment is possible with three parameters <b>-vc</b>, <b>-vsc</b>, and <b>-vbc</b>. These independently control alignment of code, side comments and block comments. They are described in the next section.</p>
<p>The parameter <b>-valign</b> is in fact an alias for <b>-vc -vsc -vbc</b>, and its negative <b>-novalign</b> is an alias for <b>-nvc -nvsc -nvbc</b>.</p>
</dd>
<dt id="Controlling-code-alignment-with---valign-code-or--vc"><b>Controlling code alignment with --valign-code or -vc</b></dt>
<dd>
<p>The <b>-vc</b> flag enables alignment of code symbols such as <b>=</b>. The default is <b>-vc</b>. For detailed control of which symbols to align, see the <b>-valign-exclude-list</b> parameter below.</p>
</dd>
<dt id="Controlling-side-comment-alignment-with---valign-side-comments-or--vsc"><b>Controlling side comment alignment with --valign-side-comments or -vsc</b></dt>
<dd>
<p>The <b>-vsc</b> flag enables alignment of side comments and is enabled by default. If side comment alignment is disabled with <b>-nvsc</b> they will appear at a fixed space from the preceding code token. The default is <b>-vsc</b></p>
</dd>
<dt id="Controlling-block-comment-alignment-with---valign-block-comments-or--vbc"><b>Controlling block comment alignment with --valign-block-comments or -vbc</b></dt>
<dd>
<p>When <b>-vbc</b> is enabled, block comments can become aligned for example if one comment of a consecutive sequence of comments becomes outdented due a length in excess of the maximum line length. If this occurs, the entire group of comments will remain aligned and be outdented by the same amount. This coordinated alignment will not occur if <b>-nvbc</b> is set. The default is <b>-vbc</b>.</p>
</dd>
<dt id="Finer-alignment-control-with---valign-exclusion-list-s-or--vxl-s-and---valign-inclusion-list-s-or--vil-s"><b>Finer alignment control with --valign-exclusion-list=s or -vxl=s and --valign-inclusion-list=s or -vil=s</b></dt>
<dd>
<p>More detailed control of alignment types is available with these two parameters. Most of the vertical alignments in typical programs occur at one of the tokens ',', '=', and '=>', but many other alignments are possible and are given in the following list:</p>
<pre><code> = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=
{ ( ? : , ; => && || ~~ !~~ =~ !~ // <=> -> q
if unless and or err for foreach while until</code></pre>
<p>These alignment types correspond to perl symbols, operators and keywords except for 'q', which refers to the special case of alignment in a 'use' statement of qw quotes and empty parens.</p>
<p>They are all enabled by default, but they can be selectively disabled by including one or more of these tokens in the space-separated list <b>valign-exclusion-list=s</b>. For example, the following would prevent alignment at <b>=</b> and <b>if</b>:</p>
<pre><code> --valign-exclusion-list='= if'</code></pre>
<p>If it is simpler to specify only the token types which are to be aligned, then include the types which are to be aligned in the list of <b>--valign-inclusion-list</b>. In that case you may leave the <b>valign-exclusion-list</b> undefined, or use the special symbol <b>*</b> for the exclusion list. For example, the following parameters enable alignment only at commas and 'fat commas':</p>
<pre><code> --valign-inclusion-list=', =>'
--valign-exclusion-list='*' ( this is optional and may be omitted )</code></pre>
<p>These parameter lists should consist of space-separated tokens from the above list of possible alignment tokens, or a '*'. If an unrecognized token appears, it is simply ignored. And if a specific token is entered in both lists by mistake then the exclusion list has priority.</p>
<p>The default values of these parameters enable all alignments and are equivalent to</p>
<pre><code> --valign-exclusion-list=' '
--valign-inclusion-list='*'</code></pre>
<p>To illustrate, consider the following snippet with default formatting</p>
<pre><code> # perltidy
$co_description = ($color) ? 'bold cyan' : ''; # descr
$co_prompt = ($color) ? 'bold green' : ''; # prompt
$co_unused = ($color) ? 'on_green' : 'reverse'; # unused</code></pre>
<p>To exclude all alignments except the equals (i.e., include only equals) we could use:</p>
<pre><code> # perltidy -vil='='
$co_description = ($color) ? 'bold cyan' : ''; # descr
$co_prompt = ($color) ? 'bold green' : ''; # prompt
$co_unused = ($color) ? 'on_green' : 'reverse'; # unused</code></pre>
<p>To exclude only the equals we could use:</p>
<pre><code> # perltidy -vxl='='
$co_description = ($color) ? 'bold cyan' : ''; # descr
$co_prompt = ($color) ? 'bold green' : ''; # prompt
$co_unused = ($color) ? 'on_green' : 'reverse'; # unused</code></pre>
<p>Notice in this last example that although only the equals alignment was excluded, the ternary alignments were also lost. This happens because the vertical aligner sweeps from left-to-right and usually stops if an important alignment cannot be made for some reason.</p>
<p>But also notice that side comments remain aligned because their alignment is controlled separately with the parameter <b>--valign-side-comments</b> described above.</p>
</dd>
<dt id="Aligning-postfix-unless-and-if-with---valign-if-unless-or--viu"><b>Aligning postfix unless and if with --valign-if-unless or -viu</b></dt>
<dd>
<p>By default, postfix <b>if</b> terms align and postfix <b>unless</b> terms align, but separately. For example,</p>
<pre><code> # perltidy [DEFAULT]
print "Tried to add: @Resolve\n" if ( @Resolve and !$Quiet );
print "Would need: @DepList\n" if ( @DepList and !$Quiet );
print "Output:\n" unless $Quiet;
print join( "\n", @Output ) . "\n" unless $Quiet;</code></pre>
<p>The <b>-viu</b> flag causes a postfix <b>unless</b> to be treated as if it were a postfix <b>if</b> for purposes of alignment, and thus they align:</p>
<pre><code> # perltidy -viu
print "Tried to add: @Resolve\n" if ( @Resolve and !$Quiet );
print "Would need: @DepList\n" if ( @DepList and !$Quiet );
print "Output:\n" unless $Quiet;
print join( "\n", @Output ) . "\n" unless $Quiet;</code></pre>
</dd>
<dt id="Aligning-signed-numbers-with---valign-signed-numbers-or--vsn"><b>Aligning signed numbers with --valign-signed-numbers or -vsn</b></dt>
<dd>
<p>Setting <b>-vsn</b> causes columns of numbers containing both signed and unsigned values to have leading signs placed in their own column. For example:</p>
<pre><code> # perltidy -vsn
my @correct = (
[ 123456.79, 86753090000.868, 11 ],
[ -123456.79, -86753090000.868, -11 ],
[ 123456.001, 80.080, 10 ],
[ -123456.001, -80.080, 0 ],
[ 10.9, 10.9, 11 ],
);</code></pre>
<p>The default is <b>-vsn</b>. This can be turned off to get is strict left justification:</p>
<pre><code> # perltidy -nvsn
my @correct = (
[ 123456.79, 86753090000.868, 11 ],
[ -123456.79, -86753090000.868, -11 ],
[ 123456.001, 80.080, 10 ],
[ -123456.001, -80.080, 0 ],
[ 10.9, 10.9, 11 ],
);</code></pre>
<p>Some points regarding <b>-vsn</b> are:</p>
<ul>
<li><p>This option works by inserting a single space ahead of unsigned numbers when possible. This is not done if it would require increasing the maximum width of a column.</p>
</li>
<li><p>This option is mainly limited to lists of comma-separated numbers. For multiline lists of numbers, having trailing commas can sometimes improve the results. If missing, perltidy can add them for example with parameters <b>-wtc=b -atc</b>. See <a href="#Adding-and-Deleting-Commas">"Adding and Deleting Commas"</a>.</p>
</li>
<li><p>This option has a control parameter <b>--valign-signed-number-limit=N</b>, or <b>-vsnl=N</b>. This value controls formatting of very long columns of numbers and should not normally need to be changed. To see its purpose, consider a very long column of just unsigned numbers, say 1000 lines. If we add a single negative number, it is undesirable to move all of the other numbers over by one space. This could create many lines of file differences but not really improve the appearance when a local section of the table was viewed. The number <b>N</b> avoids this problem by not adding extra indentation to a run of more than <b>N</b> lines of unsigned numbers. The default value, <b>N=20</b>, is set to be a number of lines for which the ends of a long column of unsigned numbers are not normally both in view.</p>
</li>
</ul>
</dd>
<dt id="Aligning-assignment-operators-with---valign-wide-equals-or--vwe"><b>Aligning assignment operators with --valign-wide-equals or -vwe</b></dt>
<dd>
<p>The following assignment operators are aligned independently by default:</p>
<pre><code> = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=</code></pre>
<p>Setting <b>--valign-wide-equals</b>, or <b>-vwe</b>, causes them to be vertically aligned together with the trailing <b>=</b> all aligned. For example, here is the default formatting for some code with several of these operators:</p>
<pre><code> $str .= SPACE x $total_pad_count;
$str_len += $total_pad_count;
$total_pad_count = 0;
$str .= $rfields->[$j];
$str_len += $rfield_lengths->[$j];</code></pre>
<p>And here is the same code formatted with <b>-vme</b>:</p>
<pre><code> # perltidy -vme
$str .= SPACE x $total_pad_count;
$str_len += $total_pad_count;
$total_pad_count = 0;
$str .= $rfields->[$j];
$str_len += $rfield_lengths->[$j];</code></pre>
<p>This option was added for issue git #135 and can improve readability, but it is off by default to avoid changing existing formatting.</p>
</dd>
</dl>
<h2 id="Extended-Syntax">Extended Syntax</h2>
<p>This section describes some parameters for dealing with extended syntax.</p>
<p>For another method of handling extended syntax see the section <a href="#Skipping-Selected-Sections-of-Code">"Skipping Selected Sections of Code"</a>.</p>
<p>Also note that the module <i>Perl::Tidy</i> supplies a pre-filter and post-filter capability. This requires calling the module from a separate program rather than through the binary <i>perltidy</i>.</p>
<dl>
<dt id="xs---extended-syntax"><b>-xs</b>, <b>--extended-syntax</b></dt>
<dd>
<p>This flag allows perltidy to handle certain common extensions to the standard syntax without complaint.</p>
<p>For example, without this flag a structure such as the following would generate a syntax error:</p>
<pre><code> Method deposit( Num $amount) {
$self->balance( $self->balance + $amount );
}</code></pre>
<p>This flag is enabled by default but it can be deactivated with <b>-nxs</b>. Probably the only reason to deactivate this flag is to generate more diagnostic messages when debugging a script.</p>
</dd>
<dt id="sal-s---sub-alias-list-s"><b>-sal=s</b>, <b>--sub-alias-list=s</b></dt>
<dd>
<p>This flag causes one or more words to be treated the same as if they were the keyword <b>sub</b>. The string <b>s</b> contains one or more alias words, separated by spaces or commas.</p>
<p>For example,</p>
<pre><code> perltidy -sal='method fun _sub M4'</code></pre>
<p>will cause the perltidy to treat the words 'method', 'fun', '_sub' and 'M4' the same as if they were 'sub'. Note that if the alias words are separated by spaces then the string of words should be placed in quotes.</p>
<p>Note that several other parameters accept a list of keywords, including 'sub' (see <a href="#Specifying-Block-Types">"Specifying Block Types"</a>). You do not need to include any sub aliases in these lists. Just include keyword 'sub' if you wish, and all aliases are automatically included.</p>
</dd>
<dt id="gal-s---grep-alias-list-s"><b>-gal=s</b>, <b>--grep-alias-list=s</b></dt>
<dd>
<p>This flag allows a code block following an external 'list operator' function to be formatted as if it followed one of the built-in keywords <b>grep</b>, <b>map</b> or <b>sort</b>. The string <b>s</b> contains the names of one or more such list operators, separated by spaces or commas.</p>
<p>By 'list operator' is meant a function which is invoked in the form</p>
<pre><code> word {BLOCK} @list</code></pre>
<p>Perltidy tries to keep code blocks for these functions intact, since they are usually short, and does not automatically break after the closing brace since a list may follow. It also does some special handling of continuation indentation.</p>
<p>For example, the code block arguments to functions 'My_grep' and 'My_map' can be given formatting like 'grep' with</p>
<pre><code> perltidy -gal='My_grep My_map'</code></pre>
<p>By default, the following list operators in List::Util are automatically included:</p>
<pre><code> all any first none notall reduce reductions</code></pre>
<p>Any operators specified with <b>--grep-alias-list</b> are added to this list. The next parameter can be used to remove words from this default list.</p>
</dd>
<dt id="gaxl-s---grep-alias-exclusion-list-s"><b>-gaxl=s</b>, <b>--grep-alias-exclusion-list=s</b></dt>
<dd>
<p>The <b>-gaxl=s</b> flag provides a method for removing any of the default list operators given above by listing them in the string <b>s</b>. To remove all of the default operators use <b>-gaxl='*'</b>.</p>
</dd>
<dt id="uf-s---use-feature-s"><b>-uf=s</b>, <b>--use-feature=s</b></dt>
<dd>
<p>This flag tells perltidy to allow or disallow the syntax associated a pragma in string <b>s</b>. The current possible settings are:</p>
<ul>
<li><p><b>--use-feature='class'</b>. This tells perltidy to recognized the special words <b>class</b>, <b>method</b>, <b>field</b>, and <b>ADJUST</b> as defined for this feature.</p>
</li>
<li><p><b>--use-feature='noclass'</b>. This tells perltidy <b>not</b> to treat words <b>class</b>, <b>method</b>, <b>field</b>, <b>ADJUST</b> specially.</p>
</li>
<li><p><b>Neither of these</b> (<b>--use-feature</b> not defined). This is the DEFAULT and recommended setting. In this case perltidy will try to automatically handle both the newer --use-feature 'class' syntax as well as some conflicting uses of some of these special words by existing modules.</p>
</li>
</ul>
<p>Note that this parameter is independent of any <b>use feature</b> control lines within a script. Perltidy does not look for or read such control lines. This is because perltidy must be able to work on small chunks of code sent from an editor, so it cannot assume that such lines will be within the lines being formatted.</p>
</dd>
<dt id="Working-around-problems-with-older-version-of-Perl"><b>Working around problems with older version of Perl</b></dt>
<dd>
<p>Perltidy contains a number of rules which help avoid known subtleties and problems with older versions of perl, and these rules always take priority over whatever formatting flags have been set. For example, perltidy will usually avoid starting a new line with a bareword, because this might cause problems if <code>use strict</code> is active.</p>
<p>There is no way to override these rules.</p>
</dd>
</dl>
<h2 id="Deleting-and-Extracting-Pod-or-Comments">Deleting and Extracting Pod or Comments</h2>
<dl>
<dt id="Deleting-selected-text"><b>Deleting selected text</b></dt>
<dd>
<p>Perltidy can selectively delete comments and/or pod documentation. The command <b>-dac</b> or <b>--delete-all-comments</b> will delete all comments <b>and</b> all pod documentation, leaving just code and any leading system control lines.</p>
<p>The command <b>-dp</b> or <b>--delete-pod</b> will remove all pod documentation (but not comments).</p>
<p>Two commands which remove comments (but not pod) are: <b>-dbc</b> or <b>--delete-block-comments</b> and <b>-dsc</b> or <b>--delete-side-comments</b>. (Hanging side comments will be deleted with side comments here.)</p>
<p>When side comments are deleted, any special control side comments for non-indenting braces will be retained unless they are deactivated with a <b>-nnib</b> flag.</p>
<p>The negatives of these commands also work, and are the defaults. When block comments are deleted, any leading 'hash-bang' will be retained. Also, if the <b>-x</b> flag is used, any system commands before a leading hash-bang will be retained (even if they are in the form of comments).</p>
</dd>
<dt id="Writing-selected-text-to-a-file"><b>Writing selected text to a file</b></dt>
<dd>
<p>When perltidy writes a formatted text file, it has the ability to also send selected text to a file with a <i>.TEE</i> extension. This text can include comments and pod documentation.</p>
<p>The command <b>-tac</b> or <b>--tee-all-comments</b> will write all comments <b>and</b> all pod documentation.</p>
<p>The command <b>-tp</b> or <b>--tee-pod</b> will write all pod documentation (but not comments).</p>
<p>The commands which write comments (but not pod) are: <b>-tbc</b> or <b>--tee-block-comments</b> and <b>-tsc</b> or <b>--tee-side-comments</b>. (Hanging side comments will be written with side comments here.)</p>
<p>The negatives of these commands also work, and are the defaults.</p>
</dd>
</dl>
<h2 id="The-perltidyrc-file">The perltidyrc file</h2>
<dl>
<dt id="Using-a-.perltidyrc-command-file"><b>Using a <i>.perltidyrc</i> command file</b></dt>
<dd>
<p>If you use perltidy frequently, you probably won't be happy until you create a <i>.perltidyrc</i> file to avoid typing commonly-used parameters. Perltidy will first look in your current directory for a command file named <i>.perltidyrc</i>. If it does not find one, it will continue looking for one in other standard locations.</p>
<p>These other locations are system-dependent, and may be displayed with the command <code>perltidy -dpro</code>. Under Unix systems, it will first look for an environment variable <b>PERLTIDY</b>. Then it will look for a <i>.perltidyrc</i> file in the home directory, and then for a system-wide file <i>/usr/local/etc/perltidyrc</i>, and then it will look for <i>/etc/perltidyrc</i>. Note that these last two system-wide files do not have a leading dot. Further system-dependent information will be found in the INSTALL file distributed with perltidy.</p>
<p>Under Windows, perltidy will also search for a configuration file named <i>perltidy.ini</i> since Windows does not allow files with a leading period (.). Use <code>perltidy -dpro</code> to see the possible locations for your system. An example might be <i>C:\Documents and Settings\All Users\perltidy.ini</i>.</p>
<p>Another option is the use of the PERLTIDY environment variable. The method for setting environment variables depends upon the version of Windows that you are using.</p>
<p>Under Windows NT / 2000 / XP the PERLTIDY environment variable can be placed in either the user section or the system section. The later makes the configuration file common to all users on the machine. Be sure to enter the full path of the configuration file in the value of the environment variable. Ex. PERLTIDY=C:\Documents and Settings\perltidy.ini</p>
<p>The configuration file is free format, and simply a list of parameters, just as they would be entered on a command line. Any number of lines may be used, with any number of parameters per line, although it may be easiest to read with one parameter per line. Comment text begins with a #, and there must also be a space before the # for side comments. It is a good idea to put complex parameters in either single or double quotes.</p>
<p>Here is an example of a <i>.perltidyrc</i> file:</p>
<pre><code> # This is a simple of a .perltidyrc configuration file
# This implements a highly spaced style
-se # errors to standard error output
-w # show all warnings
-bl # braces on new lines
-pt=0 # parens not tight at all
-bt=0 # braces not tight
-sbt=0 # square brackets not tight</code></pre>
<p>The parameters in the <i>.perltidyrc</i> file are installed first, so any parameters given on the command line will have priority over them.</p>
<p>To avoid confusion, perltidy ignores any command in the .perltidyrc file which would cause some kind of dump and an exit. These include:</p>
<pre><code> -h -v -ddf -dln -dop -dsn -dtt -dwls -dwrs -ss</code></pre>
<p>There are several options may be helpful in debugging a <i>.perltidyrc</i> file:</p>
<ul>
<li><p>A very helpful command is <b>--dump-profile</b> or <b>-dpro</b>. It writes a list of all configuration filenames tested to standard output, and if a file is found, it dumps the content to standard output before exiting. So, to find out where perltidy looks for its configuration files, and which one if any it selects, just enter</p>
<pre><code> perltidy -dpro</code></pre>
</li>
<li><p>It may be simplest to develop and test configuration files with alternative names, and invoke them with <b>-pro=filename</b> on the command line. Then rename the desired file to <i>.perltidyrc</i> when finished.</p>
</li>
<li><p>The parameters in the <i>.perltidyrc</i> file can be switched off with the <b>-npro</b> option on the command line.</p>
</li>
<li><p>Any parameter in the <i>.perltidyrc</i> file can be overridden with a replacement value on the command line. This is because the command line is processed after the <i>.perltidyrc</i> file.</p>
</li>
<li><p>The commands <b>--dump-options</b>, <b>--dump-defaults</b>, <b>--dump-long-names</b>, and <b>--dump-short-names</b>, all described below, may all be helpful.</p>
</li>
</ul>
</dd>
<dt id="Skipping-a-line-with-an-unknown-parameter"><b>Skipping a line with an unknown parameter</b></dt>
<dd>
<p>Versions of perltidy greater than 20240511 have an option to filter unrecognized parameters from a perltidy command file. If a line in the file begins with <b>three dashes</b> followed by a parameter name (rather than one or two), then the line will be removed if the parameter is unknown. Otherwise, a dash will be removed to make the line valid. This option was added to allow a single command file to be used during the transition to a new version of perltidy.</p>
</dd>
<dt id="Creating-a-new-abbreviation"><b>Creating a new abbreviation</b></dt>
<dd>
<p>A special notation is available for use in a <i>.perltidyrc</i> file for creating an abbreviation for a group of options. This can be used to create a shorthand for one or more styles which are frequently, but not always, used. The notation is to group the options within curly braces which are preceded by the name of the alias (without leading dashes), like this:</p>
<pre><code> newword {
-opt1
-opt2
}</code></pre>
<p>where <b>newword</b> is the abbreviation, and <b>opt1</b>, etc, are existing parameters <i>or other abbreviations</i>. The main syntax requirement is that the new abbreviation along with its opening curly brace must begin on a new line. Space before and after the curly braces is optional.</p>
<p>For a specific example, the following line</p>
<pre><code> oneliner { --maximum-line-length=0 --noadd-newlines --noadd-terminal-newline}</code></pre>
<p>or equivalently with abbreviations</p>
<pre><code> oneliner { -l=0 -nanl -natnl }</code></pre>
<p>could be placed in a <i>.perltidyrc</i> file to temporarily override the maximum line length with a large value, to temporarily prevent new line breaks from being added, and to prevent an extra newline character from being added the file. All other settings in the <i>.perltidyrc</i> file still apply. Thus it provides a way to format a long 'one liner' when perltidy is invoked with</p>
<pre><code> perltidy --oneliner ...</code></pre>
<p>(Either <code>-oneliner</code> or <code>--oneliner</code> may be used).</p>
</dd>
<dt id="Skipping-leading-non-perl-commands-with--x-or---look-for-hash-bang">Skipping leading non-perl commands with <b>-x</b> or <b>--look-for-hash-bang</b></dt>
<dd>
<p>If your script has leading lines of system commands or other text which are not valid perl code, and which are separated from the start of the perl code by a "hash-bang" line, ( a line of the form <code>#!...perl</code> ), you must use the <b>-x</b> flag to tell perltidy not to parse and format any lines before the "hash-bang" line. This option also invokes perl with a -x flag when checking the syntax. This option was originally added to allow perltidy to parse interactive VMS scripts, but it should be used for any script which is normally invoked with <code>perl -x</code>.</p>
<p>Please note: do not use this flag unless you are sure your script needs it. Parsing errors can occur if it does not have a hash-bang, or, for example, if the actual first hash-bang is in a here-doc. In that case a parsing error will occur because the tokenization will begin in the middle of the here-doc.</p>
</dd>
</dl>
<h2 id="Debugging-perltidy-input">Debugging perltidy input</h2>
<dl>
<dt id="The---dump-...-parameters">The <b>--dump-...</b> parameters</dt>
<dd>
<p>The following flags are available for debugging. Note that all commands named <b>--dump-...</b> will simply write some requested information to standard output and then immediately exit.</p>
<p><b>--dump-cuddled-block-list</b> or <b>-dcbl</b> will dump to standard output the internal hash of cuddled block types created by a <b>--cuddled-block-list</b> input string.</p>
<p><b>--dump-defaults</b> or <b>-ddf</b> will write the default option set to standard output and quit</p>
<p><b>--dump-integer-option-range</b> or <b>-dior</b> will write a list of comma-separated values. Each line contains the name of an integer option along with its minimum, maximum, and default values.</p>
<p><b>--dump-profile</b> or <b>-dpro</b> will write the name of the current configuration file and its contents to standard output and quit.</p>
<p><b>--dump-options</b> or <b>-dop</b> will write current option set to standard output and quit.</p>
<p><b>--dump-long-names</b> or <b>-dln</b> will write all command line long names (passed to Get_options) to standard output and quit.</p>
<p><b>--dump-short-names</b> or <b>-dsn</b> will write all command line short names to standard output and quit.</p>
<p><b>--dump-token-types</b> or <b>-dtt</b> will write a list of all token types to standard output and quit.</p>
<p><b>--dump-want-left-space</b> or <b>-dwls</b> will write the hash <code>%want_left_space</code> to standard output and quit. See the section on controlling whitespace around tokens.</p>
<p><b>--dump-want-right-space</b> or <b>-dwrs</b> will write the hash <code>%want_right_space</code> to standard output and quit. See the section on controlling whitespace around tokens.</p>
<p>See <a href="#Analyzing-Code">"Analyzing Code"</a> for additional <b>--dump-</b> parameters.</p>
</dd>
<dt id="Other-parameters-related-to-processing"><b>Other parameters related to processing</b></dt>
<dd>
<p><b>--no-memoize</b> or <b>-nmem</b> will turn of memoizing. Memoization can reduce run time when running perltidy repeatedly in a single process. It is on by default but can be deactivated for testing with <b>-nmem</b>.</p>
<p><b>--no-timestamp</b> or <b>-nts</b> will eliminate any time stamps in output files to prevent differences in dates from causing test installation scripts to fail. There are just a couple of places where timestamps normally occur. One is in the headers of html files, and another is when the <b>-cscw</b> option is selected. The default is to allow timestamps (<b>--timestamp</b> or <b>-ts</b>).</p>
<p><b>--file-size-order</b> or <b>-fso</b> will cause files to be processed in order of increasing size, when multiple files are being processed. This is particularly useful during program development, when large numbers of files with varying sizes are processed, because it can reduce virtual memory usage. This is the default and can be deactivated with <b>-nfso</b>.</p>
<p><b>--maximum-file-size-mb=n</b> or <b>-maxfs=n</b> specifies the maximum file size in megabytes that perltidy will attempt to format. This parameter is provided to avoid causing system problems by accidentally attempting to format an extremely large data file. Most perl scripts are less than about 2 MB in size. The integer <b>n</b> has a default value of 10, so perltidy will skip formatting files which have a size greater than 10 MB. The command to increase the limit to 20 MB for example would be</p>
<pre><code> perltidy -maxfs=20</code></pre>
<p>This length test is applied to named files before they are read into memory. It is applied to files arriving from standard input after they are read into memory. It is not applied to character strings arriving by a call to the Perl::Tidy module.</p>
</dd>
<dt id="Controls-for-when-to-stop-processing"><b>Controls for when to stop processing</b></dt>
<dd>
<p><b>--maximum-level-errors=n</b> or <b>-maxle=n</b> specifies the maximum number of indentation level errors are allowed before perltidy skips formatting and just outputs a file verbatim. The default is <b>n=1</b>. This means that if the final indentation of a script differs from the starting indentation by more than 1 levels, the file will be output verbatim. To avoid formatting if there are any indentation level errors use -maxle=0. To skip this check you can either set n equal to a large number, such as <b>n=100</b>, or set <b>n=-1</b>.</p>
<p>For example, the following script has level error of 3 and will be output verbatim</p>
<pre><code> Input and default output:
{{{
perltidy -maxle=100
{
{
{</code></pre>
<p><b>--maximum-unexpected-errors=n</b> or <b>-maxue=n</b> specifies the maximum number of unexpected tokenization errors are allowed before formatting is skipped and a script is output verbatim. The intention is to avoid accidentally formatting a non-perl script, such as an html file for example. This check can be turned off by setting <b>n=0</b>.</p>
<p>A recommended value is <b>n=3</b>. However, the default is <b>n=0</b> (skip this check) to avoid causing problems with scripts which have extended syntaxes.</p>
</dd>
<dt id="Handling-errors-in-options-which-take-integer-values"><b>Handling errors in options which take integer values</b></dt>
<dd>
<p>Many of the input parameters take integer values. Before processing begins, a check is made to see if any of these integer parameters exceed their valid ranges. The default behavior when a range is exceeded is to write a warning message and reset the value to its default setting. This default behavior can be changed with the parameter <b>--integer-range-check=n</b>, or <b>-irc=n</b>, as follows:</p>
<pre><code> n=0 skip check completely (for stress-testing perltidy only)
n=1 reset bad values to defaults but do not issue a warning
n=2 reset bad values to defaults and issue warning [DEFAULT]
n=3 stop if any values are out of bounds</code></pre>
<p>The values <b>n=0</b> and <b>n=1</b> are mainly useful for testing purposes.</p>
</dd>
<dt id="Debugging-perltidy-tokenization"><b>Debugging perltidy tokenization</b></dt>
<dd>
<p><b>-DEBUG, -D</b> will write a file with extension <i>.DEBUG</i> for each input file showing the tokenization of all lines of code. This can produce a lot of output and is mainly useful for debugging tokenization issues during perltidy development.</p>
</dd>
</dl>
<h2 id="Analyzing-Code">Analyzing Code</h2>
<p>Perltidy reports any obvious issues that are found during formatting, such as unbalanced braces. But several parameters are available for making certain additional checks for issues which might be of interest to a programmer. These parameters fall into two categories as indicated by their prefix, <b>--dump-</b> or <b>--warn-</b>:</p>
<ul>
<li><p>The <b>--dump-</b> parameters read a file, write information to the standard output, and then exit without doing any formatting.</p>
</li>
<li><p>The <b>--warn-</b> parameters, on the other hand, cause perltidy to function normally but issue warnings to the error output when certain conditions are encountered.</p>
</li>
</ul>
<p>Some of these have associated control parameters.</p>
<dl>
<dt id="Use---dump-block-summary-to-make-a-table-of-information-on-code-blocks"><b>Use --dump-block-summary to make a table of information on code blocks</b></dt>
<dd>
<p>A table listing information about the blocks of code in a file can be made with <b>--dump-block-summary</b>, or <b>-dbs</b>. This causes perltidy to read and parse the file, write a table of comma-separated values for selected code blocks to the standard output, and then exit. This parameter must be on the command line, not in a <i>.perlticyrc</i> file, and it requires a single file name on the command line. For example</p>
<pre><code> perltidy -dbs somefile.pl >blocks.csv</code></pre>
<p>produces an output file <i>blocks.csv</i> whose lines hold these parameters:</p>
<pre><code> filename - name of the file
line - line number of the opening brace of this block
line_count - number of lines between opening and closing braces
code_lines - number of lines excluding blanks, comments, and pod
type - block type (sub, for, foreach, ...)
name - block name if applicable (sub or asub name, label..)
depth - nesting depth of the opening block brace
max_change - change in depth to the most deeply nested code block
block_count - total number of code blocks nested in this block
mccabe_count - McCabe complexity measure of this code block</code></pre>
<p>This feature was developed to help identify complex sections of code as an aid in refactoring. The McCabe complexity measure follows the definition used by Perl::Critic. By default the table contains these values for subroutines, but the user may request them for any or all blocks of code or packages. For blocks which are loops nested within loops, a postfix '+' to the <code>type</code> is added to indicate possible code complexity. Although the table does not otherwise indicate which blocks are nested in other blocks, this can be determined by computing and comparing the block ending line numbers.</p>
<p>For subroutines, the number of call arguments (args) is listed in parentheses in the <code>type</code> column. For example, <code>sub(9)</code> indicates a sub with 9 args. Subroutines whose arg count cannot easily be determined are indicated as <code>sub(*)</code>. The count includes any leading object passed in a method call (such as <b>$self</b>).</p>
<p>By default the table lists subroutines with more than 20 <code>code_lines</code>, but this can be changed with the following two parameters:</p>
<p><b>--dump-block-minimum-lines=n</b>, or <b>-dbl=n</b>, where <b>n</b> is the minimum number of <code>code_lines</code> to be included. The default is <b>-n=20</b>. Note that <code>code_lines</code> is the number of lines excluding comments, blanks and pod.</p>
<p><b>--dump-block-types=s</b>, or <b>-dbt=s</b>, where string <b>s</b> is a list of block types to be included. The type of a block is either the name of the perl builtin keyword for that block (such as <b>sub if elsif else for foreach ..</b>) or the word immediately before the opening brace. In addition, there are a few symbols for special block types, as follows:</p>
<pre><code> if elsif else for foreach ... any keyword introducing a block
sub - any sub or anonymous sub
asub - any anonymous sub
* - any block except nameless blocks
+ - any nested inner block loop
package - any package or class
closure - any nameless block
elsif3 - an if-elsif- chain with 3 or more elsif's (see below)</code></pre>
<p>A chain of <b>if-elsif-...</b> blocks may be reported as a single line item by entering the word <b>elsif</b> with an appended integer, as indicated by the last item in this list. The integer indicates the number of <b>elsif</b> blocks required for a chain to be reported. If you use this, you may want to also use <b>-dbl=n</b>, with a smaller number of lines <b>n</b> than the default.</p>
<p>In addition, specific block loop types which are nested in other loops can be selected by adding a <b>+</b> after the block name. (Nested loops are sometimes good candidates for restructuring).</p>
<p>The default is <b>-dbt='sub'</b>.</p>
<p>In the following examples a table <code>block.csv</code> is created for a file <code>somefile.pl</code>:</p>
<ul>
<li><p>This selects both <code>subs</code> and <code>packages</code> which have 20 or more lines of code. This can be useful in code which contains multiple packages.</p>
<pre><code> perltidy -dbs -dbt='sub package' somefile.pl >blocks.csv</code></pre>
</li>
<li><p>This selects block types <code>sub for foreach while</code> with 10 or more code lines.</p>
<pre><code> perltidy -dbs -dbl=10 -dbt='sub for foreach while' somefile.pl >blocks.csv</code></pre>
</li>
<li><p>This selects blocks with 2 or more code lines which are type <code>sub</code> or which are inner loops.</p>
<pre><code> perltidy -dbs -dbl=2 -dbt='sub +' somefile.pl >blocks.csv</code></pre>
</li>
<li><p>This selects every block and package.</p>
<pre><code> perltidy -dbs -dbl=1 -dbt='* closure' somefile.pl >blocks.csv</code></pre>
</li>
<li><p>This selects every if-chain which contains 2 or more <code>elsif</code> blocks:</p>
<pre><code> perltidy -dbs -dbl=1 -dbt='elsif2' somefile.pl >blocks.csv</code></pre>
</li>
<li><p>This selects every <code>while</code> block with 6 or more code lines</p>
<pre><code> perltidy -dbs -dbt=while -dbl=6 somfile.pl >while.csv</code></pre>
</li>
</ul>
</dd>
<dt id="Use---dump-unusual-variables-to-find-unused-reused-and-certain-other-variables-of-interest"><b>Use --dump-unusual-variables to find unused, reused, and certain other variables of interest</b></dt>
<dd>
<p>Variables with certain properties of interest to a programmer can be listed with <b>--dump-unusual-variables</b> or <b>-duv</b>. This parameter must be on the command line, along with a single file name. It causes perltidy to scan the file for certain variable types, write any found to the standard output, and then immediately exit without doing any formatting. For example</p>
<pre><code> perltidy -duv somefile.pl >vars.txt</code></pre>
<p>produces a file with lines which look something like</p>
<pre><code> 1778:u: my $input_file
6089:r: my $j: reused - see line 6076</code></pre>
<p>The values on the line are separated by colons and have the following meaning:</p>
<pre><code> line number - the number of the line of the input file
issue - a single letter indicating the issue, see below
variable name - the name of the variable, preceded by a keyword
note - an optional note referring to another line</code></pre>
<p>If there are a large number of issues it can be convenient to read the file into a spreadsheet.</p>
<p>The checks are made for variables introduced by the keywords <b>my</b>, <b>state</b>, and <b>our</b>, along with variables defined with <b>use vars</b> and <b>use constant</b>. It is a good idea to also set <b>use strict</b> in a script so that Perl itself can find issues with variables which appear in a script without one of these methods.</p>
<p>The types of checks which are made are identified in the output with one of the letters <b>r</b>, <b>s</b>, <b>p</b>, <b>u</b>, and <b>c</b> as follows:</p>
<dl>
<dt id="r:-reused-variable-name"><b>r: reused variable name</b></dt>
<dd>
<p>These are variables which are re-declared in the scope of a variable with the identical name. This can be confusing, perhaps not when the code is first written, but possibly later during maintenance work. For example, this can make it difficult to locate the correct variable with an editor when changes are being made. This issue can be avoided by renaming one of the conflicting variables. Note that this is similar to the <b>Perl::Critic</b> policy <b>Variables::ProhibitReusedNames</b>.</p>
</dd>
<dt id="s:-sigil-change-but-reused-bareword"><b>s: sigil change but reused bareword</b></dt>
<dd>
<p>These are variables which have the same bareword name but a different sigil (<b>$</b>, <b>@</b>, or <b>%</b>) as another variable in the same scope. For example, this occurs if variables <b>$data</b> and <b>%data</b> share the same scope. This can also be confusing for the reasons mentioned above and can be avoided by renaming one of the variables.</p>
</dd>
<dt id="p:-package-crossing-variables"><b>p: package-crossing variables</b></dt>
<dd>
<p>These are lexical variables which are declared in one package and still visible in subroutines of a different package in the same file. This can be confusing, and it might cause the program to run differently, or fail, if the the packages were ever split into separate files. This issue can usually be avoided by placing code in block braces of some type. For example, this issue is often found in test code and can sometimes be fixed by using the structure</p>
<pre><code> main();
sub main { #<<<
## old main code goes here
}</code></pre>
<p>The <b>non-indenting-braces</b> side comment <code>#<<<</code> is not required but will keep the indentation of the old code unchanged.</p>
<p>This check is only applied to package statements which are not enclosed in block braces in order avoid warnings at temporary package changes.</p>
</dd>
<dt id="u:-unused-variables"><b>u: unused variables</b></dt>
<dd>
<p>These are lexical variables declared with <code>my</code> or <code>state</code> (but not <code>our</code>) and not referenced again within their scope. Calling them <b>unused</b> is convenient but not really accurate; this is a "gray area" for a program. There are some good reasons for having such variables. For example, they might occur in a list of values provided by another routine or data structure, and therefore must be listed, even though they might not be referenced again. Having such variables can make them immediately available for future development and debugging, and can be beneficial for program clarity.</p>
<p><b>But</b> sometimes they can occur due to being orphaned by a coding change, due to a misspelling, or by having an unintentional preceding <code>my</code>. So it is worth reviewing them, especially for new code. Here is an example of an unused variable in a script located with this method:</p>
<pre><code> BEGIN { my $string = "" }
...
$string .= "ok";</code></pre>
<p>This looks nice at first glance, but the scope of the <code>my</code> declaration is limited to the surrounding braces, so it is not the same variable as the other <code>$string</code> and must therefore be reported as unused. This particular problem would have also been caught by perl if the author had used <code>strict</code>.</p>
</dd>
<dt id="c:-unused-constants"><b>c: unused constants</b></dt>
<dd>
<p>These are names which are declared with a <code>use constant</code> and a reference was not seen again within their package. They might be needed by an external package, or a set of standard definitions, or available for future development. And in some unusual cases a reference may have been missed by perltidy. But they might also be unused remnants from code development, or due to a misspelling, so it can be worthwhile reviewing them.</p>
</dd>
</dl>
<p><b>Exception</b>: The following <b>our</b> variables are exempt from warnings: <b>$VERSION</b>, <b>@EXPORT</b>, <b>@EXPORT_OK</b>, <b>%EXPORT_TAGS</b>, <b>@ISA, $AUTOLOAD</b>.</p>
</dd>
<dt id="Use---warn-variable-types-to-warn-about-certain-variable-types"><b>Use --warn-variable-types to warn about certain variable types</b></dt>
<dd>
<p>The flag <b>--warn-variable-types=string</b>, or <b>-wvt=string</b>, is the <b>--warn</b> counterpart to <b>--dump-unusual-variables</b>, and can be used to produce a warning message if certain of the above variable types are encountered during formatting. All possible variable warnings may be requested with <b>-wvt='*'</b> or <b>-wvt=1</b>.</p>
<p>For example,</p>
<pre><code> perltidy -wvt='*' somefile.pl</code></pre>
<p>The default is not to do any of these checks, and it can also be indicated with <b>-wvt=0</b>.</p>
<p>To restrict the check to a specific set warnings, set the input <b>string</b> to be a space-separated or comma-separated list of the letters associated with the types of variables to be checked. For example:</p>
<pre><code> perltidy -wvt='s r' somefile.pl</code></pre>
<p>will process <i>somefile.pl</i> normally but issue a warning if either of the issues <b>s</b> or <b>r</b>, described above, are encountered.</p>
<p>A companion flag, <b>--warn-variable-exclusion-list=string</b>, or <b>-wvxl=string</b>, can be used to skip warning checks for a list of variable names. A leading and/or trailing '*' may be placed on any of these variable names to allow a partial match.</p>
<p>For example,</p>
<pre><code> perltidy -wvt=1 -wvxl='$self $class *_unused' somefile.pl</code></pre>
<p>will do all possible checks but not report any warnings for variables <code>$self</code>, <code>$class</code>, and for example <code>$value_unused</code>.</p>
<p>This partial match option provides a way to trigger a warning message when a new unused variable is detected in a script. This can be accomplished by adding a unique suffix to the names of existing unused variables, such as <code>_unused</code>. This suffix is then added to the exclusion list.</p>
<p>As a specific example, consider the following line which is part of some debug code which only references the latter three variables (but might someday need to reference the package variable too).</p>
<pre><code> my ( $package_uu, $filename, $line, $subroutine ) = caller();</code></pre>
<p>The unused variable, <code>$package_uu</code>, has been specially marked with suffix <code>_uu</code>. No type <b>u</b> (unused variable) warning will be produced provided that this wildcard suffix is in the exclusion list:</p>
<pre><code> -wvxl='*_uu'</code></pre>
</dd>
<dt id="Use---dump-unique-keys-to-help-locate-misspelled-hash-keys"><b>Use --dump-unique-keys</b> to help locate misspelled hash keys</dt>
<dd>
<p>The parameter <b>--dump-unique-keys</b>, or <b>-duk</b>, dumps a list of hash keys which appear to be used just once, and do not appear among the quoted strings in a file. For example:</p>
<pre><code> perltidy -duk File.pm >output.txt</code></pre>
<p>The lines in the output file list each unique key and its line number. Typically, most of the listed keys listed will be perfectly valid keys needed, for example, for communication with other modules or for future development. But the list might also include something unexpected, such as a misspelled key.</p>
<p>A program <code>dump_unique_keys.pl</code> at <a href="https://github.com/perltidy/perltidy/tree/master/examples">https://github.com/perltidy/perltidy/tree/master/examples</a> can run perltidy with <b>-duk</b> on multiple files, and then remove any common keys from the list.</p>
</dd>
<dt id="Use---dump-mixed-call-parens-to-find-functions-called-both-with-and-without-parens"><b>Use --dump-mixed-call-parens to find functions called both with and without parens</b></dt>
<dd>
<p>The parameter <b>--dump-mixed-call-parens</b>, or <b>-dmcp</b>, provides information on the use of call parens within a program. It produces a list of keywords and sub names which occur both both with and without parens. In other words, with a mixed style. This might be useful if one is working to standardize the call style for some particular keyword or function. For example,</p>
<pre><code> perltidy -dmcp somefile.pl >output.txt</code></pre>
<p>will analyze the text of <i>somefile.pl</i>, write the results to <i>output.txt</i>, and then immediately exit (like all <b>dump-</b> parameters).</p>
<p>The output shows a list of operators and the number of times they were used with parens and the number of times without parens. For example, here is a small section of the output from one file in a past Perl distribution:</p>
<pre><code> k:length:17:9
k:open:30:9
k:pop:3:4</code></pre>
<p>The first line shows that the <code>length</code> function occurs 17 times with parens and 9 times without parens. The 'k' indicates that <code>length</code> is a Perl builtin keyword ('U' would mean user-defined sub, and 'w' would mean unknown bareword). So from this partial output we see that the author had a preference for parens around the args of <code>length</code> and <code>open</code>, whereas <code>pop</code> was about equally likely to have parens as not.</p>
<p>More detailed information can be obtained with the parameters described in the next section.</p>
</dd>
<dt id="Use---want-call-parens-s-and---nowant-call-parens-s-to-warn-about-specific-missing-or-extra-call-parens"><b>Use --want-call-parens=s and --nowant-call-parens=s to warn about specific missing or extra call parens</b></dt>
<dd>
<p>The parameter <b>--want-call-parens=s</b>, or <b>-wcp=s</b>, can be used to to produce a warning message if call parens are missing from selected functions. Likewise, <b>--nowant-call-parens=s</b>, or <b>-nwcp=s</b>, can warn if call parens exist for selected functions. When either of these parameters are set, perltidy will report any discrepancies from the requested style in its error output.</p>
<p>Before using either of these parameters, it may be helpful to first use <b>--dump-mixed-call-parens=s</b>, described in the previous section, to get an overview of the existing paren usage in a file.</p>
<p>The string arguments <b>s</b> are space-separated lists of the names of the functions to be checked. The function names may be builtin keywords or user-defined subs. They may not include a package prefix or sigil. To illustrate,</p>
<pre><code> perltidy -wcp='length open' -nwcp='pop' somefile.pl</code></pre>
<p>means that the builtin functions <code>length</code> and <code>open</code> should have parens around their call args but <code>pop</code> should not. The error output might contain lines such as:</p>
<pre><code> 2314:open FD_TO_CLOSE: no call parens
3652:pop (: has call parens
3783:length $DB: no call parens
...</code></pre>
<p>For builtin keywords which have both a block form and a trailing modifier form, such as <code>if</code>, only the trailing modifier form will be checked since parens are mandatory for the block form.</p>
<p>The symbol <b>&</b> may entered instead of a function name to mean all user-defined subs not explicitly listed. So the compact expression</p>
<pre><code> perltidy -wcp='&' somefile.pl</code></pre>
<p>means that calls to all user-defined subs in the file being processed should have their call arguments enclosed in parens.</p>
<p>Perltidy does not have the ability to add or delete call parens because it is difficult to automate, so changes must be made manually. When adding or removing parentheses, it is essential to pay attention to operator precedence issues. For example, if the parens in the following statement are removed, then <code>||</code> must be changed to <code>or</code>:</p>
<pre><code> open( IN, "<", $infile ) || die("cannot open $infile:$!\n");</code></pre>
<p>Otherwise, the <code>||</code> will operate on <code>$infile</code> rather than the return value of <code>open</code>.</p>
</dd>
<dt id="Use---dump-mismatched-args-to-find-function-calls-with-args-not-matching-sub-declarations"><b>Use --dump-mismatched-args to find function calls with args not matching sub declarations</b></dt>
<dd>
<p>The parameter <b>--dump-mismatched-args</b>, or <b>-dma</b>, causes perltidy to examine the definitions of subroutines in a file, and calls to those subs, and report certain differences. Like all <b>--dump</b> commands, it writes its report to standard output and exits immediately. For example</p>
<pre><code> perltidy -dma somefile.pl >results.txt</code></pre>
<p>Four types of issues are reported, types <b>a</b>, <b>o</b>, <b>u</b>, and <b>i</b>:</p>
<dl>
<dt id="a:-calls-made-to-a-sub-both-with-and-without-the-arrow-operator"><b>a:</b> calls made to a sub both with and without the <b>arrow</b> operator</dt>
<dd>
<p>For example the following two lines would be reported as a mismatch:</p>
<pre><code> Fault();</code></pre>
<p>and</p>
<pre><code> $self->Fault();</code></pre>
<p>This may or may not be an error, but it is worth checking. It might become an error in the future if sub <code>Fault</code> starts to access <code>$self</code>.</p>
</dd>
<dt id="o:-overcount-:-the-number-of-call-args-exceeds-the-expected-number"><b>o:</b> (<b>overcount</b>): the number of call args exceeds the expected number.</dt>
<dd>
</dd>
<dt id="u:-undercount-:-the-number-of-call-args-is-less-than-the-expected-number"><b>u:</b> (<b>undercount</b>): the number of call args is less than the expected number.</dt>
<dd>
<p>For example</p>
<pre><code> sub gnab_gib {
my $self=shift;
my ($v1,$v2)=@_;
...
}
$self->gnab_gib(42);</code></pre>
<p>In this case, the sub is expecting a total of three args (<code>$self</code>, <code>$v1</code>, and <code>$v2</code>) but only receives two (<code>$self</code> and <code>42</code>), so an undercount is reported. This is not necessarily an error because the sub may allow for this possibility, but it is worth checking.</p>
<p>Although it is not possible to automatically determine which sub args are optional, if optional sub args are enclosed in an extra set of parentheses, perltidy will take this a signal that they are optional and not issue a warning. So if the above example is written as</p>
<pre><code> sub gnab_gib {
my $self = shift;
my ( $v1, ($v2) ) = @_; # <-- $v2 is optional
...;
}</code></pre>
<p>then perltidy will consider that the second arg is optional and not issue a warning for:</p>
<pre><code> $self->gnab_gib(42);</code></pre>
<p>For multiple default call args, place one set of parens around them all. Some examples:</p>
<pre><code> my ( ($v1) ) = @_; # <-- $v1 is optional
my ( $v1, ( $v2, $v3 ) ) = @_; # <-- $v2, $v3 are optional</code></pre>
</dd>
<dt id="i:-indeterminate:-a-specific-number-of-expected-args-for-a-sub-could-not-be-determined-but-it-is-called-with-a-specific-number.-This-issue-is-reported-for-the---dump--option-but-not-the---warn--option"><b>i:</b> <b>indeterminate:</b> a specific number of expected args for a sub could not be determined, but it is called with a specific number. This issue is reported for the <b>--dump-</b> option but not the <b>--warn-</b> option.</dt>
<dd>
</dd>
</dl>
<p><b>Notes and Limitations:</b></p>
<ul>
<li><p>This option works best for subs which unpack call args in an orderly manner near the beginning of the sub from <code>@_</code> and/or with <code>shift</code> operations. It will also work for direct access to specific elements of the @_ array. However if the coding for arg extraction is complex then the number of sub args will be considered indeterminate and a count cannot be checked.</p>
</li>
<li><p>Sub calls made without parentheses around the args are not checked.</p>
</li>
<li><p>Anonymous subs and lexical subs (introduced with <code>my</code>) are not checked.</p>
</li>
<li><p>Only calls which appear to be to subs defined within the file being processed are checked. But note that a file may contain multiple packages.</p>
</li>
</ul>
</dd>
<dt id="Use---warn-mismatched-args-to-produce-a-warning-for-function-calls-with-args-not-matching-sub-declarations"><b>Use --warn-mismatched-args to produce a warning for function calls with args not matching sub declarations</b>.</dt>
<dd>
<p>This is similar to the <b>-dump</b> parameter described above except that any mismatches are reported in the error file and otherwise formatting continues normally. The basic usage is</p>
<pre><code> perltidy -wma somefile.pl</code></pre>
<p>Several companion controls are available to avoid unwanted error messages:</p>
<ul>
<li><p><b>--warn-mismatched-arg-types=s</b>, or <b>-wmat=s</b>, can be used to select specific tests, type <b>a</b> (arrow test) or <b>o</b> (overcounts) or <b>u</b> (undercounts). All checks may be requested with <b>-wmat='*'</b> or <b>-wmat=1</b>. This is the default.</p>
<p>To restrict the check to a specific warning type, set the string equal to the letter of that warning, any <b>a</b>, <b>o</b>, or <b>u</b>. For example</p>
<pre><code> perltidy -wmat='a o' somefile.pl</code></pre>
<p>will format <i>somefile.pl</i> and report any arrow-type mismatches and overcount mismatches, but will skip undercount mismatches.</p>
</li>
<li><p><b>--warn-mismatched-arg-exclusion-list</b>, or <b>-wmaxl=string</b>, can be given to skip the warning checks for a list of subroutine names, entered as a quoted string of space- or comma-separated names, without a package prefix. All subs with those names will be skipped, regardless of package. A leading and/or trailing <b>*</b> on a name may be used to indicate a partial string match.</p>
</li>
<li><p><b>--warn-mismatched-arg-undercount-cutoff=n</b>, or <b>-wmauc=n</b>, can be used to avoid <b>undercount</b> warnings when the expected number of args is less than <b>n</b>. Please note that this number <b>n</b> is the number of args from the point of view of the sub definition, so an object like <code>$self</code> passed with an arrow operator counts as one arg.</p>
<p>The default value is <b>n=4</b>. This has been found to allow most programs to pass without warnings, but it should be reduced if possible for better error checking. The minimum possible value of <b>n</b> needed to avoid triggering an error for a program can be determined by running with <b>-wma -wmauc=0</b>. If there are undercount errors, a note at the bottom of the error output indicates the value of <b>n</b> required to avoid reporting them.</p>
<p>As noted above for the parameter <b>--dump-mismatched-args</b>, if optional call args are enclosed in separate parentheses, then perltidy will recognize them as optional args and avoid needless warnings. If this method is used, then <b>-wmauc=0</b> should be used for maximal checking.</p>
</li>
<li><p><b>--warn-mismatched-arg-overcount-cutoff=n</b>, or <b>-wmaoc=n</b>, can be used to avoid <b>overcount</b> warnings when the expected number of args is less than <b>n</b>. The default value is <b>n=1</b>. This avoids warning messages for subroutines which are dummy placeholders for possible expansion.</p>
</li>
</ul>
<p>To illustrate these controls,</p>
<pre><code> perltidy -wma -wmat='o u' -wmaxl='new old' -wmauc=2 somefile.pl</code></pre>
<p>means format <i>somefile.pl</i> as usual and check for mismatched overcounts and undercounts but not arrows. Skip checking for any sub named <code>new</code> or <code>old</code>, and only warn of undercounts for subs expecting more than 2 args.</p>
</dd>
<dt id="Use---dump-mismatched-returns-to-find-function-calls-where-the-number-of-requested-values-may-disagree-with-sub-return-statements"><b>Use --dump-mismatched-returns</b> to find function calls where the number of requested values may disagree with sub return statements</dt>
<dd>
<p>The parameter <b>--dump-mismatched-returns</b>, or <b>-dmr</b>, examines the return side of sub call statements. Like all <b>--dump</b> commands, it writes its report to standard output and exits immediately. For example</p>
<pre><code> perltidy -dmr somefile.pl >results.txt</code></pre>
<p>The following types of issues are reported:</p>
<dl>
<dt id="x:-calls-requesting-an-array-from-a-sub-with-no-return-statements"><b>x:</b> calls requesting an array from a sub with no return statements.</dt>
<dd>
</dd>
<dt id="y:-calls-requesting-a-scalar-from-a-sub-with-no-return-statements"><b>y:</b> calls requesting a scalar from a sub with no return statements.</dt>
<dd>
</dd>
<dt id="o:-overwant-:-calls-requesting-an-array-with-a-count-which-exceeds-the-maximum-number-returned-by-the-sub"><b>o:</b> (<b>overwant</b>): calls requesting an array with a count which exceeds the maximum number returned by the sub.</dt>
<dd>
</dd>
<dt id="u:-underwant-:-calls-requesting-an-array-with-a-count-which-is-below-the-maximum-and-which-does-not-match-a-number-returned-by-the-sub"><b>u:</b> (<b>underwant</b>): calls requesting an array with a count which is below the maximum and which does not match a number returned by the sub.</dt>
<dd>
</dd>
<dt id="s:-calls-requesting-a-scalar-from-a-sub-which-only-returns-two-or-more-items"><b>s:</b> calls requesting a scalar from a sub which only returns two or more items.</dt>
<dd>
</dd>
</dl>
<p>These issue types are illustrated with the following code</p>
<pre><code> sub macho {
...
( $name, $flags ); # 2 values but no 'return' statement
}
( $name, $flags ) = macho(); # 'x' (want array, but no return)
$name = macho(); # 'y' (want scalar but no return)
sub wimp {
...;
return ( $name, $flags ); # 2 values with 'return' statement
}
( $name, $flags, $access) = wimp(); # 'o' (want array 3 > 2)
($name) = wimp(); # 'u' (want array 1 < 2)
$name = wimp(); # 's' (want scalar but 2 values returned)</code></pre>
<p>This analysis works by scanning all call statements and all sub return statements, and comparing the the number of items wanted with the possible number of items returned. If a specific value for either of these numbers cannot be determined for a call then it cannot be checked.</p>
<p>Since only return statements are scanned for return values, this analysis will not be useful for programming which relies on the default return mechanism, as in the first sub above. Note that the <b>Perl::Critic</b> policy <b>RequireFinalReturn</b> can be used to check for code in this situation.</p>
<p>Reported issues are not necessarily errors, but they might be, or they might indicate potentially confusing code.</p>
</dd>
<dt id="Use---warn-mismatched-returns-to-issue-warnings-when-the-number-of-requested-values-may-disagree-with-sub-return-statements"><b>Use --warn-mismatched-returns</b> to issue warnings when the number of requested values may disagree with sub return statements</dt>
<dd>
<p>This is similar to the <b>-dump</b> parameter described above except that any mismatches are reported in the error file and otherwise formatting continues normally. The basic usage is</p>
<pre><code> perltidy -wmr somefile.pl</code></pre>
<p>The following companion controls are available to avoid unwanted error messages:</p>
<ul>
<li><p><b>--warn-mismatched-return-types=string</b>, or <b>-wmrt=string</b>, can be used to limit checks.</p>
<p>To restrict the checking, set the string equal to the letter(s) of that warning, any <b>x</b>, <b>y</b>, <b>o</b>, <b>u</b>, or <b>s</b>. For example</p>
<pre><code> perltidy -wmrt='x o s' somefile.pl</code></pre>
<p>will format <i>somefile.pl</i> and report issue types <b>x</b>, <b>o</b>, and <b>s</b> but not types <b>u</b> and <b>y</b>. All checks may be requested with <b>-wmrt='*'</b> or <b>-wmrt=1</b>. This is the default.</p>
</li>
<li><p><b>--warn-mismatched-return-exclusion-list</b>, or <b>-wmrxl=string</b>, can be given to skip the warning checks for a list of subroutine names, entered as a quoted string of space- or comma-separated names, without a package prefix. All subs with those names will be skipped, regardless of package. A leading and/or trailing <b>*</b> on a name may be used to indicate a partial string match.</p>
</li>
</ul>
</dd>
</dl>
<h2 id="Working-with-MakeMaker-AutoLoader-and-SelfLoader"><b>Working with MakeMaker, AutoLoader and SelfLoader</b></h2>
<p>The first $VERSION line of a file which might be eval'd by MakeMaker is passed through unchanged except for indentation. The default <b>--pass-version-line</b>, or <b>-pvl</b>, is to do this. Use <b>--nopass-version-line</b>, or <b>-npvl</b>, to deactivate this feature.</p>
<p>If the AutoLoader module is used, perltidy will continue formatting code after seeing an __END__ line. The default <b>--look-for-autoloader</b>, or <b>-lal</b>, is to do this. Use <b>--nolook-for-autoloader</b>, or <b>-nlal</b>, to deactivate this feature.</p>
<p>Likewise, if the SelfLoader module is used, perltidy will continue formatting code after seeing a __DATA__ line. The default <b>--look-for-selfloader</b>, or <b>-lsl</b>, is to do this. Use <b>--nolook-for-selfloader</b>, or <b>-nlsl</b>, to deactivate this feature.</p>
<h1 id="HTML-OPTIONS">HTML OPTIONS</h1>
<dl>
<dt id="The--html-master-switch">The <b>-html</b> master switch</dt>
<dd>
<p>The flag <b>-html</b> causes perltidy to write an html file with extension <i>.html</i>. So, for example, the following command</p>
<pre><code> perltidy -html somefile.pl</code></pre>
<p>will produce a syntax-colored html file named <i>somefile.pl.html</i> which may be viewed with a browser.</p>
<p><b>Please Note</b>: In this case, perltidy does not do any formatting to the input file, and it does not write a formatted file with extension <i>.tdy</i>. This means that two perltidy runs are required to create a fully reformatted, html copy of a script.</p>
</dd>
<dt id="The--pre-flag-for-code-snippets">The <b>-pre</b> flag for code snippets</dt>
<dd>
<p>When the <b>-pre</b> flag is given, only the pre-formatted section, within the <code><PRE</code>> and <code></PRE</code>> tags, will be output. This simplifies inclusion of the output in other files. The default is to output a complete web page.</p>
</dd>
<dt id="The--nnn-flag-for-line-numbering">The <b>-nnn</b> flag for line numbering</dt>
<dd>
<p>When the <b>-nnn</b> flag is given, the output lines will be numbered.</p>
</dd>
<dt id="The--toc-or---html-table-of-contents-flag">The <b>-toc</b>, or <b>--html-table-of-contents</b> flag</dt>
<dd>
<p>By default, a table of contents to packages and subroutines will be written at the start of html output. Use <b>-ntoc</b> to prevent this. This might be useful, for example, for a pod document which contains a number of unrelated code snippets. This flag only influences the code table of contents; it has no effect on any table of contents produced by pod2html (see next item).</p>
</dd>
<dt id="The--pod-or---pod2html-flag">The <b>-pod</b>, or <b>--pod2html</b> flag</dt>
<dd>
<p>There are two options for formatting pod documentation. The default is to pass the pod through the Pod::Html module (which forms the basis of the pod2html utility). Any code sections are formatted by perltidy, and the results then merged. Note: perltidy creates a temporary file when Pod::Html is used; see <a href="#FILES">"FILES"</a>. Also, Pod::Html creates temporary files for its cache.</p>
<p>NOTE: Perltidy counts the number of <code>=cut</code> lines, and either moves the pod text to the top of the html file if there is one <code>=cut</code>, or leaves the pod text in its original order (interleaved with code) otherwise.</p>
<p>Most of the flags accepted by pod2html may be included in the perltidy command line, and they will be passed to pod2html. In some cases, the flags have a prefix <code>pod</code> to emphasize that they are for the pod2html, and this prefix will be removed before they are passed to pod2html. The flags which have the additional <code>pod</code> prefix are:</p>
<pre><code> --[no]podheader --[no]podindex --[no]podrecurse --[no]podquiet
--[no]podverbose --podflush</code></pre>
<p>The flags which are unchanged from their use in pod2html are:</p>
<pre><code> --backlink=s --cachedir=s --htmlroot=s --libpods=s --title=s
--podpath=s --podroot=s</code></pre>
<p>where 's' is an appropriate character string. Not all of these flags are available in older versions of Pod::Html. See your Pod::Html documentation for more information.</p>
<p>The alternative, indicated with <b>-npod</b>, is not to use Pod::Html, but rather to format pod text in italics (or whatever the stylesheet indicates), without special html markup. This is useful, for example, if pod is being used as an alternative way to write comments.</p>
</dd>
<dt id="The--frm-or---frames-flag">The <b>-frm</b>, or <b>--frames</b> flag</dt>
<dd>
<p>By default, a single html output file is produced. This can be changed with the <b>-frm</b> option, which creates a frame holding a table of contents in the left panel and the source code in the right side. This simplifies code browsing. Assume, for example, that the input file is <i>MyModule.pm</i>. Then, for default file extension choices, these three files will be created:</p>
<pre><code> MyModule.pm.html - the frame
MyModule.pm.toc.html - the table of contents
MyModule.pm.src.html - the formatted source code</code></pre>
<p>Obviously this file naming scheme requires that output be directed to a real file (as opposed to, say, standard output). If this is not the case, or if the file extension is unknown, the <b>-frm</b> option will be ignored.</p>
</dd>
<dt id="The--text-s-or---html-toc-extension-flag">The <b>-text=s</b>, or <b>--html-toc-extension</b> flag</dt>
<dd>
<p>Use this flag to specify the extra file extension of the table of contents file when html frames are used. The default is "toc". See <a href="#Specifying-File-Extensions">"Specifying File Extensions"</a>.</p>
</dd>
<dt id="The--sext-s-or---html-src-extension-flag">The <b>-sext=s</b>, or <b>--html-src-extension</b> flag</dt>
<dd>
<p>Use this flag to specify the extra file extension of the content file when html frames are used. The default is "src". See <a href="#Specifying-File-Extensions">"Specifying File Extensions"</a>.</p>
</dd>
<dt id="The--hent-or---html-entities-flag">The <b>-hent</b>, or <b>--html-entities</b> flag</dt>
<dd>
<p>This flag controls the use of Html::Entities for html formatting. By default, the module Html::Entities is used to encode special symbols. This may not be the right thing for some browser/language combinations. Use --nohtml-entities or -nhent to prevent this.</p>
</dd>
<dt id="Style-Sheets"><b>Style Sheets</b></dt>
<dd>
<p>Style sheets make it very convenient to control and adjust the appearance of html pages. The default behavior is to write a page of html with an embedded style sheet.</p>
<p>An alternative to an embedded style sheet is to create a page with a link to an external style sheet. This is indicated with the <b>-css=filename</b>, where the external style sheet is <i>filename</i>. The external style sheet <i>filename</i> will be created if and only if it does not exist. This option is useful for controlling multiple pages from a single style sheet.</p>
<p>To cause perltidy to write a style sheet to standard output and exit, use the <b>-ss</b>, or <b>--stylesheet</b>, flag. This is useful if the style sheet could not be written for some reason, such as if the <b>-pre</b> flag was used. Thus, for example,</p>
<pre><code> perltidy -html -ss >mystyle.css</code></pre>
<p>will write a style sheet with the default properties to file <i>mystyle.css</i>.</p>
<p>The use of style sheets is encouraged, but a web page without a style sheets can be created with the flag <b>-nss</b>. Use this option if you must to be sure that older browsers (roughly speaking, versions prior to 4.0 of Netscape Navigator and Internet Explorer) can display the syntax-coloring of the html files.</p>
</dd>
<dt id="Controlling-HTML-properties"><b>Controlling HTML properties</b></dt>
<dd>
<p>Note: It is usually more convenient to accept the default properties and then edit the stylesheet which is produced. However, this section shows how to control the properties with flags to perltidy.</p>
<p>Syntax colors may be changed from their default values by flags of the either the long form, <b>-html-color-xxxxxx=n</b>, or more conveniently the short form, <b>-hcx=n</b>, where <b>xxxxxx</b> is one of the following words, and <b>x</b> is the corresponding abbreviation:</p>
<pre><code> Token Type xxxxxx x
---------- -------- --
comment comment c
number numeric n
identifier identifier i
bareword, function bareword w
keyword keyword k
quote, pattern quote q
here doc text here-doc-text h
here doc target here-doc-target hh
punctuation punctuation pu
parentheses paren p
structural braces structure s
semicolon semicolon sc
colon colon co
comma comma cm
label label j
sub definition name subroutine m
pod text pod-text pd</code></pre>
<p>A default set of colors has been defined, but they may be changed by providing values to any of the following parameters, where <b>n</b> is either a 6 digit hex RGB color value or an ascii name for a color, such as 'red'.</p>
<p>To illustrate, the following command will produce an html file <i>somefile.pl.html</i> with "aqua" keywords:</p>
<pre><code> perltidy -html -hck=00ffff somefile.pl</code></pre>
<p>and this should be equivalent for most browsers:</p>
<pre><code> perltidy -html -hck=aqua somefile.pl</code></pre>
<p>Perltidy merely writes any non-hex names that it sees in the html file. The following 16 color names are defined in the HTML 3.2 standard:</p>
<pre><code> black => 000000,
silver => c0c0c0,
gray => 808080,
white => ffffff,
maroon => 800000,
red => ff0000,
purple => 800080,
fuchsia => ff00ff,
green => 008000,
lime => 00ff00,
olive => 808000,
yellow => ffff00
navy => 000080,
blue => 0000ff,
teal => 008080,
aqua => 00ffff,</code></pre>
<p>Many more names are supported in specific browsers, but it is safest to use the hex codes for other colors. Helpful color tables can be located with an internet search for "HTML color tables".</p>
<p>Besides color, two other character attributes may be set: bold, and italics. To set a token type to use bold, use the flag <b>--html-bold-xxxxxx</b> or <b>-hbx</b>, where <b>xxxxxx</b> or <b>x</b> are the long or short names from the above table. Conversely, to set a token type to NOT use bold, use <b>--nohtml-bold-xxxxxx</b> or <b>-nhbx</b>.</p>
<p>Likewise, to set a token type to use an italic font, use the flag <b>--html-italic-xxxxxx</b> or <b>-hix</b>, where again <b>xxxxxx</b> or <b>x</b> are the long or short names from the above table. And to set a token type to NOT use italics, use <b>--nohtml-italic-xxxxxx</b> or <b>-nhix</b>.</p>
<p>For example, to use bold braces and lime color, non-bold, italics keywords the following command would be used:</p>
<pre><code> perltidy -html -hbs -hck=00FF00 -nhbk -hik somefile.pl</code></pre>
<p>The background color can be specified with <b>--html-color-background=n</b>, or <b>-hcbg=n</b> for short, where n is a 6 character hex RGB value. The default color of text is the value given to <b>punctuation</b>, which is black as a default.</p>
<p>Here are some notes and hints:</p>
<p>1. If you find a preferred set of these parameters, you may want to create a <i>.perltidyrc</i> file containing them. See the perltidy man page for an explanation.</p>
<p>2. Rather than specifying values for these parameters, it is probably easier to accept the defaults and then edit a style sheet. The style sheet contains comments which should make this easy.</p>
<p>3. The syntax-colored html files can be very large, so it may be best to split large files into smaller pieces to improve download times.</p>
</dd>
</dl>
<h1 id="SOME-COMMON-INPUT-CONVENTIONS">SOME COMMON INPUT CONVENTIONS</h1>
<h2 id="Specifying-Block-Types">Specifying Block Types</h2>
<p>Several parameters which refer to code block types may be customized by also specifying an associated list of block types. The type of a block is the name of the keyword which introduces that block, such as <b>if</b>, <b>else</b>, or <b>sub</b>. An exception is a labeled block, which has no keyword, and should be specified with just a colon. To specify all blocks use <b>'*'</b>.</p>
<p>The keyword <b>sub</b> indicates a named sub. For anonymous subs, use the special keyword <b>asub</b>.</p>
<p>For example, the following parameter specifies <code>sub</code>, labels, <code>BEGIN</code>, and <code>END</code> blocks:</p>
<pre><code> -cscl="sub : BEGIN END"</code></pre>
<p>(the meaning of the -cscl parameter is described above.) Note that quotes are required around the list of block types because of the spaces. For another example, the following list specifies all block types for vertical tightness:</p>
<pre><code> -bbvtl='*'</code></pre>
<h2 id="Specifying-File-Extensions">Specifying File Extensions</h2>
<p>Several parameters allow default file extensions to be overridden. For example, a backup file extension may be specified with <b>-bext=ext</b>, where <b>ext</b> is some new extension. In order to provides the user some flexibility, the following convention is used in all cases to decide if a leading '.' should be used. If the extension <code>ext</code> begins with <code>A-Z</code>, <code>a-z</code>, or <code>0-9</code>, then it will be appended to the filename with an intermediate '.' (or perhaps a '_' on VMS systems). Otherwise, it will be appended directly.</p>
<p>For example, suppose the file is <i>somefile.pl</i>. For <code>-bext=old</code>, a '.' is added to give <i>somefile.pl.old</i>. For <code>-bext=.old</code>, no additional '.' is added, so again the backup file is <i>somefile.pl.old</i>. For <code>-bext=~</code>, then no dot is added, and the backup file will be <i>somefile.pl~</i> .</p>
<h1 id="SWITCHES-WHICH-MAY-BE-NEGATED">SWITCHES WHICH MAY BE NEGATED</h1>
<p>The following list shows all short parameter names which allow a prefix 'n' to produce the negated form:</p>
<pre><code> D aia altc ame anl asbl asc ast asu atc
atnl aws b baa baao bar bbao bbb bbc bbs
bl bli boa boc bok bol bom bos bot cblx
ce conv cpb cs csc cscb cscw dac dbc dbs
dcbl dcsc ddf dia dior dln dltc dma dmcp dmr
dnl dop dp dpro drc dsc dsm dsn dtc dtco
dtt duk duv dwic dwls dwrs dws eos f fpva
frm fs fso gcs hbc hbcm hbco hbh hbhh hbi
hbj hbk hbm hbn hbp hbpd hbpu hbq hbs hbsc
hbv hbw hent hic hicm hico hih hihh hii hij
hik him hin hip hipd hipu hiq his hisc hiv
hiw hsc html ibc icb icp ils iob ipc isbc
iscl kgb kgbd kgbi kis lal log lop lp lsl
mci mem nib ohbr okw ola olc oll olq opr
opt osbc osbr otr ple pod pvl q qwaf sac
sbc sbl scbb schb scp scsb sct se sfp sfs
skp sob sobb sohb sop sosb sot ssc st sts
t tac tbc toc tp tqw trp ts tsc tso
vbc vc viu vmll vsc vsn vwe w wfc wia
wma wme wmr wn x xbt xci xlp xs</code></pre>
<p>Equivalently, the prefix 'no' or 'no-' on the corresponding long names may be used.</p>
<h1 id="LIMITATIONS">LIMITATIONS</h1>
<dl>
<dt id="Parsing-Limitations"><b>Parsing Limitations</b></dt>
<dd>
<p>Perltidy should work properly on most perl scripts. It does a lot of self-checking, but still, it is possible that an error could be introduced and go undetected. Therefore, it is essential to make careful backups and to test reformatted scripts.</p>
<p>The main current limitation is that perltidy does not scan modules included with 'use' statements. This makes it necessary to guess the context of any bare words introduced by such modules. Perltidy has good guessing algorithms, but they are not infallible. When it must guess, it leaves a message in the log file.</p>
<p>If you encounter a bug, please report it.</p>
</dd>
<dt id="What-perltidy-does-not-parse-and-format"><b>What perltidy does not parse and format</b></dt>
<dd>
<p>Perltidy indents but does not reformat comments and <code>qw</code> quotes. Perltidy does not in any way modify the contents of here documents or quoted text, even if they contain source code. (You could, however, reformat them separately). Perltidy does not format 'format' sections in any way. And, of course, it does not modify pod documents.</p>
</dd>
</dl>
<h1 id="FILES">FILES</h1>
<dl>
<dt id="Temporary-files"><b>Temporary files</b></dt>
<dd>
<p>Under the -html option with the default --pod2html flag, a temporary file is required to pass text to Pod::Html. Unix systems will try to use the POSIX tmpnam() function. Otherwise the file <i>perltidy.TMP</i> will be temporarily created in the current working directory.</p>
</dd>
<dt id="Special-files-when-standard-input-is-used"><b>Special files when standard input is used</b></dt>
<dd>
<p>When standard input is used, the log file, if saved, is <i>perltidy.LOG</i>, and any errors are written to <i>perltidy.ERR</i> unless the <b>-se</b> flag is set. These are saved in the current working directory.</p>
</dd>
<dt id="Files-overwritten"><b>Files overwritten</b></dt>
<dd>
<p>The following file extensions are used by perltidy, and files with these extensions may be overwritten or deleted: <i>.ERR</i>, <i>.LOG</i>, <i>.TEE</i>, and/or <i>.tdy</i>, <i>.html</i>, and <i>.bak</i>, depending on the run type and settings.</p>
</dd>
<dt id="Files-extensions-limitations"><b>Files extensions limitations</b></dt>
<dd>
<p>Perltidy does not operate on files for which the run could produce a file with a duplicated file extension. These extensions include <i>.LOG</i>, <i>.ERR</i>, <i>.TEE</i>, and perhaps <i>.tdy</i> and <i>.bak</i>, depending on the run type. The purpose of this rule is to prevent generating confusing filenames such as <i>somefile.tdy.tdy.tdy</i>.</p>
</dd>
</dl>
<h1 id="ERROR-HANDLING">ERROR HANDLING</h1>
<p>An exit value of 0, 1, or 2 is returned by perltidy to indicate the status of the result.</p>
<p>A exit value of 0 indicates that perltidy ran to completion with no error messages.</p>
<p>A non-zero exit value indicates some kind of problem was detected.</p>
<p>An exit value of 1 indicates that perltidy terminated prematurely, usually due to some kind of errors in the input parameters. This can happen for example if a parameter is misspelled or given an invalid value. Error messages in the standard error output will indicate the cause of any problem. If perltidy terminates prematurely then no output files will be produced.</p>
<p>An exit value of 2 indicates that perltidy was able to run to completion but there there are (1) warning messages in the standard error output related to parameter errors or problems and/or (2) warning messages in the perltidy error file(s) relating to possible syntax errors in one or more of the source script(s) being tidied. When multiple files are being processed, an error detected in any single file will produce this type of exit condition.</p>
<h1 id="SEE-ALSO">SEE ALSO</h1>
<p>perlstyle(1), Perl::Tidy(3)</p>
<h1 id="INSTALLATION">INSTALLATION</h1>
<p>The perltidy binary uses the Perl::Tidy module and is installed when that module is installed. The module name is case-sensitive. For example, the basic command for installing with cpanm is 'cpanm Perl::Tidy'.</p>
<h1 id="VERSION">VERSION</h1>
<p>This man page documents perltidy version 20250105</p>
<h1 id="BUG-REPORTS">BUG REPORTS</h1>
<p>The source code repository is at <a href="https://github.com/perltidy/perltidy">https://github.com/perltidy/perltidy</a>.</p>
<p>To report a new bug or problem, use the "issues" link on this page.</p>
<h1 id="COPYRIGHT">COPYRIGHT</h1>
<p>Copyright (c) 2000-2025 by Steve Hancock</p>
<h1 id="LICENSE">LICENSE</h1>
<p>This package is free software; you can redistribute it and/or modify it under the terms of the "GNU General Public License".</p>
<p>Please refer to the file "COPYING" for details.</p>
<h1 id="DISCLAIMER">DISCLAIMER</h1>
<p>This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</p>
<p>See the "GNU General Public License" for more details.</p>
</body>
</html>
|