perl 3.0 patch #44 patch #42, continued
[p5sagit/p5-mst-13.2.git] / Changes
CommitLineData
a687059c 1Changes to perl
2---------------
378cc40b 3
a687059c 4Apart from little bug fixes, here are the new features:
378cc40b 5
a687059c 6Perl can now handle binary data correctly and has functions to pack and
7unpack binary structures into arrays or lists. You can now do arbitrary
8ioctl functions.
378cc40b 9
a687059c 10You can do i/o with sockets and select.
378cc40b 11
a687059c 12You can now write packages with their own namespace.
378cc40b 13
a687059c 14You can now pass things to subroutines by reference.
378cc40b 15
a687059c 16The debugger now has hooks in the perl parser so it doesn't get confused.
17The 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\".
378cc40b 32
a687059c 33The rules are more consistent about where parens are needed and
34where they are not. In particular, unary operators and list operators now
35behave like functions if they're called like functions.
378cc40b 36
a687059c 37There 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
378cc40b 44
a687059c 45You 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);
378cc40b 49
a687059c 50There'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;
378cc40b 54
a687059c 55You 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);
378cc40b 58
a687059c 59Associative arrays can now be bound to a dbm or ndbm file. Perl automatically
60caches references to the dbm file for you.
378cc40b 61
a687059c 62An array or associative array can now be assigned to as part of a list, if
63it's the last thing in the list:
64 ($a,$b,@rest) = split;
378cc40b 65
a687059c 66An array or associative array may now appear in a local() list.
67 local(%assoc);
68 local(@foo) = @_;
378cc40b 69
a687059c 70Array 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)
378cc40b 75
a687059c 76Array sizes may be interpolated into strings:
77 print "The last element is $#foo.\n";
378cc40b 78
a687059c 79Array values may now be returned from subroutines, evals, and do blocks.
378cc40b 80
a687059c 81Lists of values in formats may now be arbitrary expressions, separated
82by commas.
378cc40b 83
a687059c 84Subroutine names are now distinguished by prefixing with &. You can call
85subroutines without using do, and without passing any argument list at all:
86 $foo = &min($a,$b,$c);
87 $num = &myrand;
378cc40b 88
a687059c 89You can use the new -u switch to cause perl to dump core so that you can
90run undump and produce a binary executable image. Alternately you can
91use the "dump" operator after initializing any variables and such.
378cc40b 92
a687059c 93Perl now optimizes splits that are assigned directly to an array, or
94to a list with fewer elements than the split would produce, or that
95split on a constant string.
378cc40b 96
a687059c 97Perl now optimizes on end matches such as /foo$/;
378cc40b 98
a687059c 99Perl now recognizes {n,m} in patterns to match preceding item at least n times
100and no more than m times. Also recognizes {n,} and {n} to match n or more
101times, or exactly n times. If { occurs in other than this context it is
102still treated as a normal character.
378cc40b 103
a687059c 104Perl now optimizes "next" to avoid unnecessary longjmps and subroutine calls.
378cc40b 105
a687059c 106Perl now optimizes appended input: $_ .= <>;
378cc40b 107
a687059c 108Substitutions are faster if the substituted text is constant, especially
109when substituting at the beginning of a string. This plus the previous
110optimization let you run down a file comparing multiple lines more
111efficiently. (Basically the equivalents of sed's N and D are faster.)
378cc40b 112
a687059c 113Similarly, combinations of shifts and pushes on the same array are much
114faster now--it doesn't copy all the pointers every time you shift (just
115every n times, where n is approximately the length of the array plus 10,
116more if you pre-extend the array), so you can use an array as a shift
117register much more efficiently:
118 push(@ary,shift(@ary));
119or
120 shift(@ary); push(@ary,<>);
378cc40b 121
a687059c 122The shift operator used inside subroutines now defaults to shifting
123the @_ array. You can still shift ARGV explicitly, of course.
124
125The @_ array which is passed to subroutines is a local array, but the
126elements of it are passed by reference now. This means that if you
127explicitly modify $_[0], you are actually modifying the first argument
128to the routine. Assignment to another location (such as the usual
129local($foo) = @_ trick) causes a copy of the value, so this will not
130affect most scripts. However, if you've modified @_ values in the
131subroutine you could be in for a surprise. I don't believe most people
132will find this a problem, and the long term efficiency gain is worth
133a little confusion.
134
135Perl now detects sequences of references to the same variable and builds
136switch statements internally wherever reasonable.
137
138The substr function can take offsets from the end of the string.
139
140The substr function can be assigned to in order to change the interior of a
141string in place.
142
143The split function can return as part of the returned array any substrings
144matched as part of the delimiter:
145 split(/([-,])/, '1-10,20')
146returns
147 (1,'-',10,',',20)
148
149If you specify a maximum number of fields to split, the truncation of
150trailing null fields is disabled.
151
152You can now chop lists.
153
154Perl now uses /bin/csh to do filename globbing, if available. This means
155that filenames with spaces or other strangenesses work right.
156
157Perl can now report multiple syntax errors with a single invocation.
158
159Perl syntax errors now give two tokens of context where reasonable.
160
161Perl will now report the possibility of a runaway multi-line string if
162such a string ends on a line with a syntax error.
163
164The assumed assignment in a while now works in the while modifier as
165well as the while statement.
166
167Perl can now warn you if you use numeric == on non-numeric string values.
168
169New 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
240Changes to s2p
241--------------
242
243In patterns, s2p now translates \{n,m\} correctly to {n,m}.
244
245In patterns, s2p no longer removes backslashes in front of |.
246
247In patterns, s2p now removes backslashes in front of [a-zA-Z0-9].
248
249S2p now makes use of the location of perl as determined by Configure.
250
251
252Changes to a2p
253--------------
254
255A2p can now accurately translate the "in" operator by using perl's new
256"defined" operator.
257
258A2p can now accurately translate the passing of arrays by reference.
378cc40b 259