This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 3.0 patch #20 patch #19, continued
[perl5.git] / Changes
1 Changes to perl
2 ---------------
3
4 Apart from little bug fixes, here are the new features:
5
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
8 ioctl functions.
9
10 You can do i/o with sockets and select.
11
12 You can now write packages with their own namespace.
13
14 You can now pass things to subroutines by reference.
15
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.
25         A               List line actions.
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\".
32
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.
36
37 There are some new quoting mechanisms:
38         $foo = q/"'"'"'"'"'"'"/;
39         $foo = qq/"'"''$bar"''/;
40         $foo = q(hi there);
41         $foo = <<'EOF' x 10;
42         Why, it's the old here-is mechanism!
43         EOF
44
45 You can now work with array slices (note the initial @):
46         @foo[1,2,3];
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);
49
50 There's now a range operator that works in array contexts:
51         for (1..15) { ...
52         @foo[3..5] = ('time','for','all');
53         @foo{'Sun','Mon','Tue','Wed','Thu','Fri','Sat'} = 1..7;
54
55 You can now reference associative arrays as a whole:
56         %abc = %def;
57         %foo = ('Sun',1,'Mon',2,'Tue',3,'Wed',4,'Thu',5,'Fri',6,'Sat',7);
58
59 Associative arrays can now be bound to a dbm or ndbm file.  Perl automatically
60 caches references to the dbm file for you.
61
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;
65
66 An array or associative array may now appear in a local() list.
67         local(%assoc);
68         local(@foo) = @_;
69
70 Array values may now be interpolated into strings:
71         `echo @ARGV`;
72         print "first three = @list[0..2]\n";
73         print "@ENV{keys(ENV)}";
74         ($" is used as the delimiter between array elements)
75
76 Array sizes may be interpolated into strings:
77         print "The last element is $#foo.\n";
78
79 Array values may now be returned from subroutines, evals, and do blocks.
80
81 Lists of values in formats may now be arbitrary expressions, separated
82 by commas.
83
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);
87         $num = &myrand;
88
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.
92
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.
96
97 Perl now optimizes on end matches such as /foo$/;
98
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.
103
104 Perl now optimizes "next" to avoid unnecessary longjmps and subroutine calls.
105
106 Perl now optimizes appended input: $_ .= <>;
107
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.)
112
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));
119 or
120         shift(@ary); push(@ary,<>);
121
122 The shift operator used inside subroutines now defaults to shifting
123 the @_ array.  You can still shift ARGV explicitly, of course.
124
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
133 a little confusion.
134
135 Perl now detects sequences of references to the same variable and builds
136 switch statements internally wherever reasonable.
137
138 The substr function can take offsets from the end of the string.
139
140 The substr function can be assigned to in order to change the interior of a
141 string in place.
142
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')
146 returns
147         (1,'-',10,',',20)
148
149 If you specify a maximum number of fields to split, the truncation of
150 trailing null fields is disabled.
151
152 You can now chop lists.
153
154 Perl now uses /bin/csh to do filename globbing, if available.  This means
155 that filenames with spaces or other strangenesses work right.
156
157 Perl can now report multiple syntax errors with a single invocation.
158
159 Perl syntax errors now give two tokens of context where reasonable.
160
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.
163
164 The assumed assignment in a while now works in the while modifier as
165 well as the while statement.
166
167 Perl can now warn you if you use numeric == on non-numeric string values.
168
169 New functions:
170         mkdir and rmdir
171         getppid
172         getpgrp and setpgrp
173         getpriority and setpriority
174         chroot
175         ioctl and fcntl
176         flock
177         readlink
178         lstat
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?
191         opendir
192         readdir
193         telldir
194         seekdir
195         rewinddir
196         closedir
197         syscall
198         socket
199         bind
200         connect
201         listen
202         accept
203         shutdown
204         socketpair
205         getsockname
206         getpeername
207         getsockopt
208         setsockopt
209         getpwnam
210         getpwuid
211         getpwent
212         setpwent
213         endpwent
214         getgrnam
215         getgrgid
216         getgrent
217         setgrent
218         endgrent
219         gethostbyname
220         gethostbyaddr
221         gethostent
222         sethostent
223         endhostent
224         getnetbyname
225         getnetbyaddr
226         getnetent
227         setnetent
228         endnetent
229         getprotobyname
230         getprotobynumber
231         getprotoent
232         setprotoent
233         endprotoent
234         getservbyname
235         getservbyport
236         getservent
237         setservent
238         endservent
239
240 Changes to s2p
241 --------------
242
243 In patterns, s2p now translates \{n,m\} correctly to {n,m}.
244
245 In patterns, s2p no longer removes backslashes in front of |.
246
247 In patterns, s2p now removes backslashes in front of [a-zA-Z0-9].
248
249 S2p now makes use of the location of perl as determined by Configure.
250
251
252 Changes to a2p
253 --------------
254
255 A2p can now accurately translate the "in" operator by using perl's new
256 "defined" operator.
257
258 A2p can now accurately translate the passing of arrays by reference.
259