4 Apart from little bug fixes, here are the new features:
6 Perl can now handle binary data correctly and has functions to pack and
7 unpack binary structures into arrays or lists. You can now do arbitrary
10 You can do i/o with sockets and select.
12 You can now write packages with their own namespace.
14 You can now pass things to subroutines by reference.
16 The debugger now has hooks in the perl parser so it doesn't get confused.
17 The debugger won't interfere with stdin and stdout. New debugger commands:
18 n Single step around subroutine call.
19 l min+incr List incr+1 lines starting at min.
20 l List incr+1 more lines.
21 l subname List subroutine.
22 b subname Set breakpoint at first line of subroutine.
23 S List subroutine names.
24 D Delete all breakpoints.
26 < command Define command before prompt.
27 > command Define command after prompt.
28 ! number Redo command (default previous command).
29 ! -number Redo numberth to last command.
30 h -number Display last number commands (default all).
31 p expr Same as \"print DBout expr\".
33 The rules are more consistent about where parens are needed and
34 where they are not. In particular, unary operators and list operators now
35 behave like functions if they're called like functions.
37 There are some new quoting mechanisms:
38 $foo = q/"'"'"'"'"'"'"/;
39 $foo = qq/"'"''$bar"''/;
42 Why, it's the old here-is mechanism!
45 You can now work with array slices (note the initial @):
47 @foo{'Sun','Mon','Tue','Wed','Thu','Fri','Sat'} = (1,2,3,4,5,6,7);
48 @foo{split} = (1,1,1,1,1,1,1);
50 There's now a range operator that works in array contexts:
52 @foo[3..5] = ('time','for','all');
53 @foo{'Sun','Mon','Tue','Wed','Thu','Fri','Sat'} = 1..7;
55 You can now reference associative arrays as a whole:
57 %foo = ('Sun',1,'Mon',2,'Tue',3,'Wed',4,'Thu',5,'Fri',6,'Sat',7);
59 Associative arrays can now be bound to a dbm or ndbm file. Perl automatically
60 caches references to the dbm file for you.
62 An array or associative array can now be assigned to as part of a list, if
63 it's the last thing in the list:
64 ($a,$b,@rest) = split;
66 An array or associative array may now appear in a local() list.
70 Array values may now be interpolated into strings:
72 print "first three = @list[0..2]\n";
73 print "@ENV{keys(ENV)}";
74 ($" is used as the delimiter between array elements)
76 Array sizes may be interpolated into strings:
77 print "The last element is $#foo.\n";
79 Array values may now be returned from subroutines, evals, and do blocks.
81 Lists of values in formats may now be arbitrary expressions, separated
84 Subroutine names are now distinguished by prefixing with &. You can call
85 subroutines without using do, and without passing any argument list at all:
86 $foo = &min($a,$b,$c);
89 You can use the new -u switch to cause perl to dump core so that you can
90 run undump and produce a binary executable image. Alternately you can
91 use the "dump" operator after initializing any variables and such.
93 Perl now optimizes splits that are assigned directly to an array, or
94 to a list with fewer elements than the split would produce, or that
95 split on a constant string.
97 Perl now optimizes on end matches such as /foo$/;
99 Perl now recognizes {n,m} in patterns to match preceding item at least n times
100 and no more than m times. Also recognizes {n,} and {n} to match n or more
101 times, or exactly n times. If { occurs in other than this context it is
102 still treated as a normal character.
104 Perl now optimizes "next" to avoid unnecessary longjmps and subroutine calls.
106 Perl now optimizes appended input: $_ .= <>;
108 Substitutions are faster if the substituted text is constant, especially
109 when substituting at the beginning of a string. This plus the previous
110 optimization let you run down a file comparing multiple lines more
111 efficiently. (Basically the equivalents of sed's N and D are faster.)
113 Similarly, combinations of shifts and pushes on the same array are much
114 faster now--it doesn't copy all the pointers every time you shift (just
115 every n times, where n is approximately the length of the array plus 10,
116 more if you pre-extend the array), so you can use an array as a shift
117 register much more efficiently:
118 push(@ary,shift(@ary));
120 shift(@ary); push(@ary,<>);
122 The shift operator used inside subroutines now defaults to shifting
123 the @_ array. You can still shift ARGV explicitly, of course.
125 The @_ array which is passed to subroutines is a local array, but the
126 elements of it are passed by reference now. This means that if you
127 explicitly modify $_[0], you are actually modifying the first argument
128 to the routine. Assignment to another location (such as the usual
129 local($foo) = @_ trick) causes a copy of the value, so this will not
130 affect most scripts. However, if you've modified @_ values in the
131 subroutine you could be in for a surprise. I don't believe most people
132 will find this a problem, and the long term efficiency gain is worth
135 Perl now detects sequences of references to the same variable and builds
136 switch statements internally wherever reasonable.
138 The substr function can take offsets from the end of the string.
140 The substr function can be assigned to in order to change the interior of a
143 The split function can return as part of the returned array any substrings
144 matched as part of the delimiter:
145 split(/([-,])/, '1-10,20')
149 If you specify a maximum number of fields to split, the truncation of
150 trailing null fields is disabled.
152 You can now chop lists.
154 Perl now uses /bin/csh to do filename globbing, if available. This means
155 that filenames with spaces or other strangenesses work right.
157 Perl can now report multiple syntax errors with a single invocation.
159 Perl syntax errors now give two tokens of context where reasonable.
161 Perl will now report the possibility of a runaway multi-line string if
162 such a string ends on a line with a syntax error.
164 The assumed assignment in a while now works in the while modifier as
165 well as the while statement.
167 Perl can now warn you if you use numeric == on non-numeric string values.
173 getpriority and setpriority
179 rindex - find last occurrence of substring
180 pack and unpack - turn structures into arrays and vice versa
181 read - just what you think
182 warn - like die, only not fatal
183 dbmopen and dbmclose - bind a dbm file to an associative array
184 dump - do core dump so you can undump
185 reverse - turns an array value end for end
186 defined - does an object exist?
187 undef - make an object not exist
188 vec - treat string as a vector of small integers
189 fileno - return the file descriptor for a handle
190 wantarray - was subroutine called in array context?
243 In patterns, s2p now translates \{n,m\} correctly to {n,m}.
245 In patterns, s2p no longer removes backslashes in front of |.
247 In patterns, s2p now removes backslashes in front of [a-zA-Z0-9].
249 S2p now makes use of the location of perl as determined by Configure.
255 A2p can now accurately translate the "in" operator by using perl's new
258 A2p can now accurately translate the passing of arrays by reference.