File: perlfunc.html

package info (click to toggle)
perl-doc-html 5.26.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 39,400 kB
  • sloc: xml: 36; makefile: 7
file content (7588 lines) | stat: -rw-r--r-- 810,798 bytes parent folder | download
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
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>perlfunc - perldoc.perl.org</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta http-equiv="Content-Language" content="en-gb">
  <link rel="search" type="application/opensearchdescription+xml" title="Search perldoc.perl.org" href="/static/search.xml"/>
  <link href="static/css-20100830.css" rel="stylesheet" rev="stylesheet" type="text/css" media="screen">
  <link href="static/exploreperl.css" rel="stylesheet" rev="stylesheet" type="text/css">
</head>

<body onLoad="perldoc.startup();" onPageShow="if (event.persisted) perldoc.startup();">
    <div id="page">
      
      <div id="header">
	<div id="homepage_link">
	  <a href="index.html"></a>
	</div>
	<div id="strapline">
	  Perl Programming Documentation
	</div>
	<div id="download_link" class="download">
	  <a href="http://www.perl.org/get.html">Download Perl</a>
	</div>
	<div id="explore_link" class="download">
	  <a id="explore_anchor" href="#">Explore</a>
	</div>
      </div>
      
      <div id="body">
        <div id="left_column">
          <div class="side_group">
            
	    <div class="side_panel doc_panel">
              <p>Manual</p>
              <ul>
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">History / Changes</a>
                <li><a href="index-licence.html">License</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Reference</p>
              <ul>
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Special Variables</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platform Specific</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Modules</p>
              <ul>
		<li>
		
                
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		
                  
		
		
                    <a href="index-modules-A.html">A</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-B.html">B</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-C.html">C</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-D.html">D</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-E.html">E</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-F.html">F</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-G.html">G</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-H.html">H</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-I.html">I</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-L.html">L</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-M.html">M</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-N.html">N</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-O.html">O</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-P.html">P</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-S.html">S</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-T.html">T</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-U.html">U</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-X.html">X</a>
                    
                
              </ul>
            </div>
            
	      <div class="side_panel doc_panel">
		<p>Tools</p>
		<ul>
		  <li><a href="preferences.html">Preferences</a>
		</ul>
	      </div>
            
          </div>
        </div>
        <div id="centre_column">
          <div id="content_header">
            <div id="title_bar">
              <div id="page_name">
                <h1>perlfunc</h1>
              </div>
              <div id="perl_version">
                Perl 5 version 26.0 documentation
              </div>
              <div class="page_links" id="page_links_top">
                <a href="#" onClick="toolbar.goToTop();return false;">Go to top</a>
		
              </div>
	      <div class="page_links" id="page_links_bottom">
		
                <a href="#" id="recent_pages_toggle">Show recent pages</a>		
	      </div>
	      <div id="search_form">
		<form action="search.html" method="GET" id="search">
		  <input type="text" name="q" id="search_box" alt="Search">
		</form>
	      </div>
            </div>
            <div id="breadcrumbs">
                
    <a href="index.html">Home</a> &gt;
    
      
        <a href="index-language.html">Language reference</a> &gt;
      
    
    perlfunc
  

            </div>
          </div>
          <div id="content_body">
	    <!--[if lt IE 7]>
 <div class="noscript">
   <p>
     <strong>It looks like you're using Internet Explorer 6. This is a very old
     browser which does not offer full support for modern websites.</strong>
   </p>
   <p>
     Unfortunately this means that this website will not work on
     your computer.
   </p>
   <p>
     Don't miss out though! To view the site (and get a better experience from
     many other websites), simply upgrade to
     <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet
Explorer 8</a>
     or download an alternative browser such as
     <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>,
     <a href="http://www.apple.com/safari/download/">Safari</a>, or
     <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
   </p>
   <p>
     All of these browsers are free. If you're using a PC at work, you may
     need to contact your IT administrator.
   </p>
 </div>
<![endif]-->
	    <noscript>
	      <div class="noscript">
	      <p>
                <strong>Please note: Many features of this site require JavaScript. You appear to have JavaScript disabled,
	        or are running a non-JavaScript capable web browser.</strong>
	      </p>
	      <p>
		To get the best experience, please enable JavaScript or download a modern web browser such as <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet Explorer 8</a>, <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>, <a href="http://www.apple.com/safari/download/">Safari</a>, or <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
              </p>
	      </div>
	    </noscript>

	    <div id="recent_pages" class="hud_container">
	      <div id="recent_pages_header" class="hud_header">
		<div id="recent_pages_close" class="hud_close"><a href="#" onClick="recentPages.hide();return false;"></a></div>
		<div id="recent_pages_title" class="hud_title"><span class="hud_span_top">Recently read</span></div>
		<div id="recent_pages_topright" class="hud_topright"></div>
	      </div>
	      <div id="recent_pages_content" class="hud_content">
	      </div>
	      <div id="recent_pages_footer" class="hud_footer">
		<div id="recent_pages_bottomleft" class="hud_bottomleft"></div>
		<div id="recent_pages_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
		<div id="recent_pages_resize" class="hud_resize"></div>
	      </div>
	    </div>
  
	    <div id="from_search"></div>
            <h1>perlfunc</h1>

<div class="mod_az_list">
  <a href="index-functions.html">Perl functions A-Z</a> |
  <a href="index-functions-by-cat.html">Perl functions by category</a> |
  <a href="perlfunc.html">The 'perlfunc' manpage</a>
</div>


  <!--    -->
<ul><li><a href="#NAME">NAME
</a><li><a href="#DESCRIPTION">DESCRIPTION</a><ul><li><a href="#Perl-Functions-by-Category">Perl Functions by Category
</a><li><a href="#Portability">Portability
  </a><li><a href="#Alphabetical-Listing-of-Perl-Functions">Alphabetical Listing of Perl Functions</a><li><a href="#Non-function-Keywords-by-Cross-reference">Non-function Keywords by Cross-reference</a></ul></ul><a name="NAME"></a><h1>NAME
</h1>
<p>perlfunc - Perl builtin functions</p>
<a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
<p>The functions in this section can serve as terms in an expression.
They fall into two major categories: list operators and named unary
operators.  These differ in their precedence relationship with a
following comma.  (See the precedence table in <a href="perlop.html">perlop</a>.)  List
operators take more than one argument, while unary operators can never
take more than one argument.  Thus, a comma terminates the argument of
a unary operator, but merely separates the arguments of a list
operator.  A unary operator generally provides scalar context to its
argument, while a list operator may provide either scalar or list
contexts for its arguments.  If it does both, scalar arguments
come first and list argument follow, and there can only ever
be one such list argument.  For instance,
<a href="#splice-ARRAY%2cOFFSET%2cLENGTH%2cLIST">splice</a> has three scalar arguments
followed by a list, whereas <a href="#gethostbyname-NAME">gethostbyname</a> has
four scalar arguments.</p>
<p>In the syntax descriptions that follow, list operators that expect a
list (and provide list context for elements of the list) are shown
with LIST as an argument.  Such a list may consist of any combination
of scalar arguments or list values; the list values will be included
in the list as if each individual element were interpolated at that
point in the list, forming a longer single-dimensional list value.
Commas should separate literal elements of the LIST.</p>
<p>Any function in the list below may be used either with or without
parentheses around its arguments.  (The syntax descriptions omit the
parentheses.)  If you use parentheses, the simple but occasionally
surprising rule is this: It <i>looks</i> like a function, therefore it <i>is</i> a
function, and precedence doesn't matter.  Otherwise it's a list
operator or unary operator, and precedence does matter.  Whitespace
between the function and left parenthesis doesn't count, so sometimes
you need to be careful:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="n">1</span>+<span class="n">2</span>+<span class="n">4</span><span class="sc">;</span>      <span class="c"># Prints 7.</span></li><li>    <a class="l_k" href="functions/print.html">print</a><span class="s">(</span><span class="n">1</span>+<span class="n">2</span><span class="s">)</span> + <span class="n">4</span><span class="sc">;</span>   <span class="c"># Prints 3.</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="s">(</span><span class="n">1</span>+<span class="n">2</span><span class="s">)</span>+<span class="n">4</span><span class="sc">;</span>    <span class="c"># Also prints 3!</span></li><li>    <a class="l_k" href="functions/print.html">print</a> +<span class="s">(</span><span class="n">1</span>+<span class="n">2</span><span class="s">)</span>+<span class="n">4</span><span class="sc">;</span>   <span class="c"># Prints 7.</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="s">(</span><span class="s">(</span><span class="n">1</span>+<span class="n">2</span><span class="s">)</span>+<span class="n">4</span><span class="s">)</span><span class="sc">;</span>  <span class="c"># Prints 7.</span></li></ol></pre><p>If you run Perl with the <a href="warnings.html">use warnings </a> pragma, it can warn
you about this.  For example, the third line above produces:</p>
<pre class="verbatim"><ol><li>    print (...) interpreted as function at - line 1.</li><li>    Useless use of integer addition in void context at - line 1.</li></ol></pre><p>A few functions take no arguments at all, and therefore work as neither
unary nor list operators.  These include such functions as
<a href="#time">time</a> and <a href="#endpwent">endpwent</a>.  For example,
<code class="inline"><a class="l_k" href="functions/time.html">time+86_400</a></code> always means <code class="inline"><a class="l_k" href="functions/time.html">time</a><span class="s">(</span><span class="s">)</span> + <span class="n">86_400</span></code>
.</p>
<p>For functions that can be used in either a scalar or list context,
nonabortive failure is generally indicated in scalar context by
returning the undefined value, and in list context by returning the
empty list.</p>
<p>Remember the following important rule: There is <b>no rule</b> that relates
the behavior of an expression in list context to its behavior in scalar
context, or vice versa.  It might do two totally different things.
Each operator and function decides which sort of value would be most
appropriate to return in scalar context.  Some operators return the
length of the list that would have been returned in list context.  Some
operators return the first value in the list.  Some operators return the
last value in the list.  Some operators return a count of successful
operations.  In general, they do what you want, unless you want
consistency.
</p>
<p>A named array in scalar context is quite different from what would at
first glance appear to be a list in scalar context.  You can't get a list
like <code class="inline"><span class="s">(</span><span class="n">1</span><span class="cm">,</span><span class="n">2</span><span class="cm">,</span><span class="n">3</span><span class="s">)</span></code>
 into being in scalar context, because the compiler knows
the context at compile time.  It would generate the scalar comma operator
there, not the list concatenation version of the comma.  That means it
was never a list to start with.</p>
<p>In general, functions in Perl that serve as wrappers for system calls
("syscalls") of the same name (like <i>chown(2)</i>, <i>fork(2)</i>,
<i>closedir(2)</i>, etc.) return true when they succeed and
<a href="#undef-EXPR">undef</a> otherwise, as is usually mentioned in the
descriptions below.  This is different from the C interfaces, which
return <code class="inline"><span class="n">-1</span></code>
 on failure.  Exceptions to this rule include
<a href="#wait">wait</a>, <a href="#waitpid-PID%2cFLAGS">waitpid</a>, and
<a href="#syscall-NUMBER%2c-LIST">syscall</a>.  System calls also set the special
<a href="perlvar.html#%24!">$! </a> variable on failure.  Other functions do not, except
accidentally.</p>
<p>Extension modules can also hook into the Perl parser to define new
kinds of keyword-headed expression.  These may look like functions, but
may also look completely different.  The syntax following the keyword
is defined entirely by the extension.  If you are an implementor, see
<a href="perlapi.html#PL_keyword_plugin">PL_keyword_plugin in perlapi</a> for the mechanism.  If you are using such
a module, see the module's documentation for details of the syntax that
it defines.</p>
<a name="Perl-Functions-by-Category"></a><h2>Perl Functions by Category
</h2>
<p>Here are Perl's functions (including things that look like
functions, like some keywords and named operators)
arranged by category.  Some functions appear in more
than one place.</p>
<ul>
<li><a name="Functions-for-SCALARs-or-strings"></a><b>Functions for SCALARs or strings
  </b>
<p><a href="#chomp-VARIABLE">chomp</a>, <a href="#chop-VARIABLE">chop</a>,
<a href="#chr-NUMBER">chr</a>, <a href="#crypt-PLAINTEXT%2cSALT">crypt</a>,
<a href="#fc-EXPR">fc</a>, <a href="#hex-EXPR">hex</a>,
<a href="#index-STR%2cSUBSTR%2cPOSITION">index</a>, <a href="#lc-EXPR">lc</a>,
<a href="#lcfirst-EXPR">lcfirst</a>, <a href="#length-EXPR">length</a>,
<a href="#oct-EXPR">oct</a>, <a href="#ord-EXPR">ord</a>,
<a href="#pack-TEMPLATE%2cLIST">pack</a>,
<a href="#q%2fSTRING%2f">q//</a>,
<a href="#qq%2fSTRING%2f">qq//</a>, <a href="#reverse-LIST">reverse</a>,
<a href="#rindex-STR%2cSUBSTR%2cPOSITION">rindex</a>,
<a href="#sprintf-FORMAT%2c-LIST">sprintf</a>,
<a href="#substr-EXPR%2cOFFSET%2cLENGTH%2cREPLACEMENT">substr</a>,
<a href="#tr%2f%2f%2f">tr///</a>, <a href="#uc-EXPR">uc</a>,
<a href="#ucfirst-EXPR">ucfirst</a>,
<a href="#y%2f%2f%2f">y///</a></p>
<p><a href="#fc-EXPR">fc</a> is available only if the
<a href="feature.html#The-'fc'-feature">fc feature</a> is enabled or if it is
prefixed with <code class="inline"><span class="w">CORE::</span></code>
.  The
<a href="feature.html#The-'fc'-feature">fc feature</a> is enabled automatically
with a <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="v">v5.16</span></code>
 (or higher) declaration in the current scope.</p>
</li>
<li><a name="Regular-expressions-and-pattern-matching"></a><b>Regular expressions and pattern matching
  </b>
<p><a href="#m%2f%2f">m//</a>, <a href="#pos-SCALAR">pos</a>,
<a href="#qr%2fSTRING%2f">qr//</a>,
<a href="#quotemeta-EXPR">quotemeta</a>,
<a href="#s%2f%2f%2f">s///</a>,
<a href="#split-%2fPATTERN%2f%2cEXPR%2cLIMIT">split</a>,
<a href="#study-SCALAR">study</a></p>
</li>
<li><a name="Numeric-functions"></a><b>Numeric functions
   </b>
<p><a href="#abs-VALUE">abs</a>, <a href="#atan2-Y%2cX">atan2</a>, <a href="#cos-EXPR">cos</a>,
<a href="#exp-EXPR">exp</a>, <a href="#hex-EXPR">hex</a>, <a href="#int-EXPR">int</a>,
<a href="#log-EXPR">log</a>, <a href="#oct-EXPR">oct</a>, <a href="#rand-EXPR">rand</a>,
<a href="#sin-EXPR">sin</a>, <a href="#sqrt-EXPR">sqrt</a>, <a href="#srand-EXPR">srand</a></p>
</li>
<li><a name="Functions-for-real-%40ARRAYs"></a><b>Functions for real @ARRAYs
</b>
<p><a href="#each-HASH">each</a>, <a href="#keys-HASH">keys</a>, <a href="#pop-ARRAY">pop</a>,
<a href="#push-ARRAY%2cLIST">push</a>, <a href="#shift-ARRAY">shift</a>,
<a href="#splice-ARRAY%2cOFFSET%2cLENGTH%2cLIST">splice</a>,
<a href="#unshift-ARRAY%2cLIST">unshift</a>, <a href="#values-HASH">values</a></p>
</li>
<li><a name="Functions-for-list-data"></a><b>Functions for list data
</b>
<p><a href="#grep-BLOCK-LIST">grep</a>, <a href="#join-EXPR%2cLIST">join</a>,
<a href="#map-BLOCK-LIST">map</a>, <a href="#qw%2fSTRING%2f">qw//</a>,
<a href="#reverse-LIST">reverse</a>, <a href="#sort-SUBNAME-LIST">sort</a>,
<a href="#unpack-TEMPLATE%2cEXPR">unpack</a></p>
</li>
<li><a name="Functions-for-real-%25HASHes"></a><b>Functions for real %HASHes
</b>
<p><a href="#delete-EXPR">delete</a>, <a href="#each-HASH">each</a>,
<a href="#exists-EXPR">exists</a>, <a href="#keys-HASH">keys</a>,
<a href="#values-HASH">values</a></p>
</li>
<li><a name="Input-and-output-functions"></a><b>Input and output functions
   </b>
<p><a href="#binmode-FILEHANDLE%2c-LAYER">binmode</a>, <a href="#close-FILEHANDLE">close</a>,
<a href="#closedir-DIRHANDLE">closedir</a>, <a href="#dbmclose-HASH">dbmclose</a>,
<a href="#dbmopen-HASH%2cDBNAME%2cMASK">dbmopen</a>, <a href="#die-LIST">die</a>,
<a href="#eof-FILEHANDLE">eof</a>, <a href="#fileno-FILEHANDLE">fileno</a>,
<a href="#flock-FILEHANDLE%2cOPERATION">flock</a>, <a href="#format">format</a>,
<a href="#getc-FILEHANDLE">getc</a>, <a href="#print-FILEHANDLE-LIST">print</a>,
<a href="#printf-FILEHANDLE-FORMAT%2c-LIST">printf</a>,
<a href="#read-FILEHANDLE%2cSCALAR%2cLENGTH%2cOFFSET">read</a>,
<a href="#readdir-DIRHANDLE">readdir</a>, <a href="#readline-EXPR">readline</a>,
<a href="#rewinddir-DIRHANDLE">rewinddir</a>, <a href="#say-FILEHANDLE-LIST">say</a>,
<a href="#seek-FILEHANDLE%2cPOSITION%2cWHENCE">seek</a>,
<a href="#seekdir-DIRHANDLE%2cPOS">seekdir</a>,
<a href="#select-RBITS%2cWBITS%2cEBITS%2cTIMEOUT">select</a>,
<a href="#syscall-NUMBER%2c-LIST">syscall</a>,
<a href="#sysread-FILEHANDLE%2cSCALAR%2cLENGTH%2cOFFSET">sysread</a>,
<a href="#sysseek-FILEHANDLE%2cPOSITION%2cWHENCE">sysseek</a>,
<a href="#syswrite-FILEHANDLE%2cSCALAR%2cLENGTH%2cOFFSET">syswrite</a>,
<a href="#tell-FILEHANDLE">tell</a>, <a href="#telldir-DIRHANDLE">telldir</a>,
<a href="#truncate-FILEHANDLE%2cLENGTH">truncate</a>, <a href="#warn-LIST">warn</a>,
<a href="#write-FILEHANDLE">write</a></p>
<p><a href="#say-FILEHANDLE-LIST">say</a> is available only if the
<a href="feature.html#The-'say'-feature">say feature</a> is enabled or if it is
prefixed with <code class="inline"><span class="w">CORE::</span></code>
.  The
<a href="feature.html#The-'say'-feature">say feature</a> is enabled automatically
with a <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="v">v5.10</span></code>
 (or higher) declaration in the current scope.</p>
</li>
<li><a name="Functions-for-fixed-length-data-or-records"></a><b>Functions for fixed-length data or records</b>
<p><a href="#pack-TEMPLATE%2cLIST">pack</a>,
<a href="#read-FILEHANDLE%2cSCALAR%2cLENGTH%2cOFFSET">read</a>,
<a href="#syscall-NUMBER%2c-LIST">syscall</a>,
<a href="#sysread-FILEHANDLE%2cSCALAR%2cLENGTH%2cOFFSET">sysread</a>,
<a href="#sysseek-FILEHANDLE%2cPOSITION%2cWHENCE">sysseek</a>,
<a href="#syswrite-FILEHANDLE%2cSCALAR%2cLENGTH%2cOFFSET">syswrite</a>,
<a href="#unpack-TEMPLATE%2cEXPR">unpack</a>, <a href="#vec-EXPR%2cOFFSET%2cBITS">vec</a></p>
</li>
<li><a name="Functions-for-filehandles%2c-files%2c-or-directories"></a><b>Functions for filehandles, files, or directories
     </b>
<p><a href="#-X-FILEHANDLE">-X</a>, <a href="#chdir-EXPR">chdir</a>,
<a href="#chmod-LIST">chmod</a>, <a href="#chown-LIST">chown</a>,
<a href="#chroot-FILENAME">chroot</a>,
<a href="#fcntl-FILEHANDLE%2cFUNCTION%2cSCALAR">fcntl</a>, <a href="#glob-EXPR">glob</a>,
<a href="#ioctl-FILEHANDLE%2cFUNCTION%2cSCALAR">ioctl</a>,
<a href="#link-OLDFILE%2cNEWFILE">link</a>, <a href="#lstat-FILEHANDLE">lstat</a>,
<a href="#mkdir-FILENAME%2cMASK">mkdir</a>, <a href="#open-FILEHANDLE%2cEXPR">open</a>,
<a href="#opendir-DIRHANDLE%2cEXPR">opendir</a>, <a href="#readlink-EXPR">readlink</a>,
<a href="#rename-OLDNAME%2cNEWNAME">rename</a>, <a href="#rmdir-FILENAME">rmdir</a>,
<a href="#select-FILEHANDLE">select</a>, <a href="#stat-FILEHANDLE">stat</a>,
<a href="#symlink-OLDFILE%2cNEWFILE">symlink</a>,
<a href="#sysopen-FILEHANDLE%2cFILENAME%2cMODE">sysopen</a>,
<a href="#umask-EXPR">umask</a>, <a href="#unlink-LIST">unlink</a>,
<a href="#utime-LIST">utime</a></p>
</li>
<li><a name="Keywords-related-to-the-control-flow-of-your-Perl-program"></a><b>Keywords related to the control flow of your Perl program
</b>
<p><a href="#break">break </a>, <a href="#caller-EXPR">caller</a>,
<a href="#continue-BLOCK">continue</a>, <a href="#die-LIST">die</a>, <a href="#do-BLOCK">do</a>,
<a href="#dump-LABEL">dump</a>, <a href="#eval-EXPR">eval</a>,
<a href="#evalbytes-EXPR">evalbytes</a>, <a href="#exit-EXPR">exit</a>,
<a href="#__FILE__">__FILE__ </a>, <a href="#goto-LABEL">goto</a>,
<a href="#last-LABEL">last</a>, <a href="#__LINE__">__LINE__ </a>,
<a href="#next-LABEL">next</a>, <a href="#__PACKAGE__">__PACKAGE__ </a>,
<a href="#redo-LABEL">redo</a>, <a href="#return-EXPR">return</a>,
<a href="#sub-NAME-BLOCK">sub</a>, <a href="#__SUB__">__SUB__</a>,
<a href="#wantarray">wantarray</a></p>
<p><a href="#break">break </a> is available only if you enable the experimental
<a href="feature.html#The-'switch'-feature">switch feature</a> or use the <code class="inline"><span class="w">CORE::</span></code>

prefix.  The <a href="feature.html#The-'switch'-feature">switch feature</a> also
enables the <code class="inline"><span class="w">default</span></code>
, <code class="inline">given</code>
 and <code class="inline">when</code>
 statements, which are
documented in <a href="perlsyn.html#Switch-Statements">Switch Statements in perlsyn</a>.
The <a href="feature.html#The-'switch'-feature">switch feature</a> is enabled
automatically with a <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="v">v5.10</span></code>
 (or higher) declaration in the current
scope.  In Perl v5.14 and earlier, <a href="#continue-BLOCK">continue</a>
required the <a href="feature.html#The-'switch'-feature">switch feature</a>, like
the other keywords.</p>
<p><a href="#evalbytes-EXPR">evalbytes</a> is only available with the
<a href="feature.html#The-'unicode_eval'-and-'evalbytes'-features">evalbytes feature</a>
(see <a href="feature.html">feature</a>) or if prefixed with <code class="inline"><span class="w">CORE::</span></code>
.  <a href="#__SUB__">__SUB__</a>
is only available with the
<a href="feature.html#The-'current_sub'-feature">current_sub feature</a> or if
prefixed with <code class="inline"><span class="w">CORE::</span></code>
.  Both the
<a href="feature.html#The-'unicode_eval'-and-'evalbytes'-features">evalbytes </a>
and <a href="feature.html#The-'current_sub'-feature">current_sub </a> features are
enabled automatically with a <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="v">v5.16</span></code>
 (or higher) declaration in the
current scope.</p>
</li>
<li><a name="Keywords-related-to-scoping"></a><b>Keywords related to scoping</b>
<p><a href="#caller-EXPR">caller</a>, <a href="#import-LIST">import</a>,
<a href="#local-EXPR">local</a>, <a href="#my-VARLIST">my</a>, <a href="#our-VARLIST">our</a>,
<a href="#package-NAMESPACE">package</a>, <a href="#state-VARLIST">state</a>,
<a href="#use-Module-VERSION-LIST">use</a></p>
<p><a href="#state-VARLIST">state</a> is available only if the
<a href="feature.html#The-'state'-feature">state feature</a> is enabled or if it is
prefixed with <code class="inline"><span class="w">CORE::</span></code>
.  The
<a href="feature.html#The-'state'-feature">state feature</a> is enabled
automatically with a <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="v">v5.10</span></code>
 (or higher) declaration in the current
scope.</p>
</li>
<li><a name="Miscellaneous-functions"></a><b>Miscellaneous functions</b>
<p><a href="#defined-EXPR">defined</a>, <a href="#formline-PICTURE%2cLIST">formline</a>,
<a href="#lock-THING">lock</a>, <a href="#prototype-FUNCTION">prototype</a>,
<a href="#reset-EXPR">reset</a>, <a href="#scalar-EXPR">scalar</a>,
<a href="#undef-EXPR">undef</a></p>
</li>
<li><a name="Functions-for-processes-and-process-groups"></a><b>Functions for processes and process groups
  </b>
<p><a href="#alarm-SECONDS">alarm</a>, <a href="#exec-LIST">exec</a>, <a href="#fork">fork</a>,
<a href="#getpgrp-PID">getpgrp</a>, <a href="#getppid">getppid</a>,
<a href="#getpriority-WHICH%2cWHO">getpriority</a>, <a href="#kill-SIGNAL%2c-LIST">kill</a>,
<a href="#pipe-READHANDLE%2cWRITEHANDLE">pipe</a>,
<a href="#qx%2fSTRING%2f">qx//</a>,
<a href="#readpipe-EXPR">readpipe</a>, <a href="#setpgrp-PID%2cPGRP">setpgrp</a>,
<a href="#setpriority-WHICH%2cWHO%2cPRIORITY">setpriority</a>,
<a href="#sleep-EXPR">sleep</a>, <a href="#system-LIST">system</a>, <a href="#times">times</a>,
<a href="#wait">wait</a>, <a href="#waitpid-PID%2cFLAGS">waitpid</a></p>
</li>
<li><a name="Keywords-related-to-Perl-modules"></a><b>Keywords related to Perl modules
</b>
<p><a href="#do-EXPR">do</a>, <a href="#import-LIST">import</a>,
<a href="#no-MODULE-VERSION-LIST">no</a>, <a href="#package-NAMESPACE">package</a>,
<a href="#require-VERSION">require</a>, <a href="#use-Module-VERSION-LIST">use</a></p>
</li>
<li><a name="Keywords-related-to-classes-and-object-orientation"></a><b>Keywords related to classes and object-orientation
  </b>
<p><a href="#bless-REF%2cCLASSNAME">bless</a>, <a href="#dbmclose-HASH">dbmclose</a>,
<a href="#dbmopen-HASH%2cDBNAME%2cMASK">dbmopen</a>,
<a href="#package-NAMESPACE">package</a>, <a href="#ref-EXPR">ref</a>,
<a href="#tie-VARIABLE%2cCLASSNAME%2cLIST">tie</a>, <a href="#tied-VARIABLE">tied</a>,
<a href="#untie-VARIABLE">untie</a>, <a href="#use-Module-VERSION-LIST">use</a></p>
</li>
<li><a name="Low-level-socket-functions"></a><b>Low-level socket functions
 </b>
<p><a href="#accept-NEWSOCKET%2cGENERICSOCKET">accept</a>,
<a href="#bind-SOCKET%2cNAME">bind</a>, <a href="#connect-SOCKET%2cNAME">connect</a>,
<a href="#getpeername-SOCKET">getpeername</a>,
<a href="#getsockname-SOCKET">getsockname</a>,
<a href="#getsockopt-SOCKET%2cLEVEL%2cOPTNAME">getsockopt</a>,
<a href="#listen-SOCKET%2cQUEUESIZE">listen</a>,
<a href="#recv-SOCKET%2cSCALAR%2cLENGTH%2cFLAGS">recv</a>,
<a href="#send-SOCKET%2cMSG%2cFLAGS%2cTO">send</a>,
<a href="#setsockopt-SOCKET%2cLEVEL%2cOPTNAME%2cOPTVAL">setsockopt</a>,
<a href="#shutdown-SOCKET%2cHOW">shutdown</a>,
<a href="#socket-SOCKET%2cDOMAIN%2cTYPE%2cPROTOCOL">socket</a>,
<a href="#socketpair-SOCKET1%2cSOCKET2%2cDOMAIN%2cTYPE%2cPROTOCOL">socketpair</a></p>
</li>
<li><a name="System-V-interprocess-communication-functions"></a><b>System V interprocess communication functions
     </b>
<p><a href="#msgctl-ID%2cCMD%2cARG">msgctl</a>, <a href="#msgget-KEY%2cFLAGS">msgget</a>,
<a href="#msgrcv-ID%2cVAR%2cSIZE%2cTYPE%2cFLAGS">msgrcv</a>,
<a href="#msgsnd-ID%2cMSG%2cFLAGS">msgsnd</a>,
<a href="#semctl-ID%2cSEMNUM%2cCMD%2cARG">semctl</a>,
<a href="#semget-KEY%2cNSEMS%2cFLAGS">semget</a>, <a href="#semop-KEY%2cOPSTRING">semop</a>,
<a href="#shmctl-ID%2cCMD%2cARG">shmctl</a>, <a href="#shmget-KEY%2cSIZE%2cFLAGS">shmget</a>,
<a href="#shmread-ID%2cVAR%2cPOS%2cSIZE">shmread</a>,
<a href="#shmwrite-ID%2cSTRING%2cPOS%2cSIZE">shmwrite</a></p>
</li>
<li><a name="Fetching-user-and-group-info"></a><b>Fetching user and group info
       </b>
<p><a href="#endgrent">endgrent</a>, <a href="#endhostent">endhostent</a>,
<a href="#endnetent">endnetent</a>, <a href="#endpwent">endpwent</a>,
<a href="#getgrent">getgrent</a>, <a href="#getgrgid-GID">getgrgid</a>,
<a href="#getgrnam-NAME">getgrnam</a>, <a href="#getlogin">getlogin</a>,
<a href="#getpwent">getpwent</a>, <a href="#getpwnam-NAME">getpwnam</a>,
<a href="#getpwuid-UID">getpwuid</a>, <a href="#setgrent">setgrent</a>,
<a href="#setpwent">setpwent</a></p>
</li>
<li><a name="Fetching-network-info"></a><b>Fetching network info
      </b>
<p><a href="#endprotoent">endprotoent</a>, <a href="#endservent">endservent</a>,
<a href="#gethostbyaddr-ADDR%2cADDRTYPE">gethostbyaddr</a>,
<a href="#gethostbyname-NAME">gethostbyname</a>, <a href="#gethostent">gethostent</a>,
<a href="#getnetbyaddr-ADDR%2cADDRTYPE">getnetbyaddr</a>,
<a href="#getnetbyname-NAME">getnetbyname</a>, <a href="#getnetent">getnetent</a>,
<a href="#getprotobyname-NAME">getprotobyname</a>,
<a href="#getprotobynumber-NUMBER">getprotobynumber</a>,
<a href="#getprotoent">getprotoent</a>,
<a href="#getservbyname-NAME%2cPROTO">getservbyname</a>,
<a href="#getservbyport-PORT%2cPROTO">getservbyport</a>,
<a href="#getservent">getservent</a>, <a href="#sethostent-STAYOPEN">sethostent</a>,
<a href="#setnetent-STAYOPEN">setnetent</a>,
<a href="#setprotoent-STAYOPEN">setprotoent</a>,
<a href="#setservent-STAYOPEN">setservent</a></p>
</li>
<li><a name="Time-related-functions"></a><b>Time-related functions
 </b>
<p><a href="#gmtime-EXPR">gmtime</a>, <a href="#localtime-EXPR">localtime</a>,
<a href="#time">time</a>, <a href="#times">times</a></p>
</li>
<li><a name="Non-function-keywords"></a><b>Non-function keywords</b>
<p><code class="inline">and</code>
, <code class="inline">AUTOLOAD</code>
, <code class="inline">BEGIN</code>
, <code class="inline">CHECK</code>
, <code class="inline">cmp</code>
, <code class="inline"><span class="w">CORE</span></code>
, <code class="inline"><a name="__DATA__"></a>__DATA__</code>
,
<code class="inline"><span class="w">default</span></code>
, <code class="inline">DESTROY</code>
, <code class="inline">else</code>
, <code class="inline"><a class="l_k" href="functions/elseif.html">elseif</a></code>, <code class="inline">elsif</code>
, <code class="inline">END</code>
, <code class="inline"><a name="__END__"></a>__END__</code>
,
<code class="inline">eq</code>
, <code class="inline">for</code>
, <code class="inline">foreach</code>
, <code class="inline">ge</code>
, <code class="inline">given</code>
, <code class="inline">gt</code>
, <code class="inline">if</code>
, <code class="inline">INIT</code>
, <code class="inline">le</code>
,
<code class="inline">lt</code>
, <code class="inline">ne</code>
, <code class="inline">not</code>
, <code class="inline">or</code>
, <code class="inline">UNITCHECK</code>
, <code class="inline">unless</code>
, <code class="inline">until</code>
, <code class="inline">when</code>
,
<code class="inline">while</code>
, <code class="inline"><span class="w">x</span></code>
, <code class="inline">xor</code>
</p>
</li>
</ul>
<a name="Portability"></a><h2>Portability
  </h2>
<p>Perl was born in Unix and can therefore access all common Unix
system calls.  In non-Unix environments, the functionality of some
Unix system calls may not be available or details of the available
functionality may differ slightly.  The Perl functions affected
by this are:</p>
<p><a href="#-X-FILEHANDLE">-X</a>, <a href="#binmode-FILEHANDLE%2c-LAYER">binmode</a>,
<a href="#chmod-LIST">chmod</a>, <a href="#chown-LIST">chown</a>,
<a href="#chroot-FILENAME">chroot</a>, <a href="#crypt-PLAINTEXT%2cSALT">crypt</a>,
<a href="#dbmclose-HASH">dbmclose</a>, <a href="#dbmopen-HASH%2cDBNAME%2cMASK">dbmopen</a>,
<a href="#dump-LABEL">dump</a>, <a href="#endgrent">endgrent</a>,
<a href="#endhostent">endhostent</a>, <a href="#endnetent">endnetent</a>,
<a href="#endprotoent">endprotoent</a>, <a href="#endpwent">endpwent</a>,
<a href="#endservent">endservent</a>, <a href="#exec-LIST">exec</a>,
<a href="#fcntl-FILEHANDLE%2cFUNCTION%2cSCALAR">fcntl</a>,
<a href="#flock-FILEHANDLE%2cOPERATION">flock</a>, <a href="#fork">fork</a>,
<a href="#getgrent">getgrent</a>, <a href="#getgrgid-GID">getgrgid</a>,
<a href="#gethostbyname-NAME">gethostbyname</a>, <a href="#gethostent">gethostent</a>,
<a href="#getlogin">getlogin</a>,
<a href="#getnetbyaddr-ADDR%2cADDRTYPE">getnetbyaddr</a>,
<a href="#getnetbyname-NAME">getnetbyname</a>, <a href="#getnetent">getnetent</a>,
<a href="#getppid">getppid</a>, <a href="#getpgrp-PID">getpgrp</a>,
<a href="#getpriority-WHICH%2cWHO">getpriority</a>,
<a href="#getprotobynumber-NUMBER">getprotobynumber</a>,
<a href="#getprotoent">getprotoent</a>, <a href="#getpwent">getpwent</a>,
<a href="#getpwnam-NAME">getpwnam</a>, <a href="#getpwuid-UID">getpwuid</a>,
<a href="#getservbyport-PORT%2cPROTO">getservbyport</a>,
<a href="#getservent">getservent</a>,
<a href="#getsockopt-SOCKET%2cLEVEL%2cOPTNAME">getsockopt</a>,
<a href="#glob-EXPR">glob</a>, <a href="#ioctl-FILEHANDLE%2cFUNCTION%2cSCALAR">ioctl</a>,
<a href="#kill-SIGNAL%2c-LIST">kill</a>, <a href="#link-OLDFILE%2cNEWFILE">link</a>,
<a href="#lstat-FILEHANDLE">lstat</a>, <a href="#msgctl-ID%2cCMD%2cARG">msgctl</a>,
<a href="#msgget-KEY%2cFLAGS">msgget</a>,
<a href="#msgrcv-ID%2cVAR%2cSIZE%2cTYPE%2cFLAGS">msgrcv</a>,
<a href="#msgsnd-ID%2cMSG%2cFLAGS">msgsnd</a>, <a href="#open-FILEHANDLE%2cEXPR">open</a>,
<a href="#pipe-READHANDLE%2cWRITEHANDLE">pipe</a>, <a href="#readlink-EXPR">readlink</a>,
<a href="#rename-OLDNAME%2cNEWNAME">rename</a>,
<a href="#select-RBITS%2cWBITS%2cEBITS%2cTIMEOUT">select</a>,
<a href="#semctl-ID%2cSEMNUM%2cCMD%2cARG">semctl</a>,
<a href="#semget-KEY%2cNSEMS%2cFLAGS">semget</a>, <a href="#semop-KEY%2cOPSTRING">semop</a>,
<a href="#setgrent">setgrent</a>, <a href="#sethostent-STAYOPEN">sethostent</a>,
<a href="#setnetent-STAYOPEN">setnetent</a>, <a href="#setpgrp-PID%2cPGRP">setpgrp</a>,
<a href="#setpriority-WHICH%2cWHO%2cPRIORITY">setpriority</a>,
<a href="#setprotoent-STAYOPEN">setprotoent</a>, <a href="#setpwent">setpwent</a>,
<a href="#setservent-STAYOPEN">setservent</a>,
<a href="#setsockopt-SOCKET%2cLEVEL%2cOPTNAME%2cOPTVAL">setsockopt</a>,
<a href="#shmctl-ID%2cCMD%2cARG">shmctl</a>, <a href="#shmget-KEY%2cSIZE%2cFLAGS">shmget</a>,
<a href="#shmread-ID%2cVAR%2cPOS%2cSIZE">shmread</a>,
<a href="#shmwrite-ID%2cSTRING%2cPOS%2cSIZE">shmwrite</a>,
<a href="#socket-SOCKET%2cDOMAIN%2cTYPE%2cPROTOCOL">socket</a>,
<a href="#socketpair-SOCKET1%2cSOCKET2%2cDOMAIN%2cTYPE%2cPROTOCOL">socketpair</a>,
<a href="#stat-FILEHANDLE">stat</a>, <a href="#symlink-OLDFILE%2cNEWFILE">symlink</a>,
<a href="#syscall-NUMBER%2c-LIST">syscall</a>,
<a href="#sysopen-FILEHANDLE%2cFILENAME%2cMODE">sysopen</a>,
<a href="#system-LIST">system</a>, <a href="#times">times</a>,
<a href="#truncate-FILEHANDLE%2cLENGTH">truncate</a>, <a href="#umask-EXPR">umask</a>,
<a href="#unlink-LIST">unlink</a>, <a href="#utime-LIST">utime</a>, <a href="#wait">wait</a>,
<a href="#waitpid-PID%2cFLAGS">waitpid</a></p>
<p>For more information about the portability of these functions, see
<a href="perlport.html">perlport</a> and other available platform-specific documentation.</p>
<a name="Alphabetical-Listing-of-Perl-Functions"></a><h2>Alphabetical Listing of Perl Functions</h2>
<ul>
<li><a name="-X-FILEHANDLE"></a><b>-X FILEHANDLE

</b>
</li>
<li><a name="-X-EXPR"></a><b>-X EXPR</b>
</li>
<li><a name="-X-DIRHANDLE"></a><b>-X DIRHANDLE</b>
</li>
<li><a name="-X"></a><b>-X</b>
<p>A file test, where X is one of the letters listed below.  This unary
operator takes one argument, either a filename, a filehandle, or a dirhandle,
and tests the associated file to see if something is true about it.  If the
argument is omitted, tests <a href="perlvar.html#%24_">$_ </a>, except for <code class="inline">-t</code>
, which
tests STDIN.  Unless otherwise documented, it returns <code class="inline"><span class="n">1</span></code>
 for true and
<code class="inline"><span class="q">&#39;&#39;</span></code>
 for false.  If the file doesn't exist or can't be examined, it
returns <a href="#undef-EXPR">undef</a> and sets <a href="perlvar.html#%24!">$! </a> (errno).
Despite the funny names, precedence is the same as any other named unary
operator.  The operator may be any of:</p>
<pre class="verbatim"><ol><li>    -r  <span class="w">File</span> <span class="w">is</span> <span class="w">readable</span> <span class="w">by</span> <span class="w">effective</span> <span class="w">uid</span>/<span class="w">gid</span>.</li><li>    -w  <span class="w">File</span> <span class="w">is</span> <span class="w">writable</span> <span class="w">by</span> <span class="w">effective</span> <span class="w">uid</span>/<span class="w">gid</span>.</li><li>    -x  <span class="w">File</span> <span class="w">is</span> <span class="w">executable</span> <span class="w">by</span> <span class="w">effective</span> <span class="w">uid</span>/<span class="w">gid</span>.</li><li>    -o  <span class="w">File</span> <span class="w">is</span> <span class="w">owned</span> <span class="w">by</span> <span class="w">effective</span> <span class="w">uid</span>.</li><li></li><li>    -R  <span class="w">File</span> <span class="w">is</span> <span class="w">readable</span> <span class="w">by</span> <span class="w">real</span> <span class="w">uid</span>/<span class="w">gid</span>.</li><li>    -W  <span class="w">File</span> <span class="w">is</span> <span class="w">writable</span> <span class="w">by</span> <span class="w">real</span> <span class="w">uid</span>/<span class="w">gid</span>.</li><li>    <a class="l_k" href="functions/-X.html">-X</a>  <span class="w">File</span> <span class="w">is</span> <span class="w">executable</span> <span class="w">by</span> <span class="w">real</span> <span class="w">uid</span>/<span class="w">gid</span>.</li><li>    -O  <span class="w">File</span> <span class="w">is</span> <span class="w">owned</span> <span class="w">by</span> <span class="w">real</span> <span class="w">uid</span>.</li><li></li><li>    -e  <span class="w">File</span> <a class="l_k" href="functions/exists.html">exists</a>.</li><li>    -z  <span class="w">File</span> <span class="w">has</span> <span class="w">zero</span> <span class="w">size</span> <span class="s">(</span><span class="w">is</span> <span class="w">empty</span><span class="s">)</span>.</li><li>    -s  <span class="w">File</span> <span class="w">has</span> <span class="w">nonzero</span> <span class="w">size</span> <span class="s">(</span><span class="w">returns</span> <span class="w">size</span> <span class="w">in</span> <span class="w">bytes</span><span class="s">)</span>.</li><li></li><li>    -f  <span class="w">File</span> <span class="w">is</span> <span class="w">a</span> <span class="w">plain</span> <span class="w">file</span>.</li><li>    -d  <span class="w">File</span> <span class="w">is</span> <span class="w">a</span> <span class="w">directory</span>.</li><li>    -l  <span class="w">File</span> <span class="w">is</span> <span class="w">a</span> <span class="w">symbolic</span> <a class="l_k" href="functions/link.html">link</a> <span class="s">(</span><span class="w">false</span> <a class="l_k" href="functions/if.html">if</a> <span class="w">symlinks</span> <span class="w">aren&#39;t</span></li><li>        <span class="w">supported</span> <span class="w">by</span> <span class="w">the</span> <span class="w">file</span> <a class="l_k" href="functions/system.html">system</a><span class="s">)</span>.</li><li>    -p  <span class="w">File</span> <span class="w">is</span> <span class="w">a</span> <span class="w">named</span> <a class="l_k" href="functions/pipe.html">pipe</a> <span class="s">(</span><span class="w">FIFO</span><span class="s">)</span><span class="cm">,</span> <a class="l_k" href="functions/or.html">or</a> <span class="w">Filehandle</span> <span class="w">is</span> <span class="w">a</span> <a class="l_k" href="functions/pipe.html">pipe</a>.</li><li>    -S  <span class="w">File</span> <span class="w">is</span> <span class="w">a</span> <a class="l_k" href="functions/socket.html">socket</a>.</li><li>    -b  <span class="w">File</span> <span class="w">is</span> <span class="w">a</span> <span class="w">block</span> <span class="w">special</span> <span class="w">file</span>.</li><li>    -c  <span class="w">File</span> <span class="w">is</span> <span class="w">a</span> <span class="w">character</span> <span class="w">special</span> <span class="w">file</span>.</li><li>    -t  <span class="w">Filehandle</span> <span class="w">is</span> <span class="w">opened</span> <span class="w">to</span> <span class="w">a</span> <span class="w">tty</span>.</li><li></li><li>    -u  <span class="w">File</span> <span class="w">has</span> <span class="w">setuid</span> <span class="w">bit</span> <span class="w">set</span>.</li><li>    -g  <span class="w">File</span> <span class="w">has</span> <span class="w">setgid</span> <span class="w">bit</span> <span class="w">set</span>.</li><li>    -k  <span class="w">File</span> <span class="w">has</span> <span class="w">sticky</span> <span class="w">bit</span> <span class="w">set</span>.</li><li></li><li>    -T  <span class="w">File</span> <span class="w">is</span> <span class="w">an</span> <span class="w">ASCII</span> <a class="l_k" href="functions/or.html">or</a> <span class="w">UTF</span>-<span class="n">8</span> <span class="w">text</span> <span class="w">file</span> <span class="s">(</span><span class="w">heuristic</span> <span class="w">guess</span><span class="s">)</span>.</li><li>    -B  <span class="w">File</span> <span class="w">is</span> <span class="w">a</span> <span class="q">&quot;binary&quot;</span> <span class="w">file</span> <span class="s">(</span><span class="w">opposite</span> <span class="w">of</span> -T<span class="s">)</span>.</li><li></li><li>    -M  <span class="w">Script</span> <span class="w">start</span> <a class="l_k" href="functions/time.html">time</a> <span class="w">minus</span> <span class="w">file</span> <span class="w">modification</span> <a class="l_k" href="functions/time.html">time</a><span class="cm">,</span> <span class="w">in</span> <span class="w">days</span>.</li><li>    -A  <span class="w">Same</span> <a class="l_k" href="functions/for.html">for</a> <span class="w">access</span> <a class="l_k" href="functions/time.html">time</a>.</li><li>    -C  <span class="w">Same</span> <a class="l_k" href="functions/for.html">for</a> <span class="w">inode</span> <span class="w">change</span> <a class="l_k" href="functions/time.html">time</a> <span class="s">(</span><span class="w">Unix</span><span class="cm">,</span> <span class="w">may</span> <span class="w">differ</span> <a class="l_k" href="functions/for.html">for</a> <span class="w">other</span></li><li>	<span class="w">platforms</span><span class="s">)</span></li></ol></pre><p>Example:</p>
<pre class="verbatim"><ol><li>    while <span class="s">(</span>&lt;&gt;<span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/chomp.html">chomp</a><span class="sc">;</span></li><li>        <a class="l_k" href="functions/next.html">next</a> unless -f <span class="i">$_</span><span class="sc">;</span>  <span class="c"># ignore specials</span></li><li>        <span class="c">#...</span></li><li>    <span class="s">}</span></li></ol></pre><p>Note that <code class="inline">-s/a/b/</code> does not do a negated substitution.  Saying
<code class="inline">-<a class="l_k" href="functions/exp.html">exp</a><span class="s">(</span><span class="i">$foo</span><span class="s">)</span></code>
 still works as expected, however: only single letters
following a minus are interpreted as file tests.</p>
<p>These operators are exempt from the "looks like a function rule" described
above.  That is, an opening parenthesis after the operator does not affect
how much of the following code constitutes the argument.  Put the opening
parentheses before the operator to separate it from code that follows (this
applies only to operators with higher precedence than unary operators, of
course):</p>
<pre class="verbatim"><ol><li>    -s<span class="s">(</span><span class="i">$file</span><span class="s">)</span> + <span class="n">1024</span>   <span class="c"># probably wrong; same as -s($file + 1024)</span></li><li>    <span class="s">(</span>-s <span class="i">$file</span><span class="s">)</span> + <span class="n">1024</span>  <span class="c"># correct</span></li></ol></pre><p>The interpretation of the file permission operators <code class="inline">-r</code>
, <code class="inline">-R</code>
,
<code class="inline">-w</code>
, <code class="inline">-W</code>
, <code class="inline">-x</code>
, and <code class="inline"><a class="l_k" href="functions/-X.html">-X</a></code> is by default based solely on the mode
of the file and the uids and gids of the user.  There may be other
reasons you can't actually read, write, or execute the file: for
example network filesystem access controls, ACLs (access control lists),
read-only filesystems, and unrecognized executable formats.  Note
that the use of these six specific operators to verify if some operation
is possible is usually a mistake, because it may be open to race
conditions.</p>
<p>Also note that, for the superuser on the local filesystems, the <code class="inline">-r</code>
,
<code class="inline">-R</code>
, <code class="inline">-w</code>
, and <code class="inline">-W</code>
 tests always return 1, and <code class="inline">-x</code>
 and <code class="inline"><a class="l_k" href="functions/-X.html">-X</a></code> return 1
if any execute bit is set in the mode.  Scripts run by the superuser
may thus need to do a <a href="#stat-FILEHANDLE">stat</a> to determine the
actual mode of the file, or temporarily set their effective uid to
something else.</p>
<p>If you are using ACLs, there is a pragma called <a href="filetest.html">filetest </a>
that may produce more accurate results than the bare
<a href="#stat-FILEHANDLE">stat</a> mode bits.
When under <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">filetest</span> <span class="q">&#39;access&#39;</span></code>
, the above-mentioned filetests
test whether the permission can(not) be granted using the <i>access(2)</i>
family of system calls.  Also note that the <code class="inline">-x</code>
 and <code class="inline"><a class="l_k" href="functions/-X.html">-X</a></code> tests may
under this pragma return true even if there are no execute permission
bits set (nor any extra execute permission ACLs).  This strangeness is
due to the underlying system calls' definitions.  Note also that, due to
the implementation of <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">filetest</span> <span class="q">&#39;access&#39;</span></code>
, the <code class="inline"><span class="w">_</span></code>
 special
filehandle won't cache the results of the file tests when this pragma is
in effect.  Read the documentation for the <a href="filetest.html">filetest </a>
pragma for more information.</p>
<p>The <code class="inline">-T</code>
 and <code class="inline">-B</code>
 tests work as follows.  The first block or so of
the file is examined to see if it is valid UTF-8 that includes non-ASCII
characters.  If so, it's a <code class="inline">-T</code>
 file.  Otherwise, that same portion of
the file is examined for odd characters such as strange control codes or
characters with the high bit set.  If more than a third of the
characters are strange, it's a <code class="inline">-B</code>
 file; otherwise it's a <code class="inline">-T</code>
 file.
Also, any file containing a zero byte in the examined portion is
considered a binary file.  (If executed within the scope of a <a href="perllocale.html">use locale</a> which includes <code class="inline"><span class="w">LC_CTYPE</span></code>
, odd characters are
anything that isn't a printable nor space in the current locale.)  If
<code class="inline">-T</code>
 or <code class="inline">-B</code>
 is used on a filehandle, the current IO buffer is
examined
rather than the first block.  Both <code class="inline">-T</code>
 and <code class="inline">-B</code>
 return true on an empty
file, or a file at EOF when testing a filehandle.  Because you have to
read a file to do the <code class="inline">-T</code>
 test, on most occasions you want to use a <code class="inline">-f</code>

against the file first, as in <code class="inline"><a class="l_k" href="functions/next.html">next</a> unless -f <span class="i">$file</span> &amp;&amp; -T <span class="i">$file</span></code>
.</p>
<p>If any of the file tests (or either the <a href="#stat-FILEHANDLE">stat</a> or
<a href="#lstat-FILEHANDLE">lstat</a> operator) is given the special filehandle
consisting of a solitary underline, then the stat structure of the
previous file test (or <a href="#stat-FILEHANDLE">stat</a> operator) is used,
saving a system call.  (This doesn't work with <code class="inline">-t</code>
, and you need to
remember that <a href="#lstat-FILEHANDLE">lstat</a> and <code class="inline">-l</code>
 leave values in
the stat structure for the symbolic link, not the real file.)  (Also, if
the stat buffer was filled by an <a href="#lstat-FILEHANDLE">lstat</a> call,
<code class="inline">-T</code>
 and <code class="inline">-B</code>
 will reset it with the results of <code class="inline"><a class="l_k" href="functions/stat.html">stat</a> <span class="w">_</span></code>
).
Example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Can do.\n&quot;</span> if -r <span class="i">$a</span> || -w <span class="i">_</span> || -x <span class="i">_</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/stat.html">stat</a><span class="s">(</span><span class="i">$filename</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Readable\n&quot;</span> if -r <span class="i">_</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Writable\n&quot;</span> if -w <span class="i">_</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Executable\n&quot;</span> if -x <span class="i">_</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Setuid\n&quot;</span> if -u <span class="i">_</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Setgid\n&quot;</span> if -g <span class="i">_</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Sticky\n&quot;</span> if -k <span class="i">_</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Text\n&quot;</span> if -T <span class="i">_</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Binary\n&quot;</span> if -B <span class="i">_</span><span class="sc">;</span></li></ol></pre><p>As of Perl 5.10.0, as a form of purely syntactic sugar, you can stack file
test operators, in a way that <code class="inline">-f -w -x <span class="i">$file</span></code>
 is equivalent to
<code class="inline">-x <span class="i">$file</span> &amp;&amp; -w <span class="i">_</span> &amp;&amp; -f <span class="i">_</span></code>
.  (This is only fancy syntax: if you use
the return value of <code class="inline">-f <span class="i">$file</span></code>
 as an argument to another filetest
operator, no special magic will happen.)</p>
<p>Portability issues: <a href="perlport.html#-X">-X in perlport</a>.</p>
<p>To avoid confusing would-be users of your code with mysterious
syntax errors, put something like this at the top of your script:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="n">5.010</span><span class="sc">;</span>  <span class="c"># so filetest ops can stack</span></li></ol></pre></li>
<li><a name="abs-VALUE"></a><b>abs VALUE
 </b>
</li>
<li><a name="abs"></a><b>abs</b>
<p>Returns the absolute value of its argument.
If VALUE is omitted, uses <a href="perlvar.html#%24_">$_ </a>.</p>
</li>
<li><a name="accept-NEWSOCKET%2cGENERICSOCKET"></a><b>accept NEWSOCKET,GENERICSOCKET
</b>
<p>Accepts an incoming socket connect, just as <i>accept(2)</i>
does.  Returns the packed address if it succeeded, false otherwise.
See the example in <a href="perlipc.html#Sockets%3a-Client%2fServer-Communication">Sockets: Client/Server Communication in perlipc</a>.</p>
<p>On systems that support a close-on-exec flag on files, the flag will
be set for the newly opened file descriptor, as determined by the
value of <a href="perlvar.html#%24%5eF">$^F </a>.  See <a href="perlvar.html#%24%5eF">$^F in perlvar</a>.</p>
</li>
<li><a name="alarm-SECONDS"></a><b>alarm SECONDS


</b>
</li>
<li><a name="alarm"></a><b>alarm</b>
<p>Arranges to have a SIGALRM delivered to this process after the
specified number of wallclock seconds has elapsed.  If SECONDS is not
specified, the value stored in <a href="perlvar.html#%24_">$_ </a> is used.  (On some
machines, unfortunately, the elapsed time may be up to one second less
or more than you specified because of how seconds are counted, and
process scheduling may delay the delivery of the signal even further.)</p>
<p>Only one timer may be counting at once.  Each call disables the
previous timer, and an argument of <code class="inline"><span class="n">0</span></code>
 may be supplied to cancel the
previous timer without starting a new one.  The returned value is the
amount of time remaining on the previous timer.</p>
<p>For delays of finer granularity than one second, the <a href="Time/HiRes.html">Time::HiRes</a> module
(from CPAN, and starting from Perl 5.8 part of the standard
distribution) provides
<a href="Time/HiRes.html#ualarm-(-%24useconds-%5b%2c-%24interval_useconds-%5d-)">ualarm </a>.
You may also use Perl's four-argument version of
<a href="#select-RBITS%2cWBITS%2cEBITS%2cTIMEOUT">select</a> leaving the first three
arguments undefined, or you might be able to use the
<a href="#syscall-NUMBER%2c-LIST">syscall</a> interface to access <i>setitimer(2)</i>
if your system supports it.  See <a href="perlfaq8.html">perlfaq8</a> for details.</p>
<p>It is usually a mistake to intermix <a href="#alarm-SECONDS">alarm</a> and
<a href="#sleep-EXPR">sleep</a> calls, because <a href="#sleep-EXPR">sleep</a> may be
internally implemented on your system with <a href="#alarm-SECONDS">alarm</a>.</p>
<p>If you want to use <a href="#alarm-SECONDS">alarm</a> to time out a system call
you need to use an <a href="#eval-EXPR">eval</a>/<a href="#die-LIST">die</a> pair.  You
can't rely on the alarm causing the system call to fail with
<a href="perlvar.html#%24!">$! </a> set to <code class="inline"><span class="w">EINTR</span></code>
 because Perl sets up signal handlers
to restart system calls on some systems.  Using
<a href="#eval-EXPR">eval</a>/<a href="#die-LIST">die</a> always works, modulo the
caveats given in <a href="perlipc.html#Signals">Signals in perlipc</a>.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span></li><li>        <a class="l_k" href="functions/local.html">local</a> <span class="i">$SIG</span>{<span class="w">ALRM</span>} = <a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;alarm\n&quot;</span> <span class="s">}</span><span class="sc">;</span> <span class="c"># NB: \n required</span></li><li>        <a class="l_k" href="functions/alarm.html">alarm</a> <span class="i">$timeout</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/my.html">my</a> <span class="i">$nread</span> = <a class="l_k" href="functions/sysread.html">sysread</a> <span class="i">$socket</span><span class="cm">,</span> <span class="i">$buffer</span><span class="cm">,</span> <span class="i">$size</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/alarm.html">alarm</a> <span class="n">0</span><span class="sc">;</span></li><li>    <span class="s">}</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span><span class="i">$@</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/die.html">die</a> <a class="l_k" href="functions/unless.html">unless</a> <span class="i">$@</span> <a class="l_k" href="functions/eq.html">eq</a> <span class="q">&quot;alarm\n&quot;</span><span class="sc">;</span>   <span class="c"># propagate unexpected errors</span></li><li>        <span class="c"># timed out</span></li><li>    <span class="s">}</span></li><li>    <a class="l_k" href="functions/else.html">else</a> <span class="s">{</span></li><li>        <span class="c"># didn&#39;t</span></li><li>    <span class="s">}</span></li></ol></pre><p>For more information see <a href="perlipc.html">perlipc</a>.</p>
<p>Portability issues: <a href="perlport.html#alarm">alarm in perlport</a>.</p>
</li>
<li><a name="atan2-Y%2cX"></a><b>atan2 Y,X
   </b>
<p>Returns the arctangent of Y/X in the range -PI to PI.</p>
<p>For the tangent operation, you may use the
<a href="Math/Trig.html#tan">Math::Trig::tan </a> function, or use the familiar
relation:</p>
<pre class="verbatim"><ol><li><a name="tan"></a>    sub <span class="m">tan</span> <span class="s">{</span> <a class="l_k" href="functions/sin.html">sin</a><span class="s">(</span><span class="i">$_</span>[<span class="n">0</span>]<span class="s">)</span> / <a class="l_k" href="functions/cos.html">cos</a><span class="s">(</span><span class="i">$_</span>[<span class="n">0</span>]<span class="s">)</span>  <span class="s">}</span></li></ol></pre><p>The return value for <code class="inline"><a class="l_k" href="functions/atan2.html">atan2(0,0)</a></code> is implementation-defined; consult
your <i>atan2(3)</i> manpage for more information.</p>
<p>Portability issues: <a href="perlport.html#atan2">atan2 in perlport</a>.</p>
</li>
<li><a name="bind-SOCKET%2cNAME"></a><b>bind SOCKET,NAME
</b>
<p>Binds a network address to a socket, just as <i>bind(2)</i>
does.  Returns true if it succeeded, false otherwise.  NAME should be a
packed address of the appropriate type for the socket.  See the examples in
<a href="perlipc.html#Sockets%3a-Client%2fServer-Communication">Sockets: Client/Server Communication in perlipc</a>.</p>
</li>
<li><a name="binmode-FILEHANDLE%2c-LAYER"></a><b>binmode FILEHANDLE, LAYER
    </b>
</li>
<li><a name="binmode-FILEHANDLE"></a><b>binmode FILEHANDLE</b>
<p>Arranges for FILEHANDLE to be read or written in "binary" or "text"
mode on systems where the run-time libraries distinguish between
binary and text files.  If FILEHANDLE is an expression, the value is
taken as the name of the filehandle.  Returns true on success,
otherwise it returns <a href="#undef-EXPR">undef</a> and sets
<a href="perlvar.html#%24!">$! </a> (errno).</p>
<p>On some systems (in general, DOS- and Windows-based systems)
<a href="#binmode-FILEHANDLE%2c-LAYER">binmode</a> is necessary when you're not
working with a text file.  For the sake of portability it is a good idea
always to use it when appropriate, and never to use it when it isn't
appropriate.  Also, people can set their I/O to be by default
UTF8-encoded Unicode, not bytes.</p>
<p>In other words: regardless of platform, use
<a href="#binmode-FILEHANDLE%2c-LAYER">binmode</a> on binary data, like images,
for example.</p>
<p>If LAYER is present it is a single string, but may contain multiple
directives.  The directives alter the behaviour of the filehandle.
When LAYER is present, using binmode on a text file makes sense.</p>
<p>If LAYER is omitted or specified as <code class="inline"><span class="j">:</span><span class="w">raw</span></code>
 the filehandle is made
suitable for passing binary data.  This includes turning off possible CRLF
translation and marking it as bytes (as opposed to Unicode characters).
Note that, despite what may be implied in <i>"Programming Perl"</i> (the
Camel, 3rd edition) or elsewhere, <code class="inline"><span class="j">:</span><span class="w">raw</span></code>
 is <i>not</i> simply the inverse of <code class="inline"><span class="j">:</span><span class="w">crlf</span></code>
.
Other layers that would affect the binary nature of the stream are
<i>also</i> disabled.  See <a href="PerlIO.html">PerlIO</a>, <a href="perlrun.html">perlrun</a>, and the discussion about the
PERLIO environment variable.</p>
<p>The <code class="inline"><span class="j">:</span><span class="w">bytes</span></code>
, <code class="inline"><span class="j">:</span><span class="w">crlf</span></code>
, <code class="inline"><span class="j">:</span><span class="w">utf8</span></code>
, and any other directives of the
form <code class="inline"><span class="j">:</span>...</code>
, are called I/O <i>layers</i>.  The <a href="open.html">open</a> pragma can be used to
establish default I/O layers.</p>
<p><i>The LAYER parameter of the <a href="#binmode-FILEHANDLE%2c-LAYER">binmode</a>
function is described as "DISCIPLINE" in "Programming Perl, 3rd
Edition".  However, since the publishing of this book, by many known as
"Camel III", the consensus of the naming of this functionality has moved
from "discipline" to "layer".  All documentation of this version of Perl
therefore refers to "layers" rather than to "disciplines".  Now back to
the regularly scheduled documentation...</i></p>
<p>To mark FILEHANDLE as UTF-8, use <code class="inline"><span class="j">:</span><span class="w">utf8</span></code>
 or <code class="inline"><span class="j">:</span><span class="i">encoding</span><span class="s">(</span><span class="w">UTF</span>-<span class="n">8</span><span class="s">)</span></code>
.
<code class="inline"><span class="j">:</span><span class="w">utf8</span></code>
 just marks the data as UTF-8 without further checking,
while <code class="inline"><span class="j">:</span><span class="i">encoding</span><span class="s">(</span><span class="w">UTF</span>-<span class="n">8</span><span class="s">)</span></code>
 checks the data for actually being valid
UTF-8.  More details can be found in <a href="PerlIO/encoding.html">PerlIO::encoding</a>.</p>
<p>In general, <a href="#binmode-FILEHANDLE%2c-LAYER">binmode</a> should be called
after <a href="#open-FILEHANDLE%2cEXPR">open</a> but before any I/O is done on the
filehandle.  Calling <a href="#binmode-FILEHANDLE%2c-LAYER">binmode</a> normally
flushes any pending buffered output data (and perhaps pending input
data) on the handle.  An exception to this is the <code class="inline"><span class="j">:</span><span class="w">encoding</span></code>
 layer
that changes the default character encoding of the handle.
The <code class="inline"><span class="j">:</span><span class="w">encoding</span></code>
 layer sometimes needs to be called in
mid-stream, and it doesn't flush the stream.  <code class="inline"><span class="j">:</span><span class="w">encoding</span></code>

also implicitly pushes on top of itself the <code class="inline"><span class="j">:</span><span class="w">utf8</span></code>
 layer because
internally Perl operates on UTF8-encoded Unicode characters.</p>
<p>The operating system, device drivers, C libraries, and Perl run-time
system all conspire to let the programmer treat a single
character (<code class="inline">\<span class="w">n</span></code>
) as the line terminator, irrespective of external
representation.  On many operating systems, the native text file
representation matches the internal representation, but on some
platforms the external representation of <code class="inline">\<span class="w">n</span></code>
 is made up of more than
one character.</p>
<p>All variants of Unix, Mac OS (old and new), and Stream_LF files on VMS use
a single character to end each line in the external representation of text
(even though that single character is CARRIAGE RETURN on old, pre-Darwin
flavors of Mac OS, and is LINE FEED on Unix and most VMS files).  In other
systems like OS/2, DOS, and the various flavors of MS-Windows, your program
sees a <code class="inline">\<span class="w">n</span></code>
 as a simple <code class="inline">\<span class="w">cJ</span></code>
, but what's stored in text files are the
two characters <code class="inline">\<span class="w">cM</span>\<span class="w">cJ</span></code>
.  That means that if you don't use
<a href="#binmode-FILEHANDLE%2c-LAYER">binmode</a> on these systems, <code class="inline">\<span class="w">cM</span>\<span class="w">cJ</span></code>

sequences on disk will be converted to <code class="inline">\<span class="w">n</span></code>
 on input, and any <code class="inline">\<span class="w">n</span></code>
 in
your program will be converted back to <code class="inline">\<span class="w">cM</span>\<span class="w">cJ</span></code>
 on output.  This is
what you want for text files, but it can be disastrous for binary files.</p>
<p>Another consequence of using <a href="#binmode-FILEHANDLE%2c-LAYER">binmode</a>
(on some systems) is that special end-of-file markers will be seen as
part of the data stream.  For systems from the Microsoft family this
means that, if your binary data contain <code class="inline">\<span class="w">cZ</span></code>
, the I/O subsystem will
regard it as the end of the file, unless you use
<a href="#binmode-FILEHANDLE%2c-LAYER">binmode</a>.</p>
<p><a href="#binmode-FILEHANDLE%2c-LAYER">binmode</a> is important not only for
<a href="#readline-EXPR">readline</a> and <a href="#print-FILEHANDLE-LIST">print</a>
operations, but also when using
<a href="#read-FILEHANDLE%2cSCALAR%2cLENGTH%2cOFFSET">read</a>,
<a href="#seek-FILEHANDLE%2cPOSITION%2cWHENCE">seek</a>,
<a href="#sysread-FILEHANDLE%2cSCALAR%2cLENGTH%2cOFFSET">sysread</a>,
<a href="#syswrite-FILEHANDLE%2cSCALAR%2cLENGTH%2cOFFSET">syswrite</a> and
<a href="#tell-FILEHANDLE">tell</a> (see <a href="perlport.html">perlport</a> for more details).  See the
<a href="perlvar.html#%24%2f">$/ </a> and <a href="perlvar.html#%24%5c">$\ </a> variables in
<a href="perlvar.html">perlvar</a> for how to manually set your input and output
line-termination sequences.</p>
<p>Portability issues: <a href="perlport.html#binmode">binmode in perlport</a>.</p>
</li>
<li><a name="bless-REF%2cCLASSNAME"></a><b>bless REF,CLASSNAME
</b>
</li>
<li><a name="bless-REF"></a><b>bless REF</b>
<p>This function tells the thingy referenced by REF that it is now an object
in the CLASSNAME package.  If CLASSNAME is omitted, the current package
is used.  Because a <a href="#bless-REF%2cCLASSNAME">bless</a> is often the last
thing in a constructor, it returns the reference for convenience.
Always use the two-argument version if a derived class might inherit the
method doing the blessing.  See <a href="perlobj.html">perlobj</a> for more about the blessing
(and blessings) of objects.</p>
<p>Consider always blessing objects in CLASSNAMEs that are mixed case.
Namespaces with all lowercase names are considered reserved for
Perl pragmas.  Builtin types have all uppercase names.  To prevent
confusion, you may wish to avoid such package names as well.  Make sure
that CLASSNAME is a true value.</p>
<p>See <a href="perlmod.html#Perl-Modules">Perl Modules in perlmod</a>.</p>
</li>
<li><a name="break"></a><b>break</b>
<p>Break out of a <code class="inline">given</code>
 block.</p>
<p><a href="#break">break </a> is available only if the
<a href="feature.html#The-'switch'-feature">switch feature</a> is enabled or if it
is prefixed with <code class="inline"><span class="w">CORE::</span></code>
. The
<a href="feature.html#The-'switch'-feature">switch feature</a> is enabled
automatically with a <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="v">v5.10</span></code>
 (or higher) declaration in the current
scope.</p>
</li>
<li><a name="caller-EXPR"></a><b>caller EXPR
   </b>
</li>
<li><a name="caller"></a><b>caller</b>
<p>Returns the context of the current pure perl subroutine call.  In scalar
context, returns the caller's package name if there <i>is</i> a caller (that is, if
we're in a subroutine or <a href="#eval-EXPR">eval</a> or
<a href="#require-VERSION">require</a>) and the undefined value otherwise.
caller never returns XS subs and they are skipped.  The next pure perl
sub will appear instead of the XS sub in caller's return values.  In
list context, caller returns</p>
<pre class="verbatim"><ol><li>       <span class="c"># 0         1          2</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$package</span><span class="cm">,</span> <span class="i">$filename</span><span class="cm">,</span> <span class="i">$line</span><span class="s">)</span> = <a class="l_k" href="functions/caller.html">caller</a><span class="sc">;</span></li></ol></pre><p>With EXPR, it returns some extra information that the debugger uses to
print a stack trace.  The value of EXPR indicates how many call frames
to go back before the current one.</p>
<pre class="verbatim"><ol><li>    <span class="c">#  0         1          2      3            4</span></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$package</span><span class="cm">,</span> <span class="i">$filename</span><span class="cm">,</span> <span class="i">$line</span><span class="cm">,</span> <span class="i">$subroutine</span><span class="cm">,</span> <span class="i">$hasargs</span><span class="cm">,</span></li><li></li><li>    <span class="c">#  5          6          7            8       9         10</span></li><li>    <span class="i">$wantarray</span><span class="cm">,</span> <span class="i">$evaltext</span><span class="cm">,</span> <span class="i">$is_require</span><span class="cm">,</span> <span class="i">$hints</span><span class="cm">,</span> <span class="i">$bitmask</span><span class="cm">,</span> <span class="i">$hinthash</span><span class="s">)</span></li><li>  = <a class="l_k" href="functions/caller.html">caller</a><span class="s">(</span><span class="i">$i</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Here, $subroutine is the function that the caller called (rather than the
function containing the caller).  Note that $subroutine may be <code class="inline"><span class="s">(</span><a class="l_k" href="functions/eval.html">eval</a><span class="s">)</span></code>
 if
the frame is not a subroutine call, but an <a href="#eval-EXPR">eval</a>.  In
such a case additional elements $evaltext and <code class="inline"><span class="i">$is_require</span></code>
 are set:
<code class="inline"><span class="i">$is_require</span></code>
 is true if the frame is created by a
<a href="#require-VERSION">require</a> or <a href="#use-Module-VERSION-LIST">use</a>
statement, $evaltext contains the text of the <code class="inline"><a class="l_k" href="functions/eval.html">eval</a> <span class="w">EXPR</span></code>
 statement.
In particular, for an <code class="inline"><a class="l_k" href="functions/eval.html">eval</a> <span class="w">BLOCK</span></code>
 statement, $subroutine is <code class="inline"><span class="s">(</span><a class="l_k" href="functions/eval.html">eval</a><span class="s">)</span></code>
,
but $evaltext is undefined.  (Note also that each
<a href="#use-Module-VERSION-LIST">use</a> statement creates a
<a href="#require-VERSION">require</a> frame inside an <code class="inline"><a class="l_k" href="functions/eval.html">eval</a> <span class="w">EXPR</span></code>
 frame.)
$subroutine may also be <code class="inline"><span class="s">(</span><span class="w">unknown</span><span class="s">)</span></code>
 if this particular subroutine
happens to have been deleted from the symbol table.  <code class="inline"><span class="i">$hasargs</span></code>
 is true
if a new instance of <a href="perlvar.html#%40_">@_ </a> was set up for the frame.
<code class="inline"><span class="i">$hints</span></code>
 and <code class="inline"><span class="i">$bitmask</span></code>
 contain pragmatic hints that the caller was
compiled with.  <code class="inline"><span class="i">$hints</span></code>
 corresponds to <a href="perlvar.html#%24%5eH">$^H </a>, and
<code class="inline"><span class="i">$bitmask</span></code>
 corresponds to
<a href="perlvar.html#%24%7b%5eWARNING_BITS%7d">${^WARNING_BITS} </a>.  The <code class="inline"><span class="i">$hints</span></code>
 and
<code class="inline"><span class="i">$bitmask</span></code>
 values are subject to change between versions of Perl, and
are not meant for external use.</p>
<p><code class="inline"><span class="i">$hinthash</span></code>
 is a reference to a hash containing the value of
<a href="perlvar.html#%25%5eH">%^H </a> when the caller was compiled, or
<a href="#undef-EXPR">undef</a> if <a href="perlvar.html#%25%5eH">%^H </a> was empty.  Do not
modify the values of this hash, as they are the actual values stored in
the optree.</p>
<p>Furthermore, when called from within the DB package in
list context, and with an argument, caller returns more
detailed information: it sets the list variable <code class="inline"><span class="i">@DB::args</span></code>
 to be the
arguments with which the subroutine was invoked.</p>
<p>Be aware that the optimizer might have optimized call frames away before
<a href="#caller-EXPR">caller</a> had a chance to get the information.  That
means that <code class="inline"><a class="l_k" href="functions/caller.html">caller(N)</a></code> might not return information about the call
frame you expect it to, for <code class="inline"><span class="w">N</span> &gt; <span class="n">1</span></code>
.  In particular, <code class="inline"><span class="i">@DB::args</span></code>

might have information from the previous time <a href="#caller-EXPR">caller</a>
was called.</p>
<p>Be aware that setting <code class="inline"><span class="i">@DB::args</span></code>
 is <i>best effort</i>, intended for
debugging or generating backtraces, and should not be relied upon.  In
particular, as <a href="perlvar.html#%40_">@_ </a> contains aliases to the caller's
arguments, Perl does not take a copy of <a href="perlvar.html#%40_">@_ </a>, so
<code class="inline"><span class="i">@DB::args</span></code>
 will contain modifications the subroutine makes to
<a href="perlvar.html#%40_">@_ </a> or its contents, not the original values at call
time.  <code class="inline"><span class="i">@DB::args</span></code>
, like <a href="perlvar.html#%40_">@_ </a>, does not hold explicit
references to its elements, so under certain cases its elements may have
become freed and reallocated for other variables or temporary values.
Finally, a side effect of the current implementation is that the effects
of <code class="inline"><a class="l_k" href="functions/shift.html">shift</a> <span class="i">@_</span></code>
 can <i>normally</i> be undone (but not <code class="inline"><a class="l_k" href="functions/pop.html">pop</a> <span class="i">@_</span></code>
 or other
splicing, <i>and</i> not if a reference to <a href="perlvar.html#%40_">@_ </a> has been
taken, <i>and</i> subject to the caveat about reallocated elements), so
<code class="inline"><span class="i">@DB::args</span></code>
 is actually a hybrid of the current state and initial state
of <a href="perlvar.html#%40_">@_ </a>.  Buyer beware.</p>
</li>
<li><a name="chdir-EXPR"></a><b>chdir EXPR


</b>
</li>
<li><a name="chdir-FILEHANDLE"></a><b>chdir FILEHANDLE</b>
</li>
<li><a name="chdir-DIRHANDLE"></a><b>chdir DIRHANDLE</b>
</li>
<li><a name="chdir"></a><b>chdir</b>
<p>Changes the working directory to EXPR, if possible.  If EXPR is omitted,
changes to the directory specified by <code class="inline"><span class="i">$ENV</span>{<span class="w">HOME</span>}</code>
, if set; if not,
changes to the directory specified by <code class="inline"><span class="i">$ENV</span>{<span class="w">LOGDIR</span>}</code>
.  (Under VMS, the
variable <code class="inline"><span class="i">$ENV</span>{<span class="q">&#39;SYS$LOGIN&#39;</span>}</code>
 is also checked, and used if it is set.)  If
neither is set, <a href="#chdir-EXPR">chdir</a> does nothing and fails.  It
returns true on success, false otherwise.  See the example under
<a href="#die-LIST">die</a>.</p>
<p>On systems that support <i>fchdir(2)</i>, you may pass a filehandle or
directory handle as the argument.  On systems that don't support <i>fchdir(2)</i>,
passing handles raises an exception.</p>
</li>
<li><a name="chmod-LIST"></a><b>chmod LIST
  </b>
<p>Changes the permissions of a list of files.  The first element of the
list must be the numeric mode, which should probably be an octal
number, and which definitely should <i>not</i> be a string of octal digits:
<code class="inline"><span class="n">0644</span></code>
 is okay, but <code class="inline"><span class="q">&quot;0644&quot;</span></code>
 is not.  Returns the number of files
successfully changed.  See also <a href="#oct-EXPR">oct</a> if all you have is a
string.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$cnt</span> = <a class="l_k" href="functions/chmod.html">chmod</a> <span class="n">0755</span><span class="cm">,</span> <span class="q">&quot;foo&quot;</span><span class="cm">,</span> <span class="q">&quot;bar&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/chmod.html">chmod</a> <span class="n">0755</span><span class="cm">,</span> <span class="i">@executables</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$mode</span> = <span class="q">&quot;0644&quot;</span><span class="sc">;</span> <a class="l_k" href="functions/chmod.html">chmod</a> <span class="i">$mode</span><span class="cm">,</span> <span class="q">&quot;foo&quot;</span><span class="sc">;</span>      <span class="c"># !!! sets mode to</span></li><li>                                                <span class="c"># --w----r-T</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$mode</span> = <span class="q">&quot;0644&quot;</span><span class="sc">;</span> <a class="l_k" href="functions/chmod.html">chmod</a> <a class="l_k" href="functions/oct.html">oct</a><span class="s">(</span><span class="i">$mode</span><span class="s">)</span><span class="cm">,</span> <span class="q">&quot;foo&quot;</span><span class="sc">;</span> <span class="c"># this is better</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$mode</span> = <span class="n">0644</span><span class="sc">;</span>   <a class="l_k" href="functions/chmod.html">chmod</a> <span class="i">$mode</span><span class="cm">,</span> <span class="q">&quot;foo&quot;</span><span class="sc">;</span>      <span class="c"># this is best</span></li></ol></pre><p>On systems that support <i>fchmod(2)</i>, you may pass filehandles among the
files.  On systems that don't support <i>fchmod(2)</i>, passing filehandles raises
an exception.  Filehandles must be passed as globs or glob references to be
recognized; barewords are considered filenames.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;&lt;&quot;</span><span class="cm">,</span> <span class="q">&quot;foo&quot;</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$perm</span> = <span class="s">(</span><a class="l_k" href="functions/stat.html">stat</a> <span class="i">$fh</span><span class="s">)</span>[<span class="n">2</span>] &amp; <span class="n">07777</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/chmod.html">chmod</a><span class="s">(</span><span class="i">$perm</span> | <span class="n">0600</span><span class="cm">,</span> <span class="i">$fh</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>You can also import the symbolic <code class="inline"><span class="w">S_I</span>*</code>
 constants from the
<a href="Fcntl.html">Fcntl </a> module:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Fcntl</span> <span class="q">qw( :mode )</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/chmod.html">chmod</a> <span class="w">S_IRWXU</span>|<span class="w">S_IRGRP</span>|<span class="w">S_IXGRP</span>|<span class="w">S_IROTH</span>|<span class="w">S_IXOTH</span><span class="cm">,</span> <span class="i">@executables</span><span class="sc">;</span></li><li>    <span class="c"># Identical to the chmod 0755 of the example above.</span></li></ol></pre><p>Portability issues: <a href="perlport.html#chmod">chmod in perlport</a>.</p>
</li>
<li><a name="chomp-VARIABLE"></a><b>chomp VARIABLE
    </b>
</li>
<li><a name="chomp(-LIST-)"></a><b>chomp( LIST )</b>
</li>
<li><a name="chomp"></a><b>chomp</b>
<p>This safer version of <a href="#chop-VARIABLE">chop</a> removes any trailing
string that corresponds to the current value of
<a href="perlvar.html#%24%2f">$/ </a> (also known as <code class="inline"><span class="i">$INPUT_RECORD_SEPARATOR</span></code>

in the <a href="English.html">English </a> module).  It returns the total
number of characters removed from all its arguments.  It's often used to
remove the newline from the end of an input record when you're worried
that the final record may be missing its newline.  When in paragraph
mode (<code class="inline"><span class="i">$/</span> = <span class="q">&#39;&#39;</span></code>
), it removes all trailing newlines from the string.
When in slurp mode (<code class="inline"><span class="i">$/</span> = <a class="l_k" href="functions/undef.html">undef</a></code>
) or fixed-length record mode
(<a href="perlvar.html#%24%2f">$/ </a> is a reference to an integer or the like;
see <a href="perlvar.html">perlvar</a>), <a href="#chomp-VARIABLE">chomp</a> won't remove anything.
If VARIABLE is omitted, it chomps <a href="perlvar.html#%24_">$_ </a>.  Example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/while.html">while</a> <span class="s">(</span>&lt;&gt;<span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/chomp.html">chomp</a><span class="sc">;</span>  <span class="c"># avoid \n on last field</span></li><li>        <a class="l_k" href="functions/my.html">my</a> <span class="i">@array</span> = <a class="l_k" href="functions/split.html">split</a><span class="s">(</span><span class="q">/:/</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="c"># ...</span></li><li>    <span class="s">}</span></li></ol></pre><p>If VARIABLE is a hash, it chomps the hash's values, but not its keys,
resetting the <a href="#each-HASH">each</a> iterator in the process.</p>
<p>You can actually chomp anything that's an lvalue, including an assignment:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/chomp.html">chomp</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$cwd</span> = <span class="q">`pwd`</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/chomp.html">chomp</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$answer</span> = <span class="q">&lt;STDIN&gt;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>If you chomp a list, each element is chomped, and the total number of
characters removed is returned.</p>
<p>Note that parentheses are necessary when you're chomping anything
that is not a simple variable.  This is because <code class="inline"><a class="l_k" href="functions/chomp.html">chomp</a> <span class="i">$cwd</span> = <span class="q">`pwd`</span><span class="sc">;</span></code>

is interpreted as <code class="inline"><span class="s">(</span><a class="l_k" href="functions/chomp.html">chomp</a> <span class="i">$cwd</span><span class="s">)</span> = <span class="q">`pwd`</span><span class="sc">;</span></code>
, rather than as
<code class="inline"><a class="l_k" href="functions/chomp.html">chomp</a><span class="s">(</span> <span class="i">$cwd</span> = <span class="q">`pwd`</span> <span class="s">)</span></code>
 which you might expect.  Similarly,
<code class="inline"><a class="l_k" href="functions/chomp.html">chomp</a> <span class="i">$a</span><span class="cm">,</span> <span class="i">$b</span></code>
 is interpreted as <code class="inline"><a class="l_k" href="functions/chomp.html">chomp</a><span class="s">(</span><span class="i">$a</span><span class="s">)</span><span class="cm">,</span> <span class="i">$b</span></code>
 rather than
as <code class="inline"><a class="l_k" href="functions/chomp.html">chomp</a><span class="s">(</span><span class="i">$a</span><span class="cm">,</span> <span class="i">$b</span><span class="s">)</span></code>
.</p>
</li>
<li><a name="chop-VARIABLE"></a><b>chop VARIABLE
</b>
</li>
<li><a name="chop(-LIST-)"></a><b>chop( LIST )</b>
</li>
<li><a name="chop"></a><b>chop</b>
<p>Chops off the last character of a string and returns the character
chopped.  It is much more efficient than <code class="inline"><a class="l_k" href="functions/s.html">s/.$//s</a></code> because it neither
scans nor copies the string.  If VARIABLE is omitted, chops
<a href="perlvar.html#%24_">$_ </a>.
If VARIABLE is a hash, it chops the hash's values, but not its keys,
resetting the <a href="#each-HASH">each</a> iterator in the process.</p>
<p>You can actually chop anything that's an lvalue, including an assignment.</p>
<p>If you chop a list, each element is chopped.  Only the value of the
last <a href="#chop-VARIABLE">chop</a> is returned.</p>
<p>Note that <a href="#chop-VARIABLE">chop</a> returns the last character.  To
return all but the last character, use <code class="inline"><a class="l_k" href="functions/substr.html">substr</a><span class="s">(</span><span class="i">$string</span><span class="cm">,</span> <span class="n">0</span><span class="cm">,</span> <span class="n">-1</span><span class="s">)</span></code>
.</p>
<p>See also <a href="#chomp-VARIABLE">chomp</a>.</p>
</li>
<li><a name="chown-LIST"></a><b>chown LIST
   </b>
<p>Changes the owner (and group) of a list of files.  The first two
elements of the list must be the <i>numeric</i> uid and gid, in that
order.  A value of -1 in either position is interpreted by most
systems to leave that value unchanged.  Returns the number of files
successfully changed.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$cnt</span> = <a class="l_k" href="functions/chown.html">chown</a> <span class="i">$uid</span><span class="cm">,</span> <span class="i">$gid</span><span class="cm">,</span> <span class="q">&#39;foo&#39;</span><span class="cm">,</span> <span class="q">&#39;bar&#39;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/chown.html">chown</a> <span class="i">$uid</span><span class="cm">,</span> <span class="i">$gid</span><span class="cm">,</span> <span class="i">@filenames</span><span class="sc">;</span></li></ol></pre><p>On systems that support <i>fchown(2)</i>, you may pass filehandles among the
files.  On systems that don't support <i>fchown(2)</i>, passing filehandles raises
an exception.  Filehandles must be passed as globs or glob references to be
recognized; barewords are considered filenames.</p>
<p>Here's an example that looks up nonnumeric uids in the passwd file:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;User: &quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/chomp.html">chomp</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$user</span> = <span class="q">&lt;STDIN&gt;</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Files: &quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/chomp.html">chomp</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$pattern</span> = <span class="q">&lt;STDIN&gt;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$login</span><span class="cm">,</span><span class="i">$pass</span><span class="cm">,</span><span class="i">$uid</span><span class="cm">,</span><span class="i">$gid</span><span class="s">)</span> = <a class="l_k" href="functions/getpwnam.html">getpwnam</a><span class="s">(</span><span class="i">$user</span><span class="s">)</span></li><li>        <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;$user not in passwd file&quot;</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@ary</span> = <a class="l_k" href="functions/glob.html">glob</a><span class="s">(</span><span class="i">$pattern</span><span class="s">)</span><span class="sc">;</span>  <span class="c"># expand filenames</span></li><li>    <a class="l_k" href="functions/chown.html">chown</a> <span class="i">$uid</span><span class="cm">,</span> <span class="i">$gid</span><span class="cm">,</span> <span class="i">@ary</span><span class="sc">;</span></li></ol></pre><p>On most systems, you are not allowed to change the ownership of the
file unless you're the superuser, although you should be able to change
the group to any of your secondary groups.  On insecure systems, these
restrictions may be relaxed, but this is not a portable assumption.
On POSIX systems, you can detect this condition this way:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">POSIX</span> <span class="q">qw(sysconf _PC_CHOWN_RESTRICTED)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$can_chown_giveaway</span> = ! <span class="i">sysconf</span><span class="s">(</span><span class="w">_PC_CHOWN_RESTRICTED</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Portability issues: <a href="perlport.html#chown">chown in perlport</a>.</p>
</li>
<li><a name="chr-NUMBER"></a><b>chr NUMBER
   </b>
</li>
<li><a name="chr"></a><b>chr</b>
<p>Returns the character represented by that NUMBER in the character set.
For example, <code class="inline"><a class="l_k" href="functions/chr.html">chr(65)</a></code> is <code class="inline"><span class="q">&quot;A&quot;</span></code>
 in either ASCII or Unicode, and
chr(0x263a) is a Unicode smiley face.</p>
<p>Negative values give the Unicode replacement character (chr(0xfffd)),
except under the <a href="bytes.html">bytes</a> pragma, where the low eight bits of the value
(truncated to an integer) are used.</p>
<p>If NUMBER is omitted, uses <a href="perlvar.html#%24_">$_ </a>.</p>
<p>For the reverse, use <a href="#ord-EXPR">ord</a>.</p>
<p>Note that characters from 128 to 255 (inclusive) are by default
internally not encoded as UTF-8 for backward compatibility reasons.</p>
<p>See <a href="perlunicode.html">perlunicode</a> for more about Unicode.</p>
</li>
<li><a name="chroot-FILENAME"></a><b>chroot FILENAME
 </b>
</li>
<li><a name="chroot"></a><b>chroot</b>
<p>This function works like the system call by the same name: it makes the
named directory the new root directory for all further pathnames that
begin with a <code class="inline">/</code> by your process and all its children.  (It doesn't
change your current working directory, which is unaffected.)  For security
reasons, this call is restricted to the superuser.  If FILENAME is
omitted, does a <a href="#chroot-FILENAME">chroot</a> to <a href="perlvar.html#%24_">$_ </a>.</p>
<p><b>NOTE:</b>  It is good security practice to do <code class="inline"><a class="l_k" href="functions/chdir.html">chdir("/")</a></code>
(<a href="#chdir-EXPR">chdir</a> to the root directory) immediately after a
<a href="#chroot-FILENAME">chroot</a>.</p>
<p>Portability issues: <a href="perlport.html#chroot">chroot in perlport</a>.</p>
</li>
<li><a name="close-FILEHANDLE"></a><b>close FILEHANDLE
</b>
</li>
<li><a name="close"></a><b>close</b>
<p>Closes the file or pipe associated with the filehandle, flushes the IO
buffers, and closes the system file descriptor.  Returns true if those
operations succeed and if no error was reported by any PerlIO
layer.  Closes the currently selected filehandle if the argument is
omitted.</p>
<p>You don't have to close FILEHANDLE if you are immediately going to do
another <a href="#open-FILEHANDLE%2cEXPR">open</a> on it, because
<a href="#open-FILEHANDLE%2cEXPR">open</a> closes it for you.  (See
<a href="#open-FILEHANDLE%2cEXPR">open</a>.) However, an explicit
<a href="#close-FILEHANDLE">close</a> on an input file resets the line counter
(<a href="perlvar.html#%24.">$. </a>), while the implicit close done by
<a href="#open-FILEHANDLE%2cEXPR">open</a> does not.</p>
<p>If the filehandle came from a piped open, <a href="#close-FILEHANDLE">close</a>
returns false if one of the other syscalls involved fails or if its
program exits with non-zero status.  If the only problem was that the
program exited non-zero, <a href="perlvar.html#%24!">$! </a> will be set to <code class="inline"><span class="n">0</span></code>
.
Closing a pipe also waits for the process executing on the pipe to
exit--in case you wish to look at the output of the pipe afterwards--and
implicitly puts the exit status value of that command into
<a href="perlvar.html#%24%3f">$? </a> and
<a href="perlvar.html#%24%7b%5eCHILD_ERROR_NATIVE%7d">${^CHILD_ERROR_NATIVE} </a>.</p>
<p>If there are multiple threads running, <a href="#close-FILEHANDLE">close</a> on
a filehandle from a piped open returns true without waiting for the
child process to terminate, if the filehandle is still open in another
thread.</p>
<p>Closing the read end of a pipe before the process writing to it at the
other end is done writing results in the writer receiving a SIGPIPE.  If
the other end can't handle that, be sure to read all the data before
closing the pipe.</p>
<p>Example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">OUTPUT</span><span class="cm">,</span> <span class="q">&#39;|sort &gt;foo&#39;</span><span class="s">)</span>  <span class="c"># pipe to sort</span></li><li>        or <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t start sort: $!&quot;</span><span class="sc">;</span></li><li>    <span class="c">#...                        # print stuff to output</span></li><li>    <a class="l_k" href="functions/close.html">close</a> <span class="w">OUTPUT</span>                <span class="c"># wait for sort to finish</span></li><li>        or <a class="l_k" href="functions/warn.html">warn</a> <span class="i">$!</span> ? <span class="q">&quot;Error closing sort pipe: $!&quot;</span></li><li>                   <span class="co">:</span> <span class="q">&quot;Exit status $? from sort&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">INPUT</span><span class="cm">,</span> <span class="q">&#39;foo&#39;</span><span class="s">)</span>          <span class="c"># get sort&#39;s results</span></li><li>        or <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open &#39;foo&#39; for input: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>FILEHANDLE may be an expression whose value can be used as an indirect
filehandle, usually the real filehandle name or an autovivified handle.</p>
</li>
<li><a name="closedir-DIRHANDLE"></a><b>closedir DIRHANDLE
</b>
<p>Closes a directory opened by <a href="#opendir-DIRHANDLE%2cEXPR">opendir</a> and
returns the success of that system call.</p>
</li>
<li><a name="connect-SOCKET%2cNAME"></a><b>connect SOCKET,NAME
</b>
<p>Attempts to connect to a remote socket, just like <i>connect(2)</i>.
Returns true if it succeeded, false otherwise.  NAME should be a
packed address of the appropriate type for the socket.  See the examples in
<a href="perlipc.html#Sockets%3a-Client%2fServer-Communication">Sockets: Client/Server Communication in perlipc</a>.</p>
</li>
<li><a name="continue-BLOCK"></a><b>continue BLOCK
</b>
</li>
<li><a name="continue"></a><b>continue</b>
<p>When followed by a BLOCK, <a href="#continue-BLOCK">continue</a> is actually a
flow control statement rather than a function.  If there is a
<a href="#continue-BLOCK">continue</a> BLOCK attached to a BLOCK (typically in a
<code class="inline">while</code>
 or <code class="inline">foreach</code>
), it is always executed just before the
conditional is about to be evaluated again, just like the third part of
a <code class="inline">for</code>
 loop in C.  Thus it can be used to increment a loop variable,
even when the loop has been continued via the <a href="#next-LABEL">next</a>
statement (which is similar to the C <a href="#continue-BLOCK">continue</a>
statement).</p>
<p><a href="#last-LABEL">last</a>, <a href="#next-LABEL">next</a>, or
<a href="#redo-LABEL">redo</a> may appear within a
<a href="#continue-BLOCK">continue</a> block; <a href="#last-LABEL">last</a> and
<a href="#redo-LABEL">redo</a> behave as if they had been executed within the
main block.  So will <a href="#next-LABEL">next</a>, but since it will execute a
<a href="#continue-BLOCK">continue</a> block, it may be more entertaining.</p>
<pre class="verbatim"><ol><li>    while <span class="s">(</span><span class="w">EXPR</span><span class="s">)</span> <span class="s">{</span></li><li>        <span class="c">### redo always comes here</span></li><li>        <span class="w">do_something</span><span class="sc">;</span></li><li>    <span class="s">}</span> <a class="l_k" href="functions/continue.html">continue</a> <span class="s">{</span></li><li>        <span class="c">### next always comes here</span></li><li>        <span class="w">do_something_else</span><span class="sc">;</span></li><li>        <span class="c"># then back the top to re-check EXPR</span></li><li>    <span class="s">}</span></li><li>    <span class="c">### last always comes here</span></li></ol></pre><p>Omitting the <a href="#continue-BLOCK">continue</a> section is equivalent to
using an empty one, logically enough, so <a href="#next-LABEL">next</a> goes
directly back to check the condition at the top of the loop.</p>
<p>When there is no BLOCK, <a href="#continue-BLOCK">continue</a> is a function
that falls through the current <code class="inline">when</code>
 or <code class="inline"><span class="w">default</span></code>
 block instead of
iterating a dynamically enclosing <code class="inline">foreach</code>
 or exiting a lexically
enclosing <code class="inline">given</code>
.  In Perl 5.14 and earlier, this form of
<a href="#continue-BLOCK">continue</a> was only available when the
<a href="feature.html#The-'switch'-feature">switch feature</a> was enabled.  See
<a href="feature.html">feature</a> and <a href="perlsyn.html#Switch-Statements">Switch Statements in perlsyn</a> for more information.</p>
</li>
<li><a name="cos-EXPR"></a><b>cos EXPR
   </b>
</li>
<li><a name="cos"></a><b>cos</b>
<p>Returns the cosine of EXPR (expressed in radians).  If EXPR is omitted,
takes the cosine of <a href="perlvar.html#%24_">$_ </a>.</p>
<p>For the inverse cosine operation, you may use the
<a href="Math/Trig.html">Math::Trig::acos </a> function, or use this relation:</p>
<pre class="verbatim"><ol><li><a name="acos"></a>    sub <span class="m">acos</span> <span class="s">{</span> <a class="l_k" href="functions/atan2.html">atan2</a><span class="s">(</span> <a class="l_k" href="functions/sqrt.html">sqrt</a><span class="s">(</span><span class="n">1</span> - <span class="i">$_</span>[<span class="n">0</span>] * <span class="i">$_</span>[<span class="n">0</span>]<span class="s">)</span><span class="cm">,</span> <span class="i">$_</span>[<span class="n">0</span>] <span class="s">)</span> <span class="s">}</span></li></ol></pre></li>
<li><a name="crypt-PLAINTEXT%2cSALT"></a><b>crypt PLAINTEXT,SALT
     
   </b>
<p>Creates a digest string exactly like the <i>crypt(3)</i> function in the C
library (assuming that you actually have a version there that has not
been extirpated as a potential munition).</p>
<p><a href="#crypt-PLAINTEXT%2cSALT">crypt</a> is a one-way hash function.  The
PLAINTEXT and SALT are turned
into a short string, called a digest, which is returned.  The same
PLAINTEXT and SALT will always return the same string, but there is no
(known) way to get the original PLAINTEXT from the hash.  Small
changes in the PLAINTEXT or SALT will result in large changes in the
digest.</p>
<p>There is no decrypt function.  This function isn't all that useful for
cryptography (for that, look for <i>Crypt</i> modules on your nearby CPAN
mirror) and the name "crypt" is a bit of a misnomer.  Instead it is
primarily used to check if two pieces of text are the same without
having to transmit or store the text itself.  An example is checking
if a correct password is given.  The digest of the password is stored,
not the password itself.  The user types in a password that is
<a href="#crypt-PLAINTEXT%2cSALT">crypt</a>'d with the same salt as the stored
digest.  If the two digests match, the password is correct.</p>
<p>When verifying an existing digest string you should use the digest as
the salt (like <code class="inline"><a class="l_k" href="functions/crypt.html">crypt</a><span class="s">(</span><span class="i">$plain</span><span class="cm">,</span> <span class="i">$digest</span><span class="s">)</span> eq <span class="i">$digest</span></code>
).  The SALT used
to create the digest is visible as part of the digest.  This ensures
<a href="#crypt-PLAINTEXT%2cSALT">crypt</a> will hash the new string with the same
salt as the digest.  This allows your code to work with the standard
<a href="#crypt-PLAINTEXT%2cSALT">crypt</a> and with more exotic implementations.
In other words, assume nothing about the returned string itself nor
about how many bytes of SALT may matter.</p>
<p>Traditionally the result is a string of 13 bytes: two first bytes of
the salt, followed by 11 bytes from the set <code class="inline">[./0-9A-Za-z]</code>, and only
the first eight bytes of PLAINTEXT mattered.  But alternative
hashing schemes (like MD5), higher level security schemes (like C2),
and implementations on non-Unix platforms may produce different
strings.</p>
<p>When choosing a new salt create a random two character string whose
characters come from the set <code class="inline">[./0-9A-Za-z]</code> (like <code class="inline"><a class="l_k" href="functions/join.html">join</a> <span class="q">&#39;&#39;</span><span class="cm">,</span> <span class="s">(</span><span class="q">&#39;.&#39;</span><span class="cm">,</span>
<span class="q">&#39;/&#39;</span><span class="cm">,</span> <span class="n">0</span>..<span class="n">9</span><span class="cm">,</span> <span class="q">&#39;A&#39;</span>..<span class="q">&#39;Z&#39;</span><span class="cm">,</span> <span class="q">&#39;a&#39;</span>..<span class="q">&#39;z&#39;</span><span class="s">)</span>[<a class="l_k" href="functions/rand.html">rand</a> <span class="n">64</span><span class="cm">,</span> <a class="l_k" href="functions/rand.html">rand</a> <span class="n">64</span>]</code>
).  This set of
characters is just a recommendation; the characters allowed in
the salt depend solely on your system's crypt library, and Perl can't
restrict what salts <a href="#crypt-PLAINTEXT%2cSALT">crypt</a> accepts.</p>
<p>Here's an example that makes sure that whoever runs this program knows
their password:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$pwd</span> = <span class="s">(</span><a class="l_k" href="functions/getpwuid.html">getpwuid</a><span class="s">(</span><span class="i">$&lt;</span><span class="s">)</span><span class="s">)</span>[<span class="n">1</span>]<span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/system.html">system</a> <span class="q">&quot;stty -echo&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Password: &quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/chomp.html">chomp</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$word</span> = <span class="q">&lt;STDIN&gt;</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;\n&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/system.html">system</a> <span class="q">&quot;stty echo&quot;</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span><a class="l_k" href="functions/crypt.html">crypt</a><span class="s">(</span><span class="i">$word</span><span class="cm">,</span> <span class="i">$pwd</span><span class="s">)</span> <a class="l_k" href="functions/ne.html">ne</a> <span class="i">$pwd</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Sorry...\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span> <a class="l_k" href="functions/else.html">else</a> <span class="s">{</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;ok\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>Of course, typing in your own password to whoever asks you
for it is unwise.</p>
<p>The <a href="#crypt-PLAINTEXT%2cSALT">crypt</a> function is unsuitable for hashing
large quantities of data, not least of all because you can't get the
information back.  Look at the <a href="Digest.html">Digest</a> module for more robust
algorithms.</p>
<p>If using <a href="#crypt-PLAINTEXT%2cSALT">crypt</a> on a Unicode string (which
<i>potentially</i> has characters with codepoints above 255), Perl tries to
make sense of the situation by trying to downgrade (a copy of) the
string back to an eight-bit byte string before calling
<a href="#crypt-PLAINTEXT%2cSALT">crypt</a> (on that copy).  If that works, good.
If not, <a href="#crypt-PLAINTEXT%2cSALT">crypt</a> dies with
<a href="perldiag.html#Wide-character-in-%25s">Wide character in crypt </a>.</p>
<p>Portability issues: <a href="perlport.html#crypt">crypt in perlport</a>.</p>
</li>
<li><a name="dbmclose-HASH"></a><b>dbmclose HASH
</b>
<p>[This function has been largely superseded by the
<a href="#untie-VARIABLE">untie</a> function.]</p>
<p>Breaks the binding between a DBM file and a hash.</p>
<p>Portability issues: <a href="perlport.html#dbmclose">dbmclose in perlport</a>.</p>
</li>
<li><a name="dbmopen-HASH%2cDBNAME%2cMASK"></a><b>dbmopen HASH,DBNAME,MASK
    </b>
<p>[This function has been largely superseded by the
<a href="#tie-VARIABLE%2cCLASSNAME%2cLIST">tie</a> function.]</p>
<p>This binds a <i>dbm(3)</i>, <i>ndbm(3)</i>, <i>sdbm(3)</i>, <i>gdbm(3)</i>, or Berkeley
DB file to a hash.  HASH is the name of the hash.  (Unlike normal
<a href="#open-FILEHANDLE%2cEXPR">open</a>, the first argument is <i>not</i> a
filehandle, even though it looks like one).  DBNAME is the name of the
database (without the <i>.dir</i> or <i>.pag</i> extension if any).  If the
database does not exist, it is created with protection specified by MASK
(as modified by the <a href="#umask-EXPR">umask</a>).  To prevent creation of
the database if it doesn't exist, you may specify a MODE of 0, and the
function will return a false value if it can't find an existing
database.  If your system supports only the older DBM functions, you may
make only one <a href="#dbmopen-HASH%2cDBNAME%2cMASK">dbmopen</a> call in your
program.  In older versions of Perl, if your system had neither DBM nor
ndbm, calling <a href="#dbmopen-HASH%2cDBNAME%2cMASK">dbmopen</a> produced a fatal
error; it now falls back to <i>sdbm(3)</i>.</p>
<p>If you don't have write access to the DBM file, you can only read hash
variables, not set them.  If you want to test whether you can write,
either use file tests or try setting a dummy hash entry inside an
<a href="#eval-EXPR">eval</a> to trap the error.</p>
<p>Note that functions such as <a href="#keys-HASH">keys</a> and
<a href="#values-HASH">values</a> may return huge lists when used on large DBM
files.  You may prefer to use the <a href="#each-HASH">each</a> function to
iterate over large DBM files.  Example:</p>
<pre class="verbatim"><ol><li>    <span class="c"># print out history file offsets</span></li><li>    <a class="l_k" href="functions/dbmopen.html">dbmopen</a><span class="s">(</span><span class="i">%HIST</span><span class="cm">,</span><span class="q">&#39;/usr/lib/news/history&#39;</span><span class="cm">,</span><span class="n">0666</span><span class="s">)</span><span class="sc">;</span></li><li>    while <span class="s">(</span><span class="s">(</span><span class="i">$key</span><span class="cm">,</span><span class="i">$val</span><span class="s">)</span> = <a class="l_k" href="functions/each.html">each</a> <span class="i">%HIST</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="i">$key</span><span class="cm">,</span> <span class="q">&#39; = &#39;</span><span class="cm">,</span> <a class="l_k" href="functions/unpack.html">unpack</a><span class="s">(</span><span class="q">&#39;L&#39;</span><span class="cm">,</span><span class="i">$val</span><span class="s">)</span><span class="cm">,</span> <span class="q">&quot;\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li><li>    <a class="l_k" href="functions/dbmclose.html">dbmclose</a><span class="s">(</span><span class="i">%HIST</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>See also <a href="AnyDBM_File.html">AnyDBM_File</a> for a more general description of the pros and
cons of the various dbm approaches, as well as <a href="DB_File.html">DB_File</a> for a particularly
rich implementation.</p>
<p>You can control which DBM library you use by loading that library
before you call <a href="#dbmopen-HASH%2cDBNAME%2cMASK">dbmopen</a>:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">DB_File</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/dbmopen.html">dbmopen</a><span class="s">(</span><span class="i">%NS_Hist</span><span class="cm">,</span> <span class="q">&quot;$ENV{HOME}/.netscape/history.db&quot;</span><span class="s">)</span></li><li>        or <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open netscape history file: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>Portability issues: <a href="perlport.html#dbmopen">dbmopen in perlport</a>.</p>
</li>
<li><a name="defined-EXPR"></a><b>defined EXPR
  </b>
</li>
<li><a name="defined"></a><b>defined</b>
<p>Returns a Boolean value telling whether EXPR has a value other than the
undefined value <a href="#undef-EXPR">undef</a>.  If EXPR is not present,
<a href="perlvar.html#%24_">$_ </a> is checked.</p>
<p>Many operations return <a href="#undef-EXPR">undef</a> to indicate failure, end
of file, system error, uninitialized variable, and other exceptional
conditions.  This function allows you to distinguish
<a href="#undef-EXPR">undef</a> from other values.  (A simple Boolean test will
not distinguish among <a href="#undef-EXPR">undef</a>, zero, the empty string,
and <code class="inline"><span class="q">&quot;0&quot;</span></code>
, which are all equally false.)  Note that since
<a href="#undef-EXPR">undef</a> is a valid scalar, its presence doesn't
<i>necessarily</i> indicate an exceptional condition: <a href="#pop-ARRAY">pop</a>
returns <a href="#undef-EXPR">undef</a> when its argument is an empty array,
<i>or</i> when the element to return happens to be <a href="#undef-EXPR">undef</a>.</p>
<p>You may also use <code class="inline"><a class="l_k" href="functions/defined.html">defined(&func)</a></code> to check whether subroutine <code class="inline"><span class="w">func</span></code>

has ever been defined.  The return value is unaffected by any forward
declarations of <code class="inline"><span class="w">func</span></code>
.  A subroutine that is not defined
may still be callable: its package may have an <code class="inline">AUTOLOAD</code>
 method that
makes it spring into existence the first time that it is called; see
<a href="perlsub.html">perlsub</a>.</p>
<p>Use of <a href="#defined-EXPR">defined</a> on aggregates (hashes and arrays) is
no longer supported. It used to report whether memory for that
aggregate had ever been allocated.  You should instead use a simple
test for size:</p>
<pre class="verbatim"><ol><li>    if <span class="s">(</span><span class="i">@an_array</span><span class="s">)</span> <span class="s">{</span> <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;has array elements\n&quot;</span> <span class="s">}</span></li><li>    if <span class="s">(</span><span class="i">%a_hash</span><span class="s">)</span>   <span class="s">{</span> <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;has hash members\n&quot;</span>   <span class="s">}</span></li></ol></pre><p>When used on a hash element, it tells you whether the value is defined,
not whether the key exists in the hash.  Use <a href="#exists-EXPR">exists</a>
for the latter purpose.</p>
<p>Examples:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <a class="l_k" href="functions/if.html">if</a> <a class="l_k" href="functions/defined.html">defined</a> <span class="i">$switch</span>{<span class="w">D</span>}<span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;$val\n&quot;</span> <a class="l_k" href="functions/while.html">while</a> <a class="l_k" href="functions/defined.html">defined</a><span class="s">(</span><span class="i">$val</span> = <a class="l_k" href="functions/pop.html">pop</a><span class="s">(</span><span class="i">@ary</span><span class="s">)</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t readlink $sym: $!&quot;</span></li><li>        <a class="l_k" href="functions/unless.html">unless</a> <a class="l_k" href="functions/defined.html">defined</a><span class="s">(</span><span class="i">$value</span> = <a class="l_k" href="functions/readlink.html">readlink</a> <span class="i">$sym</span><span class="s">)</span><span class="sc">;</span></li><li><a name="foo"></a>    sub <span class="m">foo</span> <span class="s">{</span> <a class="l_k" href="functions/defined.html">defined</a> <span class="i">&amp;$bar</span> ? <span class="i">$bar</span>-&gt;<span class="s">(</span><span class="i">@_</span><span class="s">)</span> <span class="co">:</span> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;No bar&quot;</span><span class="sc">;</span> <span class="s">}</span></li><li>    <span class="i">$debugging</span> = <span class="n">0</span> <a class="l_k" href="functions/unless.html">unless</a> <a class="l_k" href="functions/defined.html">defined</a> <span class="i">$debugging</span><span class="sc">;</span></li></ol></pre><p>Note:  Many folks tend to overuse <a href="#defined-EXPR">defined</a> and are
then surprised to discover that the number <code class="inline"><span class="n">0</span></code>
 and <code class="inline"><span class="q">&quot;&quot;</span></code>
 (the
zero-length string) are, in fact, defined values.  For example, if you
say</p>
<pre class="verbatim"><ol><li>    <span class="q">&quot;ab&quot;</span> =~ <span class="q">/a(.*)b/</span><span class="sc">;</span></li></ol></pre><p>The pattern match succeeds and <code class="inline"><span class="i">$1</span></code>
 is defined, although it
matched "nothing".  It didn't really fail to match anything.  Rather, it
matched something that happened to be zero characters long.  This is all
very above-board and honest.  When a function returns an undefined value,
it's an admission that it couldn't give you an honest answer.  So you
should use <a href="#defined-EXPR">defined</a> only when questioning the
integrity of what you're trying to do.  At other times, a simple
comparison to <code class="inline"><span class="n">0</span></code>
 or <code class="inline"><span class="q">&quot;&quot;</span></code>
 is what you want.</p>
<p>See also <a href="#undef-EXPR">undef</a>, <a href="#exists-EXPR">exists</a>,
<a href="#ref-EXPR">ref</a>.</p>
</li>
<li><a name="delete-EXPR"></a><b>delete EXPR
</b>
<p>Given an expression that specifies an element or slice of a hash,
<a href="#delete-EXPR">delete</a> deletes the specified elements from that hash
so that <a href="#exists-EXPR">exists</a> on that element no longer returns
true.  Setting a hash element to the undefined value does not remove its
key, but deleting it does; see <a href="#exists-EXPR">exists</a>.</p>
<p>In list context, returns the value or values deleted, or the last such
element in scalar context.  The return list's length always matches that of
the argument list: deleting non-existent elements returns the undefined value
in their corresponding positions.</p>
<p><a href="#delete-EXPR">delete</a> may also be used on arrays and array slices,
but its behavior is less straightforward.  Although
<a href="#exists-EXPR">exists</a> will return false for deleted entries,
deleting array elements never changes indices of existing values; use
<a href="#shift-ARRAY">shift</a> or <a href="#splice-ARRAY%2cOFFSET%2cLENGTH%2cLIST">splice</a> for that.  However, if any deleted elements
fall at the end of an array, the array's size shrinks to the position of
the highest element that still tests true for <a href="#exists-EXPR">exists</a>,
or to 0 if none do.  In other words, an array won't have trailing
nonexistent elements after a delete.</p>
<p><b>WARNING:</b> Calling <a href="#delete-EXPR">delete</a> on array values is
strongly discouraged.  The
notion of deleting or checking the existence of Perl array elements is not
conceptually coherent, and can lead to surprising behavior.</p>
<p>Deleting from <a href="perlvar.html#%25ENV">%ENV </a> modifies the environment.
Deleting from a hash tied to a DBM file deletes the entry from the DBM
file.  Deleting from a <a href="#tied-VARIABLE">tied</a> hash or array may not
necessarily return anything; it depends on the implementation of the
<a href="#tied-VARIABLE">tied</a> package's DELETE method, which may do whatever
it pleases.</p>
<p>The <code class="inline"><a class="l_k" href="functions/delete.html">delete</a> <a class="l_k" href="functions/local.html">local</a> <span class="w">EXPR</span></code>
 construct localizes the deletion to the current
block at run time.  Until the block exits, elements locally deleted
temporarily no longer exist.  See <a href="perlsub.html#Localized-deletion-of-elements-of-composite-types">Localized deletion of elements of composite types in perlsub</a>.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">%hash</span> = <span class="s">(</span><span class="w">foo</span> <span class="cm">=&gt;</span> <span class="n">11</span><span class="cm">,</span> <span class="w">bar</span> <span class="cm">=&gt;</span> <span class="n">22</span><span class="cm">,</span> <span class="w">baz</span> <span class="cm">=&gt;</span> <span class="n">33</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$scalar</span> = <a class="l_k" href="functions/delete.html">delete</a> <span class="i">$hash</span>{<span class="w">foo</span>}<span class="sc">;</span>         <span class="c"># $scalar is 11</span></li><li>    <span class="i">$scalar</span> = <a class="l_k" href="functions/delete.html">delete</a> <span class="i">@hash</span>{<span class="q">qw(foo bar)</span>}<span class="sc">;</span> <span class="c"># $scalar is 22</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@array</span>  = <a class="l_k" href="functions/delete.html">delete</a> <span class="i">@hash</span>{<span class="q">qw(foo baz)</span>}<span class="sc">;</span> <span class="c"># @array  is (undef,33)</span></li></ol></pre><p>The following (inefficiently) deletes all the values of %HASH and @ARRAY:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/foreach.html">foreach</a> <a class="l_k" href="functions/my.html">my</a> <span class="i">$key</span> <span class="s">(</span><a class="l_k" href="functions/keys.html">keys</a> <span class="i">%HASH</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/delete.html">delete</a> <span class="i">$HASH</span>{<span class="i">$key</span>}<span class="sc">;</span></li><li>    <span class="s">}</span></li><li></li><li>    <a class="l_k" href="functions/foreach.html">foreach</a> <a class="l_k" href="functions/my.html">my</a> <span class="i">$index</span> <span class="s">(</span><span class="n">0</span> .. <span class="i">$#ARRAY</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/delete.html">delete</a> <span class="i">$ARRAY</span>[<span class="i">$index</span>]<span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>And so do these:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/delete.html">delete</a> <span class="i">@HASH</span>{<a class="l_k" href="functions/keys.html">keys</a> <span class="i">%HASH</span>}<span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/delete.html">delete</a> <span class="i">@ARRAY</span>[<span class="n">0</span> .. <span class="i">$#ARRAY</span>]<span class="sc">;</span></li></ol></pre><p>But both are slower than assigning the empty list
or undefining %HASH or @ARRAY, which is the customary
way to empty out an aggregate:</p>
<pre class="verbatim"><ol><li>    <span class="i">%HASH</span> = <span class="s">(</span><span class="s">)</span><span class="sc">;</span>     <span class="c"># completely empty %HASH</span></li><li>    <a class="l_k" href="functions/undef.html">undef</a> <span class="i">%HASH</span><span class="sc">;</span>    <span class="c"># forget %HASH ever existed</span></li><li></li><li>    <span class="i">@ARRAY</span> = <span class="s">(</span><span class="s">)</span><span class="sc">;</span>    <span class="c"># completely empty @ARRAY</span></li><li>    <a class="l_k" href="functions/undef.html">undef</a> <span class="i">@ARRAY</span><span class="sc">;</span>   <span class="c"># forget @ARRAY ever existed</span></li></ol></pre><p>The EXPR can be arbitrarily complicated provided its
final operation is an element or slice of an aggregate:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/delete.html">delete</a> <span class="i">$ref</span>-&gt;[<span class="i">$x</span>][<span class="i">$y</span>]{<span class="i">$key</span>}<span class="sc">;</span></li><li>    <a class="l_k" href="functions/delete.html">delete</a> <span class="i">@</span>{<span class="i">$ref</span>-&gt;[<span class="i">$x</span>][<span class="i">$y</span>]}{<span class="i">$key1</span><span class="cm">,</span> <span class="i">$key2</span><span class="cm">,</span> <span class="i">@morekeys</span>}<span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/delete.html">delete</a> <span class="i">$ref</span>-&gt;[<span class="i">$x</span>][<span class="i">$y</span>][<span class="i">$index</span>]<span class="sc">;</span></li><li>    <a class="l_k" href="functions/delete.html">delete</a> <span class="i">@</span>{<span class="i">$ref</span>-&gt;[<span class="i">$x</span>][<span class="i">$y</span>]}[<span class="i">$index1</span><span class="cm">,</span> <span class="i">$index2</span><span class="cm">,</span> <span class="i">@moreindices</span>]<span class="sc">;</span></li></ol></pre></li>
<li><a name="die-LIST"></a><b>die LIST
     </b>
<p><a href="#die-LIST">die</a> raises an exception.  Inside an
<a href="#eval-EXPR">eval</a> the error message is stuffed into
<a href="perlvar.html#%24%40">$@ </a> and the <a href="#eval-EXPR">eval</a> is terminated with the
undefined value.  If the exception is outside of all enclosing
<a href="#eval-EXPR">eval</a>s, then the uncaught exception prints LIST to
<code class="inline"><span class="w">STDERR</span></code>
 and exits with a non-zero value.  If you need to exit the
process with a specific exit code, see <a href="#exit-EXPR">exit</a>.</p>
<p>Equivalent examples:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t cd to spool: $!\n&quot;</span> unless <a class="l_k" href="functions/chdir.html">chdir</a> <span class="q">&#39;/usr/spool/news&#39;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/chdir.html">chdir</a> <span class="q">&#39;/usr/spool/news&#39;</span> or <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t cd to spool: $!\n&quot;</span></li></ol></pre><p>If the last element of LIST does not end in a newline, the current
script line number and input line number (if any) are also printed,
and a newline is supplied.  Note that the "input line number" (also
known as "chunk") is subject to whatever notion of "line" happens to
be currently in effect, and is also available as the special variable
<a href="perlvar.html#%24.">$. </a>.  See <a href="perlvar.html#%24%2f">$/ in perlvar</a> and <a href="perlvar.html#%24.">$. in perlvar</a>.</p>
<p>Hint: sometimes appending <code class="inline"><span class="q">&quot;, stopped&quot;</span></code>
 to your message will cause it
to make better sense when the string <code class="inline"><span class="q">&quot;at foo line 123&quot;</span></code>
 is appended.
Suppose you are running script "canasta".</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;/etc/games is no good&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;/etc/games is no good, stopped&quot;</span><span class="sc">;</span></li></ol></pre><p>produce, respectively</p>
<pre class="verbatim"><ol><li>    /etc/games is no good at canasta line 123.</li><li>    /etc/games is no good, stopped at canasta line 123.</li></ol></pre><p>If the output is empty and <a href="perlvar.html#%24%40">$@ </a> already contains a value
(typically from a previous <a href="#eval-EXPR">eval</a>) that value is reused after
appending <code class="inline"><span class="q">&quot;\t...propagated&quot;</span></code>
.  This is useful for propagating exceptions:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span> ... <span class="s">}</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/die.html">die</a> unless <span class="i">$@</span> =~ <span class="q">/Expected exception/</span><span class="sc">;</span></li></ol></pre><p>If the output is empty and <a href="perlvar.html#%24%40">$@ </a> contains an object
reference that has a <code class="inline"><span class="w">PROPAGATE</span></code>
 method, that method will be called
with additional file and line number parameters.  The return value
replaces the value in <a href="perlvar.html#%24%40">$@ </a>;  i.e., as if
<code class="inline"><span class="i">$@</span> = <a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span> <span class="i">$@</span><span class="i">-&gt;PROPAGATE</span><span class="s">(</span><span class="w">__FILE__</span><span class="cm">,</span> <span class="w">__LINE__</span><span class="s">)</span> <span class="s">}</span><span class="sc">;</span></code>
 were called.</p>
<p>If <a href="perlvar.html#%24%40">$@ </a> is empty, then the string <code class="inline"><span class="q">&quot;Died&quot;</span></code>
 is used.</p>
<p>If an uncaught exception results in interpreter exit, the exit code is
determined from the values of <a href="perlvar.html#%24!">$! </a> and
<a href="perlvar.html#%24%3f">$? </a> with this pseudocode:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/exit.html">exit</a> <span class="i">$!</span> if <span class="i">$!</span><span class="sc">;</span>              <span class="c"># errno</span></li><li>    <a class="l_k" href="functions/exit.html">exit</a> <span class="i">$?</span> &gt;&gt; <span class="n">8</span> if <span class="i">$?</span> &gt;&gt; <span class="n">8</span><span class="sc">;</span>    <span class="c"># child exit status</span></li><li>    <a class="l_k" href="functions/exit.html">exit</a> <span class="n">255</span><span class="sc">;</span>                   <span class="c"># last resort</span></li></ol></pre><p>As with <a href="#exit-EXPR">exit</a>, <a href="perlvar.html#%24%3f">$? </a> is set prior to
unwinding the call stack; any <code class="inline">DESTROY</code>
 or <code class="inline">END</code>
 handlers can then
alter this value, and thus Perl's exit code.</p>
<p>The intent is to squeeze as much possible information about the likely cause
into the limited space of the system exit code.  However, as
<a href="perlvar.html#%24!">$! </a> is the value of C's <code class="inline"><span class="w">errno</span></code>
, which can be set by
any system call, this means that the value of the exit code used by
<a href="#die-LIST">die</a> can be non-predictable, so should not be relied
upon, other than to be non-zero.</p>
<p>You can also call <a href="#die-LIST">die</a> with a reference argument, and if
this is trapped within an <a href="#eval-EXPR">eval</a>, <a href="perlvar.html#%24%40">$@ </a>
contains that reference.  This permits more elaborate exception handling
using objects that maintain arbitrary state about the exception.  Such a
scheme is sometimes preferable to matching particular string values of
<a href="perlvar.html#%24%40">$@ </a> with regular expressions.  Because
<a href="perlvar.html#%24%40">$@ </a> is a global variable and <a href="#eval-EXPR">eval</a> may
be used within object implementations, be careful that analyzing the
error object doesn't replace the reference in the global variable.  It's
easiest to make a local copy of the reference before any manipulations.
Here's an example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Scalar::Util</span> <span class="q">&quot;blessed&quot;</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span> ... <span class="sc">;</span> <a class="l_k" href="functions/die.html">die</a> <span class="w">Some::Module::Exception</span><span class="w">-&gt;new</span><span class="s">(</span> <span class="w">FOO</span> <span class="cm">=&gt;</span> <span class="q">&quot;bar&quot;</span> <span class="s">)</span> <span class="s">}</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$ev_err</span> = <span class="i">$@</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span><span class="i">blessed</span><span class="s">(</span><span class="i">$ev_err</span><span class="s">)</span></li><li>            &amp;&amp; <span class="i">$ev_err</span><span class="i">-&gt;isa</span><span class="s">(</span><span class="q">&quot;Some::Module::Exception&quot;</span><span class="s">)</span><span class="s">)</span> <span class="s">{</span></li><li>            <span class="c"># handle Some::Module::Exception</span></li><li>        <span class="s">}</span></li><li>        <a class="l_k" href="functions/else.html">else</a> <span class="s">{</span></li><li>            <span class="c"># handle all other possible exceptions</span></li><li>        <span class="s">}</span></li><li>    <span class="s">}</span></li></ol></pre><p>Because Perl stringifies uncaught exception messages before display,
you'll probably want to overload stringification operations on
exception objects.  See <a href="overload.html">overload</a> for details about that.</p>
<p>You can arrange for a callback to be run just before the
<a href="#die-LIST">die</a> does its deed, by setting the
<a href="perlvar.html#%25SIG">$SIG{__DIE__} </a> hook.  The associated handler is called
with the error text and can change the error message, if it sees fit, by
calling <a href="#die-LIST">die</a> again.  See <a href="perlvar.html#%25SIG">%SIG in perlvar</a> for details on
setting <a href="perlvar.html#%25SIG">%SIG </a> entries, and <a href="#eval-EXPR">eval</a> for some
examples.  Although this feature was to be run only right before your
program was to exit, this is not currently so: the
<a href="perlvar.html#%25SIG">$SIG{__DIE__} </a> hook is currently called even inside
<a href="#eval-EXPR">eval</a>ed blocks/strings!  If one wants the hook to do
nothing in such situations, put</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/die.html">die</a> <span class="i">@_</span> if <span class="i">$^S</span><span class="sc">;</span></li></ol></pre><p>as the first line of the handler (see <a href="perlvar.html#%24%5eS">$^S in perlvar</a>).  Because
this promotes strange action at a distance, this counterintuitive
behavior may be fixed in a future release.</p>
<p>See also <a href="#exit-EXPR">exit</a>, <a href="#warn-LIST">warn</a>, and the <a href="Carp.html">Carp</a>
module.</p>
</li>
<li><a name="do-BLOCK"></a><b>do BLOCK
 </b>
<p>Not really a function.  Returns the value of the last command in the
sequence of commands indicated by BLOCK.  When modified by the <code class="inline">while</code>
 or
<code class="inline">until</code>
 loop modifier, executes the BLOCK once before testing the loop
condition.  (On other statements the loop modifiers test the conditional
first.)</p>
<p><code class="inline"><a class="l_k" href="functions/do.html">do</a> <span class="w">BLOCK</span></code>
 does <i>not</i> count as a loop, so the loop control statements
<a href="#next-LABEL">next</a>, <a href="#last-LABEL">last</a>, or
<a href="#redo-LABEL">redo</a> cannot be used to leave or restart the block.
See <a href="perlsyn.html">perlsyn</a> for alternative strategies.</p>
</li>
<li><a name="do-EXPR"></a><b>do EXPR
</b>
<p>Uses the value of EXPR as a filename and executes the contents of the
file as a Perl script:</p>
<pre class="verbatim"><ol><li>    <span class="c"># load the exact specified file (./ and ../ special-cased)</span></li><li>    <a class="l_k" href="functions/do.html">do</a> <span class="q">&#39;/foo/stat.pl&#39;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/do.html">do</a> <span class="q">&#39;./stat.pl&#39;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/do.html">do</a> <span class="q">&#39;../foo/stat.pl&#39;</span><span class="sc">;</span></li><li></li><li>    <span class="c"># search for the named file within @INC</span></li><li>    <a class="l_k" href="functions/do.html">do</a> <span class="q">&#39;stat.pl&#39;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/do.html">do</a> <span class="q">&#39;foo/stat.pl&#39;</span><span class="sc">;</span></li></ol></pre><p><code class="inline"><a class="l_k" href="functions/do.html">do</a> <span class="q">&#39;./stat.pl&#39;</span></code>
 is largely like</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="q">`cat stat.pl`</span><span class="sc">;</span></li></ol></pre><p>except that it's more concise, runs no external processes, and keeps
track of the current filename for error messages. It also differs in that
code evaluated with <code class="inline"><a class="l_k" href="functions/do.html">do</a> <span class="w">FILE</span></code>
 cannot see lexicals in the enclosing
scope; <code class="inline"><a class="l_k" href="functions/eval.html">eval</a> <span class="w">STRING</span></code>
 does.  It's the same, however, in that it does
reparse the file every time you call it, so you probably don't want
to do this inside a loop.</p>
<p>Using <code class="inline"><a class="l_k" href="functions/do.html">do</a></code> with a relative path (except for <i>./</i> and <i>../</i>), like</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/do.html">do</a> <span class="q">&#39;foo/stat.pl&#39;</span><span class="sc">;</span></li></ol></pre><p>will search the <a href="perlvar.html#%40INC">@INC </a> directories, and update
<a href="perlvar.html#%25INC">%INC </a> if the file is found.  See <a href="perlvar.html#%40INC">@INC in perlvar</a>
and <a href="perlvar.html#%25INC">%INC in perlvar</a> for these variables. In particular, note that
whilst historically <a href="perlvar.html#%40INC">@INC </a> contained '.' (the
current directory) making these two cases equivalent, that is no
longer necessarily the case, as '.' is not included in <code class="inline"><span class="i">@INC</span></code>
 by default
in perl versions 5.26.0 onwards. Instead, perl will now warn:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/do.html">do</a> <span class="q">&quot;stat.pl&quot;</span> <span class="w">failed</span><span class="cm">,</span> <span class="q">&#39;.&#39;</span> <span class="w">is</span> <a class="l_k" href="functions/no.html">no</a> <span class="w">longer</span> <span class="w">in</span> <span class="i">@INC</span><span class="sc">;</span></li><li>    <span class="w">did</span> <span class="w">you</span> <span class="w">mean</span> <a class="l_k" href="functions/do.html">do</a> <span class="q">&quot;./stat.pl&quot;</span>?</li></ol></pre><p>If <a href="#do-EXPR">do</a> can read the file but cannot compile it, it
returns <a href="#undef-EXPR">undef</a> and sets an error message in
<a href="perlvar.html#%24%40">$@ </a>.  If <a href="#do-EXPR">do</a> cannot read the file, it
returns undef and sets <a href="perlvar.html#%24!">$! </a> to the error.  Always check
<a href="perlvar.html#%24%40">$@ </a> first, as compilation could fail in a way that also
sets <a href="perlvar.html#%24!">$! </a>.  If the file is successfully compiled,
<a href="#do-EXPR">do</a> returns the value of the last expression evaluated.</p>
<p>Inclusion of library modules is better done with the
<a href="#use-Module-VERSION-LIST">use</a> and <a href="#require-VERSION">require</a>
operators, which also do automatic error checking and raise an exception
if there's a problem.</p>
<p>You might like to use <a href="#do-EXPR">do</a> to read in a program
configuration file.  Manual error checking can be done this way:</p>
<pre class="verbatim"><ol><li>    <span class="c"># Read in config files: system first, then user.</span></li><li>    <span class="c"># Beware of using relative pathnames here.</span></li><li>    <a class="l_k" href="functions/for.html">for</a> <span class="i">$file</span> <span class="s">(</span><span class="q">&quot;/share/prog/defaults.rc&quot;</span><span class="cm">,</span></li><li>               <span class="q">&quot;$ENV{HOME}/.someprogrc&quot;</span><span class="s">)</span></li><li>    <span class="s">{</span></li><li>        <a class="l_k" href="functions/unless.html">unless</a> <span class="s">(</span><span class="i">$return</span> = <a class="l_k" href="functions/do.html">do</a> <span class="i">$file</span><span class="s">)</span> <span class="s">{</span></li><li>            <a class="l_k" href="functions/warn.html">warn</a> <span class="q">&quot;couldn&#39;t parse $file: $@&quot;</span> <a class="l_k" href="functions/if.html">if</a> <span class="i">$@</span><span class="sc">;</span></li><li>            <a class="l_k" href="functions/warn.html">warn</a> <span class="q">&quot;couldn&#39;t do $file: $!&quot;</span>    <a class="l_k" href="functions/unless.html">unless</a> <a class="l_k" href="functions/defined.html">defined</a> <span class="i">$return</span><span class="sc">;</span></li><li>            <a class="l_k" href="functions/warn.html">warn</a> <span class="q">&quot;couldn&#39;t run $file&quot;</span>       <a class="l_k" href="functions/unless.html">unless</a> <span class="i">$return</span><span class="sc">;</span></li><li>        <span class="s">}</span></li><li>    <span class="s">}</span></li></ol></pre></li>
<li><a name="dump-LABEL"></a><b>dump LABEL
  </b>
</li>
<li><a name="dump-EXPR"></a><b>dump EXPR</b>
</li>
<li><a name="dump"></a><b>dump</b>
<p>This function causes an immediate core dump.  See also the <b>-u</b>
command-line switch in <a href="perlrun.html">perlrun</a>, which does the same thing.
Primarily this is so that you can use the <b>undump</b> program (not
supplied) to turn your core dump into an executable binary after
having initialized all your variables at the beginning of the
program.  When the new binary is executed it will begin by executing
a <code class="inline"><a class="l_k" href="functions/goto.html">goto</a> <span class="j">LABEL</span></code>
 (with all the restrictions that <a href="#goto-LABEL">goto</a>
suffers).
Think of it as a goto with an intervening core dump and reincarnation.
If <code class="inline"><span class="w">LABEL</span></code>
 is omitted, restarts the program from the top.  The
<code class="inline"><a class="l_k" href="functions/dump.html">dump</a> <span class="w">EXPR</span></code>
 form, available starting in Perl 5.18.0, allows a name to be
computed at run time, being otherwise identical to <code class="inline"><a class="l_k" href="functions/dump.html">dump</a> <span class="w">LABEL</span></code>
.</p>
<p><b>WARNING</b>: Any files opened at the time of the dump will <i>not</i>
be open any more when the program is reincarnated, with possible
resulting confusion by Perl.</p>
<p>This function is now largely obsolete, mostly because it's very hard to
convert a core file into an executable.  That's why you should now invoke
it as <code class="inline"><span class="i">CORE::dump</span><span class="s">(</span><span class="s">)</span></code>
 if you don't want to be warned against a possible
typo.</p>
<p>Unlike most named operators, this has the same precedence as assignment.
It is also exempt from the looks-like-a-function rule, so
<code class="inline"><a class="l_k" href="functions/dump.html">dump</a> <span class="s">(</span><span class="q">&quot;foo&quot;</span><span class="s">)</span>.<span class="q">&quot;bar&quot;</span></code>
 will cause "bar" to be part of the argument to
<a href="#dump-LABEL">dump</a>.</p>
<p>Portability issues: <a href="perlport.html#dump">dump in perlport</a>.</p>
</li>
<li><a name="each-HASH"></a><b>each HASH
 </b>
</li>
<li><a name="each-ARRAY"></a><b>each ARRAY
</b>
<p>When called on a hash in list context, returns a 2-element list
consisting of the key and value for the next element of a hash.  In Perl
5.12 and later only, it will also return the index and value for the next
element of an array so that you can iterate over it; older Perls consider
this a syntax error.  When called in scalar context, returns only the key
(not the value) in a hash, or the index in an array.</p>
<p>Hash entries are returned in an apparently random order.  The actual random
order is specific to a given hash; the exact same series of operations
on two hashes may result in a different order for each hash.  Any insertion
into the hash may change the order, as will any deletion, with the exception
that the most recent key returned by <a href="#each-HASH">each</a> or
<a href="#keys-HASH">keys</a> may be deleted without changing the order.  So
long as a given hash is unmodified you may rely on
<a href="#keys-HASH">keys</a>, <a href="#values-HASH">values</a> and
<a href="#each-HASH">each</a> to repeatedly return the same order
as each other.  See <a href="perlsec.html#Algorithmic-Complexity-Attacks">Algorithmic Complexity Attacks in perlsec</a> for
details on why hash order is randomized.  Aside from the guarantees
provided here the exact details of Perl's hash algorithm and the hash
traversal order are subject to change in any release of Perl.</p>
<p>After <a href="#each-HASH">each</a> has returned all entries from the hash or
array, the next call to <a href="#each-HASH">each</a> returns the empty list in
list context and <a href="#undef-EXPR">undef</a> in scalar context; the next
call following <i>that</i> one restarts iteration.  Each hash or array has
its own internal iterator, accessed by <a href="#each-HASH">each</a>,
<a href="#keys-HASH">keys</a>, and <a href="#values-HASH">values</a>.  The iterator is
implicitly reset when <a href="#each-HASH">each</a> has reached the end as just
described; it can be explicitly reset by calling <a href="#keys-HASH">keys</a>
or <a href="#values-HASH">values</a> on the hash or array.  If you add or delete
a hash's elements while iterating over it, the effect on the iterator is
unspecified; for example, entries may be skipped or duplicated--so don't
do that.  Exception: It is always safe to delete the item most recently
returned by <a href="#each-HASH">each</a>, so the following code works properly:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/while.html">while</a> <span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$key</span><span class="cm">,</span> <span class="i">$value</span><span class="s">)</span> = <a class="l_k" href="functions/each.html">each</a> <span class="i">%hash</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="i">$key</span><span class="cm">,</span> <span class="q">&quot;\n&quot;</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/delete.html">delete</a> <span class="i">$hash</span>{<span class="i">$key</span>}<span class="sc">;</span>   <span class="c"># This is safe</span></li><li>    <span class="s">}</span></li></ol></pre><p>Tied hashes may have a different ordering behaviour to perl's hash
implementation.</p>
<p>This prints out your environment like the <i>printenv(1)</i> program,
but in a different order:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/while.html">while</a> <span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$key</span><span class="cm">,</span><span class="i">$value</span><span class="s">)</span> = <a class="l_k" href="functions/each.html">each</a> <span class="i">%ENV</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;$key=$value\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>Starting with Perl 5.14, an experimental feature allowed
<a href="#each-HASH">each</a> to take a scalar expression. This experiment has
been deemed unsuccessful, and was removed as of Perl 5.24.</p>
<p>As of Perl 5.18 you can use a bare <a href="#each-HASH">each</a> in a <code class="inline">while</code>

loop, which will set <a href="perlvar.html#%24_">$_ </a> on every iteration.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/while.html">while</a> <span class="s">(</span><a class="l_k" href="functions/each.html">each</a> <span class="i">%ENV</span><span class="s">)</span> <span class="s">{</span></li><li>	<a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;$_=$ENV{$_}\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>To avoid confusing would-be users of your code who are running earlier
versions of Perl with mysterious syntax errors, put this sort of thing at
the top of your file to signal that your code will work <i>only</i> on Perls of
a recent vintage:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="n">5.012</span><span class="sc">;</span>	<span class="c"># so keys/values/each work on arrays</span></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="n">5.018</span><span class="sc">;</span>	<span class="c"># so each assigns to $_ in a lone while test</span></li></ol></pre><p>See also <a href="#keys-HASH">keys</a>, <a href="#values-HASH">values</a>, and
<a href="#sort-SUBNAME-LIST">sort</a>.</p>
</li>
<li><a name="eof-FILEHANDLE"></a><b>eof FILEHANDLE


</b>
</li>
<li><a name="eof-()"></a><b>eof ()</b>
</li>
<li><a name="eof"></a><b>eof</b>
<p>Returns 1 if the next read on FILEHANDLE will return end of file <i>or</i> if
FILEHANDLE is not open.  FILEHANDLE may be an expression whose value
gives the real filehandle.  (Note that this function actually
reads a character and then <code class="inline"><span class="w">ungetc</span></code>
s it, so isn't useful in an
interactive context.)  Do not read from a terminal file (or call
<code class="inline"><a class="l_k" href="functions/eof.html">eof(FILEHANDLE)</a></code> on it) after end-of-file is reached.  File types such
as terminals may lose the end-of-file condition if you do.</p>
<p>An <a href="#eof-FILEHANDLE">eof</a> without an argument uses the last file
read.  Using <a href="#eof-FILEHANDLE">eof()</a> with empty parentheses is
different.  It refers to the pseudo file formed from the files listed on
the command line and accessed via the <code class="inline">&lt;&gt;</code>
 operator.  Since
<code class="inline">&lt;&gt;</code>
 isn't explicitly opened, as a normal filehandle is, an
<a href="#eof-FILEHANDLE">eof()</a> before <code class="inline">&lt;&gt;</code>
 has been used will cause
<a href="perlvar.html#%40ARGV">@ARGV </a> to be examined to determine if input is
available.   Similarly, an <a href="#eof-FILEHANDLE">eof()</a> after <code class="inline">&lt;&gt;</code>

has returned end-of-file will assume you are processing another
<a href="perlvar.html#%40ARGV">@ARGV </a> list, and if you haven't set
<a href="perlvar.html#%40ARGV">@ARGV </a>, will read input from <code class="inline"><span class="w">STDIN</span></code>
; see
<a href="perlop.html#I%2fO-Operators">I/O Operators in perlop</a>.</p>
<p>In a <code class="inline">while <span class="s">(</span>&lt;&gt;<span class="s">)</span></code>
 loop, <a href="#eof-FILEHANDLE">eof</a> or <code class="inline"><a class="l_k" href="functions/eof.html">eof(ARGV)</a></code>
can be used to detect the end of each file, whereas
<a href="#eof-FILEHANDLE">eof()</a> will detect the end of the very last file
only.  Examples:</p>
<pre class="verbatim"><ol><li>    <span class="c"># reset line numbering on each input file</span></li><li>    <a class="l_k" href="functions/while.html">while</a> <span class="s">(</span>&lt;&gt;<span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/next.html">next</a> <a class="l_k" href="functions/if.html">if</a> <span class="q">/^\s*#/</span><span class="sc">;</span>  <span class="c"># skip comments</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;$.\t$_&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span> <a class="l_k" href="functions/continue.html">continue</a> <span class="s">{</span></li><li>        <a class="l_k" href="functions/close.html">close</a> <span class="w">ARGV</span> <a class="l_k" href="functions/if.html">if</a> <a class="l_k" href="functions/eof.html">eof</a><span class="sc">;</span>  <span class="c"># Not eof()!</span></li><li>    <span class="s">}</span></li><li></li><li>    <span class="c"># insert dashes just before last line of last file</span></li><li>    <a class="l_k" href="functions/while.html">while</a> <span class="s">(</span>&lt;&gt;<span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span><a class="l_k" href="functions/eof.html">eof</a><span class="s">(</span><span class="s">)</span><span class="s">)</span> <span class="s">{</span>  <span class="c"># check for end of last file</span></li><li>            <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;--------------\n&quot;</span><span class="sc">;</span></li><li>        <span class="s">}</span></li><li>        <a class="l_k" href="functions/print.html">print</a><span class="sc">;</span></li><li>        <a class="l_k" href="functions/last.html">last</a> <a class="l_k" href="functions/if.html">if</a> <a class="l_k" href="functions/eof.html">eof</a><span class="s">(</span><span class="s">)</span><span class="sc">;</span>     <span class="c"># needed if we&#39;re reading from a terminal</span></li><li>    <span class="s">}</span></li></ol></pre><p>Practical hint: you almost never need to use <a href="#eof-FILEHANDLE">eof</a>
in Perl, because the input operators typically return <a href="#undef-EXPR">undef</a> when they run out of data or encounter an error.</p>
</li>
<li><a name="eval-EXPR"></a><b>eval EXPR
     
 </b>
</li>
<li><a name="eval-BLOCK"></a><b>eval BLOCK</b>
</li>
<li><a name="eval"></a><b>eval</b>
<p><code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> in all its forms is used to execute a little Perl program,
trapping any errors encountered so they don't crash the calling program.</p>
<p>Plain <code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> with no argument is just <code class="inline"><a class="l_k" href="functions/eval.html">eval</a> <span class="w">EXPR</span></code>
, where the
expression is understood to be contained in <a href="perlvar.html#%24_">$_ </a>.  Thus
there are only two real <code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> forms; the one with an EXPR is often
called "string eval".  In a string eval, the value of the expression
(which is itself determined within scalar context) is first parsed, and
if there were no errors, executed as a block within the lexical context
of the current Perl program.  This form is typically used to delay
parsing and subsequent execution of the text of EXPR until run time.
Note that the value is parsed every time the <code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> executes.</p>
<p>The other form is called "block eval".  It is less general than string
eval, but the code within the BLOCK is parsed only once (at the same
time the code surrounding the <code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> itself was parsed) and executed
within the context of the current Perl program.  This form is typically
used to trap exceptions more efficiently than the first, while also
providing the benefit of checking the code within BLOCK at compile time.
BLOCK is parsed and compiled just once.  Since errors are trapped, it
often is used to check if a given feature is available.</p>
<p>In both forms, the value returned is the value of the last expression
evaluated inside the mini-program; a return statement may also be used, just
as with subroutines.  The expression providing the return value is evaluated
in void, scalar, or list context, depending on the context of the
<code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> itself.  See <a href="#wantarray">wantarray</a> for more
on how the evaluation context can be determined.</p>
<p>If there is a syntax error or runtime error, or a <a href="#die-LIST">die</a>
statement is executed, <code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> returns
<a href="#undef-EXPR">undef</a> in scalar context, or an empty list in list
context, and <a href="perlvar.html#%24%40">$@ </a> is set to the error message.  (Prior to
5.16, a bug caused <a href="#undef-EXPR">undef</a> to be returned in list
context for syntax errors, but not for runtime errors.) If there was no
error, <a href="perlvar.html#%24%40">$@ </a> is set to the empty string.  A control flow
operator like <a href="#last-LABEL">last</a> or <a href="#goto-LABEL">goto</a> can
bypass the setting of <a href="perlvar.html#%24%40">$@ </a>.  Beware that using
<code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> neither silences Perl from printing warnings to
STDERR, nor does it stuff the text of warning messages into
<a href="perlvar.html#%24%40">$@ </a>.  To do either of those, you have to use the
<a href="perlvar.html#%25SIG">$SIG{__WARN__} </a> facility, or turn off warnings inside
the BLOCK or EXPR using <code class="inline"><a class="l_k" href="functions/no.html">no</a> <span class="w">warnings</span> <span class="q">&#39;all&#39;</span></code>
.  See
<a href="#warn-LIST">warn</a>, <a href="perlvar.html">perlvar</a>, and <a href="warnings.html">warnings</a>.</p>
<p>Note that, because <code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> traps otherwise-fatal errors,
it is useful for determining whether a particular feature (such as
<a href="#socket-SOCKET%2cDOMAIN%2cTYPE%2cPROTOCOL">socket</a> or
<a href="#symlink-OLDFILE%2cNEWFILE">symlink</a>) is implemented.  It is also
Perl's exception-trapping mechanism, where the <a href="#die-LIST">die</a>
operator is used to raise exceptions.</p>
<p>Before Perl 5.14, the assignment to <a href="perlvar.html#%24%40">$@ </a> occurred before
restoration
of localized variables, which means that for your code to run on older
versions, a temporary is required if you want to mask some, but not all
errors:</p>
<pre class="verbatim"><ol><li> <span class="c"># alter $@ on nefarious repugnancy only</span></li><li> <span class="s">{</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$e</span><span class="sc">;</span></li><li>    <span class="s">{</span></li><li>      <a class="l_k" href="functions/local.html">local</a> <span class="i">$@</span><span class="sc">;</span> <span class="c"># protect existing $@</span></li><li>      <a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span> <span class="i">test_repugnancy</span><span class="s">(</span><span class="s">)</span> <span class="s">}</span><span class="sc">;</span></li><li>      <span class="c"># $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only</span></li><li>      <span class="i">$@</span> =~ <span class="q">/nefarious/</span> <a class="l_k" href="functions/and.html">and</a> <span class="i">$e</span> = <span class="i">$@</span><span class="sc">;</span></li><li>    <span class="s">}</span></li><li>    <a class="l_k" href="functions/die.html">die</a> <span class="i">$e</span> <a class="l_k" href="functions/if.html">if</a> <a class="l_k" href="functions/defined.html">defined</a> <span class="i">$e</span></li><li> <span class="s">}</span></li></ol></pre><p>There are some different considerations for each form:</p>
<ul>
<li><a name="String-eval"></a><b>String eval</b>
<p>Since the return value of EXPR is executed as a block within the lexical
context of the current Perl program, any outer lexical variables are
visible to it, and any package variable settings or subroutine and
format definitions remain afterwards.</p>
<ul>
<li><a name="Under-the-feature%2fThe-'unicode_eval'-and-'evalbytes'-features"></a><b>Under the <a href="feature.html#The-'unicode_eval'-and-'evalbytes'-features">unicode_eval feature</a></b>
<p>If this feature is enabled (which is the default under a <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="n">5.16</span></code>
 or
higher declaration), EXPR is considered to be
in the same encoding as the surrounding program.  Thus if
<a href="utf8.html">use utf8 </a> is in effect, the string will be treated as being
UTF-8 encoded.  Otherwise, the string is considered to be a sequence of
independent bytes.  Bytes that correspond to ASCII-range code points
will have their normal meanings for operators in the string.  The
treatment of the other bytes depends on if the
<a href="feature.html#The-'unicode_strings'-feature">&#39;unicode_strings&quot; feature</a> is
in effect.</p>
<p>In a plain <code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> without an EXPR argument, being in <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">utf8</span></code>
 or
not is irrelevant; the UTF-8ness of <code class="inline"><span class="i">$_</span></code>
 itself determines the
behavior.</p>
<p>Any <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">utf8</span></code>
 or <code class="inline"><a class="l_k" href="functions/no.html">no</a> <span class="w">utf8</span></code>
 declarations within the string have
no effect, and source filters are forbidden.  (<code class="inline"><span class="w">unicode_strings</span></code>
,
however, can appear within the string.)  See also the
<a href="#evalbytes-EXPR">evalbytes</a> operator, which works properly with
source filters.</p>
<p>Variables defined outside the <code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> and used inside it retain their
original UTF-8ness.  Everything inside the string follows the normal
rules for a Perl program with the given state of <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">utf8</span></code>
.</p>
</li>
<li><a name="Outside-the-%22unicode_eval%22-feature"></a><b>Outside the <code class="inline"><span class="q">&quot;unicode_eval&quot;</span></code>
 feature</b>
<p>In this case, the behavior is problematic and is not so easily
described.  Here are two bugs that cannot easily be fixed without
breaking existing programs:</p>
<ul>
<li>
<p>It can lose track of whether something should be encoded as UTF-8 or
not.</p>
</li>
<li>
<p>Source filters activated within <code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> leak out into whichever file
scope is currently being compiled.  To give an example with the CPAN module
<a href="http://search.cpan.org/perldoc/Semi::Semicolons">Semi::Semicolons</a>:</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/BEGIN.html">BEGIN</a> <span class="s">{</span> <a class="l_k" href="functions/eval.html">eval</a> <span class="q">&quot;use Semi::Semicolons; # not filtered&quot;</span> <span class="s">}</span></li><li> <span class="c"># filtered here!</span></li></ol></pre><p><a href="#evalbytes-EXPR">evalbytes</a> fixes that to work the way one would
expect:</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">feature</span> <span class="q">&quot;evalbytes&quot;</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/BEGIN.html">BEGIN</a> <span class="s">{</span> <span class="w">evalbytes</span> <span class="q">&quot;use Semi::Semicolons; # filtered&quot;</span> <span class="s">}</span></li><li> <span class="c"># not filtered</span></li></ol></pre></li>
</ul>
</li>
</ul>
<p>Problems can arise if the string expands a scalar containing a floating
point number.  That scalar can expand to letters, such as <code class="inline"><span class="q">&quot;NaN&quot;</span></code>
 or
<code class="inline"><span class="q">&quot;Infinity&quot;</span></code>
; or, within the scope of a <a href="locale.html">use locale </a>, the
decimal point character may be something other than a dot (such as a
comma).  None of these are likely to parse as you are likely expecting.</p>
<p>You should be especially careful to remember what's being looked at
when:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="i">$x</span><span class="sc">;</span>        <span class="c"># CASE 1</span></li><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="q">&quot;$x&quot;</span><span class="sc">;</span>      <span class="c"># CASE 2</span></li><li></li><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="q">&#39;$x&#39;</span><span class="sc">;</span>      <span class="c"># CASE 3</span></li><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span> <span class="i">$x</span> <span class="s">}</span><span class="sc">;</span>    <span class="c"># CASE 4</span></li><li></li><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="q">&quot;\$$x++&quot;</span><span class="sc">;</span>  <span class="c"># CASE 5</span></li><li>    <span class="i">$$x</span>++<span class="sc">;</span>          <span class="c"># CASE 6</span></li></ol></pre><p>Cases 1 and 2 above behave identically: they run the code contained in
the variable $x.  (Although case 2 has misleading double quotes making
the reader wonder what else might be happening (nothing is).)  Cases 3
and 4 likewise behave in the same way: they run the code <code class="inline"><span class="q">&#39;$x&#39;</span></code>
, which
does nothing but return the value of $x.  (Case 4 is preferred for
purely visual reasons, but it also has the advantage of compiling at
compile-time instead of at run-time.)  Case 5 is a place where
normally you <i>would</i> like to use double quotes, except that in this
particular situation, you can just use symbolic references instead, as
in case 6.</p>
<p>An <code class="inline"><a class="l_k" href="functions/eval.html">eval</a> <span class="q">&#39;&#39;</span></code>
 executed within a subroutine defined
in the <code class="inline"><span class="w">DB</span></code>
 package doesn't see the usual
surrounding lexical scope, but rather the scope of the first non-DB piece
of code that called it.  You don't normally need to worry about this unless
you are writing a Perl debugger.</p>
<p>The final semicolon, if any, may be omitted from the value of EXPR.</p>
</li>
<li><a name="Block-eval"></a><b>Block eval</b>
<p>If the code to be executed doesn't vary, you may use the eval-BLOCK
form to trap run-time errors without incurring the penalty of
recompiling each time.  The error, if any, is still returned in
<a href="perlvar.html#%24%40">$@ </a>.
Examples:</p>
<pre class="verbatim"><ol><li>    <span class="c"># make divide-by-zero nonfatal</span></li><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span> <span class="i">$answer</span> = <span class="i">$a</span> / <span class="i">$b</span><span class="sc">;</span> <span class="s">}</span><span class="sc">;</span> <a class="l_k" href="functions/warn.html">warn</a> <span class="i">$@</span> if <span class="i">$@</span><span class="sc">;</span></li><li></li><li>    <span class="c"># same thing, but less efficient</span></li><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="q">&#39;$answer = $a / $b&#39;</span><span class="sc">;</span> <a class="l_k" href="functions/warn.html">warn</a> <span class="i">$@</span> if <span class="i">$@</span><span class="sc">;</span></li><li></li><li>    <span class="c"># a compile-time error</span></li><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span> <span class="i">$answer</span> = <span class="s">}</span><span class="sc">;</span> <span class="c"># WRONG</span></li><li></li><li>    <span class="c"># a run-time error</span></li><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="q">&#39;$answer =&#39;</span><span class="sc">;</span>   <span class="c"># sets $@</span></li></ol></pre><p>If you want to trap errors when loading an XS module, some problems with
the binary interface (such as Perl version skew) may be fatal even with
<code class="inline"><a class="l_k" href="functions/eval.html">eval</a></code> unless <code class="inline"><span class="i">$ENV</span>{<span class="w">PERL_DL_NONLAZY</span>}</code>
 is set.  See
<a href="perlrun.html">perlrun</a>.</p>
<p>Using the <code class="inline"><a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span><span class="s">}</span></code>
 form as an exception trap in libraries does have some
issues.  Due to the current arguably broken state of <code class="inline"><span class="w">__DIE__</span></code>
 hooks, you
may wish not to trigger any <code class="inline"><span class="w">__DIE__</span></code>
 hooks that user code may have installed.
You can use the <code class="inline"><a class="l_k" href="functions/local.html">local</a> <span class="i">$SIG</span>{<span class="w">__DIE__</span>}</code>
 construct for this purpose,
as this example shows:</p>
<pre class="verbatim"><ol><li>    <span class="c"># a private exception trap for divide-by-zero</span></li><li>    <a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span> <a class="l_k" href="functions/local.html">local</a> <span class="i">$SIG</span>{<span class="q">&#39;__DIE__&#39;</span>}<span class="sc">;</span> <span class="i">$answer</span> = <span class="i">$a</span> / <span class="i">$b</span><span class="sc">;</span> <span class="s">}</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/warn.html">warn</a> <span class="i">$@</span> if <span class="i">$@</span><span class="sc">;</span></li></ol></pre><p>This is especially significant, given that <code class="inline"><span class="w">__DIE__</span></code>
 hooks can call
<a href="#die-LIST">die</a> again, which has the effect of changing their error
messages:</p>
<pre class="verbatim"><ol><li>    <span class="c"># __DIE__ hooks may modify error messages</span></li><li>    <span class="s">{</span></li><li>       <a class="l_k" href="functions/local.html">local</a> <span class="i">$SIG</span>{<span class="q">&#39;__DIE__&#39;</span>} =</li><li>              <a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span> <span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$x</span> = <span class="i">$_</span>[<span class="n">0</span>]<span class="s">)</span> =~ <span class="q">s/foo/bar/g</span><span class="sc">;</span> <a class="l_k" href="functions/die.html">die</a> <span class="i">$x</span> <span class="s">}</span><span class="sc">;</span></li><li>       <a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;foo lives here&quot;</span> <span class="s">}</span><span class="sc">;</span></li><li>       <a class="l_k" href="functions/print.html">print</a> <span class="i">$@</span> if <span class="i">$@</span><span class="sc">;</span>                <span class="c"># prints &quot;bar lives here&quot;</span></li><li>    <span class="s">}</span></li></ol></pre><p>Because this promotes action at a distance, this counterintuitive behavior
may be fixed in a future release.</p>
<p><code class="inline"><a class="l_k" href="functions/eval.html">eval</a> <span class="w">BLOCK</span></code>
 does <i>not</i> count as a loop, so the loop control statements
<a href="#next-LABEL">next</a>, <a href="#last-LABEL">last</a>, or
<a href="#redo-LABEL">redo</a> cannot be used to leave or restart the block.</p>
<p>The final semicolon, if any, may be omitted from within the BLOCK.</p>
</li>
</ul>
</li>
<li><a name="evalbytes-EXPR"></a><b>evalbytes EXPR
</b>
</li>
<li><a name="evalbytes"></a><b>evalbytes</b>
<p>This function is similar to a <a href="#eval-EXPR">string eval</a>, except it
always parses its argument (or <a href="perlvar.html#%24_">$_ </a> if EXPR is omitted)
as a string of independent bytes.</p>
<p>If called when <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">utf8</span></code>
 is in effect, the string will be assumed
to be encoded in UTF-8, and <code class="inline"><a class="l_k" href="functions/evalbytes.html">evalbytes</a></code> will make a temporary copy to
work from, downgraded to non-UTF-8.  If this is not possible
(because one or more characters in it require UTF-8), the <code class="inline"><a class="l_k" href="functions/evalbytes.html">evalbytes</a></code>
will fail with the error stored in <code class="inline"><span class="i">$@</span></code>
.</p>
<p>Bytes that correspond to ASCII-range code points will have their normal
meanings for operators in the string.  The treatment of the other bytes
depends on if the <a href="feature.html#The-'unicode_strings'-feature">&#39;unicode_strings&quot; feature</a> is in effect.</p>
<p>Of course, variables that are UTF-8 and are referred to in the string
retain that:</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">$a</span> = <span class="q">&quot;\x{100}&quot;</span><span class="sc">;</span></li><li> <span class="w">evalbytes</span> <span class="q">&#39;print ord $a, &quot;\n&quot;&#39;</span><span class="sc">;</span></li></ol></pre><p>prints</p>
<pre class="verbatim"><ol><li> <span class="n">256</span></li></ol></pre><p>and <code class="inline"><span class="i">$@</span></code>
 is empty.</p>
<p>Source filters activated within the evaluated code apply to the code
itself.</p>
<p><a href="#evalbytes-EXPR">evalbytes</a> is available starting in Perl v5.16.  To
access it, you must say <code class="inline"><span class="w">CORE::evalbytes</span></code>
, but you can omit the
<code class="inline"><span class="w">CORE::</span></code>
 if the
<a href="feature.html#The-'unicode_eval'-and-'evalbytes'-features">evalbytes feature</a>
is enabled.  This is enabled automatically with a <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="v">v5.16</span></code>
 (or
higher) declaration in the current scope.</p>
</li>
<li><a name="exec-LIST"></a><b>exec LIST
 </b>
</li>
<li><a name="exec-PROGRAM-LIST"></a><b>exec PROGRAM LIST</b>
<p>The <a href="#exec-LIST">exec</a> function executes a system command <i>and never
returns</i>; use <a href="#system-LIST">system</a> instead of <a href="#exec-LIST">exec</a>
if you want it to return.  It fails and
returns false only if the command does not exist <i>and</i> it is executed
directly instead of via your system's command shell (see below).</p>
<p>Since it's a common mistake to use <a href="#exec-LIST">exec</a> instead of
<a href="#system-LIST">system</a>, Perl warns you if <a href="#exec-LIST">exec</a> is
called in void context and if there is a following statement that isn't
<a href="#die-LIST">die</a>, <a href="#warn-LIST">warn</a>, or <a href="#exit-EXPR">exit</a> (if
<a href="warnings.html">warnings</a> are enabled--but you always do that, right?).  If you
<i>really</i> want to follow an <a href="#exec-LIST">exec</a> with some other
statement, you can use one of these styles to avoid the warning:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/exec.html">exec</a> <span class="s">(</span><span class="q">&#39;foo&#39;</span><span class="s">)</span>   or <a class="l_k" href="functions/print.html">print</a> <span class="i">STDERR</span> <span class="q">&quot;couldn&#39;t exec foo: $!&quot;</span><span class="sc">;</span></li><li>    <span class="s">{</span> <a class="l_k" href="functions/exec.html">exec</a> <span class="s">(</span><span class="q">&#39;foo&#39;</span><span class="s">)</span> <span class="s">}</span><span class="sc">;</span> <a class="l_k" href="functions/print.html">print</a> <span class="i">STDERR</span> <span class="q">&quot;couldn&#39;t exec foo: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>If there is more than one argument in LIST, this calls <i>execvp(3)</i> with the
arguments in LIST.  If there is only one element in LIST, the argument is
checked for shell metacharacters, and if there are any, the entire
argument is passed to the system's command shell for parsing (this is
<code class="inline">/bin/sh -c</code> on Unix platforms, but varies on other platforms).  If
there are no shell metacharacters in the argument, it is split into words
and passed directly to <code class="inline"><span class="w">execvp</span></code>
, which is more efficient.  Examples:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/exec.html">exec</a> <span class="q">&#39;/bin/echo&#39;</span><span class="cm">,</span> <span class="q">&#39;Your arguments are: &#39;</span><span class="cm">,</span> <span class="i">@ARGV</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/exec.html">exec</a> <span class="q">&quot;sort $outfile | uniq&quot;</span><span class="sc">;</span></li></ol></pre><p>If you don't really want to execute the first argument, but want to lie
to the program you are executing about its own name, you can specify
the program you actually want to run as an "indirect object" (without a
comma) in front of the LIST, as in <code class="inline"><a class="l_k" href="functions/exec.html">exec</a> <span class="i">PROGRAM</span> <span class="w">LIST</span></code>
.  (This always
forces interpretation of the LIST as a multivalued list, even if there
is only a single scalar in the list.)  Example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$shell</span> = <span class="q">&#39;/bin/csh&#39;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/exec.html">exec</a> <span class="i">$shell</span> <span class="q">&#39;-sh&#39;</span><span class="sc">;</span>    <span class="c"># pretend it&#39;s a login shell</span></li></ol></pre><p>or, more directly,</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/exec.html">exec</a> <span class="s">{</span><span class="q">&#39;/bin/csh&#39;</span><span class="s">}</span> <span class="q">&#39;-sh&#39;</span><span class="sc">;</span>  <span class="c"># pretend it&#39;s a login shell</span></li></ol></pre><p>When the arguments get executed via the system shell, results are
subject to its quirks and capabilities.  See <a href="perlop.html#%60STRING%60">`STRING` in perlop</a>
for details.</p>
<p>Using an indirect object with <a href="#exec-LIST">exec</a> or
<a href="#system-LIST">system</a> is also more secure.  This usage (which also
works fine with <a href="#system-LIST">system</a>) forces
interpretation of the arguments as a multivalued list, even if the
list had just one argument.  That way you're safe from the shell
expanding wildcards or splitting up words with whitespace in them.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@args</span> = <span class="s">(</span> <span class="q">&quot;echo surprise&quot;</span> <span class="s">)</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/exec.html">exec</a> <span class="i">@args</span><span class="sc">;</span>               <span class="c"># subject to shell escapes</span></li><li>                                <span class="c"># if @args == 1</span></li><li>    <a class="l_k" href="functions/exec.html">exec</a> <span class="s">{</span> <span class="i">$args</span>[<span class="n">0</span>] <span class="s">}</span> <span class="i">@args</span><span class="sc">;</span>  <span class="c"># safe even with one-arg list</span></li></ol></pre><p>The first version, the one without the indirect object, ran the <i>echo</i>
program, passing it <code class="inline"><span class="q">&quot;surprise&quot;</span></code>
 an argument.  The second version didn't;
it tried to run a program named <i>"echo surprise"</i>, didn't find it, and set
<a href="perlvar.html#%24%3f">$? </a> to a non-zero value indicating failure.</p>
<p>On Windows, only the <code class="inline"><a class="l_k" href="functions/exec.html">exec</a> <span class="i">PROGRAM</span> <span class="w">LIST</span></code>
 indirect object syntax will
reliably avoid using the shell; <code class="inline"><a class="l_k" href="functions/exec.html">exec</a> <span class="i">LIST</span></code>
, even with more than one
element, will fall back to the shell if the first spawn fails.</p>
<p>Perl attempts to flush all files opened for output before the exec,
but this may not be supported on some platforms (see <a href="perlport.html">perlport</a>).
To be safe, you may need to set <a href="http://search.cpan.org/perldoc/|perlvar#%24%7c">$</a>
(<code class="inline"><span class="i">$AUTOFLUSH</span></code>
 in <a href="English.html">English</a>) or call the <code class="inline"><span class="w">autoflush</span></code>
 method of
<a href="IO/Handle.html#METHODS">IO::Handle </a> on any open handles to avoid lost
output.</p>
<p>Note that <a href="#exec-LIST">exec</a> will not call your <code class="inline">END</code>
 blocks, nor
will it invoke <code class="inline">DESTROY</code>
 methods on your objects.</p>
<p>Portability issues: <a href="perlport.html#exec">exec in perlport</a>.</p>
</li>
<li><a name="exists-EXPR"></a><b>exists EXPR
 </b>
<p>Given an expression that specifies an element of a hash, returns true if the
specified element in the hash has ever been initialized, even if the
corresponding value is undefined.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Exists\n&quot;</span>    if <a class="l_k" href="functions/exists.html">exists</a> <span class="i">$hash</span>{<span class="i">$key</span>}<span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Defined\n&quot;</span>   if <a class="l_k" href="functions/defined.html">defined</a> <span class="i">$hash</span>{<span class="i">$key</span>}<span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;True\n&quot;</span>      if <span class="i">$hash</span>{<span class="i">$key</span>}<span class="sc">;</span></li></ol></pre><p>exists may also be called on array elements, but its behavior is much less
obvious and is strongly tied to the use of <a href="#delete-EXPR">delete</a> on
arrays.</p>
<p><b>WARNING:</b> Calling <a href="#exists-EXPR">exists</a> on array values is
strongly discouraged.  The
notion of deleting or checking the existence of Perl array elements is not
conceptually coherent, and can lead to surprising behavior.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Exists\n&quot;</span>    if <a class="l_k" href="functions/exists.html">exists</a> <span class="i">$array</span>[<span class="i">$index</span>]<span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Defined\n&quot;</span>   if <a class="l_k" href="functions/defined.html">defined</a> <span class="i">$array</span>[<span class="i">$index</span>]<span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;True\n&quot;</span>      if <span class="i">$array</span>[<span class="i">$index</span>]<span class="sc">;</span></li></ol></pre><p>A hash or array element can be true only if it's defined and defined only if
it exists, but the reverse doesn't necessarily hold true.</p>
<p>Given an expression that specifies the name of a subroutine,
returns true if the specified subroutine has ever been declared, even
if it is undefined.  Mentioning a subroutine name for exists or defined
does not count as declaring it.  Note that a subroutine that does not
exist may still be callable: its package may have an <code class="inline">AUTOLOAD</code>

method that makes it spring into existence the first time that it is
called; see <a href="perlsub.html">perlsub</a>.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Exists\n&quot;</span>  if <a class="l_k" href="functions/exists.html">exists</a> <span class="i">&amp;subroutine</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Defined\n&quot;</span> if <a class="l_k" href="functions/defined.html">defined</a> <span class="i">&amp;subroutine</span><span class="sc">;</span></li></ol></pre><p>Note that the EXPR can be arbitrarily complicated as long as the final
operation is a hash or array key lookup or subroutine name:</p>
<pre class="verbatim"><ol><li>    if <span class="s">(</span><a class="l_k" href="functions/exists.html">exists</a> <span class="i">$ref</span>-&gt;{<span class="w">A</span>}-&gt;{<span class="w">B</span>}-&gt;{<span class="i">$key</span>}<span class="s">)</span>  <span class="s">{</span> <span class="s">}</span></li><li>    if <span class="s">(</span><a class="l_k" href="functions/exists.html">exists</a> <span class="i">$hash</span>{<span class="w">A</span>}{<span class="w">B</span>}{<span class="i">$key</span>}<span class="s">)</span>       <span class="s">{</span> <span class="s">}</span></li><li></li><li>    if <span class="s">(</span><a class="l_k" href="functions/exists.html">exists</a> <span class="i">$ref</span>-&gt;{<span class="w">A</span>}-&gt;{<span class="w">B</span>}-&gt;[<span class="i">$ix</span>]<span class="s">)</span>   <span class="s">{</span> <span class="s">}</span></li><li>    if <span class="s">(</span><a class="l_k" href="functions/exists.html">exists</a> <span class="i">$hash</span>{<span class="w">A</span>}{<span class="w">B</span>}[<span class="i">$ix</span>]<span class="s">)</span>        <span class="s">{</span> <span class="s">}</span></li><li></li><li>    if <span class="s">(</span><a class="l_k" href="functions/exists.html">exists</a> <span class="i">&amp;</span>{<span class="i">$ref</span>-&gt;{<span class="w">A</span>}{<span class="w">B</span>}{<span class="i">$key</span>}}<span class="s">)</span>   <span class="s">{</span> <span class="s">}</span></li></ol></pre><p>Although the most deeply nested array or hash element will not spring into
existence just because its existence was tested, any intervening ones will.
Thus <code class="inline"><span class="i">$ref</span>-&gt;{<span class="q">&quot;A&quot;</span>}</code>
 and <code class="inline"><span class="i">$ref</span>-&gt;{<span class="q">&quot;A&quot;</span>}-&gt;{<span class="q">&quot;B&quot;</span>}</code>
 will spring
into existence due to the existence test for the <code class="inline"><span class="i">$key</span></code>
 element above.
This happens anywhere the arrow operator is used, including even here:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/undef.html">undef</a> <span class="i">$ref</span><span class="sc">;</span></li><li>    if <span class="s">(</span><a class="l_k" href="functions/exists.html">exists</a> <span class="i">$ref</span>-&gt;{<span class="q">&quot;Some key&quot;</span>}<span class="s">)</span>    <span class="s">{</span> <span class="s">}</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$ref</span><span class="sc">;</span>  <span class="c"># prints HASH(0x80d3d5c)</span></li></ol></pre><p>This surprising autovivification in what does not at first--or even
second--glance appear to be an lvalue context may be fixed in a future
release.</p>
<p>Use of a subroutine call, rather than a subroutine name, as an argument
to <a href="#exists-EXPR">exists</a> is an error.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/exists.html">exists</a> <span class="i">&amp;sub</span><span class="sc">;</span>    <span class="c"># OK</span></li><li>    <a class="l_k" href="functions/exists.html">exists</a> <span class="i">&amp;sub</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span>  <span class="c"># Error</span></li></ol></pre></li>
<li><a name="exit-EXPR"></a><b>exit EXPR
  </b>
</li>
<li><a name="exit"></a><b>exit</b>
<p>Evaluates EXPR and exits immediately with that value.    Example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$ans</span> = <span class="q">&lt;STDIN&gt;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/exit.html">exit</a> <span class="n">0</span> <a class="l_k" href="functions/if.html">if</a> <span class="i">$ans</span> =~ <span class="q">/^[Xx]/</span><span class="sc">;</span></li></ol></pre><p>See also <a href="#die-LIST">die</a>.  If EXPR is omitted, exits with <code class="inline"><span class="n">0</span></code>

status.  The only
universally recognized values for EXPR are <code class="inline"><span class="n">0</span></code>
 for success and <code class="inline"><span class="n">1</span></code>

for error; other values are subject to interpretation depending on the
environment in which the Perl program is running.  For example, exiting
69 (EX_UNAVAILABLE) from a <i>sendmail</i> incoming-mail filter will cause
the mailer to return the item undelivered, but that's not true everywhere.</p>
<p>Don't use <a href="#exit-EXPR">exit</a> to abort a subroutine if there's any
chance that someone might want to trap whatever error happened.  Use
<a href="#die-LIST">die</a> instead, which can be trapped by an
<a href="#eval-EXPR">eval</a>.</p>
<p>The <a href="#exit-EXPR">exit</a> function does not always exit immediately.  It
calls any defined <code class="inline">END</code>
 routines first, but these <code class="inline">END</code>
 routines may
not themselves abort the exit.  Likewise any object destructors that
need to be called are called before the real exit.  <code class="inline">END</code>
 routines and
destructors can change the exit status by modifying <a href="perlvar.html#%24%3f">$? </a>.
If this is a problem, you can call
<a href="POSIX.html#_exit">POSIX::_exit($status) </a> to avoid <code class="inline">END</code>
 and destructor
processing.  See <a href="perlmod.html">perlmod</a> for details.</p>
<p>Portability issues: <a href="perlport.html#exit">exit in perlport</a>.</p>
</li>
<li><a name="exp-EXPR"></a><b>exp EXPR
    </b>
</li>
<li><a name="exp"></a><b>exp</b>
<p>Returns <i>e</i> (the natural logarithm base) to the power of EXPR.
If EXPR is omitted, gives <code class="inline"><a class="l_k" href="functions/exp.html">exp($_)</a></code>.</p>
</li>
<li><a name="fc-EXPR"></a><b>fc EXPR
    </b>
</li>
<li><a name="fc"></a><b>fc</b>
<p>Returns the casefolded version of EXPR.  This is the internal function
implementing the <code class="inline">\<span class="w">F</span></code>
 escape in double-quoted strings.</p>
<p>Casefolding is the process of mapping strings to a form where case
differences are erased; comparing two strings in their casefolded
form is effectively a way of asking if two strings are equal,
regardless of case.</p>
<p>Roughly, if you ever found yourself writing this</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/lc.html">lc</a><span class="s">(</span><span class="i">$this</span><span class="s">)</span> <a class="l_k" href="functions/eq.html">eq</a> <a class="l_k" href="functions/lc.html">lc</a><span class="s">(</span><span class="i">$that</span><span class="s">)</span>    <span class="c"># Wrong!</span></li><li>        <span class="c"># or</span></li><li>    <a class="l_k" href="functions/uc.html">uc</a><span class="s">(</span><span class="i">$this</span><span class="s">)</span> <a class="l_k" href="functions/eq.html">eq</a> <a class="l_k" href="functions/uc.html">uc</a><span class="s">(</span><span class="i">$that</span><span class="s">)</span>    <span class="c"># Also wrong!</span></li><li>        <span class="c"># or</span></li><li>    <span class="i">$this</span> =~ <span class="q">/^\Q$that\E\z/i</span>  <span class="c"># Right!</span></li></ol></pre><p>Now you can write</p>
<pre class="verbatim"><ol><li>    <span class="i">fc</span><span class="s">(</span><span class="i">$this</span><span class="s">)</span> <a class="l_k" href="functions/eq.html">eq</a> <span class="i">fc</span><span class="s">(</span><span class="i">$that</span><span class="s">)</span></li></ol></pre><p>And get the correct results.</p>
<p>Perl only implements the full form of casefolding, but you can access
the simple folds using <a href="Unicode/UCD.html#casefold()">casefold() in Unicode::UCD</a> and
<a href="Unicode/UCD.html#prop_invmap()">prop_invmap() in Unicode::UCD</a>.
For further information on casefolding, refer to
the Unicode Standard, specifically sections 3.13 <code class="inline"><span class="w">Default</span> <span class="w">Case</span> <span class="w">Operations</span></code>
,
4.2 <code class="inline"><span class="w">Case</span>-<span class="w">Normative</span></code>
, and 5.18 <code class="inline"><span class="w">Case</span> <span class="w">Mappings</span></code>
,
available at <a href="http://www.unicode.org/versions/latest/">http://www.unicode.org/versions/latest/</a>, as well as the
Case Charts available at <a href="http://www.unicode.org/charts/case/">http://www.unicode.org/charts/case/</a>.</p>
<p>If EXPR is omitted, uses <a href="perlvar.html#%24_">$_ </a>.</p>
<p>This function behaves the same way under various pragmas, such as within
<a href="feature.html#The-'unicode_strings'-feature">use feature &#39;unicode_strings </a>,
as <a href="#lc-EXPR">lc</a> does, with the single exception of
<a href="#fc-EXPR">fc</a> of <i>LATIN CAPITAL LETTER SHARP S</i> (U+1E9E) within the
scope of <a href="locale.html">use locale </a>.  The foldcase of this character
would normally be <code class="inline"><span class="q">&quot;ss&quot;</span></code>
, but as explained in the <a href="#lc-EXPR">lc</a>
section, case
changes that cross the 255/256 boundary are problematic under locales,
and are hence prohibited.  Therefore, this function under locale returns
instead the string <code class="inline"><span class="q">&quot;\x{17F}\x{17F}&quot;</span></code>
, which is the <i>LATIN SMALL LETTER
LONG S</i>.  Since that character itself folds to <code class="inline"><span class="q">&quot;s&quot;</span></code>
, the string of two
of them together should be equivalent to a single U+1E9E when foldcased.</p>
<p>While the Unicode Standard defines two additional forms of casefolding,
one for Turkic languages and one that never maps one character into multiple
characters, these are not provided by the Perl core.  However, the CPAN module
<a href="http://search.cpan.org/perldoc/Unicode::Casing">Unicode::Casing </a> may be used to provide an implementation.</p>
<p><a href="#fc-EXPR">fc</a> is available only if the
<a href="feature.html#The-'fc'-feature">fc feature</a> is enabled or if it is
prefixed with <code class="inline"><span class="w">CORE::</span></code>
.  The
<a href="feature.html#The-'fc'-feature">fc feature</a> is enabled automatically
with a <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="v">v5.16</span></code>
 (or higher) declaration in the current scope.</p>
</li>
<li><a name="fcntl-FILEHANDLE%2cFUNCTION%2cSCALAR"></a><b>fcntl FILEHANDLE,FUNCTION,SCALAR
</b>
<p>Implements the <i>fcntl(2)</i> function.  You'll probably have to say</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Fcntl</span><span class="sc">;</span></li></ol></pre><p>first to get the correct constant definitions.  Argument processing and
value returned work just like <a href="#ioctl-FILEHANDLE%2cFUNCTION%2cSCALAR">ioctl</a> below.  For example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Fcntl</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$flags</span> = <a class="l_k" href="functions/fcntl.html">fcntl</a><span class="s">(</span><span class="i">$filehandle</span><span class="cm">,</span> <span class="w">F_GETFL</span><span class="cm">,</span> <span class="n">0</span><span class="s">)</span></li><li>        <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t fcntl F_GETFL: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>You don't have to check for <a href="#defined-EXPR">defined</a> on the return
from <a href="#fcntl-FILEHANDLE%2cFUNCTION%2cSCALAR">fcntl</a>.  Like
<a href="#ioctl-FILEHANDLE%2cFUNCTION%2cSCALAR">ioctl</a>, it maps a <code class="inline"><span class="n">0</span></code>
 return
from the system call into <code class="inline"><span class="q">&quot;0 but true&quot;</span></code>
 in Perl.  This string is true
in boolean context and <code class="inline"><span class="n">0</span></code>
 in numeric context.  It is also exempt from
the normal
<a href="perldiag.html#Argument-%22%25s%22-isn't-numeric%25s">Argument ... isn&#39;t numeric </a>
<a href="warnings.html">warnings</a> on improper numeric conversions.</p>
<p>Note that <a href="#fcntl-FILEHANDLE%2cFUNCTION%2cSCALAR">fcntl</a> raises an
exception if used on a machine that doesn't implement <i>fcntl(2)</i>.  See
the <a href="Fcntl.html">Fcntl</a> module or your <i>fcntl(2)</i> manpage to learn what functions
are available on your system.</p>
<p>Here's an example of setting a filehandle named <code class="inline"><span class="i">$REMOTE</span></code>
 to be
non-blocking at the system level.  You'll have to negotiate
<a href="http://search.cpan.org/perldoc/|perlvar#%24%7c">$</a> on your own, though.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Fcntl</span> <span class="q">qw(F_GETFL F_SETFL O_NONBLOCK)</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$flags</span> = <a class="l_k" href="functions/fcntl.html">fcntl</a><span class="s">(</span><span class="i">$REMOTE</span><span class="cm">,</span> <span class="w">F_GETFL</span><span class="cm">,</span> <span class="n">0</span><span class="s">)</span></li><li>        <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t get flags for the socket: $!\n&quot;</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/fcntl.html">fcntl</a><span class="s">(</span><span class="i">$REMOTE</span><span class="cm">,</span> <span class="w">F_SETFL</span><span class="cm">,</span> <span class="i">$flags</span> | <span class="w">O_NONBLOCK</span><span class="s">)</span></li><li>        <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t set flags for the socket: $!\n&quot;</span><span class="sc">;</span></li></ol></pre><p>Portability issues: <a href="perlport.html#fcntl">fcntl in perlport</a>.</p>
</li>
<li><a name="__FILE__"></a><b>__FILE__
</b>
<p>A special token that returns the name of the file in which it occurs.</p>
</li>
<li><a name="fileno-FILEHANDLE"></a><b>fileno FILEHANDLE
</b>
<p>Returns the file descriptor for a filehandle, or undefined if the
filehandle is not open.  If there is no real file descriptor at the OS
level, as can happen with filehandles connected to memory objects via
<a href="#open-FILEHANDLE%2cEXPR">open</a> with a reference for the third
argument, -1 is returned.</p>
<p>This is mainly useful for constructing bitmaps for
<a href="#select-RBITS%2cWBITS%2cEBITS%2cTIMEOUT">select</a> and low-level POSIX
tty-handling operations.
If FILEHANDLE is an expression, the value is taken as an indirect
filehandle, generally its name.</p>
<p>You can use this to find out whether two handles refer to the
same underlying descriptor:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span><a class="l_k" href="functions/fileno.html">fileno</a><span class="s">(</span><span class="i">$this</span><span class="s">)</span> != <span class="n">-1</span> &amp;&amp; <a class="l_k" href="functions/fileno.html">fileno</a><span class="s">(</span><span class="i">$this</span><span class="s">)</span> == <a class="l_k" href="functions/fileno.html">fileno</a><span class="s">(</span><span class="i">$that</span><span class="s">)</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;\$this and \$that are dups\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span> <a class="l_k" href="functions/elsif.html">elsif</a> <span class="s">(</span><a class="l_k" href="functions/fileno.html">fileno</a><span class="s">(</span><span class="i">$this</span><span class="s">)</span> != <span class="n">-1</span> &amp;&amp; <a class="l_k" href="functions/fileno.html">fileno</a><span class="s">(</span><span class="i">$that</span><span class="s">)</span> != <span class="n">-1</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;\$this and \$that have different &quot;</span> .</li><li>            <span class="q">&quot;underlying file descriptors\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span> <a class="l_k" href="functions/else.html">else</a> <span class="s">{</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;At least one of \$this and \$that does &quot;</span> .</li><li>            <span class="q">&quot;not have a real file descriptor\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>The behavior of <a href="#fileno-FILEHANDLE">fileno</a> on a directory handle
depends on the operating system.  On a system with <i>dirfd(3)</i> or
similar, <a href="#fileno-FILEHANDLE">fileno</a> on a directory
handle returns the underlying file descriptor associated with the
handle; on systems with no such support, it returns the undefined value,
and sets <a href="perlvar.html#%24!">$! </a> (errno).</p>
</li>
<li><a name="flock-FILEHANDLE%2cOPERATION"></a><b>flock FILEHANDLE,OPERATION
  </b>
<p>Calls <i>flock(2)</i>, or an emulation of it, on FILEHANDLE.  Returns true
for success, false on failure.  Produces a fatal error if used on a
machine that doesn't implement <i>flock(2)</i>, <i>fcntl(2)</i> locking, or
<i>lockf(3)</i>.  <a href="#flock-FILEHANDLE%2cOPERATION">flock</a> is Perl's portable
file-locking interface, although it locks entire files only, not
records.</p>
<p>Two potentially non-obvious but traditional <a href="#flock-FILEHANDLE%2cOPERATION">flock</a> semantics are
that it waits indefinitely until the lock is granted, and that its locks
are <b>merely advisory</b>.  Such discretionary locks are more flexible, but
offer fewer guarantees.  This means that programs that do not also use
<a href="#flock-FILEHANDLE%2cOPERATION">flock</a> may modify files locked with
<a href="#flock-FILEHANDLE%2cOPERATION">flock</a>.  See <a href="perlport.html">perlport</a>,
your port's specific documentation, and your system-specific local manpages
for details.  It's best to assume traditional behavior if you're writing
portable programs.  (But if you're not, you should as always feel perfectly
free to write for your own system's idiosyncrasies (sometimes called
"features").  Slavish adherence to portability concerns shouldn't get
in the way of your getting your job done.)</p>
<p>OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with
LOCK_NB.  These constants are traditionally valued 1, 2, 8 and 4, but
you can use the symbolic names if you import them from the <a href="Fcntl.html">Fcntl</a> module,
either individually, or as a group using the <code class="inline"><span class="j">:</span><a class="l_k" href="functions/flock.html">flock</a></code>
 tag.  LOCK_SH
requests a shared lock, LOCK_EX requests an exclusive lock, and LOCK_UN
releases a previously requested lock.  If LOCK_NB is bitwise-or'ed with
LOCK_SH or LOCK_EX, then <a href="#flock-FILEHANDLE%2cOPERATION">flock</a> returns
immediately rather than blocking waiting for the lock; check the return
status to see if you got it.</p>
<p>To avoid the possibility of miscoordination, Perl now flushes FILEHANDLE
before locking or unlocking it.</p>
<p>Note that the emulation built with <i>lockf(3)</i> doesn't provide shared
locks, and it requires that FILEHANDLE be open with write intent.  These
are the semantics that <i>lockf(3)</i> implements.  Most if not all systems
implement <i>lockf(3)</i> in terms of <i>fcntl(2)</i> locking, though, so the
differing semantics shouldn't bite too many people.</p>
<p>Note that the <i>fcntl(2)</i> emulation of <i>flock(3)</i> requires that FILEHANDLE
be open with read intent to use LOCK_SH and requires that it be open
with write intent to use LOCK_EX.</p>
<p>Note also that some versions of <a href="#flock-FILEHANDLE%2cOPERATION">flock</a>
cannot lock things over the network; you would need to use the more
system-specific <a href="#fcntl-FILEHANDLE%2cFUNCTION%2cSCALAR">fcntl</a> for
that.  If you like you can force Perl to ignore your system's <i>flock(2)</i>
function, and so provide its own <i>fcntl(2)</i>-based emulation, by passing
the switch <code class="inline">-<span class="w">Ud_flock</span></code>
 to the <i>Configure</i> program when you configure
and build a new Perl.</p>
<p>Here's a mailbox appender for BSD systems.</p>
<pre class="verbatim"><ol><li>    <span class="c"># import LOCK_* and SEEK_END constants</span></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Fcntl</span> <span class="q">qw(:flock SEEK_END)</span><span class="sc">;</span></li><li></li><li><a name="lock"></a>    sub <span class="m">lock</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$fh</span><span class="s">)</span> = <span class="i">@_</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/flock.html">flock</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span> <span class="w">LOCK_EX</span><span class="s">)</span> <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Cannot lock mailbox - $!\n&quot;</span><span class="sc">;</span></li><li></li><li>        <span class="c"># and, in case someone appended while we were waiting...</span></li><li>        <a class="l_k" href="functions/seek.html">seek</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span> <span class="n">0</span><span class="cm">,</span> <span class="w">SEEK_END</span><span class="s">)</span> <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Cannot seek - $!\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li><li></li><li><a name="unlock"></a>    sub <span class="m">unlock</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$fh</span><span class="s">)</span> = <span class="i">@_</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/flock.html">flock</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span> <span class="w">LOCK_UN</span><span class="s">)</span> <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Cannot unlock mailbox - $!\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li><li></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$mbox</span><span class="cm">,</span> <span class="q">&quot;&gt;&gt;&quot;</span><span class="cm">,</span> <span class="q">&quot;/usr/spool/mail/$ENV{&#39;USER&#39;}&quot;</span><span class="s">)</span></li><li>        <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open mailbox: $!&quot;</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/lock.html">lock</a><span class="s">(</span><span class="i">$mbox</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$mbox</span> <span class="i">$msg</span><span class="cm">,</span><span class="q">&quot;\n\n&quot;</span><span class="sc">;</span></li><li>    <span class="i">unlock</span><span class="s">(</span><span class="i">$mbox</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>On systems that support a real <i>flock(2)</i>, locks are inherited across
<a href="#fork">fork</a> calls, whereas those that must resort to the more
capricious <i>fcntl(2)</i> function lose their locks, making it seriously
harder to write servers.</p>
<p>See also <a href="DB_File.html">DB_File</a> for other <a href="#flock-FILEHANDLE%2cOPERATION">flock</a>
examples.</p>
<p>Portability issues: <a href="perlport.html#flock">flock in perlport</a>.</p>
</li>
<li><a name="fork"></a><b>fork
  </b>
<p>Does a <i>fork(2)</i> system call to create a new process running the
same program at the same point.  It returns the child pid to the
parent process, <code class="inline"><span class="n">0</span></code>
 to the child process, or <a href="#undef-EXPR">undef</a> if
the fork is
unsuccessful.  File descriptors (and sometimes locks on those descriptors)
are shared, while everything else is copied.  On most systems supporting
<i>fork(2)</i>, great care has gone into making it extremely efficient (for
example, using copy-on-write technology on data pages), making it the
dominant paradigm for multitasking over the last few decades.</p>
<p>Perl attempts to flush all files opened for output before forking the
child process, but this may not be supported on some platforms (see
<a href="perlport.html">perlport</a>).  To be safe, you may need to set
<a href="http://search.cpan.org/perldoc/|perlvar#%24%7c">$</a> (<code class="inline"><span class="i">$AUTOFLUSH</span></code>
 in <a href="English.html">English</a>) or
call the <code class="inline"><span class="w">autoflush</span></code>
 method of <a href="IO/Handle.html#METHODS">IO::Handle </a> on
any open handles to avoid duplicate output.</p>
<p>If you <a href="#fork">fork</a> without ever waiting on your children, you will
accumulate zombies.  On some systems, you can avoid this by setting
<a href="perlvar.html#%25SIG">$SIG{CHLD} </a> to <code class="inline"><span class="q">&quot;IGNORE&quot;</span></code>
.  See also <a href="perlipc.html">perlipc</a> for
more examples of forking and reaping moribund children.</p>
<p>Note that if your forked child inherits system file descriptors like
STDIN and STDOUT that are actually connected by a pipe or socket, even
if you exit, then the remote server (such as, say, a CGI script or a
backgrounded job launched from a remote shell) won't think you're done.
You should reopen those to <i>/dev/null</i> if it's any issue.</p>
<p>On some platforms such as Windows, where the <i>fork(2)</i> system call is
not available, Perl can be built to emulate <a href="#fork">fork</a> in the Perl
interpreter.  The emulation is designed, at the level of the Perl
program, to be as compatible as possible with the "Unix" <i>fork(2)</i>.
However it has limitations that have to be considered in code intended
to be portable.  See <a href="perlfork.html">perlfork</a> for more details.</p>
<p>Portability issues: <a href="perlport.html#fork">fork in perlport</a>.</p>
</li>
<li><a name="format"></a><b>format
</b>
<p>Declare a picture format for use by the <a href="#write-FILEHANDLE">write</a>
function.  For example:</p>
<pre class="verbatim"><ol><li>    format Something =</li><li>        Test: @&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; @||||| @&gt;&gt;&gt;&gt;&gt;</li><li>              $str,     $%,    '$' . int($num)</li><li>    .</li><li></li><li>    $str = "widget";</li><li>    $num = $cost/$quantity;</li><li>    $~ = 'Something';</li><li>    write;</li></ol></pre><p>See <a href="perlform.html">perlform</a> for many details and examples.</p>
</li>
<li><a name="formline-PICTURE%2cLIST"></a><b>formline PICTURE,LIST
</b>
<p>This is an internal function used by <a href="#format">format</a>s, though you
may call it, too.  It formats (see <a href="perlform.html">perlform</a>) a list of values
according to the contents of PICTURE, placing the output into the format
output accumulator, <a href="perlvar.html#%24%5eA">$^A </a> (or <code class="inline"><span class="i">$ACCUMULATOR</span></code>
 in
<a href="English.html">English</a>).  Eventually, when a <a href="#write-FILEHANDLE">write</a> is done,
the contents of <a href="perlvar.html#%24%5eA">$^A </a> are written to some filehandle.
You could also read <a href="perlvar.html#%24%5eA">$^A </a> and then set
<a href="perlvar.html#%24%5eA">$^A </a> back to <code class="inline"><span class="q">&quot;&quot;</span></code>
.  Note that a format typically does
one <a href="#formline-PICTURE%2cLIST">formline</a> per line of form, but the
<a href="#formline-PICTURE%2cLIST">formline</a> function itself doesn't care how
many newlines are embedded in the PICTURE.  This means that the <code class="inline">~</code>
 and
<code class="inline">~~</code>
 tokens treat the entire PICTURE as a single line.  You may
therefore need to use multiple formlines to implement a single record
format, just like the <a href="#format">format</a> compiler.</p>
<p>Be careful if you put double quotes around the picture, because an <code class="inline"><span class="i">@</span></code>

character may be taken to mean the beginning of an array name.
<a href="#formline-PICTURE%2cLIST">formline</a> always returns true.  See
<a href="perlform.html">perlform</a> for other examples.</p>
<p>If you are trying to use this instead of <a href="#write-FILEHANDLE">write</a>
to capture the output, you may find it easier to open a filehandle to a
scalar (<code class="inline"><a class="l_k" href="functions/open.html">open</a> <a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;&gt;&quot;</span><span class="cm">,</span> \<span class="i">$output</span></code>
) and write to that instead.</p>
</li>
<li><a name="getc-FILEHANDLE"></a><b>getc FILEHANDLE
   </b>
</li>
<li><a name="getc"></a><b>getc</b>
<p>Returns the next character from the input file attached to FILEHANDLE,
or the undefined value at end of file or if there was an error (in
the latter case <a href="perlvar.html#%24!">$! </a> is set).  If FILEHANDLE is omitted,
reads from
STDIN.  This is not particularly efficient.  However, it cannot be
used by itself to fetch single characters without waiting for the user
to hit enter.  For that, try something more like:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span><span class="i">$BSD_STYLE</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/system.html">system</a> <span class="q">&quot;stty cbreak &lt;/dev/tty &gt;/dev/tty 2&gt;&amp;1&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li><li>    <a class="l_k" href="functions/else.html">else</a> <span class="s">{</span></li><li>        <a class="l_k" href="functions/system.html">system</a> <span class="q">&quot;stty&quot;</span><span class="cm">,</span> <span class="q">&#39;-icanon&#39;</span><span class="cm">,</span> <span class="q">&#39;eol&#39;</span><span class="cm">,</span> <span class="q">&quot;\001&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li><li></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$key</span> = <a class="l_k" href="functions/getc.html">getc</a><span class="s">(</span><span class="w">STDIN</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span><span class="i">$BSD_STYLE</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/system.html">system</a> <span class="q">&quot;stty -cbreak &lt;/dev/tty &gt;/dev/tty 2&gt;&amp;1&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li><li>    <a class="l_k" href="functions/else.html">else</a> <span class="s">{</span></li><li>        <a class="l_k" href="functions/system.html">system</a> <span class="q">&#39;stty&#39;</span><span class="cm">,</span> <span class="q">&#39;icanon&#39;</span><span class="cm">,</span> <span class="q">&#39;eol&#39;</span><span class="cm">,</span> <span class="q">&#39;^@&#39;</span><span class="sc">;</span> <span class="c"># ASCII NUL</span></li><li>    <span class="s">}</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;\n&quot;</span><span class="sc">;</span></li></ol></pre><p>Determination of whether <code class="inline"><span class="i">$BSD_STYLE</span></code>
 should be set is left as an
exercise to the reader.</p>
<p>The <a href="POSIX.html#getattr">POSIX::getattr </a> function can do this more
portably on systems purporting POSIX compliance.  See also the
<a href="http://search.cpan.org/perldoc/Term::ReadKey">Term::ReadKey </a> module on CPAN.</p>
</li>
<li><a name="getlogin"></a><b>getlogin
 </b>
<p>This implements the C library function of the same name, which on most
systems returns the current login from <i>/etc/utmp</i>, if any.  If it
returns the empty string, use <a href="#getpwuid-UID">getpwuid</a>.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$login</span> = <a class="l_k" href="functions/getlogin.html">getlogin</a> || <a class="l_k" href="functions/getpwuid.html">getpwuid</a><span class="s">(</span><span class="i">$&lt;</span><span class="s">)</span> || <span class="q">&quot;Kilroy&quot;</span><span class="sc">;</span></li></ol></pre><p>Do not consider <a href="#getlogin">getlogin</a> for authentication: it is not
as secure as <a href="#getpwuid-UID">getpwuid</a>.</p>
<p>Portability issues: <a href="perlport.html#getlogin">getlogin in perlport</a>.</p>
</li>
<li><a name="getpeername-SOCKET"></a><b>getpeername SOCKET
 </b>
<p>Returns the packed sockaddr address of the other end of the SOCKET
connection.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$hersockaddr</span>    = <a class="l_k" href="functions/getpeername.html">getpeername</a><span class="s">(</span><span class="i">$sock</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$port</span><span class="cm">,</span> <span class="i">$iaddr</span><span class="s">)</span> = <span class="i">sockaddr_in</span><span class="s">(</span><span class="i">$hersockaddr</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$herhostname</span>    = <a class="l_k" href="functions/gethostbyaddr.html">gethostbyaddr</a><span class="s">(</span><span class="i">$iaddr</span><span class="cm">,</span> <span class="w">AF_INET</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$herstraddr</span>     = <span class="i">inet_ntoa</span><span class="s">(</span><span class="i">$iaddr</span><span class="s">)</span><span class="sc">;</span></li></ol></pre></li>
<li><a name="getpgrp-PID"></a><b>getpgrp PID
 </b>
<p>Returns the current process group for the specified PID.  Use
a PID of <code class="inline"><span class="n">0</span></code>
 to get the current process group for the
current process.  Will raise an exception if used on a machine that
doesn't implement <i>getpgrp(2)</i>.  If PID is omitted, returns the process
group of the current process.  Note that the POSIX version of
<a href="#getpgrp-PID">getpgrp</a> does not accept a PID argument, so only
<code class="inline"><span class="w">PID</span>==<span class="n">0</span></code>
 is truly portable.</p>
<p>Portability issues: <a href="perlport.html#getpgrp">getpgrp in perlport</a>.</p>
</li>
<li><a name="getppid"></a><b>getppid
  </b>
<p>Returns the process id of the parent process.</p>
<p>Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work
around non-POSIX thread semantics the minority of Linux systems (and
Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation
has since been removed.  See the documentation for <a href="perlvar.html#%24%24">$$</a> for
details.</p>
<p>Portability issues: <a href="perlport.html#getppid">getppid in perlport</a>.</p>
</li>
<li><a name="getpriority-WHICH%2cWHO"></a><b>getpriority WHICH,WHO
  </b>
<p>Returns the current priority for a process, a process group, or a user.
(See <i>getpriority(2)</i>.)  Will raise a fatal exception if used on a
machine that doesn't implement <i>getpriority(2)</i>.</p>
<p>Portability issues: <a href="perlport.html#getpriority">getpriority in perlport</a>.</p>
</li>
<li><a name="getpwnam-NAME"></a><b>getpwnam NAME
    
    
    
     
     
  </b>
</li>
<li><a name="getgrnam-NAME"></a><b>getgrnam NAME</b>
</li>
<li><a name="gethostbyname-NAME"></a><b>gethostbyname NAME</b>
</li>
<li><a name="getnetbyname-NAME"></a><b>getnetbyname NAME</b>
</li>
<li><a name="getprotobyname-NAME"></a><b>getprotobyname NAME</b>
</li>
<li><a name="getpwuid-UID"></a><b>getpwuid UID</b>
</li>
<li><a name="getgrgid-GID"></a><b>getgrgid GID</b>
</li>
<li><a name="getservbyname-NAME%2cPROTO"></a><b>getservbyname NAME,PROTO</b>
</li>
<li><a name="gethostbyaddr-ADDR%2cADDRTYPE"></a><b>gethostbyaddr ADDR,ADDRTYPE</b>
</li>
<li><a name="getnetbyaddr-ADDR%2cADDRTYPE"></a><b>getnetbyaddr ADDR,ADDRTYPE</b>
</li>
<li><a name="getprotobynumber-NUMBER"></a><b>getprotobynumber NUMBER</b>
</li>
<li><a name="getservbyport-PORT%2cPROTO"></a><b>getservbyport PORT,PROTO</b>
</li>
<li><a name="getpwent"></a><b>getpwent</b>
</li>
<li><a name="getgrent"></a><b>getgrent</b>
</li>
<li><a name="gethostent"></a><b>gethostent</b>
</li>
<li><a name="getnetent"></a><b>getnetent</b>
</li>
<li><a name="getprotoent"></a><b>getprotoent</b>
</li>
<li><a name="getservent"></a><b>getservent</b>
</li>
<li><a name="setpwent"></a><b>setpwent</b>
</li>
<li><a name="setgrent"></a><b>setgrent</b>
</li>
<li><a name="sethostent-STAYOPEN"></a><b>sethostent STAYOPEN</b>
</li>
<li><a name="setnetent-STAYOPEN"></a><b>setnetent STAYOPEN</b>
</li>
<li><a name="setprotoent-STAYOPEN"></a><b>setprotoent STAYOPEN</b>
</li>
<li><a name="setservent-STAYOPEN"></a><b>setservent STAYOPEN</b>
</li>
<li><a name="endpwent"></a><b>endpwent</b>
</li>
<li><a name="endgrent"></a><b>endgrent</b>
</li>
<li><a name="endhostent"></a><b>endhostent</b>
</li>
<li><a name="endnetent"></a><b>endnetent</b>
</li>
<li><a name="endprotoent"></a><b>endprotoent</b>
</li>
<li><a name="endservent"></a><b>endservent</b>
<p>These routines are the same as their counterparts in the
system C library.  In list context, the return values from the
various get routines are as follows:</p>
<pre class="verbatim"><ol><li> <span class="c">#    0        1          2           3         4</span></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span> <span class="i">$name</span><span class="cm">,</span>   <span class="i">$passwd</span><span class="cm">,</span>   <span class="i">$gid</span><span class="cm">,</span>       <span class="i">$members</span>  <span class="s">)</span> = <span class="w">getgr</span>*</li><li> <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span> <span class="i">$name</span><span class="cm">,</span>   <span class="i">$aliases</span><span class="cm">,</span>  <span class="i">$addrtype</span><span class="cm">,</span>  <span class="i">$net</span>      <span class="s">)</span> = <span class="w">getnet</span>*</li><li> <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span> <span class="i">$name</span><span class="cm">,</span>   <span class="i">$aliases</span><span class="cm">,</span>  <span class="i">$port</span><span class="cm">,</span>      <span class="i">$proto</span>    <span class="s">)</span> = <span class="w">getserv</span>*</li><li> <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span> <span class="i">$name</span><span class="cm">,</span>   <span class="i">$aliases</span><span class="cm">,</span>  <span class="i">$proto</span>                <span class="s">)</span> = <span class="w">getproto</span>*</li><li> <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span> <span class="i">$name</span><span class="cm">,</span>   <span class="i">$aliases</span><span class="cm">,</span>  <span class="i">$addrtype</span><span class="cm">,</span>  <span class="i">$length</span><span class="cm">,</span>  <span class="i">@addrs</span> <span class="s">)</span> = <span class="w">gethost</span>*</li><li> <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span> <span class="i">$name</span><span class="cm">,</span>   <span class="i">$passwd</span><span class="cm">,</span>   <span class="i">$uid</span><span class="cm">,</span>       <span class="i">$gid</span><span class="cm">,</span>     <span class="i">$quota</span><span class="cm">,</span></li><li>    <span class="i">$comment</span><span class="cm">,</span>  <span class="i">$gcos</span><span class="cm">,</span>     <span class="i">$dir</span><span class="cm">,</span>       <span class="i">$shell</span><span class="cm">,</span>   <span class="i">$expire</span> <span class="s">)</span> = <span class="w">getpw</span>*</li><li> <span class="c">#    5        6          7           8         9</span></li></ol></pre><p>(If the entry doesn't exist, the return value is a single meaningless true
value.)</p>
<p>The exact meaning of the $gcos field varies but it usually contains
the real name of the user (as opposed to the login name) and other
information pertaining to the user.  Beware, however, that in many
system users are able to change this information and therefore it
cannot be trusted and therefore the $gcos is tainted (see
<a href="perlsec.html">perlsec</a>).  The $passwd and $shell, user's encrypted password and
login shell, are also tainted, for the same reason.</p>
<p>In scalar context, you get the name, unless the function was a
lookup by name, in which case you get the other thing, whatever it is.
(If the entry doesn't exist you get the undefined value.)  For example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$uid</span>   = <a class="l_k" href="functions/getpwnam.html">getpwnam</a><span class="s">(</span><span class="i">$name</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$name</span>  = <a class="l_k" href="functions/getpwuid.html">getpwuid</a><span class="s">(</span><span class="i">$num</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$name</span>  = <a class="l_k" href="functions/getpwent.html">getpwent</a><span class="s">(</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$gid</span>   = <a class="l_k" href="functions/getgrnam.html">getgrnam</a><span class="s">(</span><span class="i">$name</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$name</span>  = <a class="l_k" href="functions/getgrgid.html">getgrgid</a><span class="s">(</span><span class="i">$num</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$name</span>  = <a class="l_k" href="functions/getgrent.html">getgrent</a><span class="s">(</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="c"># etc.</span></li></ol></pre><p>In <i>getpw*()</i> the fields $quota, $comment, and $expire are special
in that they are unsupported on many systems.  If the
$quota is unsupported, it is an empty scalar.  If it is supported, it
usually encodes the disk quota.  If the $comment field is unsupported,
it is an empty scalar.  If it is supported it usually encodes some
administrative comment about the user.  In some systems the $quota
field may be $change or $age, fields that have to do with password
aging.  In some systems the $comment field may be $class.  The $expire
field, if present, encodes the expiration period of the account or the
password.  For the availability and the exact meaning of these fields
in your system, please consult <i>getpwnam(3)</i> and your system's
<i>pwd.h</i> file.  You can also find out from within Perl what your
$quota and $comment fields mean and whether you have the $expire field
by using the <a href="Config.html">Config </a> module and the values <code class="inline"><span class="w">d_pwquota</span></code>
, <code class="inline"><span class="w">d_pwage</span></code>
,
<code class="inline"><span class="w">d_pwchange</span></code>
, <code class="inline"><span class="w">d_pwcomment</span></code>
, and <code class="inline"><span class="w">d_pwexpire</span></code>
.  Shadow password
files are supported only if your vendor has implemented them in the
intuitive fashion that calling the regular C library routines gets the
shadow versions if you're running under privilege or if there exists
the <i>shadow(3)</i> functions as found in System V (this includes Solaris
and Linux).  Those systems that implement a proprietary shadow password
facility are unlikely to be supported.</p>
<p>The $members value returned by <i>getgr*()</i> is a space-separated list of
the login names of the members of the group.</p>
<p>For the <i>gethost*()</i> functions, if the <code class="inline"><span class="w">h_errno</span></code>
 variable is supported in
C, it will be returned to you via <a href="perlvar.html#%24%3f">$? </a> if the function
call fails.  The
<code class="inline"><span class="i">@addrs</span></code>
 value returned by a successful call is a list of raw
addresses returned by the corresponding library call.  In the
Internet domain, each address is four bytes long; you can unpack it
by saying something like:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$w</span><span class="cm">,</span><span class="i">$x</span><span class="cm">,</span><span class="i">$y</span><span class="cm">,</span><span class="i">$z</span><span class="s">)</span> = <a class="l_k" href="functions/unpack.html">unpack</a><span class="s">(</span><span class="q">&#39;W4&#39;</span><span class="cm">,</span><span class="i">$addr</span>[<span class="n">0</span>]<span class="s">)</span><span class="sc">;</span></li></ol></pre><p>The Socket library makes this slightly easier:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$iaddr</span> = <span class="i">inet_aton</span><span class="s">(</span><span class="q">&quot;127.1&quot;</span><span class="s">)</span><span class="sc">;</span> <span class="c"># or whatever address</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$name</span>  = <a class="l_k" href="functions/gethostbyaddr.html">gethostbyaddr</a><span class="s">(</span><span class="i">$iaddr</span><span class="cm">,</span> <span class="w">AF_INET</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>    <span class="c"># or going the other way</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$straddr</span> = <span class="i">inet_ntoa</span><span class="s">(</span><span class="i">$iaddr</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>In the opposite way, to resolve a hostname to the IP address
you can write this:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$packed_ip</span> = <a class="l_k" href="functions/gethostbyname.html">gethostbyname</a><span class="s">(</span><span class="q">&quot;www.perl.org&quot;</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$ip_address</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span><a class="l_k" href="functions/defined.html">defined</a> <span class="i">$packed_ip</span><span class="s">)</span> <span class="s">{</span></li><li>        <span class="i">$ip_address</span> = <span class="i">inet_ntoa</span><span class="s">(</span><span class="i">$packed_ip</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>Make sure <a href="#gethostbyname-NAME">gethostbyname</a> is called in SCALAR
context and that its return value is checked for definedness.</p>
<p>The <a href="#getprotobynumber-NUMBER">getprotobynumber</a> function, even
though it only takes one argument, has the precedence of a list
operator, so beware:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/getprotobynumber.html">getprotobynumber</a> <span class="i">$number</span> <a class="l_k" href="functions/eq.html">eq</a> <span class="q">&#39;icmp&#39;</span>   <span class="c"># WRONG</span></li><li>    <a class="l_k" href="functions/getprotobynumber.html">getprotobynumber</a><span class="s">(</span><span class="i">$number</span> <a class="l_k" href="functions/eq.html">eq</a> <span class="q">&#39;icmp&#39;</span><span class="s">)</span>  <span class="c"># actually means this</span></li><li>    <a class="l_k" href="functions/getprotobynumber.html">getprotobynumber</a><span class="s">(</span><span class="i">$number</span><span class="s">)</span> <a class="l_k" href="functions/eq.html">eq</a> <span class="q">&#39;icmp&#39;</span>  <span class="c"># better this way</span></li></ol></pre><p>If you get tired of remembering which element of the return list
contains which return value, by-name interfaces are provided in standard
modules: <a href="File/stat.html">File::stat </a>, <a href="Net/hostent.html">Net::hostent </a>,
<a href="Net/netent.html">Net::netent </a>, <a href="Net/protoent.html">Net::protoent </a>,
<a href="Net/servent.html">Net::servent </a>, <a href="Time/gmtime.html">Time::gmtime </a>,
<a href="Time/localtime.html">Time::localtime </a>, and
<a href="User/grent.html">User::grent </a>.  These override the normal built-ins,
supplying versions that return objects with the appropriate names for
each field.  For example:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">File::stat</span><span class="sc">;</span></li><li>   <a class="l_k" href="functions/use.html">use</a> <span class="w">User::pwent</span><span class="sc">;</span></li><li>   <a class="l_k" href="functions/my.html">my</a> <span class="i">$is_his</span> = <span class="s">(</span><a class="l_k" href="functions/stat.html">stat</a><span class="s">(</span><span class="i">$filename</span><span class="s">)</span><span class="i">-&gt;uid</span> == <span class="i">pwent</span><span class="s">(</span><span class="i">$whoever</span><span class="s">)</span><span class="i">-&gt;uid</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Even though it looks as though they're the same method calls (uid),
they aren't, because a <code class="inline"><span class="w">File::stat</span></code>
 object is different from
a <code class="inline"><span class="w">User::pwent</span></code>
 object.</p>
<p>Portability issues: <a href="perlport.html#getpwnam">getpwnam in perlport</a> to <a href="perlport.html#endservent">endservent in perlport</a>.</p>
</li>
<li><a name="getsockname-SOCKET"></a><b>getsockname SOCKET
</b>
<p>Returns the packed sockaddr address of this end of the SOCKET connection,
in case you don't know the address because you have several different
IPs that the connection might have come in on.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$mysockaddr</span> = <a class="l_k" href="functions/getsockname.html">getsockname</a><span class="s">(</span><span class="i">$sock</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$port</span><span class="cm">,</span> <span class="i">$myaddr</span><span class="s">)</span> = <span class="i">sockaddr_in</span><span class="s">(</span><span class="i">$mysockaddr</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/printf.html">printf</a> <span class="q">&quot;Connect to %s [%s]\n&quot;</span><span class="cm">,</span></li><li>       <a class="l_k" href="functions/scalar.html">scalar</a> <a class="l_k" href="functions/gethostbyaddr.html">gethostbyaddr</a><span class="s">(</span><span class="i">$myaddr</span><span class="cm">,</span> <span class="w">AF_INET</span><span class="s">)</span><span class="cm">,</span></li><li>       <span class="i">inet_ntoa</span><span class="s">(</span><span class="i">$myaddr</span><span class="s">)</span><span class="sc">;</span></li></ol></pre></li>
<li><a name="getsockopt-SOCKET%2cLEVEL%2cOPTNAME"></a><b>getsockopt SOCKET,LEVEL,OPTNAME
</b>
<p>Queries the option named OPTNAME associated with SOCKET at a given LEVEL.
Options may exist at multiple protocol levels depending on the socket
type, but at least the uppermost socket level SOL_SOCKET (defined in the
<a href="Socket.html">Socket </a> module) will exist.  To query options at another
level the protocol number of the appropriate protocol controlling the
option should be supplied.  For example, to indicate that an option is
to be interpreted by the TCP protocol, LEVEL should be set to the
protocol number of TCP, which you can get using
<a href="#getprotobyname-NAME">getprotobyname</a>.</p>
<p>The function returns a packed string representing the requested socket
option, or <a href="#undef-EXPR">undef</a> on error, with the reason for the
error placed in <a href="perlvar.html#%24!">$! </a>.  Just what is in the packed string
depends on LEVEL and OPTNAME; consult <i>getsockopt(2)</i> for details.  A
common case is that the option is an integer, in which case the result
is a packed integer, which you can decode using
<a href="#unpack-TEMPLATE%2cEXPR">unpack</a> with the <code class="inline"><span class="w">i</span></code>
 (or <code class="inline"><span class="w">I</span></code>
) format.</p>
<p>Here's an example to test whether Nagle's algorithm is enabled on a socket:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Socket</span> <span class="q">qw(:all)</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/defined.html">defined</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$tcp</span> = <a class="l_k" href="functions/getprotobyname.html">getprotobyname</a><span class="s">(</span><span class="q">&quot;tcp&quot;</span><span class="s">)</span><span class="s">)</span></li><li>        <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Could not determine the protocol number for tcp&quot;</span><span class="sc">;</span></li><li>    <span class="c"># my $tcp = IPPROTO_TCP; # Alternative</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$packed</span> = <a class="l_k" href="functions/getsockopt.html">getsockopt</a><span class="s">(</span><span class="i">$socket</span><span class="cm">,</span> <span class="i">$tcp</span><span class="cm">,</span> <span class="w">TCP_NODELAY</span><span class="s">)</span></li><li>        <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;getsockopt TCP_NODELAY: $!&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$nodelay</span> = <a class="l_k" href="functions/unpack.html">unpack</a><span class="s">(</span><span class="q">&quot;I&quot;</span><span class="cm">,</span> <span class="i">$packed</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;Nagle&#39;s algorithm is turned &quot;</span><span class="cm">,</span></li><li>           <span class="i">$nodelay</span> ? <span class="q">&quot;off\n&quot;</span> <span class="co">:</span> <span class="q">&quot;on\n&quot;</span><span class="sc">;</span></li></ol></pre><p>Portability issues: <a href="perlport.html#getsockopt">getsockopt in perlport</a>.</p>
</li>
<li><a name="glob-EXPR"></a><b>glob EXPR
   </b>
</li>
<li><a name="glob"></a><b>glob</b>
<p>In list context, returns a (possibly empty) list of filename expansions on
the value of EXPR such as the standard Unix shell <i>/bin/csh</i> would do.  In
scalar context, glob iterates through such filename expansions, returning
undef when the list is exhausted.  This is the internal function
implementing the <code class="inline"><span class="q">&lt;*.c&gt;</span></code>
 operator, but you can use it directly.  If
EXPR is omitted, <a href="perlvar.html#%24_">$_ </a> is used.  The <code class="inline"><span class="q">&lt;*.c&gt;</span></code>
 operator
is discussed in more detail in <a href="perlop.html#I%2fO-Operators">I/O Operators in perlop</a>.</p>
<p>Note that <a href="#glob-EXPR">glob</a> splits its arguments on whitespace and
treats
each segment as separate pattern.  As such, <code class="inline"><a class="l_k" href="functions/glob.html">glob</a><span class="s">(</span><span class="q">&quot;*.c *.h&quot;</span><span class="s">)</span></code>

matches all files with a <i>.c</i> or <i>.h</i> extension.  The expression
<code class="inline"><a class="l_k" href="functions/glob.html">glob</a><span class="s">(</span><span class="q">&quot;.* *&quot;</span><span class="s">)</span></code>
 matches all files in the current working directory.
If you want to glob filenames that might contain whitespace, you'll
have to use extra quotes around the spacey filename to protect it.
For example, to glob filenames that have an <code class="inline"><span class="w">e</span></code>
 followed by a space
followed by an <code class="inline"><span class="w">f</span></code>
, use one of:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@spacies</span> = <span class="q">&lt;&quot;*e f*&quot;&gt;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@spacies</span> = <a class="l_k" href="functions/glob.html">glob</a> <span class="q">&#39;&quot;*e f*&quot;&#39;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@spacies</span> = <a class="l_k" href="functions/glob.html">glob</a> <span class="q">q(&quot;*e f*&quot;)</span><span class="sc">;</span></li></ol></pre><p>If you had to get a variable through, you could do this:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@spacies</span> = <a class="l_k" href="functions/glob.html">glob</a> <span class="q">&quot;&#39;*${var}e f*&#39;&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@spacies</span> = <a class="l_k" href="functions/glob.html">glob</a> <span class="q">qq(&quot;*${var}e f*&quot;)</span><span class="sc">;</span></li></ol></pre><p>If non-empty braces are the only wildcard characters used in the
<a href="#glob-EXPR">glob</a>, no filenames are matched, but potentially many
strings are returned.  For example, this produces nine strings, one for
each pairing of fruits and colors:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@many</span> = <a class="l_k" href="functions/glob.html">glob</a> <span class="q">&quot;{apple,tomato,cherry}={green,yellow,red}&quot;</span><span class="sc">;</span></li></ol></pre><p>This operator is implemented using the standard <code class="inline"><span class="w">File::Glob</span></code>
 extension.
See <a href="File/Glob.html">File::Glob</a> for details, including
<a href="File/Glob.html#bsd_glob">bsd_glob </a>, which does not treat whitespace
as a pattern separator.</p>
<p>Portability issues: <a href="perlport.html#glob">glob in perlport</a>.</p>
</li>
<li><a name="gmtime-EXPR"></a><b>gmtime EXPR
  </b>
</li>
<li><a name="gmtime"></a><b>gmtime</b>
<p>Works just like <a href="#localtime-EXPR">localtime</a> but the returned values
are localized for the standard Greenwich time zone.</p>
<p>Note: When called in list context, $isdst, the last value
returned by gmtime, is always <code class="inline"><span class="n">0</span></code>
.  There is no
Daylight Saving Time in GMT.</p>
<p>Portability issues: <a href="perlport.html#gmtime">gmtime in perlport</a>.</p>
</li>
<li><a name="goto-LABEL"></a><b>goto LABEL
  </b>
</li>
<li><a name="goto-EXPR"></a><b>goto EXPR</b>
</li>
<li><a name="goto-%26NAME"></a><b>goto &amp;NAME</b>
<p>The <code class="inline"><a class="l_k" href="functions/goto.html">goto</a> <span class="j">LABEL</span></code>
 form finds the statement labeled with LABEL and
resumes execution there.  It can't be used to get out of a block or
subroutine given to <a href="#sort-SUBNAME-LIST">sort</a>.  It can be used to go
almost anywhere else within the dynamic scope, including out of
subroutines, but it's usually better to use some other construct such as
<a href="#last-LABEL">last</a> or <a href="#die-LIST">die</a>.  The author of Perl has
never felt the need to use this form of <a href="#goto-LABEL">goto</a> (in Perl,
that is; C is another matter).  (The difference is that C does not offer
named loops combined with loop control.  Perl does, and this replaces
most structured uses of <a href="#goto-LABEL">goto</a> in other languages.)</p>
<p>The <code class="inline"><a class="l_k" href="functions/goto.html">goto</a> <span class="j">EXPR</span></code>
 form expects to evaluate <code class="inline"><span class="w">EXPR</span></code>
 to a code reference or
a label name.  If it evaluates to a code reference, it will be handled
like <code class="inline"><a class="l_k" href="functions/goto.html">goto</a> <span class="i">&amp;NAME</span></code>
, below.  This is especially useful for implementing
tail recursion via <code class="inline"><a class="l_k" href="functions/goto.html">goto</a> <span class="j">__SUB__</span></code>
.</p>
<p>If the expression evaluates to a label name, its scope will be resolved
dynamically.  This allows for computed <a href="#goto-LABEL">goto</a>s per
FORTRAN, but isn't necessarily recommended if you're optimizing for
maintainability:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/goto.html">goto</a> <span class="s">(</span><span class="q">&quot;FOO&quot;</span><span class="cm">,</span> <span class="q">&quot;BAR&quot;</span><span class="cm">,</span> <span class="q">&quot;GLARCH&quot;</span><span class="s">)</span>[<span class="i">$i</span>]<span class="sc">;</span></li></ol></pre><p>As shown in this example, <code class="inline"><a class="l_k" href="functions/goto.html">goto</a> <span class="j">EXPR</span></code>
 is exempt from the "looks like a
function" rule.  A pair of parentheses following it does not (necessarily)
delimit its argument.  <code class="inline"><a class="l_k" href="functions/goto.html">goto("NE")."XT"</a></code> is equivalent to <code class="inline"><a class="l_k" href="functions/goto.html">goto</a> <span class="j">NEXT</span></code>
.
Also, unlike most named operators, this has the same precedence as
assignment.</p>
<p>Use of <code class="inline"><a class="l_k" href="functions/goto.html">goto</a> <span class="j">LABEL</span></code>
 or <code class="inline"><a class="l_k" href="functions/goto.html">goto</a> <span class="j">EXPR</span></code>
 to jump into a construct is
deprecated and will issue a warning.  Even then, it may not be used to
go into any construct that requires initialization, such as a
subroutine or a <code class="inline">foreach</code>
 loop.  It also can't be used to go into a
construct that is optimized away.</p>
<p>The <code class="inline"><a class="l_k" href="functions/goto.html">goto</a> <span class="i">&amp;NAME</span></code>
 form is quite different from the other forms of
<a href="#goto-LABEL">goto</a>.  In fact, it isn't a goto in the normal sense at
all, and doesn't have the stigma associated with other gotos.  Instead,
it exits the current subroutine (losing any changes set by
<a href="#local-EXPR">local</a>) and immediately calls in its place the named
subroutine using the current value of <a href="perlvar.html#%40_">@_ </a>.  This is used
by <code class="inline">AUTOLOAD</code>
 subroutines that wish to load another subroutine and then
pretend that the other subroutine had been called in the first place
(except that any modifications to <a href="perlvar.html#%40_">@_ </a> in the current
subroutine are propagated to the other subroutine.) After the
<a href="#goto-LABEL">goto</a>, not even <a href="#caller-EXPR">caller</a> will be able
to tell that this routine was called first.</p>
<p>NAME needn't be the name of a subroutine; it can be a scalar variable
containing a code reference or a block that evaluates to a code
reference.</p>
</li>
<li><a name="grep-BLOCK-LIST"></a><b>grep BLOCK LIST
</b>
</li>
<li><a name="grep-EXPR%2cLIST"></a><b>grep EXPR,LIST</b>
<p>This is similar in spirit to, but not the same as, <i>grep(1)</i> and its
relatives.  In particular, it is not limited to using regular expressions.</p>
<p>Evaluates the BLOCK or EXPR for each element of LIST (locally setting
<a href="perlvar.html#%24_">$_ </a> to each element) and returns the list value
consisting of those
elements for which the expression evaluated to true.  In scalar
context, returns the number of times the expression was true.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@foo</span> = <a class="l_k" href="functions/grep.html">grep</a><span class="s">(</span>!<span class="q">/^#/</span><span class="cm">,</span> <span class="i">@bar</span><span class="s">)</span><span class="sc">;</span>    <span class="c"># weed out comments</span></li></ol></pre><p>or equivalently,</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@foo</span> = <a class="l_k" href="functions/grep.html">grep</a> <span class="s">{</span>!<span class="q">/^#/</span><span class="s">}</span> <span class="i">@bar</span><span class="sc">;</span>    <span class="c"># weed out comments</span></li></ol></pre><p>Note that <a href="perlvar.html#%24_">$_ </a> is an alias to the list value, so it can
be used to
modify the elements of the LIST.  While this is useful and supported,
it can cause bizarre results if the elements of LIST are not variables.
Similarly, grep returns aliases into the original list, much as a for
loop's index variable aliases the list elements.  That is, modifying an
element of a list returned by grep (for example, in a <code class="inline">foreach</code>
,
<a href="#map-BLOCK-LIST">map</a> or another <a href="#grep-BLOCK-LIST">grep</a>)
actually modifies the element in the original list.
This is usually something to be avoided when writing clear code.</p>
<p>See also <a href="#map-BLOCK-LIST">map</a> for a list composed of the results of
the BLOCK or EXPR.</p>
</li>
<li><a name="hex-EXPR"></a><b>hex EXPR
 </b>
</li>
<li><a name="hex"></a><b>hex</b>
<p>Interprets EXPR as a hex string and returns the corresponding numeric value.
If EXPR is omitted, uses <a href="perlvar.html#%24_">$_ </a>.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/print.html">print</a> <a class="l_k" href="functions/hex.html">hex</a> <span class="q">&#39;0xAf&#39;</span><span class="sc">;</span> <span class="c"># prints &#39;175&#39;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <a class="l_k" href="functions/hex.html">hex</a> <span class="q">&#39;aF&#39;</span><span class="sc">;</span>   <span class="c"># same</span></li><li>    <span class="i">$valid_input</span> =~ <span class="q">/\A(?:0?[xX])?(?:_?[0-9a-fA-F])*\z/</span></li></ol></pre><p>A hex string consists of hex digits and an optional <code class="inline"><span class="n">0</span>x</code>
 or <code class="inline"><span class="w">x</span></code>
 prefix.
Each hex digit may be preceded by a single underscore, which will be ignored.
Any other character triggers a warning and causes the rest of the string
to be ignored (even leading whitespace, unlike <a href="#oct-EXPR">oct</a>).
Only integers can be represented, and integer overflow triggers a warning.</p>
<p>To convert strings that might start with any of <code class="inline"><span class="n">0</span></code>
, <code class="inline"><span class="n">0</span>x</code>
, or <code class="inline">0b</code>,
see <a href="#oct-EXPR">oct</a>.  To present something as hex, look into
<a href="#printf-FILEHANDLE-FORMAT%2c-LIST">printf</a>,
<a href="#sprintf-FORMAT%2c-LIST">sprintf</a>, and
<a href="#unpack-TEMPLATE%2cEXPR">unpack</a>.</p>
</li>
<li><a name="import-LIST"></a><b>import LIST
</b>
<p>There is no builtin <a href="#import-LIST">import</a> function.  It is just an
ordinary method (subroutine) defined (or inherited) by modules that wish
to export names to another module.  The
<a href="#use-Module-VERSION-LIST">use</a> function calls the
<a href="#import-LIST">import</a> method for the package used.  See also
<a href="#use-Module-VERSION-LIST">use</a>, <a href="perlmod.html">perlmod</a>, and <a href="Exporter.html">Exporter</a>.</p>
</li>
<li><a name="index-STR%2cSUBSTR%2cPOSITION"></a><b>index STR,SUBSTR,POSITION
  </b>
</li>
<li><a name="index-STR%2cSUBSTR"></a><b>index STR,SUBSTR</b>
<p>The index function searches for one string within another, but without
the wildcard-like behavior of a full regular-expression pattern match.
It returns the position of the first occurrence of SUBSTR in STR at
or after POSITION.  If POSITION is omitted, starts searching from the
beginning of the string.  POSITION before the beginning of the string
or after its end is treated as if it were the beginning or the end,
respectively.  POSITION and the return value are based at zero.
If the substring is not found, <a href="#index-STR%2cSUBSTR%2cPOSITION">index</a>
returns -1.</p>
</li>
<li><a name="int-EXPR"></a><b>int EXPR
    </b>
</li>
<li><a name="int"></a><b>int</b>
<p>Returns the integer portion of EXPR.  If EXPR is omitted, uses
<a href="perlvar.html#%24_">$_ </a>.
You should not use this function for rounding: one because it truncates
towards <code class="inline"><span class="n">0</span></code>
, and two because machine representations of floating-point
numbers can sometimes produce counterintuitive results.  For example,
<code class="inline"><a class="l_k" href="functions/int.html">int(-6.725/0.025)</a></code> produces -268 rather than the correct -269; that's
because it's really more like -268.99999999999994315658 instead.  Usually,
the <a href="#sprintf-FORMAT%2c-LIST">sprintf</a>,
<a href="#printf-FILEHANDLE-FORMAT%2c-LIST">printf</a>, or the
<a href="POSIX.html#floor">POSIX::floor </a> and <a href="POSIX.html#ceil">POSIX::ceil </a>
functions will serve you better than will <a href="#int-EXPR">int</a>.</p>
</li>
<li><a name="ioctl-FILEHANDLE%2cFUNCTION%2cSCALAR"></a><b>ioctl FILEHANDLE,FUNCTION,SCALAR
</b>
<p>Implements the <i>ioctl(2)</i> function.  You'll probably first have to say</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/require.html">require</a> <span class="q">&quot;sys/ioctl.ph&quot;</span><span class="sc">;</span>  <span class="c"># probably in</span></li><li>                             <span class="c"># $Config{archlib}/sys/ioctl.ph</span></li></ol></pre><p>to get the correct function definitions.  If <i>sys/ioctl.ph</i> doesn't
exist or doesn't have the correct definitions you'll have to roll your
own, based on your C header files such as <i>&lt;sys/ioctl.h&gt;</i>.
(There is a Perl script called <b>h2ph</b> that comes with the Perl kit that
may help you in this, but it's nontrivial.)  SCALAR will be read and/or
written depending on the FUNCTION; a C pointer to the string value of SCALAR
will be passed as the third argument of the actual
<a href="#ioctl-FILEHANDLE%2cFUNCTION%2cSCALAR">ioctl</a> call.  (If SCALAR
has no string value but does have a numeric value, that value will be
passed rather than a pointer to the string value.  To guarantee this to be
true, add a <code class="inline"><span class="n">0</span></code>
 to the scalar before using it.)  The
<a href="#pack-TEMPLATE%2cLIST">pack</a> and <a href="#unpack-TEMPLATE%2cEXPR">unpack</a>
functions may be needed to manipulate the values of structures used by
<a href="#ioctl-FILEHANDLE%2cFUNCTION%2cSCALAR">ioctl</a>.</p>
<p>The return value of <a href="#ioctl-FILEHANDLE%2cFUNCTION%2cSCALAR">ioctl</a> (and
<a href="#fcntl-FILEHANDLE%2cFUNCTION%2cSCALAR">fcntl</a>) is as follows:</p>
<pre class="verbatim"><ol><li>    if OS returns:      then Perl returns:</li><li>        -1               undefined value</li><li>         0              string "0 but true"</li><li>    anything else           that number</li></ol></pre><p>Thus Perl returns true on success and false on failure, yet you can
still easily determine the actual value returned by the operating
system:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$retval</span> = <a class="l_k" href="functions/ioctl.html">ioctl</a><span class="s">(</span>...<span class="s">)</span> || <span class="n">-1</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/printf.html">printf</a> <span class="q">&quot;System returned %d\n&quot;</span><span class="cm">,</span> <span class="i">$retval</span><span class="sc">;</span></li></ol></pre><p>The special string <code class="inline"><span class="q">&quot;0 but true&quot;</span></code>
 is exempt from
<a href="perldiag.html#Argument-%22%25s%22-isn't-numeric%25s">Argument ... isn&#39;t numeric </a>
<a href="warnings.html">warnings</a> on improper numeric conversions.</p>
<p>Portability issues: <a href="perlport.html#ioctl">ioctl in perlport</a>.</p>
</li>
<li><a name="join-EXPR%2cLIST"></a><b>join EXPR,LIST
</b>
<p>Joins the separate strings of LIST into a single string with fields
separated by the value of EXPR, and returns that new string.  Example:</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/my.html">my</a> <span class="i">$rec</span> = <a class="l_k" href="functions/join.html">join</a><span class="s">(</span><span class="q">&#39;:&#39;</span><span class="cm">,</span> <span class="i">$login</span><span class="cm">,</span><span class="i">$passwd</span><span class="cm">,</span><span class="i">$uid</span><span class="cm">,</span><span class="i">$gid</span><span class="cm">,</span><span class="i">$gcos</span><span class="cm">,</span><span class="i">$home</span><span class="cm">,</span><span class="i">$shell</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Beware that unlike <a href="#split-%2fPATTERN%2f%2cEXPR%2cLIMIT">split</a>,
<a href="#join-EXPR%2cLIST">join</a> doesn't take a pattern as its first argument.
Compare <a href="#split-%2fPATTERN%2f%2cEXPR%2cLIMIT">split</a>.</p>
</li>
<li><a name="keys-HASH"></a><b>keys HASH
 </b>
</li>
<li><a name="keys-ARRAY"></a><b>keys ARRAY</b>
<p>Called in list context, returns a list consisting of all the keys of the
named hash, or in Perl 5.12 or later only, the indices of an array.  Perl
releases prior to 5.12 will produce a syntax error if you try to use an
array argument.  In scalar context, returns the number of keys or indices.</p>
<p>Hash entries are returned in an apparently random order.  The actual random
order is specific to a given hash; the exact same series of operations
on two hashes may result in a different order for each hash.  Any insertion
into the hash may change the order, as will any deletion, with the exception
that the most recent key returned by <a href="#each-HASH">each</a> or
<a href="#keys-HASH">keys</a> may be deleted without changing the order.  So
long as a given hash is unmodified you may rely on
<a href="#keys-HASH">keys</a>, <a href="#values-HASH">values</a> and <a href="#each-HASH">each</a> to repeatedly return the same order
as each other.  See <a href="perlsec.html#Algorithmic-Complexity-Attacks">Algorithmic Complexity Attacks in perlsec</a> for
details on why hash order is randomized.  Aside from the guarantees
provided here the exact details of Perl's hash algorithm and the hash
traversal order are subject to change in any release of Perl.  Tied hashes
may behave differently to Perl's hashes with respect to changes in order on
insertion and deletion of items.</p>
<p>As a side effect, calling <a href="#keys-HASH">keys</a> resets the internal
iterator of the HASH or ARRAY (see <a href="#each-HASH">each</a>).  In
particular, calling <a href="#keys-HASH">keys</a> in void context resets the
iterator with no other overhead.</p>
<p>Here is yet another way to print your environment:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@keys</span> = <a class="l_k" href="functions/keys.html">keys</a> <span class="i">%ENV</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@values</span> = <a class="l_k" href="functions/values.html">values</a> <span class="i">%ENV</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/while.html">while</a> <span class="s">(</span><span class="i">@keys</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <a class="l_k" href="functions/pop.html">pop</a><span class="s">(</span><span class="i">@keys</span><span class="s">)</span><span class="cm">,</span> <span class="q">&#39;=&#39;</span><span class="cm">,</span> <a class="l_k" href="functions/pop.html">pop</a><span class="s">(</span><span class="i">@values</span><span class="s">)</span><span class="cm">,</span> <span class="q">&quot;\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>or how about sorted by key:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/foreach.html">foreach</a> <a class="l_k" href="functions/my.html">my</a> <span class="i">$key</span> <span class="s">(</span><a class="l_k" href="functions/sort.html">sort</a><span class="s">(</span><a class="l_k" href="functions/keys.html">keys</a> <span class="i">%ENV</span><span class="s">)</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="i">$key</span><span class="cm">,</span> <span class="q">&#39;=&#39;</span><span class="cm">,</span> <span class="i">$ENV</span>{<span class="i">$key</span>}<span class="cm">,</span> <span class="q">&quot;\n&quot;</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>The returned values are copies of the original keys in the hash, so
modifying them will not affect the original hash.  Compare
<a href="#values-HASH">values</a>.</p>
<p>To sort a hash by value, you'll need to use a
<a href="#sort-SUBNAME-LIST">sort</a> function.  Here's a descending numeric
sort of a hash by its values:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/foreach.html">foreach</a> <a class="l_k" href="functions/my.html">my</a> <span class="i">$key</span> <span class="s">(</span><a class="l_k" href="functions/sort.html">sort</a> <span class="s">{</span> <span class="i">$hash</span>{<span class="i">$b</span>} &lt;=&gt; <span class="i">$hash</span>{<span class="i">$a</span>} <span class="s">}</span> <a class="l_k" href="functions/keys.html">keys</a> <span class="i">%hash</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/printf.html">printf</a> <span class="q">&quot;%4d %s\n&quot;</span><span class="cm">,</span> <span class="i">$hash</span>{<span class="i">$key</span>}<span class="cm">,</span> <span class="i">$key</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>Used as an lvalue, <a href="#keys-HASH">keys</a> allows you to increase the
number of hash buckets
allocated for the given hash.  This can gain you a measure of efficiency if
you know the hash is going to get big.  (This is similar to pre-extending
an array by assigning a larger number to $#array.)  If you say</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/keys.html">keys</a> <span class="i">%hash</span> = <span class="n">200</span><span class="sc">;</span></li></ol></pre><p>then <code class="inline"><span class="i">%hash</span></code>
 will have at least 200 buckets allocated for it--256 of them,
in fact, since it rounds up to the next power of two.  These
buckets will be retained even if you do <code class="inline"><span class="i">%hash</span> = <span class="s">(</span><span class="s">)</span></code>
, use <code class="inline"><a class="l_k" href="functions/undef.html">undef</a>
<span class="i">%hash</span></code>
 if you want to free the storage while <code class="inline"><span class="i">%hash</span></code>
 is still in scope.
You can't shrink the number of buckets allocated for the hash using
<a href="#keys-HASH">keys</a> in this way (but you needn't worry about doing
this by accident, as trying has no effect).  <code class="inline"><a class="l_k" href="functions/keys.html">keys</a> <span class="i">@array</span></code>
 in an lvalue
context is a syntax error.</p>
<p>Starting with Perl 5.14, an experimental feature allowed
<a href="#keys-HASH">keys</a> to take a scalar expression. This experiment has
been deemed unsuccessful, and was removed as of Perl 5.24.</p>
<p>To avoid confusing would-be users of your code who are running earlier
versions of Perl with mysterious syntax errors, put this sort of thing at
the top of your file to signal that your code will work <i>only</i> on Perls of
a recent vintage:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="n">5.012</span><span class="sc">;</span>	<span class="c"># so keys/values/each work on arrays</span></li></ol></pre><p>See also <a href="#each-HASH">each</a>, <a href="#values-HASH">values</a>, and
<a href="#sort-SUBNAME-LIST">sort</a>.</p>
</li>
<li><a name="kill-SIGNAL%2c-LIST"></a><b>kill SIGNAL, LIST</b>
</li>
<li><a name="kill-SIGNAL"></a><b>kill SIGNAL
 </b>
<p>Sends a signal to a list of processes.  Returns the number of arguments
that were successfully used to signal (which is not necessarily the same
as the number of processes actually killed, e.g. where a process group is
killed).</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$cnt</span> = <a class="l_k" href="functions/kill.html">kill</a> <span class="q">&#39;HUP&#39;</span><span class="cm">,</span> <span class="i">$child1</span><span class="cm">,</span> <span class="i">$child2</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/kill.html">kill</a> <span class="q">&#39;KILL&#39;</span><span class="cm">,</span> <span class="i">@goners</span><span class="sc">;</span></li></ol></pre><p>SIGNAL may be either a signal name (a string) or a signal number.  A signal
name may start with a <code class="inline"><span class="w">SIG</span></code>
 prefix, thus <code class="inline"><span class="w">FOO</span></code>
 and <code class="inline"><span class="w">SIGFOO</span></code>
 refer to the
same signal.  The string form of SIGNAL is recommended for portability because
the same signal may have different numbers in different operating systems.</p>
<p>A list of signal names supported by the current platform can be found in
<code class="inline"><span class="i">$Config</span>{<span class="w">sig_name</span>}</code>
, which is provided by the <a href="Config.html">Config </a>
module.  See <a href="Config.html">Config</a> for more details.</p>
<p>A negative signal name is the same as a negative signal number, killing process
groups instead of processes.  For example, <code class="inline"><a class="l_k" href="functions/kill.html">kill</a> <span class="q">&#39;-KILL&#39;</span><span class="cm">,</span> <span class="i">$pgrp</span></code>
 and
<code class="inline"><a class="l_k" href="functions/kill.html">kill</a> <span class="n">-9</span><span class="cm">,</span> <span class="i">$pgrp</span></code>
 will send <code class="inline"><span class="w">SIGKILL</span></code>
 to
the entire process group specified.  That
means you usually want to use positive not negative signals.</p>
<p>If SIGNAL is either the number 0 or the string <code class="inline"><span class="w">ZERO</span></code>
 (or <code class="inline"><span class="w">SIGZERO</span></code>
),
no signal is sent to the process, but <a href="#kill-SIGNAL%2c-LIST">kill</a>
checks whether it's <i>possible</i> to send a signal to it
(that means, to be brief, that the process is owned by the same user, or we are
the super-user).  This is useful to check that a child process is still
alive (even if only as a zombie) and hasn't changed its UID.  See
<a href="perlport.html">perlport</a> for notes on the portability of this construct.</p>
<p>The behavior of kill when a <i>PROCESS</i> number is zero or negative depends on
the operating system.  For example, on POSIX-conforming systems, zero will
signal the current process group, -1 will signal all processes, and any
other negative PROCESS number will act as a negative signal number and
kill the entire process group specified.</p>
<p>If both the SIGNAL and the PROCESS are negative, the results are undefined.
A warning may be produced in a future version.</p>
<p>See <a href="perlipc.html#Signals">Signals in perlipc</a> for more details.</p>
<p>On some platforms such as Windows where the <i>fork(2)</i> system call is not
available, Perl can be built to emulate <a href="#fork">fork</a> at the
interpreter level.
This emulation has limitations related to kill that have to be considered,
for code running on Windows and in code intended to be portable.</p>
<p>See <a href="perlfork.html">perlfork</a> for more details.</p>
<p>If there is no <i>LIST</i> of processes, no signal is sent, and the return
value is 0.  This form is sometimes used, however, because it causes
tainting checks to be run.  But see
<a href="perlsec.html#Laundering-and-Detecting-Tainted-Data">Laundering and Detecting Tainted Data in perlsec</a>.</p>
<p>Portability issues: <a href="perlport.html#kill">kill in perlport</a>.</p>
</li>
<li><a name="last-LABEL"></a><b>last LABEL
 </b>
</li>
<li><a name="last-EXPR"></a><b>last EXPR</b>
</li>
<li><a name="last"></a><b>last</b>
<p>The <a href="#last-LABEL">last</a> command is like the <code class="inline"><span class="w">break</span></code>
 statement in C
(as used in
loops); it immediately exits the loop in question.  If the LABEL is
omitted, the command refers to the innermost enclosing
loop.  The <code class="inline"><a class="l_k" href="functions/last.html">last</a> <span class="j">EXPR</span></code>
 form, available starting in Perl
5.18.0, allows a label name to be computed at run time,
and is otherwise identical to <code class="inline"><a class="l_k" href="functions/last.html">last</a> <span class="j">LABEL</span></code>
.  The
<a href="#continue-BLOCK">continue</a> block, if any, is not executed:</p>
<pre class="verbatim"><ol><li>    <span class="j">LINE:</span> while <span class="s">(</span><span class="q">&lt;STDIN&gt;</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/last.html">last</a> <span class="j">LINE</span> if <span class="q">/^$/</span><span class="sc">;</span>  <span class="c"># exit when done with header</span></li><li>        <span class="c">#...</span></li><li>    <span class="s">}</span></li></ol></pre><p><a href="#last-LABEL">last</a> cannot be used to exit a block that returns a
value such as <code class="inline"><a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span><span class="s">}</span></code>
, <code class="inline"><a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span><span class="s">}</span></code>
, or <code class="inline"><a class="l_k" href="functions/do.html">do</a> <span class="s">{</span><span class="s">}</span></code>
, and should not be used
to exit a <a href="#grep-BLOCK-LIST">grep</a> or <a href="#map-BLOCK-LIST">map</a>
operation.</p>
<p>Note that a block by itself is semantically identical to a loop
that executes once.  Thus <a href="#last-LABEL">last</a> can be used to effect
an early exit out of such a block.</p>
<p>See also <a href="#continue-BLOCK">continue</a> for an illustration of how
<a href="#last-LABEL">last</a>, <a href="#next-LABEL">next</a>, and
<a href="#redo-LABEL">redo</a> work.</p>
<p>Unlike most named operators, this has the same precedence as assignment.
It is also exempt from the looks-like-a-function rule, so
<code class="inline"><a class="l_k" href="functions/last.html">last</a> <span class="s">(</span><span class="q">&quot;foo&quot;</span><span class="s">)</span>.<span class="q">&quot;bar&quot;</span></code>
 will cause "bar" to be part of the argument to
<a href="#last-LABEL">last</a>.</p>
</li>
<li><a name="lc-EXPR"></a><b>lc EXPR
 </b>
</li>
<li><a name="lc"></a><b>lc</b>
<p>Returns a lowercased version of EXPR.  This is the internal function
implementing the <code class="inline">\<span class="w">L</span></code>
 escape in double-quoted strings.</p>
<p>If EXPR is omitted, uses <a href="perlvar.html#%24_">$_ </a>.</p>
<p>What gets returned depends on several factors:</p>
<ul>
<li><a name="If-use-bytes-is-in-effect%3a"></a><b>If <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">bytes</span></code>
 is in effect:</b>
<p>The results follow ASCII rules.  Only the characters <code class="inline"><span class="w">A</span>-<span class="w">Z</span></code>
 change,
to <code class="inline"><span class="w">a</span>-z</code>
 respectively.</p>
</li>
<li><a name="Otherwise%2c-if-use-locale-for-LC_CTYPE-is-in-effect%3a"></a><b>Otherwise, if <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">locale</span></code>
 for <code class="inline"><span class="w">LC_CTYPE</span></code>
 is in effect:</b>
<p>Respects current <code class="inline"><span class="w">LC_CTYPE</span></code>
 locale for code points &lt; 256; and uses Unicode
rules for the remaining code points (this last can only happen if
the UTF8 flag is also set).  See <a href="perllocale.html">perllocale</a>.</p>
<p>Starting in v5.20, Perl uses full Unicode rules if the locale is
UTF-8.  Otherwise, there is a deficiency in this scheme, which is that
case changes that cross the 255/256
boundary are not well-defined.  For example, the lower case of LATIN CAPITAL
LETTER SHARP S (U+1E9E) in Unicode rules is U+00DF (on ASCII
platforms).   But under <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">locale</span></code>
 (prior to v5.20 or not a UTF-8
locale), the lower case of U+1E9E is
itself, because 0xDF may not be LATIN SMALL LETTER SHARP S in the
current locale, and Perl has no way of knowing if that character even
exists in the locale, much less what code point it is.  Perl returns
a result that is above 255 (almost always the input character unchanged),
for all instances (and there aren't many) where the 255/256 boundary
would otherwise be crossed; and starting in v5.22, it raises a
<a href="perldiag.html#Can't-do-%25s(%22%25s%22)-on-non-UTF-8-locale%3b-resolved-to-%22%25s%22.">locale</a> warning.</p>
</li>
<li><a name="Otherwise%2c-If-EXPR-has-the-UTF8-flag-set%3a"></a><b>Otherwise, If EXPR has the UTF8 flag set:</b>
<p>Unicode rules are used for the case change.</p>
</li>
<li><a name="Otherwise%2c-if-use-feature-'unicode_strings'-or-use-locale-'%3anot_characters'-is-in-effect%3a"></a><b>Otherwise, if <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">feature</span> <span class="q">&#39;unicode_strings&#39;</span></code>
 or <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">locale</span> <span class="q">&#39;:not_characters&#39;</span></code>
 is in effect:</b>
<p>Unicode rules are used for the case change.</p>
</li>
<li><a name="Otherwise%3a"></a><b>Otherwise:</b>
<p>ASCII rules are used for the case change.  The lowercase of any character
outside the ASCII range is the character itself.</p>
</li>
</ul>
</li>
<li><a name="lcfirst-EXPR"></a><b>lcfirst EXPR
 </b>
</li>
<li><a name="lcfirst"></a><b>lcfirst</b>
<p>Returns the value of EXPR with the first character lowercased.  This
is the internal function implementing the <code class="inline">\<span class="w">l</span></code>
 escape in
double-quoted strings.</p>
<p>If EXPR is omitted, uses <a href="perlvar.html#%24_">$_ </a>.</p>
<p>This function behaves the same way under various pragmas, such as in a locale,
as <a href="#lc-EXPR">lc</a> does.</p>
</li>
<li><a name="length-EXPR"></a><b>length EXPR
 </b>
</li>
<li><a name="length"></a><b>length</b>
<p>Returns the length in <i>characters</i> of the value of EXPR.  If EXPR is
omitted, returns the length of <a href="perlvar.html#%24_">$_ </a>.  If EXPR is
undefined, returns <a href="#undef-EXPR">undef</a>.</p>
<p>This function cannot be used on an entire array or hash to find out how
many elements these have.  For that, use <code class="inline"><a class="l_k" href="functions/scalar.html">scalar</a> <span class="i">@array</span></code>
 and <code class="inline"><a class="l_k" href="functions/scalar.html">scalar</a> <a class="l_k" href="functions/keys.html">keys</a>
<span class="i">%hash</span></code>
, respectively.</p>
<p>Like all Perl character operations, <a href="#length-EXPR">length</a> normally
deals in logical
characters, not physical bytes.  For how many bytes a string encoded as
UTF-8 would take up, use <code class="inline"><a class="l_k" href="functions/length.html">length</a><span class="s">(</span><span class="i">Encode::encode</span><span class="s">(</span><span class="q">&#39;UTF-8&#39;</span><span class="cm">,</span> <span class="w">EXPR</span><span class="s">)</span><span class="s">)</span></code>

(you'll have to <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">Encode</span></code>
 first).  See <a href="Encode.html">Encode</a> and <a href="perlunicode.html">perlunicode</a>.</p>
</li>
<li><a name="__LINE__"></a><b>__LINE__
</b>
<p>A special token that compiles to the current line number.</p>
</li>
<li><a name="link-OLDFILE%2cNEWFILE"></a><b>link OLDFILE,NEWFILE
</b>
<p>Creates a new filename linked to the old filename.  Returns true for
success, false otherwise.</p>
<p>Portability issues: <a href="perlport.html#link">link in perlport</a>.</p>
</li>
<li><a name="listen-SOCKET%2cQUEUESIZE"></a><b>listen SOCKET,QUEUESIZE
</b>
<p>Does the same thing that the <i>listen(2)</i> system call does.  Returns true if
it succeeded, false otherwise.  See the example in
<a href="perlipc.html#Sockets%3a-Client%2fServer-Communication">Sockets: Client/Server Communication in perlipc</a>.</p>
</li>
<li><a name="local-EXPR"></a><b>local EXPR
</b>
<p>You really probably want to be using <a href="#my-VARLIST">my</a> instead,
because <a href="#local-EXPR">local</a> isn't what most people think of as
"local".  See <a href="perlsub.html#Private-Variables-via-my()">Private Variables via my() in perlsub</a> for details.</p>
<p>A local modifies the listed variables to be local to the enclosing
block, file, or eval.  If more than one value is listed, the list must
be placed in parentheses.  See <a href="perlsub.html#Temporary-Values-via-local()">Temporary Values via local() in perlsub</a>
for details, including issues with tied arrays and hashes.</p>
<p>The <code class="inline"><a class="l_k" href="functions/delete.html">delete</a> <a class="l_k" href="functions/local.html">local</a> <span class="w">EXPR</span></code>
 construct can also be used to localize the deletion
of array/hash elements to the current block.
See <a href="perlsub.html#Localized-deletion-of-elements-of-composite-types">Localized deletion of elements of composite types in perlsub</a>.</p>
</li>
<li><a name="localtime-EXPR"></a><b>localtime EXPR
 </b>
</li>
<li><a name="localtime"></a><b>localtime</b>
<p>Converts a time as returned by the time function to a 9-element list
with the time analyzed for the local time zone.  Typically used as
follows:</p>
<pre class="verbatim"><ol><li>    <span class="c">#     0    1    2     3     4    5     6     7     8</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span><span class="i">$sec</span><span class="cm">,</span><span class="i">$min</span><span class="cm">,</span><span class="i">$hour</span><span class="cm">,</span><span class="i">$mday</span><span class="cm">,</span><span class="i">$mon</span><span class="cm">,</span><span class="i">$year</span><span class="cm">,</span><span class="i">$wday</span><span class="cm">,</span><span class="i">$yday</span><span class="cm">,</span><span class="i">$isdst</span><span class="s">)</span> =</li><li>                                                <a class="l_k" href="functions/localtime.html">localtime</a><span class="s">(</span><a class="l_k" href="functions/time.html">time</a><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>All list elements are numeric and come straight out of the C `struct
tm'.  <code class="inline"><span class="i">$sec</span></code>
, <code class="inline"><span class="i">$min</span></code>
, and <code class="inline"><span class="i">$hour</span></code>
 are the seconds, minutes, and hours
of the specified time.</p>
<p><code class="inline"><span class="i">$mday</span></code>
 is the day of the month and <code class="inline"><span class="i">$mon</span></code>
 the month in
the range <code class="inline"><span class="n">0</span>..<span class="n">11</span></code>
, with 0 indicating January and 11 indicating December.
This makes it easy to get a month name from a list:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@abbr</span> = <span class="q">qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;$abbr[$mon] $mday&quot;</span><span class="sc">;</span></li><li>    <span class="c"># $mon=9, $mday=18 gives &quot;Oct 18&quot;</span></li></ol></pre><p><code class="inline"><span class="i">$year</span></code>
 contains the number of years since 1900.  To get a 4-digit
year write:</p>
<pre class="verbatim"><ol><li>    <span class="i">$year</span> += <span class="n">1900</span><span class="sc">;</span></li></ol></pre><p>To get the last two digits of the year (e.g., "01" in 2001) do:</p>
<pre class="verbatim"><ol><li>    <span class="i">$year</span> = <a class="l_k" href="functions/sprintf.html">sprintf</a><span class="s">(</span><span class="q">&quot;%02d&quot;</span><span class="cm">,</span> <span class="i">$year</span> % <span class="n">100</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p><code class="inline"><span class="i">$wday</span></code>
 is the day of the week, with 0 indicating Sunday and 3 indicating
Wednesday.  <code class="inline"><span class="i">$yday</span></code>
 is the day of the year, in the range <code class="inline"><span class="n">0</span>..<span class="n">364</span></code>

(or <code class="inline"><span class="n">0</span>..<span class="n">365</span></code>
 in leap years.)</p>
<p><code class="inline"><span class="i">$isdst</span></code>
 is true if the specified time occurs during Daylight Saving
Time, false otherwise.</p>
<p>If EXPR is omitted, <a href="#localtime-EXPR">localtime</a> uses the current
time (as returned by <a href="#time">time</a>).</p>
<p>In scalar context, <a href="#localtime-EXPR">localtime</a> returns the
<i>ctime(3)</i> value:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$now_string</span> = <a class="l_k" href="functions/localtime.html">localtime</a><span class="sc">;</span>  <span class="c"># e.g., &quot;Thu Oct 13 04:54:34 1994&quot;</span></li></ol></pre><p>The format of this scalar value is <b>not</b> locale-dependent but built
into Perl.  For GMT instead of local time use the
<a href="#gmtime-EXPR">gmtime</a> builtin.  See also the
<a href="Time/Local.html">Time::Local </a> module (for converting seconds, minutes,
hours, and such back to the integer value returned by <a href="#time">time</a>),
and the <a href="POSIX.html">POSIX</a> module's <a href="POSIX.html#strftime">strftime </a> and
<a href="POSIX.html#mktime">mktime </a> functions.</p>
<p>To get somewhat similar but locale-dependent date strings, set up your
locale environment variables appropriately (please see <a href="perllocale.html">perllocale</a>) and
try for example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">POSIX</span> <span class="q">qw(strftime)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$now_string</span> = <span class="w">strftime</span> <span class="q">&quot;%a %b %e %H:%M:%S %Y&quot;</span><span class="cm">,</span> <a class="l_k" href="functions/localtime.html">localtime</a><span class="sc">;</span></li><li>    <span class="c"># or for GMT formatted appropriately for your locale:</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$now_string</span> = <span class="w">strftime</span> <span class="q">&quot;%a %b %e %H:%M:%S %Y&quot;</span><span class="cm">,</span> <a class="l_k" href="functions/gmtime.html">gmtime</a><span class="sc">;</span></li></ol></pre><p>Note that <code class="inline"><span class="i">%a</span></code>
 and <code class="inline"><span class="i">%b</span></code>
, the short forms of the day of the week
and the month of the year, may not necessarily be three characters wide.</p>
<p>The <a href="Time/gmtime.html">Time::gmtime</a> and <a href="Time/localtime.html">Time::localtime</a> modules provide a convenient,
by-name access mechanism to the <a href="#gmtime-EXPR">gmtime</a> and
<a href="#localtime-EXPR">localtime</a> functions, respectively.</p>
<p>For a comprehensive date and time representation look at the
<a href="http://search.cpan.org/perldoc/DateTime">DateTime</a> module on CPAN.</p>
<p>Portability issues: <a href="perlport.html#localtime">localtime in perlport</a>.</p>
</li>
<li><a name="lock-THING"></a><b>lock THING
</b>
<p>This function places an advisory lock on a shared variable or referenced
object contained in <i>THING</i> until the lock goes out of scope.</p>
<p>The value returned is the scalar itself, if the argument is a scalar, or a
reference, if the argument is a hash, array or subroutine.</p>
<p><a href="#lock-THING">lock</a> is a "weak keyword"; this means that if you've
defined a function
by this name (before any calls to it), that function will be called
instead.  If you are not under <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">threads::shared</span></code>
 this does nothing.
See <a href="threads/shared.html">threads::shared</a>.</p>
</li>
<li><a name="log-EXPR"></a><b>log EXPR
    </b>
</li>
<li><a name="log"></a><b>log</b>
<p>Returns the natural logarithm (base <i>e</i>) of EXPR.  If EXPR is omitted,
returns the log of <a href="perlvar.html#%24_">$_ </a>.  To get the
log of another base, use basic algebra:
The base-N log of a number is equal to the natural log of that number
divided by the natural log of N.  For example:</p>
<pre class="verbatim"><ol><li><a name="log10"></a>    sub <span class="m">log10</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/my.html">my</a> <span class="i">$n</span> = <a class="l_k" href="functions/shift.html">shift</a><span class="sc">;</span></li><li>        <a class="l_k" href="functions/return.html">return</a> <a class="l_k" href="functions/log.html">log</a><span class="s">(</span><span class="i">$n</span><span class="s">)</span>/<a class="l_k" href="functions/log.html">log</a><span class="s">(</span><span class="n">10</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>See also <a href="#exp-EXPR">exp</a> for the inverse operation.</p>
</li>
<li><a name="lstat-FILEHANDLE"></a><b>lstat FILEHANDLE
</b>
</li>
<li><a name="lstat-EXPR"></a><b>lstat EXPR</b>
</li>
<li><a name="lstat-DIRHANDLE"></a><b>lstat DIRHANDLE</b>
</li>
<li><a name="lstat"></a><b>lstat</b>
<p>Does the same thing as the <a href="#stat-FILEHANDLE">stat</a> function
(including setting the special <code class="inline"><span class="w">_</span></code>
 filehandle) but stats a symbolic
link instead of the file the symbolic link points to.  If symbolic links
are unimplemented on your system, a normal <a href="#stat-FILEHANDLE">stat</a>
is done.  For much more detailed information, please see the
documentation for <a href="#stat-FILEHANDLE">stat</a>.</p>
<p>If EXPR is omitted, stats <a href="perlvar.html#%24_">$_ </a>.</p>
<p>Portability issues: <a href="perlport.html#lstat">lstat in perlport</a>.</p>
</li>
<li><a name="m%2f%2f"></a><b>m//</b>
<p>The match operator.  See <a href="perlop.html#Regexp-Quote-Like-Operators">Regexp Quote-Like Operators in perlop</a>.</p>
</li>
<li><a name="map-BLOCK-LIST"></a><b>map BLOCK LIST
</b>
</li>
<li><a name="map-EXPR%2cLIST"></a><b>map EXPR,LIST</b>
<p>Evaluates the BLOCK or EXPR for each element of LIST (locally setting
<a href="perlvar.html#%24_">$_ </a> to each element) and returns the list value composed
of the
results of each such evaluation.  In scalar context, returns the
total number of elements so generated.  Evaluates BLOCK or EXPR in
list context, so each element of LIST may produce zero, one, or
more elements in the returned value.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@chars</span> = <a class="l_k" href="functions/map.html">map</a><span class="s">(</span><a class="l_k" href="functions/chr.html">chr</a><span class="cm">,</span> <span class="i">@numbers</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>translates a list of numbers to the corresponding characters.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@squares</span> = <a class="l_k" href="functions/map.html">map</a> <span class="s">{</span> <span class="i">$_</span> * <span class="i">$_</span> <span class="s">}</span> <span class="i">@numbers</span><span class="sc">;</span></li></ol></pre><p>translates a list of numbers to their squared values.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@squares</span> = <a class="l_k" href="functions/map.html">map</a> <span class="s">{</span> <span class="i">$_</span> &gt; <span class="n">5</span> ? <span class="s">(</span><span class="i">$_</span> * <span class="i">$_</span><span class="s">)</span> <span class="co">:</span> <span class="s">(</span><span class="s">)</span> <span class="s">}</span> <span class="i">@numbers</span><span class="sc">;</span></li></ol></pre><p>shows that number of returned elements can differ from the number of
input elements.  To omit an element, return an empty list ().
This could also be achieved by writing</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@squares</span> = <a class="l_k" href="functions/map.html">map</a> <span class="s">{</span> <span class="i">$_</span> * <span class="i">$_</span> <span class="s">}</span> <a class="l_k" href="functions/grep.html">grep</a> <span class="s">{</span> <span class="i">$_</span> &gt; <span class="n">5</span> <span class="s">}</span> <span class="i">@numbers</span><span class="sc">;</span></li></ol></pre><p>which makes the intention more clear.</p>
<p>Map always returns a list, which can be
assigned to a hash such that the elements
become key/value pairs.  See <a href="perldata.html">perldata</a> for more details.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">%hash</span> = <a class="l_k" href="functions/map.html">map</a> <span class="s">{</span> <span class="i">get_a_key_for</span><span class="s">(</span><span class="i">$_</span><span class="s">)</span> <span class="cm">=&gt;</span> <span class="i">$_</span> <span class="s">}</span> <span class="i">@array</span><span class="sc">;</span></li></ol></pre><p>is just a funny way to write</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">%hash</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/foreach.html">foreach</a> <span class="s">(</span><span class="i">@array</span><span class="s">)</span> <span class="s">{</span></li><li>        <span class="i">$hash</span>{<span class="i">get_a_key_for</span><span class="s">(</span><span class="i">$_</span><span class="s">)</span>} = <span class="i">$_</span><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>Note that <a href="perlvar.html#%24_">$_ </a> is an alias to the list value, so it can
be used to modify the elements of the LIST.  While this is useful and
supported, it can cause bizarre results if the elements of LIST are not
variables.  Using a regular <code class="inline">foreach</code>
 loop for this purpose would be
clearer in most cases.  See also <a href="#grep-BLOCK-LIST">grep</a> for a
list composed of those items of the original list for which the BLOCK
or EXPR evaluates to true.</p>
<p><code class="inline">{</code> starts both hash references and blocks, so <code class="inline">map { ...</code> could be either
the start of map BLOCK LIST or map EXPR, LIST.  Because Perl doesn't look
ahead for the closing <code class="inline">}</code> it has to take a guess at which it's dealing with
based on what it finds just after the
<code class="inline">{</code>.  Usually it gets it right, but if it
doesn't it won't realize something is wrong until it gets to the <code class="inline">}</code> and
encounters the missing (or unexpected) comma.  The syntax error will be
reported close to the <code class="inline">}</code>, but you'll need to change something near the <code class="inline">{</code>
such as using a unary <code class="inline">+</code>
 or semicolon to give Perl some help:</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">%hash</span> = <a class="l_k" href="functions/map.html">map</a> <span class="s">{</span>  <span class="q">&quot;\L$_&quot;</span> <span class="cm">=&gt;</span> <span class="n">1</span>  <span class="s">}</span> <span class="i">@array</span> <span class="c"># perl guesses EXPR. wrong</span></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">%hash</span> = <a class="l_k" href="functions/map.html">map</a> <span class="s">{</span> +<span class="q">&quot;\L$_&quot;</span> <span class="cm">=&gt;</span> <span class="n">1</span>  <span class="s">}</span> <span class="i">@array</span> <span class="c"># perl guesses BLOCK. right</span></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">%hash</span> = <a class="l_k" href="functions/map.html">map</a> <span class="s">{</span><span class="sc">;</span> <span class="q">&quot;\L$_&quot;</span> <span class="cm">=&gt;</span> <span class="n">1</span>  <span class="s">}</span> <span class="i">@array</span> <span class="c"># this also works</span></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">%hash</span> = <a class="l_k" href="functions/map.html">map</a> <span class="s">{</span> <span class="s">(</span><span class="q">&quot;\L$_&quot;</span> <span class="cm">=&gt;</span> <span class="n">1</span><span class="s">)</span> <span class="s">}</span> <span class="i">@array</span> <span class="c"># as does this</span></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">%hash</span> = <a class="l_k" href="functions/map.html">map</a> <span class="s">{</span>  <a class="l_k" href="functions/lc.html">lc</a><span class="s">(</span><span class="i">$_</span><span class="s">)</span> <span class="cm">=&gt;</span> <span class="n">1</span>  <span class="s">}</span> <span class="i">@array</span> <span class="c"># and this.</span></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">%hash</span> = <a class="l_k" href="functions/map.html">map</a> +<span class="s">(</span> <a class="l_k" href="functions/lc.html">lc</a><span class="s">(</span><span class="i">$_</span><span class="s">)</span> <span class="cm">=&gt;</span> <span class="n">1</span> <span class="s">)</span><span class="cm">,</span> <span class="i">@array</span> <span class="c"># this is EXPR and works!</span></li><li></li><li> <a class="l_k" href="functions/my.html">my</a> <span class="i">%hash</span> = <a class="l_k" href="functions/map.html">map</a>  <span class="s">(</span> <a class="l_k" href="functions/lc.html">lc</a><span class="s">(</span><span class="i">$_</span><span class="s">)</span><span class="cm">,</span> <span class="n">1</span> <span class="s">)</span><span class="cm">,</span>   <span class="i">@array</span> <span class="c"># evaluates to (1, @array)</span></li></ol></pre><p>or to force an anon hash constructor use <code class="inline">+{</code>:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">@hashes</span> = <a class="l_k" href="functions/map.html">map</a> +<span class="s">{</span> <a class="l_k" href="functions/lc.html">lc</a><span class="s">(</span><span class="i">$_</span><span class="s">)</span> <span class="cm">=&gt;</span> <span class="n">1</span> <span class="s">}</span><span class="cm">,</span> <span class="i">@array</span> <span class="c"># EXPR, so needs</span></li><li>                                              <span class="c"># comma at end</span></li></ol></pre><p>to get a list of anonymous hashes each with only one entry apiece.</p>
</li>
<li><a name="mkdir-FILENAME%2cMASK"></a><b>mkdir FILENAME,MASK
  </b>
</li>
<li><a name="mkdir-FILENAME"></a><b>mkdir FILENAME</b>
</li>
<li><a name="mkdir"></a><b>mkdir</b>
<p>Creates the directory specified by FILENAME, with permissions
specified by MASK (as modified by <a href="#umask-EXPR">umask</a>).  If it
succeeds it returns true; otherwise it returns false and sets
<a href="perlvar.html#%24!">$! </a> (errno).
MASK defaults to 0777 if omitted, and FILENAME defaults
to <a href="perlvar.html#%24_">$_ </a> if omitted.</p>
<p>In general, it is better to create directories with a permissive MASK
and let the user modify that with their <a href="#umask-EXPR">umask</a> than it
is to supply
a restrictive MASK and give the user no way to be more permissive.
The exceptions to this rule are when the file or directory should be
kept private (mail files, for instance).  The documentation for
<a href="#umask-EXPR">umask</a> discusses the choice of MASK in more detail.</p>
<p>Note that according to the POSIX 1003.1-1996 the FILENAME may have any
number of trailing slashes.  Some operating and filesystems do not get
this right, so Perl automatically removes all trailing slashes to keep
everyone happy.</p>
<p>To recursively create a directory structure, look at
the <a href="File/Path.html#make_path(-%24dir1%2c-%24dir2%2c-....-)">make_path </a> function
of the <a href="File/Path.html">File::Path</a> module.</p>
</li>
<li><a name="msgctl-ID%2cCMD%2cARG"></a><b>msgctl ID,CMD,ARG
</b>
<p>Calls the System V IPC function <i>msgctl(2)</i>.  You'll probably have to say</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">IPC::SysV</span><span class="sc">;</span></li></ol></pre><p>first to get the correct constant definitions.  If CMD is <code class="inline"><span class="w">IPC_STAT</span></code>
,
then ARG must be a variable that will hold the returned <code class="inline"><span class="w">msqid_ds</span></code>

structure.  Returns like <a href="#ioctl-FILEHANDLE%2cFUNCTION%2cSCALAR">ioctl</a>:
the undefined value for error, <code class="inline"><span class="q">&quot;0 but true&quot;</span></code>
 for zero, or the actual
return value otherwise.  See also <a href="perlipc.html#SysV-IPC">SysV IPC in perlipc</a> and the
documentation for <a href="IPC/SysV.html">IPC::SysV </a> and
<a href="IPC/Semaphore.html">IPC::Semaphore </a>.</p>
<p>Portability issues: <a href="perlport.html#msgctl">msgctl in perlport</a>.</p>
</li>
<li><a name="msgget-KEY%2cFLAGS"></a><b>msgget KEY,FLAGS
</b>
<p>Calls the System V IPC function <i>msgget(2)</i>.  Returns the message queue
id, or <a href="#undef-EXPR">undef</a> on error.  See also <a href="perlipc.html#SysV-IPC">SysV IPC in perlipc</a>
and the documentation for <a href="IPC/SysV.html">IPC::SysV </a> and
<a href="IPC/Msg.html">IPC::Msg </a>.</p>
<p>Portability issues: <a href="perlport.html#msgget">msgget in perlport</a>.</p>
</li>
<li><a name="msgrcv-ID%2cVAR%2cSIZE%2cTYPE%2cFLAGS"></a><b>msgrcv ID,VAR,SIZE,TYPE,FLAGS
</b>
<p>Calls the System V IPC function msgrcv to receive a message from
message queue ID into variable VAR with a maximum message size of
SIZE.  Note that when a message is received, the message type as a
native long integer will be the first thing in VAR, followed by the
actual message.  This packing may be opened with <code class="inline"><a class="l_k" href="functions/unpack.html">unpack</a><span class="s">(</span><span class="q">&quot;l! a*&quot;</span><span class="s">)</span></code>
.
Taints the variable.  Returns true if successful, false
on error.  See also <a href="perlipc.html#SysV-IPC">SysV IPC in perlipc</a> and the documentation for
<a href="IPC/SysV.html">IPC::SysV </a> and <a href="IPC/Msg.html">IPC::Msg </a>.</p>
<p>Portability issues: <a href="perlport.html#msgrcv">msgrcv in perlport</a>.</p>
</li>
<li><a name="msgsnd-ID%2cMSG%2cFLAGS"></a><b>msgsnd ID,MSG,FLAGS
</b>
<p>Calls the System V IPC function msgsnd to send the message MSG to the
message queue ID.  MSG must begin with the native long integer message
type, be followed by the length of the actual message, and then finally
the message itself.  This kind of packing can be achieved with
<code class="inline"><a class="l_k" href="functions/pack.html">pack</a><span class="s">(</span><span class="q">&quot;l! a*&quot;</span><span class="cm">,</span> <span class="i">$type</span><span class="cm">,</span> <span class="i">$message</span><span class="s">)</span></code>
.  Returns true if successful,
false on error.  See also <a href="perlipc.html#SysV-IPC">SysV IPC in perlipc</a> and the documentation
for <a href="IPC/SysV.html">IPC::SysV </a> and <a href="IPC/Msg.html">IPC::Msg </a>.</p>
<p>Portability issues: <a href="perlport.html#msgsnd">msgsnd in perlport</a>.</p>
</li>
<li><a name="my-VARLIST"></a><b>my VARLIST
</b>
</li>
<li><a name="my-TYPE-VARLIST"></a><b>my TYPE VARLIST</b>
</li>
<li><a name="my-VARLIST-%3a-ATTRS"></a><b>my VARLIST : ATTRS</b>
</li>
<li><a name="my-TYPE-VARLIST-%3a-ATTRS"></a><b>my TYPE VARLIST : ATTRS</b>
<p>A <a href="#my-VARLIST">my</a> declares the listed variables to be local
(lexically) to the enclosing block, file, or <a href="#eval-EXPR">eval</a>.  If
more than one variable is listed, the list must be placed in
parentheses.</p>
<p>The exact semantics and interface of TYPE and ATTRS are still
evolving.  TYPE may be a bareword, a constant declared
with <a href="constant.html">use constant </a>, or <a href="#__PACKAGE__">__PACKAGE__ </a>.  It
is
currently bound to the use of the <a href="fields.html">fields</a> pragma,
and attributes are handled using the <a href="attributes.html">attributes</a> pragma, or starting
from Perl 5.8.0 also via the <a href="Attribute/Handlers.html">Attribute::Handlers</a> module.  See
<a href="perlsub.html#Private-Variables-via-my()">Private Variables via my() in perlsub</a> for details.</p>
<p>Note that with a parenthesised list, <a href="#undef-EXPR">undef</a> can be used
as a dummy placeholder, for example to skip assignment of initial
values:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="s">(</span> <a class="l_k" href="functions/undef.html">undef</a><span class="cm">,</span> <span class="i">$min</span><span class="cm">,</span> <span class="i">$hour</span> <span class="s">)</span> = <a class="l_k" href="functions/localtime.html">localtime</a><span class="sc">;</span></li></ol></pre></li>
<li><a name="next-LABEL"></a><b>next LABEL
 </b>
</li>
<li><a name="next-EXPR"></a><b>next EXPR</b>
</li>
<li><a name="next"></a><b>next</b>
<p>The <a href="#next-LABEL">next</a> command is like the <code class="inline"><a class="l_k" href="functions/continue.html">continue</a></code> statement in
C; it starts the next iteration of the loop:</p>
<pre class="verbatim"><ol><li>    <span class="j">LINE:</span> while <span class="s">(</span><span class="q">&lt;STDIN&gt;</span><span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/next.html">next</a> <span class="j">LINE</span> if <span class="q">/^#/</span><span class="sc">;</span>  <span class="c"># discard comments</span></li><li>        <span class="c">#...</span></li><li>    <span class="s">}</span></li></ol></pre><p>Note that if there were a <a href="#continue-BLOCK">continue</a> block on the
above, it would get
executed even on discarded lines.  If LABEL is omitted, the command
refers to the innermost enclosing loop.  The <code class="inline"><a class="l_k" href="functions/next.html">next</a> <span class="j">EXPR</span></code>
 form, available
as of Perl 5.18.0, allows a label name to be computed at run time, being
otherwise identical to <code class="inline"><a class="l_k" href="functions/next.html">next</a> <span class="j">LABEL</span></code>
.</p>
<p><a href="#next-LABEL">next</a> cannot be used to exit a block which returns a
value such as <code class="inline"><a class="l_k" href="functions/eval.html">eval</a> <span class="s">{</span><span class="s">}</span></code>
, <code class="inline"><a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span><span class="s">}</span></code>
, or <code class="inline"><a class="l_k" href="functions/do.html">do</a> <span class="s">{</span><span class="s">}</span></code>
, and should not be used
to exit a <a href="#grep-BLOCK-LIST">grep</a> or <a href="#map-BLOCK-LIST">map</a>
operation.</p>
<p>Note that a block by itself is semantically identical to a loop
that executes once.  Thus <a href="#next-LABEL">next</a> will exit such a block
early.</p>
<p>See also <a href="#continue-BLOCK">continue</a> for an illustration of how
<a href="#last-LABEL">last</a>, <a href="#next-LABEL">next</a>, and
<a href="#redo-LABEL">redo</a> work.</p>
<p>Unlike most named operators, this has the same precedence as assignment.
It is also exempt from the looks-like-a-function rule, so
<code class="inline"><a class="l_k" href="functions/next.html">next</a> <span class="s">(</span><span class="q">&quot;foo&quot;</span><span class="s">)</span>.<span class="q">&quot;bar&quot;</span></code>
 will cause "bar" to be part of the argument to
<a href="#next-LABEL">next</a>.</p>
</li>
<li><a name="no-MODULE-VERSION-LIST"></a><b>no MODULE VERSION LIST

</b>
</li>
<li><a name="no-MODULE-VERSION"></a><b>no MODULE VERSION</b>
</li>
<li><a name="no-MODULE-LIST"></a><b>no MODULE LIST</b>
</li>
<li><a name="no-MODULE"></a><b>no MODULE</b>
</li>
<li><a name="no-VERSION"></a><b>no VERSION</b>
<p>See the <a href="#use-Module-VERSION-LIST">use</a> function, of which
<a href="#no-MODULE-VERSION-LIST">no</a> is the opposite.</p>
</li>
<li><a name="oct-EXPR"></a><b>oct EXPR
     </b>
</li>
<li><a name="oct"></a><b>oct</b>
<p>Interprets EXPR as an octal string and returns the corresponding
value.  (If EXPR happens to start off with <code class="inline"><span class="n">0</span>x</code>
, interprets it as a
hex string.  If EXPR starts off with <code class="inline">0b</code>, it is interpreted as a
binary string.  Leading whitespace is ignored in all three cases.)
The following will handle decimal, binary, octal, and hex in standard
Perl notation:</p>
<pre class="verbatim"><ol><li>    <span class="i">$val</span> = <a class="l_k" href="functions/oct.html">oct</a><span class="s">(</span><span class="i">$val</span><span class="s">)</span> if <span class="i">$val</span> =~ <span class="q">/^0/</span><span class="sc">;</span></li></ol></pre><p>If EXPR is omitted, uses <a href="perlvar.html#%24_">$_ </a>.   To go the other way
(produce a number in octal), use <a href="#sprintf-FORMAT%2c-LIST">sprintf</a> or
<a href="#printf-FILEHANDLE-FORMAT%2c-LIST">printf</a>:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$dec_perms</span> = <span class="s">(</span><a class="l_k" href="functions/stat.html">stat</a><span class="s">(</span><span class="q">&quot;filename&quot;</span><span class="s">)</span><span class="s">)</span>[<span class="n">2</span>] &amp; <span class="n">07777</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$oct_perm_str</span> = <a class="l_k" href="functions/sprintf.html">sprintf</a> <span class="q">&quot;%o&quot;</span><span class="cm">,</span> <span class="i">$perms</span><span class="sc">;</span></li></ol></pre><p>The <a href="#oct-EXPR">oct</a> function is commonly used when a string such as
<code class="inline"><span class="n">644</span></code>
 needs
to be converted into a file mode, for example.  Although Perl
automatically converts strings into numbers as needed, this automatic
conversion assumes base 10.</p>
<p>Leading white space is ignored without warning, as too are any trailing
non-digits, such as a decimal point (<a href="#oct-EXPR">oct</a> only handles
non-negative integers, not negative integers or floating point).</p>
</li>
<li><a name="open-FILEHANDLE%2cEXPR"></a><b>open FILEHANDLE,EXPR
   </b>
</li>
<li><a name="open-FILEHANDLE%2cMODE%2cEXPR"></a><b>open FILEHANDLE,MODE,EXPR</b>
</li>
<li><a name="open-FILEHANDLE%2cMODE%2cEXPR%2cLIST"></a><b>open FILEHANDLE,MODE,EXPR,LIST</b>
</li>
<li><a name="open-FILEHANDLE%2cMODE%2cREFERENCE"></a><b>open FILEHANDLE,MODE,REFERENCE</b>
</li>
<li><a name="open-FILEHANDLE"></a><b>open FILEHANDLE</b>
<p>Opens the file whose filename is given by EXPR, and associates it with
FILEHANDLE.</p>
<p>Simple examples to open a file for reading:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;&lt;&quot;</span><span class="cm">,</span> <span class="q">&quot;input.txt&quot;</span><span class="s">)</span></li><li>	<a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open &lt; input.txt: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>and for writing:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;&gt;&quot;</span><span class="cm">,</span> <span class="q">&quot;output.txt&quot;</span><span class="s">)</span></li><li>	<a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open &gt; output.txt: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>(The following is a comprehensive reference to
<a href="#open-FILEHANDLE%2cEXPR">open</a>: for a gentler introduction you may
consider <a href="perlopentut.html">perlopentut</a>.)</p>
<p>If FILEHANDLE is an undefined scalar variable (or array or hash element), a
new filehandle is autovivified, meaning that the variable is assigned a
reference to a newly allocated anonymous filehandle.  Otherwise if
FILEHANDLE is an expression, its value is the real filehandle.  (This is
considered a symbolic reference, so <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">strict</span> <span class="q">&quot;refs&quot;</span></code>
 should <i>not</i> be
in effect.)</p>
<p>If three (or more) arguments are specified, the open mode (including
optional encoding) in the second argument are distinct from the filename in
the third.  If MODE is <code class="inline">&lt;</code>
 or nothing, the file is opened for input.
If MODE is <code class="inline">&gt;</code>, the file is opened for output, with existing files
first being truncated ("clobbered") and nonexisting files newly created.
If MODE is <code class="inline">&gt;&gt;</code>
, the file is opened for appending, again being
created if necessary.</p>
<p>You can put a <code class="inline">+</code>
 in front of the <code class="inline">&gt;</code> or <code class="inline">&lt;</code>
 to
indicate that you want both read and write access to the file; thus
<code class="inline">+&lt;</code>
 is almost always preferred for read/write updates--the
<code class="inline">+&gt;</code> mode would clobber the file first.  You can't usually use
either read-write mode for updating textfiles, since they have
variable-length records.  See the <b>-i</b> switch in <a href="perlrun.html">perlrun</a> for a
better approach.  The file is created with permissions of <code class="inline"><span class="n">0666</span></code>

modified by the process's <a href="#umask-EXPR">umask</a> value.</p>
<p>These various prefixes correspond to the <i>fopen(3)</i> modes of <code class="inline"><span class="w">r</span></code>
,
<code class="inline"><span class="w">r</span>+</code>
, <code class="inline"><span class="w">w</span></code>
, <code class="inline"><span class="w">w</span>+</code>
, <code class="inline"><span class="w">a</span></code>
, and <code class="inline"><span class="w">a</span>+</code>
.</p>
<p>In the one- and two-argument forms of the call, the mode and filename
should be concatenated (in that order), preferably separated by white
space.  You can--but shouldn't--omit the mode in these forms when that mode
is <code class="inline">&lt;</code>
.  It is safe to use the two-argument form of
<a href="#open-FILEHANDLE%2cEXPR">open</a> if the filename argument is a known literal.</p>
<p>For three or more arguments if MODE is <code class="inline">|-</code>, the filename is
interpreted as a command to which output is to be piped, and if MODE
is <code class="inline">-|</code>, the filename is interpreted as a command that pipes
output to us.  In the two-argument (and one-argument) form, one should
replace dash (<code class="inline">-</code>
) with the command.
See <a href="perlipc.html#Using-open()-for-IPC">Using open() for IPC in perlipc</a> for more examples of this.
(You are not allowed to <a href="#open-FILEHANDLE%2cEXPR">open</a> to a command
that pipes both in <i>and</i> out, but see <a href="IPC/Open2.html">IPC::Open2</a>, <a href="IPC/Open3.html">IPC::Open3</a>, and
<a href="perlipc.html#Bidirectional-Communication-with-Another-Process">Bidirectional Communication with Another Process in perlipc</a> for
alternatives.)</p>
<p>In the form of pipe opens taking three or more arguments, if LIST is specified
(extra arguments after the command name) then LIST becomes arguments
to the command invoked if the platform supports it.  The meaning of
<a href="#open-FILEHANDLE%2cEXPR">open</a> with more than three arguments for
non-pipe modes is not yet defined, but experimental "layers" may give
extra LIST arguments meaning.</p>
<p>In the two-argument (and one-argument) form, opening <code class="inline">&lt;-</code>

or <code class="inline">-</code>
 opens STDIN and opening <code class="inline">&gt;-</code>
 opens STDOUT.</p>
<p>You may (and usually should) use the three-argument form of open to specify
I/O layers (sometimes referred to as "disciplines") to apply to the handle
that affect how the input and output are processed (see <a href="open.html">open</a> and
<a href="PerlIO.html">PerlIO</a> for more details).  For example:</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;&lt;:encoding(UTF-8)&quot;</span><span class="cm">,</span> <span class="i">$filename</span><span class="s">)</span></li><li>    || <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open UTF-8 encoded $filename: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>opens the UTF8-encoded file containing Unicode characters;
see <a href="perluniintro.html">perluniintro</a>.  Note that if layers are specified in the
three-argument form, then default layers stored in ${^OPEN} (see <a href="perlvar.html">perlvar</a>;
usually set by the <a href="open.html">open</a> pragma or the switch <code class="inline">-<span class="w">CioD</span></code>
) are ignored.
Those layers will also be ignored if you specify a colon with no name
following it.  In that case the default layer for the operating system
(:raw on Unix, :crlf on Windows) is used.</p>
<p>Open returns nonzero on success, the undefined value otherwise.  If
the <a href="#open-FILEHANDLE%2cEXPR">open</a> involved a pipe, the return value
happens to be the pid of the subprocess.</p>
<p>On some systems (in general, DOS- and Windows-based systems)
<a href="#binmode-FILEHANDLE%2c-LAYER">binmode</a> is necessary when you're not
working with a text file.  For the sake of portability it is a good idea
always to use it when appropriate, and never to use it when it isn't
appropriate.  Also, people can set their I/O to be by default
UTF8-encoded Unicode, not bytes.</p>
<p>When opening a file, it's seldom a good idea to continue
if the request failed, so <a href="#open-FILEHANDLE%2cEXPR">open</a> is frequently
used with <a href="#die-LIST">die</a>.  Even if <a href="#die-LIST">die</a> won't do
what you want (say, in a CGI script,
where you want to format a suitable error message (but there are
modules that can help with that problem)) always check
the return value from opening a file.</p>
<p>The filehandle will be closed when its reference count reaches zero.
If it is a lexically scoped variable declared with <a href="#my-VARLIST">my</a>,
that usually
means the end of the enclosing scope.  However, this automatic close
does not check for errors, so it is better to explicitly close
filehandles, especially those used for writing:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/close.html">close</a><span class="s">(</span><span class="i">$handle</span><span class="s">)</span></li><li>       || <a class="l_k" href="functions/warn.html">warn</a> <span class="q">&quot;close failed: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>An older style is to use a bareword as the filehandle, as</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">FH</span><span class="cm">,</span> <span class="q">&quot;&lt;&quot;</span><span class="cm">,</span> <span class="q">&quot;input.txt&quot;</span><span class="s">)</span></li><li>       <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open &lt; input.txt: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>Then you can use <code class="inline"><span class="w">FH</span></code>
 as the filehandle, in <code class="inline"><a class="l_k" href="functions/close.html">close</a> <span class="w">FH</span></code>
 and <code class="inline"><span class="q">&lt;FH&gt;</span></code>
 and so on.  Note that it's a global variable, so this form is
not recommended in new code.</p>
<p>As a shortcut a one-argument call takes the filename from the global
scalar variable of the same name as the filehandle:</p>
<pre class="verbatim"><ol><li>    <span class="i">$ARTICLE</span> = <span class="n">100</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">ARTICLE</span><span class="s">)</span> <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t find article $ARTICLE: $!\n&quot;</span><span class="sc">;</span></li></ol></pre><p>Here <code class="inline"><span class="i">$ARTICLE</span></code>
 must be a global (package) scalar variable - not one
declared with <a href="#my-VARLIST">my</a> or <a href="#state-VARLIST">state</a>.</p>
<p>As a special case the three-argument form with a read/write mode and the third
argument being <a href="#undef-EXPR">undef</a>:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$tmp</span><span class="cm">,</span> <span class="q">&quot;+&gt;&quot;</span><span class="cm">,</span> <a class="l_k" href="functions/undef.html">undef</a><span class="s">)</span> or <a class="l_k" href="functions/die.html">die</a> ...</li></ol></pre><p>opens a filehandle to a newly created empty anonymous temporary file.
(This happens under any mode, which makes <code class="inline">+&gt;</code> the only useful and
sensible mode to use.)  You will need to
<a href="#seek-FILEHANDLE%2cPOSITION%2cWHENCE">seek</a> to do the reading.</p>
<p>Perl is built using PerlIO by default.  Unless you've
changed this (such as building Perl with <code class="inline"><span class="w">Configure</span> -<span class="w">Uuseperlio</span></code>
), you can
open filehandles directly to Perl scalars via:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;&gt;&quot;</span><span class="cm">,</span> \<span class="i">$variable</span><span class="s">)</span> || ..</li></ol></pre><p>To (re)open <code class="inline"><span class="w">STDOUT</span></code>
 or <code class="inline"><span class="w">STDERR</span></code>
 as an in-memory file, close it first:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/close.html">close</a> <span class="w">STDOUT</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">STDOUT</span><span class="cm">,</span> <span class="q">&quot;&gt;&quot;</span><span class="cm">,</span> \<span class="i">$variable</span><span class="s">)</span></li><li>	or <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open STDOUT: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>See <a href="perliol.html">perliol</a> for detailed info on PerlIO.</p>
<p>General examples:</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$log</span><span class="cm">,</span> <span class="q">&quot;&gt;&gt;&quot;</span><span class="cm">,</span> <span class="q">&quot;/usr/spool/news/twitlog&quot;</span><span class="s">)</span><span class="sc">;</span></li><li> <span class="c"># if the open fails, output is discarded</span></li><li></li><li> <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$dbase</span><span class="cm">,</span> <span class="q">&quot;+&lt;&quot;</span><span class="cm">,</span> <span class="q">&quot;dbase.mine&quot;</span><span class="s">)</span>      <span class="c"># open for update</span></li><li>     <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open &#39;dbase.mine&#39; for update: $!&quot;</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$dbase</span><span class="cm">,</span> <span class="q">&quot;+&lt;dbase.mine&quot;</span><span class="s">)</span>          <span class="c"># ditto</span></li><li>     <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open &#39;dbase.mine&#39; for update: $!&quot;</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$article_fh</span><span class="cm">,</span> <span class="q">&quot;-|&quot;</span><span class="cm">,</span> <span class="q">&quot;caesar &lt;$article&quot;</span><span class="s">)</span>  <span class="c"># decrypt</span></li><li>                                                 <span class="c"># article</span></li><li>     <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t start caesar: $!&quot;</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$article_fh</span><span class="cm">,</span> <span class="q">&quot;caesar &lt;$article |&quot;</span><span class="s">)</span>      <span class="c"># ditto</span></li><li>     <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t start caesar: $!&quot;</span><span class="sc">;</span></li><li></li><li> <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$out_fh</span><span class="cm">,</span> <span class="q">&quot;|-&quot;</span><span class="cm">,</span> <span class="q">&quot;sort &gt;Tmp$$&quot;</span><span class="s">)</span>    <span class="c"># $$ is our process id</span></li><li>     <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t start sort: $!&quot;</span><span class="sc">;</span></li><li></li><li> <span class="c"># in-memory files</span></li><li> <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$memory</span><span class="cm">,</span> <span class="q">&quot;&gt;&quot;</span><span class="cm">,</span> \<span class="i">$var</span><span class="s">)</span></li><li>     <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open memory file: $!&quot;</span><span class="sc">;</span></li><li> <a class="l_k" href="functions/print.html">print</a> <span class="i">$memory</span> <span class="q">&quot;foo!\n&quot;</span><span class="sc">;</span>              <span class="c"># output will appear in $var</span></li></ol></pre><p>You may also, in the Bourne shell tradition, specify an EXPR beginning
with <code class="inline">&gt;&amp;</code>, in which case the rest of the string is interpreted
as the name of a filehandle (or file descriptor, if numeric) to be
duped (as in <i>dup(2)</i>) and opened.  You may use <code class="inline"><span class="i">&amp;</span></code>
 after <code class="inline">&gt;</code>,
<code class="inline">&gt;&gt;</code>
, <code class="inline">&lt;</code>
, <code class="inline">+&gt;</code>, <code class="inline">+&gt;&gt;</code>
, and <code class="inline">+&lt;</code>
.
The mode you specify should match the mode of the original filehandle.
(Duping a filehandle does not take into account any existing contents
of IO buffers.)  If you use the three-argument
form, then you can pass either a
number, the name of a filehandle, or the normal "reference to a glob".</p>
<p>Here is a script that saves, redirects, and restores <code class="inline"><span class="w">STDOUT</span></code>
 and
<code class="inline"><span class="w">STDERR</span></code>
 using various methods:</p>
<pre class="verbatim"><ol><li>    <span class="c">#!/usr/bin/perl</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$oldout</span><span class="cm">,</span> <span class="q">&quot;&gt;&amp;STDOUT&quot;</span><span class="s">)</span>     or <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t dup STDOUT: $!&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">OLDERR</span><span class="cm">,</span>     <span class="q">&quot;&gt;&amp;&quot;</span><span class="cm">,</span> \<span class="i">*STDERR</span><span class="s">)</span> or <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t dup STDERR: $!&quot;</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">STDOUT</span><span class="cm">,</span> <span class="q">&#39;&gt;&#39;</span><span class="cm">,</span> <span class="q">&quot;foo.out&quot;</span><span class="s">)</span> or <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t redirect STDOUT: $!&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">STDERR</span><span class="cm">,</span> <span class="q">&quot;&gt;&amp;STDOUT&quot;</span><span class="s">)</span>     or <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t dup STDOUT: $!&quot;</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/select.html">select</a> <span class="w">STDERR</span><span class="sc">;</span> <span class="i">$|</span> = <span class="n">1</span><span class="sc">;</span>  <span class="c"># make unbuffered</span></li><li>    <a class="l_k" href="functions/select.html">select</a> <span class="w">STDOUT</span><span class="sc">;</span> <span class="i">$|</span> = <span class="n">1</span><span class="sc">;</span>  <span class="c"># make unbuffered</span></li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">STDOUT</span> <span class="q">&quot;stdout 1\n&quot;</span><span class="sc">;</span>  <span class="c"># this works for</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">STDERR</span> <span class="q">&quot;stderr 1\n&quot;</span><span class="sc">;</span>  <span class="c"># subprocesses too</span></li><li></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">STDOUT</span><span class="cm">,</span> <span class="q">&quot;&gt;&amp;&quot;</span><span class="cm">,</span> <span class="i">$oldout</span><span class="s">)</span> or <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t dup \$oldout: $!&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">STDERR</span><span class="cm">,</span> <span class="q">&quot;&gt;&amp;OLDERR&quot;</span><span class="s">)</span>    or <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t dup OLDERR: $!&quot;</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">STDOUT</span> <span class="q">&quot;stdout 2\n&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">STDERR</span> <span class="q">&quot;stderr 2\n&quot;</span><span class="sc">;</span></li></ol></pre><p>If you specify <code class="inline"><span class="q">&#39;&lt;&amp;=X&#39;</span></code>
, where <code class="inline"><span class="w">X</span></code>
 is a file descriptor number
or a filehandle, then Perl will do an equivalent of C's <i>fdopen(3)</i> of
that file descriptor (and not call <i>dup(2)</i>); this is more
parsimonious of file descriptors.  For example:</p>
<pre class="verbatim"><ol><li>    <span class="c"># open for input, reusing the fileno of $fd</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;&lt;&amp;=&quot;</span><span class="cm">,</span> <span class="i">$fd</span><span class="s">)</span></li></ol></pre><p>or</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;&lt;&amp;=$fd&quot;</span><span class="s">)</span></li></ol></pre><p>or</p>
<pre class="verbatim"><ol><li>    <span class="c"># open for append, using the fileno of $oldfh</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;&gt;&gt;&amp;=&quot;</span><span class="cm">,</span> <span class="i">$oldfh</span><span class="s">)</span></li></ol></pre><p>Being parsimonious on filehandles is also useful (besides being
parsimonious) for example when something is dependent on file
descriptors, like for example locking using
<a href="#flock-FILEHANDLE%2cOPERATION">flock</a>.  If you do just
<code class="inline"><a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$A</span><span class="cm">,</span> <span class="q">&quot;&gt;&gt;&amp;&quot;</span><span class="cm">,</span> <span class="i">$B</span><span class="s">)</span></code>
, the filehandle <code class="inline"><span class="i">$A</span></code>
 will not have the
same file descriptor as <code class="inline"><span class="i">$B</span></code>
, and therefore <code class="inline"><a class="l_k" href="functions/flock.html">flock($A)</a></code> will not
<code class="inline"><a class="l_k" href="functions/flock.html">flock($B)</a></code> nor vice versa.  But with <code class="inline"><a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$A</span><span class="cm">,</span> <span class="q">&quot;&gt;&gt;&amp;=&quot;</span><span class="cm">,</span> <span class="i">$B</span><span class="s">)</span></code>
,
the filehandles will share the same underlying system file descriptor.</p>
<p>Note that under Perls older than 5.8.0, Perl uses the standard C library's'
<i>fdopen(3)</i> to implement the <code class="inline">=</code>
 functionality.  On many Unix systems,
<i>fdopen(3)</i> fails when file descriptors exceed a certain value, typically 255.
For Perls 5.8.0 and later, PerlIO is (most often) the default.</p>
<p>You can see whether your Perl was built with PerlIO by running
<code class="inline"><span class="w">perl</span> -<span class="w">V</span><span class="co">:</span><span class="w">useperlio</span></code>
.  If it says <code class="inline"><span class="q">&#39;define&#39;</span></code>
, you have PerlIO;
otherwise you don't.</p>
<p>If you open a pipe on the command <code class="inline">-</code>
 (that is, specify either <code class="inline">|-</code> or <code class="inline">-|</code>
with the one- or two-argument forms of
<a href="#open-FILEHANDLE%2cEXPR">open</a>), an implicit <a href="#fork">fork</a> is done,
so <a href="#open-FILEHANDLE%2cEXPR">open</a> returns twice: in the parent process
it returns the pid
of the child process, and in the child process it returns (a defined) <code class="inline"><span class="n">0</span></code>
.
Use <code class="inline"><a class="l_k" href="functions/defined.html">defined($pid)</a></code> or <code class="inline"><span class="q">//</span></code>
 to determine whether the open was successful.</p>
<p>For example, use either</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/my.html">my</a> <span class="i">$child_pid</span> = <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$from_kid</span><span class="cm">,</span> <span class="q">&quot;-|&quot;</span><span class="s">)</span> // <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t fork: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>or</p>
<pre class="verbatim"><ol><li>   <a class="l_k" href="functions/my.html">my</a> <span class="i">$child_pid</span> = <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$to_kid</span><span class="cm">,</span>   <span class="q">&quot;|-&quot;</span><span class="s">)</span> // <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t fork: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>followed by</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/if.html">if</a> <span class="s">(</span><span class="i">$child_pid</span><span class="s">)</span> <span class="s">{</span></li><li>	<span class="c"># am the parent:</span></li><li>	<span class="c"># either write $to_kid or else read $from_kid</span></li><li>	...</li><li>       <a class="l_k" href="functions/waitpid.html">waitpid</a> <span class="i">$child_pid</span><span class="cm">,</span> <span class="n">0</span><span class="sc">;</span></li><li>    <span class="s">}</span> <a class="l_k" href="functions/else.html">else</a> <span class="s">{</span></li><li>	<span class="c"># am the child; use STDIN/STDOUT normally</span></li><li>	...</li><li>	<a class="l_k" href="functions/exit.html">exit</a><span class="sc">;</span></li><li>    <span class="s">}</span></li></ol></pre><p>The filehandle behaves normally for the parent, but I/O to that
filehandle is piped from/to the STDOUT/STDIN of the child process.
In the child process, the filehandle isn't opened--I/O happens from/to
the new STDOUT/STDIN.  Typically this is used like the normal
piped open when you want to exercise more control over just how the
pipe command gets executed, such as when running setuid and
you don't want to have to scan shell commands for metacharacters.</p>
<p>The following blocks are more or less equivalent:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;|tr &#39;[a-z]&#39; &#39;[A-Z]&#39;&quot;</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;|-&quot;</span><span class="cm">,</span> <span class="q">&quot;tr &#39;[a-z]&#39; &#39;[A-Z]&#39;&quot;</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;|-&quot;</span><span class="s">)</span> || <a class="l_k" href="functions/exec.html">exec</a> <span class="q">&#39;tr&#39;</span><span class="cm">,</span> <span class="q">&#39;[a-z]&#39;</span><span class="cm">,</span> <span class="q">&#39;[A-Z]&#39;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;|-&quot;</span><span class="cm">,</span> <span class="q">&quot;tr&quot;</span><span class="cm">,</span> <span class="q">&#39;[a-z]&#39;</span><span class="cm">,</span> <span class="q">&#39;[A-Z]&#39;</span><span class="s">)</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;cat -n &#39;$file&#39;|&quot;</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;-|&quot;</span><span class="cm">,</span> <span class="q">&quot;cat -n &#39;$file&#39;&quot;</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;-|&quot;</span><span class="s">)</span> || <a class="l_k" href="functions/exec.html">exec</a> <span class="q">&quot;cat&quot;</span><span class="cm">,</span> <span class="q">&quot;-n&quot;</span><span class="cm">,</span> <span class="i">$file</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;-|&quot;</span><span class="cm">,</span> <span class="q">&quot;cat&quot;</span><span class="cm">,</span> <span class="q">&quot;-n&quot;</span><span class="cm">,</span> <span class="i">$file</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>The last two examples in each block show the pipe as "list form", which is
not yet supported on all platforms.  A good rule of thumb is that if
your platform has a real <a href="#fork">fork</a> (in other words, if your platform is
Unix, including Linux and MacOS X), you can use the list form.  You would
want to use the list form of the pipe so you can pass literal arguments
to the command without risk of the shell interpreting any shell metacharacters
in them.  However, this also bars you from opening pipes to commands
that intentionally contain shell metacharacters, such as:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;|cat -n | expand -4 | lpr&quot;</span><span class="s">)</span></li><li>	|| <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open pipeline to lpr: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>See <a href="perlipc.html#Safe-Pipe-Opens">Safe Pipe Opens in perlipc</a> for more examples of this.</p>
<p>Perl will attempt to flush all files opened for
output before any operation that may do a fork, but this may not be
supported on some platforms (see <a href="perlport.html">perlport</a>).  To be safe, you may need
to set <a href="http://search.cpan.org/perldoc/|perlvar#%24%7c">$</a> (<code class="inline"><span class="i">$AUTOFLUSH</span></code>
 in <a href="English.html">English</a>)
or call the <code class="inline"><span class="w">autoflush</span></code>
 method of <a href="IO/Handle.html#METHODS">IO::Handle </a>
on any open handles.</p>
<p>On systems that support a close-on-exec flag on files, the flag will
be set for the newly opened file descriptor as determined by the value
of <a href="perlvar.html#%24%5eF">$^F </a>.  See <a href="perlvar.html#%24%5eF">$^F in perlvar</a>.</p>
<p>Closing any piped filehandle causes the parent process to wait for the
child to finish, then returns the status value in <a href="perlvar.html#%24%3f">$? </a> and
<a href="perlvar.html#%24%7b%5eCHILD_ERROR_NATIVE%7d">${^CHILD_ERROR_NATIVE} </a>.</p>
<p>The filename passed to the one- and two-argument forms of
<a href="#open-FILEHANDLE%2cEXPR">open</a> will
have leading and trailing whitespace deleted and normal
redirection characters honored.  This property, known as "magic open",
can often be used to good effect.  A user could specify a filename of
<i>"rsh cat file |"</i>, or you could change certain filenames as needed:</p>
<pre class="verbatim"><ol><li>    <span class="i">$filename</span> =~ <span class="q">s/(.*\.gz)\s*$/gzip -dc &lt; $1|/</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="i">$filename</span><span class="s">)</span> <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open $filename: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>Use the three-argument form to open a file with arbitrary weird characters in it,</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;&lt;&quot;</span><span class="cm">,</span> <span class="i">$file</span><span class="s">)</span></li><li>	|| <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open $file: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>otherwise it's necessary to protect any leading and trailing whitespace:</p>
<pre class="verbatim"><ol><li>    <span class="i">$file</span> =~ <span class="q">s#^(\s)#./$1#</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="q">&quot;&lt; $file\0&quot;</span><span class="s">)</span></li><li>	|| <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open $file: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>(this may not work on some bizarre filesystems).  One should
conscientiously choose between the <i>magic</i> and <i>three-argument</i> form
of <a href="#open-FILEHANDLE%2cEXPR">open</a>:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$in</span><span class="cm">,</span> <span class="i">$ARGV</span>[<span class="n">0</span>]<span class="s">)</span> || <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open $ARGV[0]: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>will allow the user to specify an argument of the form <code class="inline"><span class="q">&quot;rsh cat file |&quot;</span></code>
,
but will not work on a filename that happens to have a trailing space, while</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$in</span><span class="cm">,</span> <span class="q">&quot;&lt;&quot;</span><span class="cm">,</span> <span class="i">$ARGV</span>[<span class="n">0</span>]<span class="s">)</span></li><li>	|| <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open $ARGV[0]: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>will have exactly the opposite restrictions. (However, some shells
support the syntax <code class="inline"><span class="w">perl</span> <span class="w">your_program</span>.<span class="w">pl</span> &lt;<span class="s">(</span> <span class="w">rsh</span> <span class="w">cat</span> <span class="w">file</span> <span class="s">)</span></code>
, which
produces a filename that can be opened normally.)</p>
<p>If you want a "real" C <i>open(2)</i>, then you should use the
<a href="#sysopen-FILEHANDLE%2cFILENAME%2cMODE">sysopen</a> function, which involves
no such magic (but uses different filemodes than Perl
<a href="#open-FILEHANDLE%2cEXPR">open</a>, which corresponds to C <i>fopen(3)</i>).
This is another way to protect your filenames from interpretation.  For
example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">IO::Handle</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/sysopen.html">sysopen</a><span class="s">(</span><a class="l_k" href="functions/my.html">my</a> <span class="i">$fh</span><span class="cm">,</span> <span class="i">$path</span><span class="cm">,</span> <span class="w">O_RDWR</span>|<span class="w">O_CREAT</span>|<span class="w">O_EXCL</span><span class="s">)</span></li><li>        <a class="l_k" href="functions/or.html">or</a> <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open $path: $!&quot;</span><span class="sc">;</span></li><li>    <span class="i">$fh</span><span class="i">-&gt;autoflush</span><span class="s">(</span><span class="n">1</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$fh</span> <span class="q">&quot;stuff $$\n&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/seek.html">seek</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span> <span class="n">0</span><span class="cm">,</span> <span class="n">0</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;File contains: &quot;</span><span class="cm">,</span> <a class="l_k" href="functions/readline.html">readline</a><span class="s">(</span><span class="i">$fh</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>See <a href="#seek-FILEHANDLE%2cPOSITION%2cWHENCE">seek</a> for some details about
mixing reading and writing.</p>
<p>Portability issues: <a href="perlport.html#open">open in perlport</a>.</p>
</li>
<li><a name="opendir-DIRHANDLE%2cEXPR"></a><b>opendir DIRHANDLE,EXPR
</b>
<p>Opens a directory named EXPR for processing by
<a href="#readdir-DIRHANDLE">readdir</a>, <a href="#telldir-DIRHANDLE">telldir</a>,
<a href="#seekdir-DIRHANDLE%2cPOS">seekdir</a>,
<a href="#rewinddir-DIRHANDLE">rewinddir</a>, and
<a href="#closedir-DIRHANDLE">closedir</a>.  Returns true if successful.
DIRHANDLE may be an expression whose value can be used as an indirect
dirhandle, usually the real dirhandle name.  If DIRHANDLE is an undefined
scalar variable (or array or hash element), the variable is assigned a
reference to a new anonymous dirhandle; that is, it's autovivified.
DIRHANDLEs have their own namespace separate from FILEHANDLEs.</p>
<p>See the example at <a href="#readdir-DIRHANDLE">readdir</a>.</p>
</li>
<li><a name="ord-EXPR"></a><b>ord EXPR
 </b>
</li>
<li><a name="ord"></a><b>ord</b>
<p>Returns the numeric value of the first character of EXPR.
If EXPR is an empty string, returns 0.  If EXPR is omitted, uses
<a href="perlvar.html#%24_">$_ </a>.
(Note <i>character</i>, not byte.)</p>
<p>For the reverse, see <a href="#chr-NUMBER">chr</a>.
See <a href="perlunicode.html">perlunicode</a> for more about Unicode.</p>
</li>
<li><a name="our-VARLIST"></a><b>our VARLIST
 </b>
</li>
<li><a name="our-TYPE-VARLIST"></a><b>our TYPE VARLIST</b>
</li>
<li><a name="our-VARLIST-%3a-ATTRS"></a><b>our VARLIST : ATTRS</b>
</li>
<li><a name="our-TYPE-VARLIST-%3a-ATTRS"></a><b>our TYPE VARLIST : ATTRS</b>
<p><a href="#our-VARLIST">our</a> makes a lexical alias to a package (i.e. global)
variable of the same name in the current package for use within the
current lexical scope.</p>
<p><a href="#our-VARLIST">our</a> has the same scoping rules as
<a href="#my-VARLIST">my</a> or <a href="#state-VARLIST">state</a>, meaning that it is
only valid within a lexical scope.  Unlike <a href="#my-VARLIST">my</a> and
<a href="#state-VARLIST">state</a>, which both declare new (lexical) variables,
<a href="#our-VARLIST">our</a> only creates an alias to an existing variable: a
package variable of the same name.</p>
<p>This means that when <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">strict</span> <span class="q">&#39;vars&#39;</span></code>
 is in effect, <a href="#our-VARLIST">our</a> lets you use a package variable without qualifying it with the
package name, but only within the lexical scope of the
<a href="#our-VARLIST">our</a> declaration.  This applies immediately--even
within the same statement.</p>
<pre class="verbatim"><ol><li><a name="package-Foo"></a>    package <span class="i">Foo</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">strict</span><span class="sc">;</span></li><li></li><li>    <span class="i">$Foo::foo</span> = <span class="n">23</span><span class="sc">;</span></li><li></li><li>    <span class="s">{</span></li><li>        <a class="l_k" href="functions/our.html">our</a> <span class="i">$foo</span><span class="sc">;</span>   <span class="c"># alias to $Foo::foo</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="i">$foo</span><span class="sc">;</span> <span class="c"># prints 23</span></li><li>    <span class="s">}</span></li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$Foo::foo</span><span class="sc">;</span> <span class="c"># prints 23</span></li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$foo</span><span class="sc">;</span> <span class="c"># ERROR: requires explicit package name</span></li></ol></pre><p>This works even if the package variable has not been used before, as
package variables spring into existence when first used.</p>
<pre class="verbatim"><ol><li><a name="package-Foo"></a>    package <span class="i">Foo</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">strict</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/our.html">our</a> <span class="i">$foo</span> = <span class="n">23</span><span class="sc">;</span>   <span class="c"># just like $Foo::foo = 23</span></li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$Foo::foo</span><span class="sc">;</span> <span class="c"># prints 23</span></li></ol></pre><p>Because the variable becomes legal immediately under <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">strict</span> <span class="q">&#39;vars&#39;</span></code>
, so
long as there is no variable with that name is already in scope, you can then
reference the package variable again even within the same statement.</p>
<pre class="verbatim"><ol><li><a name="package-Foo"></a>    package <span class="i">Foo</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">strict</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/my.html">my</a>  <span class="i">$foo</span> = <span class="i">$foo</span><span class="sc">;</span> <span class="c"># error, undeclared $foo on right-hand side</span></li><li>    <a class="l_k" href="functions/our.html">our</a> <span class="i">$foo</span> = <span class="i">$foo</span><span class="sc">;</span> <span class="c"># no errors</span></li></ol></pre><p>If more than one variable is listed, the list must be placed
in parentheses.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/our.html">our</a><span class="s">(</span><span class="i">$bar</span><span class="cm">,</span> <span class="i">$baz</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>An <a href="#our-VARLIST">our</a> declaration declares an alias for a package
variable that will be visible
across its entire lexical scope, even across package boundaries.  The
package in which the variable is entered is determined at the point
of the declaration, not at the point of use.  This means the following
behavior holds:</p>
<pre class="verbatim"><ol><li><a name="package-Foo"></a>    package <span class="i">Foo</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/our.html">our</a> <span class="i">$bar</span><span class="sc">;</span>      <span class="c"># declares $Foo::bar for rest of lexical scope</span></li><li>    <span class="i">$bar</span> = <span class="n">20</span><span class="sc">;</span></li><li></li><li><a name="package-Bar"></a>    package <span class="i">Bar</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$bar</span><span class="sc">;</span>    <span class="c"># prints 20, as it refers to $Foo::bar</span></li></ol></pre><p>Multiple <a href="#our-VARLIST">our</a> declarations with the same name in the
same lexical
scope are allowed if they are in different packages.  If they happen
to be in the same package, Perl will emit warnings if you have asked
for them, just like multiple <a href="#my-VARLIST">my</a> declarations.  Unlike
a second <a href="#my-VARLIST">my</a> declaration, which will bind the name to a
fresh variable, a second <a href="#our-VARLIST">our</a> declaration in the same
package, in the same scope, is merely redundant.</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">warnings</span><span class="sc">;</span></li><li><a name="package-Foo"></a>    package <span class="i">Foo</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/our.html">our</a> <span class="i">$bar</span><span class="sc">;</span>      <span class="c"># declares $Foo::bar for rest of lexical scope</span></li><li>    <span class="i">$bar</span> = <span class="n">20</span><span class="sc">;</span></li><li></li><li><a name="package-Bar"></a>    package <span class="i">Bar</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/our.html">our</a> <span class="i">$bar</span> = <span class="n">30</span><span class="sc">;</span> <span class="c"># declares $Bar::bar for rest of lexical scope</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$bar</span><span class="sc">;</span>    <span class="c"># prints 30</span></li><li></li><li>    <a class="l_k" href="functions/our.html">our</a> <span class="i">$bar</span><span class="sc">;</span>      <span class="c"># emits warning but has no other effect</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="i">$bar</span><span class="sc">;</span>    <span class="c"># still prints 30</span></li></ol></pre><p>An <a href="#our-VARLIST">our</a> declaration may also have a list of attributes
associated with it.</p>
<p>The exact semantics and interface of TYPE and ATTRS are still
evolving.  TYPE is currently bound to the use of the <a href="fields.html">fields</a> pragma,
and attributes are handled using the <a href="attributes.html">attributes</a> pragma, or, starting
from Perl 5.8.0, also via the <a href="Attribute/Handlers.html">Attribute::Handlers</a> module.  See
<a href="perlsub.html#Private-Variables-via-my()">Private Variables via my() in perlsub</a> for details.</p>
<p>Note that with a parenthesised list, <a href="#undef-EXPR">undef</a> can be used
as a dummy placeholder, for example to skip assignment of initial
values:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/our.html">our</a> <span class="s">(</span> <a class="l_k" href="functions/undef.html">undef</a><span class="cm">,</span> <span class="i">$min</span><span class="cm">,</span> <span class="i">$hour</span> <span class="s">)</span> = <a class="l_k" href="functions/localtime.html">localtime</a><span class="sc">;</span></li></ol></pre><p><a href="#our-VARLIST">our</a> differs from <a href="vars.html">use vars </a>, which allows
use of an unqualified name <i>only</i> within the affected package, but
across scopes.</p>
</li>
<li><a name="pack-TEMPLATE%2cLIST"></a><b>pack TEMPLATE,LIST
</b>
<p>Takes a LIST of values and converts it into a string using the rules
given by the TEMPLATE.  The resulting string is the concatenation of
the converted values.  Typically, each converted value looks
like its machine-level representation.  For example, on 32-bit machines
an integer may be represented by a sequence of 4 bytes, which  will in
Perl be presented as a string that's 4 characters long.</p>
<p>See <a href="perlpacktut.html">perlpacktut</a> for an introduction to this function.</p>
<p>The TEMPLATE is a sequence of characters that give the order and type
of values, as follows:</p>
<pre class="verbatim"><ol><li>    <span class="w">a</span>  <span class="w">A</span> <span class="w">string</span> <span class="w">with</span> <span class="w">arbitrary</span> <span class="w">binary</span> <span class="w">data</span><span class="cm">,</span> <span class="w">will</span> <span class="w">be</span> <span class="w">null</span> <span class="w">padded</span>.</li><li>    <span class="w">A</span>  <span class="w">A</span> <span class="w">text</span> <span class="s">(</span><span class="w">ASCII</span><span class="s">)</span> <span class="w">string</span><span class="cm">,</span> <span class="w">will</span> <span class="w">be</span> <span class="w">space</span> <span class="w">padded</span>.</li><li>    <span class="w">Z</span>  <span class="w">A</span> <span class="w">null</span>-<span class="w">terminated</span> <span class="s">(</span><span class="w">ASCIZ</span><span class="s">)</span> <span class="w">string</span><span class="cm">,</span> <span class="w">will</span> <span class="w">be</span> <span class="w">null</span> <span class="w">padded</span>.</li><li></li><li>    <span class="w">b</span>  <span class="w">A</span> <span class="w">bit</span> <span class="w">string</span> <span class="s">(</span><span class="w">ascending</span> <span class="w">bit</span> <span class="w">order</span> <span class="w">inside</span> <a class="l_k" href="functions/each.html">each</a> <span class="w">byte</span><span class="cm">,</span></li><li>       <span class="w">like</span> <a class="l_k" href="functions/vec.html">vec</a><span class="s">(</span><span class="s">)</span><span class="s">)</span>.</li><li>    <span class="w">B</span>  <span class="w">A</span> <span class="w">bit</span> <span class="w">string</span> <span class="s">(</span><span class="w">descending</span> <span class="w">bit</span> <span class="w">order</span> <span class="w">inside</span> <a class="l_k" href="functions/each.html">each</a> <span class="w">byte</span><span class="s">)</span>.</li><li>    <span class="w">h</span>  <span class="w">A</span> <a class="l_k" href="functions/hex.html">hex</a> <span class="w">string</span> <span class="s">(</span><span class="w">low</span> <span class="w">nybble</span> <span class="w">first</span><span class="s">)</span>.</li><li>    <span class="w">H</span>  <span class="w">A</span> <a class="l_k" href="functions/hex.html">hex</a> <span class="w">string</span> <span class="s">(</span><span class="w">high</span> <span class="w">nybble</span> <span class="w">first</span><span class="s">)</span>.</li><li></li><li>    <span class="w">c</span>  <span class="w">A</span> <span class="w">signed</span> <span class="w">char</span> <span class="s">(</span><span class="n">8</span>-<span class="w">bit</span><span class="s">)</span> <span class="w">value</span>.</li><li>    <span class="w">C</span>  <span class="w">An</span> <span class="w">unsigned</span> <span class="w">char</span> <span class="s">(</span><span class="w">octet</span><span class="s">)</span> <span class="w">value</span>.</li><li>    <span class="w">W</span>  <span class="w">An</span> <span class="w">unsigned</span> <span class="w">char</span> <span class="w">value</span> <span class="s">(</span><span class="w">can</span> <span class="w">be</span> <span class="w">greater</span> <span class="w">than</span> <span class="n">255</span><span class="s">)</span>.</li><li></li><li>    <span class="q">s  A signed short (16-bit) value.</span></li><li>    <span class="q">    S  An unsigned short value.</span></li><li></li><li>    <span class="q">    l  A</span> <span class="w">signed</span> <span class="w">long</span> <span class="s">(</span><span class="n">32</span>-<span class="w">bit</span><span class="s">)</span> <span class="w">value</span>.</li><li>    <span class="w">L</span>  <span class="w">An</span> <span class="w">unsigned</span> <span class="w">long</span> <span class="w">value</span>.</li><li></li><li>    <span class="q">q  A signed quad (64-bit) value.</span></li><li>    <span class="q">    Q  An</span> <span class="w">unsigned</span> <span class="w">quad</span> <span class="w">value</span>.</li><li>         <span class="s">(</span><span class="w">Quads</span> <span class="w">are</span> <span class="w">available</span> <span class="w">only</span> <a class="l_k" href="functions/if.html">if</a> <span class="w">your</span> <a class="l_k" href="functions/system.html">system</a> <span class="i">supports</span> <span class="n">64</span>-<span class="w">bit</span></li><li>          <span class="w">integer</span> <a class="l_k" href="functions/values.html">values</a> <span class="w">_and_</span> <a class="l_k" href="functions/if.html">if</a> <span class="w">Perl</span> <span class="w">has</span> <span class="w">been</span> <span class="w">compiled</span> <span class="w">to</span> <span class="w">support</span></li><li>          <span class="w">those</span>.  <span class="w">Raises</span> <span class="w">an</span> <span class="w">exception</span> <span class="w">otherwise</span>.<span class="s">)</span></li><li></li><li>    <span class="w">i</span>  <span class="w">A</span> <span class="w">signed</span> <span class="w">integer</span> <span class="w">value</span>.</li><li>    <span class="w">I</span>  <span class="w">A</span> <span class="w">unsigned</span> <span class="w">integer</span> <span class="w">value</span>.</li><li>         <span class="s">(</span><span class="w">This</span> <span class="q">&#39;integer&#39;</span> <span class="w">is</span> <span class="w">_at_least_</span> <span class="n">32</span> <span class="w">bits</span> <span class="w">wide</span>.  <span class="w">Its</span> <span class="w">exact</span></li><li>          <span class="w">size</span> <span class="w">depends</span> <span class="w">on</span> <span class="w">what</span> <span class="w">a</span> <a class="l_k" href="functions/local.html">local</a> <span class="w">C</span> <span class="w">compiler</span> <span class="w">calls</span> <span class="q">&#39;int&#39;</span>.<span class="s">)</span></li><li></li><li>    <span class="w">n</span>  <span class="w">An</span> <span class="w">unsigned</span> <span class="w">short</span> <span class="s">(</span><span class="n">16</span>-<span class="w">bit</span><span class="s">)</span> <span class="w">in</span> <span class="q">&quot;network&quot;</span> <span class="s">(</span><span class="w">big</span>-<span class="w">endian</span><span class="s">)</span> <span class="w">order</span>.</li><li>    <span class="w">N</span>  <span class="w">An</span> <span class="w">unsigned</span> <span class="w">long</span> <span class="s">(</span><span class="n">32</span>-<span class="w">bit</span><span class="s">)</span> <span class="w">in</span> <span class="q">&quot;network&quot;</span> <span class="s">(</span><span class="w">big</span>-<span class="w">endian</span><span class="s">)</span> <span class="w">order</span>.</li><li>    <span class="w">v</span>  <span class="w">An</span> <span class="w">unsigned</span> <span class="w">short</span> <span class="s">(</span><span class="n">16</span>-<span class="w">bit</span><span class="s">)</span> <span class="w">in</span> <span class="q">&quot;VAX&quot;</span> <span class="s">(</span><span class="w">little</span>-<span class="w">endian</span><span class="s">)</span> <span class="w">order</span>.</li><li>    <span class="w">V</span>  <span class="w">An</span> <span class="w">unsigned</span> <span class="w">long</span> <span class="s">(</span><span class="n">32</span>-<span class="w">bit</span><span class="s">)</span> <span class="w">in</span> <span class="q">&quot;VAX&quot;</span> <span class="s">(</span><span class="w">little</span>-<span class="w">endian</span><span class="s">)</span> <span class="w">order</span>.</li><li></li><li>    <span class="w">j</span>  <span class="w">A</span> <span class="w">Perl</span> <span class="w">internal</span> <span class="w">signed</span> <span class="w">integer</span> <span class="w">value</span> <span class="s">(</span><span class="w">IV</span><span class="s">)</span>.</li><li>    <span class="w">J</span>  <span class="w">A</span> <span class="w">Perl</span> <span class="w">internal</span> <span class="w">unsigned</span> <span class="w">integer</span> <span class="w">value</span> <span class="s">(</span><span class="w">UV</span><span class="s">)</span>.</li><li></li><li>    <span class="w">f</span>  <span class="w">A</span> <span class="w">single</span>-<span class="w">precision</span> <span class="w">float</span> <span class="w">in</span> <span class="w">native</span> format.</li><li><span class="hh">    d  A double-precision float in native format.</span></li><li></li><li><span class="hh">    F  A Perl internal floating-point value (NV) in native format</span></li><li><span class="hh">    D  A float of long-double precision in native format.</span></li><li><span class="hh">         (Long doubles are available only if your system supports</span></li><li><span class="hh">          long double values _and_ if Perl has been compiled to</span></li><li><span class="hh">          support those.  Raises an exception otherwise.</span></li><li><span class="hh">          Note that there are different long double formats.)</span></li><li></li><li><span class="hh">    p  A pointer to a null-terminated string.</span></li><li><span class="hh">    P  A pointer to a structure (fixed-length string).</span></li><li></li><li><span class="hh">    u  A uuencoded string.</span></li><li><span class="hh">    U  A Unicode character number.  Encodes to a character in char-</span></li><li><span class="hh">       acter mode and UTF-8 (or UTF-EBCDIC in EBCDIC platforms) in</span></li><li><span class="hh">       byte mode.</span></li><li></li><li><span class="hh">    w  A BER compressed integer (not an ASN.1 BER, see perlpacktut</span></li><li><span class="hh">       for details).  Its bytes represent an unsigned integer in</span></li><li><span class="hh">       base 128, most significant digit first, with as few digits</span></li><li><span class="hh">       as possible.  Bit eight (the high bit) is set on each byte</span></li><li><span class="hh">       except the last.</span></li><li></li><li><span class="hh">    x  A null byte (a.k.a ASCII NUL, &quot;\000&quot;, chr(0))</span></li><li><span class="hh">    X  Back up a byte.</span></li><li><span class="hh">    @  Null-fill or truncate to absolute position, counted from the</span></li><li><span class="hh">       start of the innermost ()-group.</span></li><li><span class="hh">    .  Null-fill or truncate to absolute position specified by</span></li><li><span class="hh">       the value.</span></li><li><span class="hh">    (  Start of a ()-group.</span></li></ol></pre><p>One or more modifiers below may optionally follow certain letters in the
TEMPLATE (the second column lists letters for which the modifier is valid):</p>
<pre class="verbatim"><ol><li>    !   <span class="w">sSlLiI</span>     <span class="w">Forces</span> <span class="w">native</span> <span class="s">(</span><span class="w">short</span><span class="cm">,</span> <span class="w">long</span><span class="cm">,</span> <a class="l_k" href="functions/int.html">int</a><span class="s">)</span> <span class="w">sizes</span> <span class="w">instead</span></li><li>                   <span class="w">of</span> <span class="w">fixed</span> <span class="s">(</span><span class="n">16</span>-<span class="q">/32-bit) sizes.</span></li><li></li><li>    <span class="q">    !   xX         Make x and X act as alignment commands.</span></li><li></li><li>    <span class="q">    !   nNvV       Treat integers as signed instead of unsigned.</span>&