diff options
Diffstat (limited to 'Changes')
-rw-r--r-- | Changes | 290 |
1 files changed, 230 insertions, 60 deletions
@@ -1,89 +1,259 @@ -New regexp routines derived from Henry Spencer's. - Support for /(foo|bar)/. - Support for /(foo)*/ and /(foo)+/. - \s for whitespace, \S nonwhitespace - \d for digit, \D nondigit +Changes to perl +--------------- -Local variables in blocks, subroutines and evals. +Apart from little bug fixes, here are the new features: -Recursive subroutine calls are now supported. +Perl can now handle binary data correctly and has functions to pack and +unpack binary structures into arrays or lists. You can now do arbitrary +ioctl functions. -Array values may now be interpolated into lists: - unlink 'foo', 'bar', @trashcan, 'tmp'; +You can do i/o with sockets and select. -File globbing via <*.foo>. +You can now write packages with their own namespace. -Use of <> in array contexts returns the whole file or glob list: - unlink <*.foo>; +You can now pass things to subroutines by reference. -New iterator for normal arrays, foreach, that allows both read and write: - foreach $elem ($array) { - $elem =~ s/foo/bar/; - } +The debugger now has hooks in the perl parser so it doesn't get confused. +The debugger won't interfere with stdin and stdout. New debugger commands: + n Single step around subroutine call. + l min+incr List incr+1 lines starting at min. + l List incr+1 more lines. + l subname List subroutine. + b subname Set breakpoint at first line of subroutine. + S List subroutine names. + D Delete all breakpoints. + A List line actions. + < command Define command before prompt. + > command Define command after prompt. + ! number Redo command (default previous command). + ! -number Redo numberth to last command. + h -number Display last number commands (default all). + p expr Same as \"print DBout expr\". -Ability to open pipe to a forked off script for secure pipes in setuid scripts. +The rules are more consistent about where parens are needed and +where they are not. In particular, unary operators and list operators now +behave like functions if they're called like functions. -File inclusion via - do 'foo.pl'; +There are some new quoting mechanisms: + $foo = q/"'"'"'"'"'"'"/; + $foo = qq/"'"''$bar"''/; + $foo = q(hi there); + $foo = <<'EOF' x 10; + Why, it's the old here-is mechanism! + EOF -More file tests, including -t to see if, for instance, stdin is -a terminal. File tests now behave in a more correct manner. You can do -file tests on filehandles as well as filenames. The special filetests --T and -B test a file to see if it's text or binary. +You can now work with array slices (note the initial @): + @foo[1,2,3]; + @foo{'Sun','Mon','Tue','Wed','Thu','Fri','Sat'} = (1,2,3,4,5,6,7); + @foo{split} = (1,1,1,1,1,1,1); -An eof can now be used on each file of the <> input for such purposes -as resetting the line numbers or appending to each file of an inplace edit. +There's now a range operator that works in array contexts: + for (1..15) { ... + @foo[3..5] = ('time','for','all'); + @foo{'Sun','Mon','Tue','Wed','Thu','Fri','Sat'} = 1..7; -Assignments can now function as lvalues, so you can say things like - ($HOST = $host) =~ tr/a-z/A-Z/; - ($obj = $src) =~ s/\.c$/.o/; +You can now reference associative arrays as a whole: + %abc = %def; + %foo = ('Sun',1,'Mon',2,'Tue',3,'Wed',4,'Thu',5,'Fri',6,'Sat',7); -You can now do certain file operations with a variable which holds the name -of a filehandle, e.g. open(++$incl,$includefilename); $foo = <$incl>; +Associative arrays can now be bound to a dbm or ndbm file. Perl automatically +caches references to the dbm file for you. -You can now a subroutine indirectly through a scalar variable: - $which = 'xyz'; - do $which('foo'); # calls xyz +An array or associative array can now be assigned to as part of a list, if +it's the last thing in the list: + ($a,$b,@rest) = split; -Warnings are now available (with -w) on use of uninitialized variables and on -identifiers that are mentioned only once, and on reference to various -undefined things. +An array or associative array may now appear in a local() list. + local(%assoc); + local(@foo) = @_; -The -S switch causes perl to search the PATH for the script so that you can say - eval "exec /usr/bin/perl -S $0 $*" - if $running_under_some_shell; +Array values may now be interpolated into strings: + `echo @ARGV`; + print "first three = @list[0..2]\n"; + print "@ENV{keys(ENV)}"; + ($" is used as the delimiter between array elements) -Reset now resets arrays and associative arrays as well as string variables. +Array sizes may be interpolated into strings: + print "The last element is $#foo.\n"; -Assigning off the end of an array now nulls out any intervening values. +Array values may now be returned from subroutines, evals, and do blocks. -$#foo is now an lvalue. You can preallocate or truncate arrays, or recover -values lost to prior truncation. +Lists of values in formats may now be arbitrary expressions, separated +by commas. -$#foo is now indexed to $[ properly. +Subroutine names are now distinguished by prefixing with &. You can call +subroutines without using do, and without passing any argument list at all: + $foo = &min($a,$b,$c); + $num = &myrand; -s/foo/bar/i optimization bug fixed. +You can use the new -u switch to cause perl to dump core so that you can +run undump and produce a binary executable image. Alternately you can +use the "dump" operator after initializing any variables and such. -The $x = "...$x..."; bug is fixed. +Perl now optimizes splits that are assigned directly to an array, or +to a list with fewer elements than the split would produce, or that +split on a constant string. -The @ary = (1); bug is now fixed. You can even say @ary = 1; +Perl now optimizes on end matches such as /foo$/; -$= now returns the correct value. +Perl now recognizes {n,m} in patterns to match preceding item at least n times +and no more than m times. Also recognizes {n,} and {n} to match n or more +times, or exactly n times. If { occurs in other than this context it is +still treated as a normal character. -Several of the larger files are now split into smaller pieces for easier -compilation. +Perl now optimizes "next" to avoid unnecessary longjmps and subroutine calls. -Pattern matches evaluated in an array context now return ($1, $2...). +Perl now optimizes appended input: $_ .= <>; -There is now a wait operator. +Substitutions are faster if the substituted text is constant, especially +when substituting at the beginning of a string. This plus the previous +optimization let you run down a file comparing multiple lines more +efficiently. (Basically the equivalents of sed's N and D are faster.) -There is now a sort operator. +Similarly, combinations of shifts and pushes on the same array are much +faster now--it doesn't copy all the pointers every time you shift (just +every n times, where n is approximately the length of the array plus 10, +more if you pre-extend the array), so you can use an array as a shift +register much more efficiently: + push(@ary,shift(@ary)); +or + shift(@ary); push(@ary,<>); -The requirement of parens around certain expressions when taking their value -has been lifted. In particular, you can say - $x = print "foo","bar"; - $x = unlink "foo","bar"; - chdir "foo" || die "Can't chdir to foo\n"; +The shift operator used inside subroutines now defaults to shifting +the @_ array. You can still shift ARGV explicitly, of course. + +The @_ array which is passed to subroutines is a local array, but the +elements of it are passed by reference now. This means that if you +explicitly modify $_[0], you are actually modifying the first argument +to the routine. Assignment to another location (such as the usual +local($foo) = @_ trick) causes a copy of the value, so this will not +affect most scripts. However, if you've modified @_ values in the +subroutine you could be in for a surprise. I don't believe most people +will find this a problem, and the long term efficiency gain is worth +a little confusion. + +Perl now detects sequences of references to the same variable and builds +switch statements internally wherever reasonable. + +The substr function can take offsets from the end of the string. + +The substr function can be assigned to in order to change the interior of a +string in place. + +The split function can return as part of the returned array any substrings +matched as part of the delimiter: + split(/([-,])/, '1-10,20') +returns + (1,'-',10,',',20) + +If you specify a maximum number of fields to split, the truncation of +trailing null fields is disabled. + +You can now chop lists. + +Perl now uses /bin/csh to do filename globbing, if available. This means +that filenames with spaces or other strangenesses work right. + +Perl can now report multiple syntax errors with a single invocation. + +Perl syntax errors now give two tokens of context where reasonable. + +Perl will now report the possibility of a runaway multi-line string if +such a string ends on a line with a syntax error. + +The assumed assignment in a while now works in the while modifier as +well as the while statement. + +Perl can now warn you if you use numeric == on non-numeric string values. + +New functions: + mkdir and rmdir + getppid + getpgrp and setpgrp + getpriority and setpriority + chroot + ioctl and fcntl + flock + readlink + lstat + rindex - find last occurrence of substring + pack and unpack - turn structures into arrays and vice versa + read - just what you think + warn - like die, only not fatal + dbmopen and dbmclose - bind a dbm file to an associative array + dump - do core dump so you can undump + reverse - turns an array value end for end + defined - does an object exist? + undef - make an object not exist + vec - treat string as a vector of small integers + fileno - return the file descriptor for a handle + wantarray - was subroutine called in array context? + opendir + readdir + telldir + seekdir + rewinddir + closedir + syscall + socket + bind + connect + listen + accept + shutdown + socketpair + getsockname + getpeername + getsockopt + setsockopt + getpwnam + getpwuid + getpwent + setpwent + endpwent + getgrnam + getgrgid + getgrent + setgrent + endgrent + gethostbyname + gethostbyaddr + gethostent + sethostent + endhostent + getnetbyname + getnetbyaddr + getnetent + setnetent + endnetent + getprotobyname + getprotobynumber + getprotoent + setprotoent + endprotoent + getservbyname + getservbyport + getservent + setservent + endservent + +Changes to s2p +-------------- + +In patterns, s2p now translates \{n,m\} correctly to {n,m}. + +In patterns, s2p no longer removes backslashes in front of |. + +In patterns, s2p now removes backslashes in front of [a-zA-Z0-9]. + +S2p now makes use of the location of perl as determined by Configure. + + +Changes to a2p +-------------- + +A2p can now accurately translate the "in" operator by using perl's new +"defined" operator. + +A2p can now accurately translate the passing of arrays by reference. -The manual is now not lying when it says that perl is generally faster than -sed. I hope. |