Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RE match problem in Perl 2.0 pl 18

0 views
Skip to first unread message

J Greely

unread,
Aug 24, 1989, 3:18:25 PM8/24/89
to
In article <JV.89Aug...@mhres.mh.nl> j...@mh.nl (Johan Vromans) writes:
>Using a regular expression in a match pattern seems to destroy the
>usability of the "$`" (dollar-leftquote) variable:

It's fixed in 3.0 alpha. My output was:

$` = abc, $' = ghi
$` = abc, $' = ghi
$` = , $' = defghi
$` = abcdef, $' =

-=-
J Greely (jgr...@cis.ohio-state.edu; osu-cis!jgreely)

Johan Vromans

unread,
Aug 24, 1989, 6:37:06 PM8/24/89
to
Perl version:

$Header: perly.c,v 2.0.1.10 88/11/22 01:14:58 lwall Locked $
Patch level: 18

Using a regular expression in a match pattern seems to destroy the
usability of the "$`" (dollar-leftquote) variable:

$a = "abcdefghi";
printf "\$` = %s, \$' = %s\n", $`, $' if $a =~ /def/;
printf "\$` = %s, \$' = %s\n", $`, $' if $a =~ /d.f/;
printf "\$` = %s, \$' = %s\n", $`, $' if $a =~ /^abc/;
printf "\$` = %s, \$' = %s\n", $`, $' if $a =~ /ghi$/;

produces:

$` = abc, $' = ghi

$` = , $' = ghi <== $` should be "abc"
$` = , $' = defghi <== could be correct...
$` = , $' = <== $` should be "abcdef"

--
johan
--
Johan Vromans j...@mh.nl via internet backbones
Multihouse Automatisering bv uucp: ..!{mcvax,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands phone/fax: +31 1820 62944/62500
------------------------ "Arms are made for hugging" -------------------------

Theodore Y. Ts'o

unread,
Aug 29, 1989, 2:16:41 AM8/29/89
to
In article <JGREELY.89...@oz.cis.ohio-state.edu> J Greely <jgr...@cis.ohio-state.edu> writes:
>It's fixed in 3.0 alpha. My output was:

Do you know when perl 3.0 will be coming out? What sort of features
does it have?

(Slobber, slobber..... an avid and enthusiastic user of perl 2.0
awaits.... :-)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Theodore Ts'o bloom-beacon!mit-athena!tytso
3 Ames St., Cambridge, MA 02139 ty...@athena.mit.edu
Everybody's playing the game, but nobody's rules are the same!

Larry Wall

unread,
Aug 29, 1989, 8:16:04 PM8/29/89
to
In article <13...@bloom-beacon.MIT.EDU> ty...@athena.mit.edu (Theodore Y. Ts'o) writes:
: Do you know when perl 3.0 will be coming out? What sort of features

: does it have?
:
: (Slobber, slobber..... an avid and enthusiastic user of perl 2.0
: awaits.... :-)

The beta will be coming out in a few days. I don't know what you're expecting,
I only made a few changes...

Here's the current change list:

Changes to perl
---------------

Apart from little bug fixes, here are the new features:

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.

You can do i/o with sockets and select.

You can now write packages with their own namespace.

You can now pass arrays and such to subroutines by reference.

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 Delete all line actions.
V package List all variables in a package.
< 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\".

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.

There are some new quoting mechanisms:
$foo = q/"'"'"'"'"'"'"/; # generalized single quote
$foo = qq/"'"''$bar"''/; # generalized double quote
$foo = <<'EOF' x 10;
Why, it's the old here-is mechanism!
EOF

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);

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;

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);

Associative arrays can now be bound to a dbm or ndbm file. Perl automatically
caches references to the dbm file for you.

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;

An array or associative array may now appear in a local() list.
local(%assoc);
local(@foo) = @_;

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)

Array sizes may be interpolated into strings:
print "The last element is $#foo.\n";

Array values may now be returned from subroutines, evals, and do blocks.

Lists of values in formats may now be arbitrary expressions, separated
by commas.

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;

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.

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.

Perl now optimizes on end matches such as /foo$/;

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.

Perl now optimizes "next" to avoid unnecessary longjmps and subroutine calls.

Perl now optimizes appended input: $_ .= <>;

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.)

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,<>);

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 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.

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


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.

------------------------------------------------

Larry Wall
lw...@jpl-devvax.jpl.nasa.gov

Mitchell Wyle

unread,
Aug 31, 1989, 9:45:32 AM8/31/89
to
I am still using awk because the book _The_AWK_Programming_Language_ is
so good. The examples in the book are useful and motivating.

Perl is better than awk. The man page is slightly better than awk's.
There is no book as good as A,W, and K's, however :-(

Are there enough of us who would buy the book to make it worth NASA's
while to pay Larry to write it?

Is there any political support (politics a la X-windows) to get someone
else to write it?

Is there a Perl-users mailing list?

A tout alors mes amours, -Mitch

J Greely

unread,
Aug 31, 1989, 2:15:26 PM8/31/89
to
In article <13...@ethz-inf.UUCP> wy...@inf.ethz.ch (Mitchell Wyle) writes:
>Perl is better than awk. The man page is slightly better than awk's.
>There is no book as good as A,W, and K's, however :-(
>Are there enough of us who would buy the book to make it worth NASA's
>while to pay Larry to write it?

Maybe, but what would you *call* it? "Kitchen Sink Shell
Programming"? "Cultered Perl"? "Diamonds in Perl"? "Never mind the
catsup, pass the features"?

>Is there a Perl-users mailing list?

No, but we could always start one. The scripts to manage it would, of
course, be in Perl (I have this nifty digest-maker, pity it breaks
under 3.0a...). As soon as my job situation settles a bit, I'd even
be willing to run it.


"Okay, Max, we need something from
each of the four basic food groups:
something from the dough-and-frosting
group, something from the carbonation-
and-caramel-coloring group --"

"How about the chewy-nougat-
center-and-chocolaty-coating
group?"

"Don't forget the orange marshmellow
peanuts! I think those are a
vegetable."

Larry Wall

unread,
Sep 1, 1989, 3:51:21 AM9/1/89
to
J Greely <jgr...@cis.ohio-state.edu> writes:
: Maybe, but what would you *call* it? "Kitchen Sink Shell

: Programming"? "Cultered Perl"? "Diamonds in Perl"? "Never mind the
: catsup, pass the features"?

"Don't Cast Your Perl's Before Swine", obviously. :-)

I am seriously considering writing a Perl book in my copious free time.
After all, it's the only way I'm ever gonna make any money off it.
Unless there's some billionaire out there that wants to set up a
foundation for aging techno-nerd hackers like me...

How about "The Perl of Great Price"?

Larry Wall
lw...@jpl-devvax.jpl.nasa.gov

Randal Schwartz

unread,
Sep 1, 1989, 11:23:37 AM9/1/89
to

As a heavy Perl user, and alpha tester for version 3 (a few of the
features in soon-to-be-released version were at my request), I dunno
about buying the book, but I'd contribute to *writing* it. (After
all, I've spent roughly half of the past 15 years putting black dots
on white paper for various computer companies, and the other half
shuffling ones and zeroes around...)

I think Perl should replace almost *any* use of sed or awk (maybe even
grep :-), because it does things so nicely. It was also written in
the traditional UNIX philosphy... build a toolset that is powerful and
robust and predictable enough so that you can do almost any task
"cleanly".

So, whadda ya say, Larry? How about a joint effort for a book on
"everything you've wanted to compute in Perl but were afraid to ask
LWALL..."? (And, when are you going to rewrite the Configure script
for Perl in Perl? :-)

Just another satisfied customer,
--
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel, Hillsboro, Oregon, USA |
| mer...@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/

Bakul Shah

unread,
Sep 2, 1989, 4:29:47 PM9/2/89
to
In article <59...@jpl-devvax.JPL.NASA.GOV> lw...@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
> ...
>How about "The Perl of Great Price"?

How about `programming perl'...

-- Bakul Shah <..!{ames,sun,ucbvax,uunet}!amdcad!light!bvs>

Tony Li

unread,
Sep 3, 1989, 3:56:57 AM9/3/89
to

The Perloined Program?

Tony Li - USC University Computing Services
Internet: t...@usc.edu Uucp: usc!tli Bitnet: tli@gamera, tli@ramoth
This is a test. This is a only a test. In the event of a real life
you would have been given instructions.

David Herron -- One of the vertebrae

unread,
Sep 4, 1989, 4:37:02 PM9/4/89
to
The Perls of Perline?
--
<- David Herron; an MMDF guy <da...@ms.uky.edu>
<- ska: David le casse\*' {rutgers,uunet}!ukma!david, da...@UKMA.BITNET
<-
<- "So raise your right hand if you thought that was a Russian water tentacle."

Perry Hutchison

unread,
Sep 5, 1989, 4:04:48 PM9/5/89
to
Redirecting this thread to comp.sources.d.

J Greely

unread,
Sep 6, 1989, 6:21:20 PM9/6/89
to
In article <12...@s.ms.uky.edu> da...@ms.uky.edu
(David Herron -- One of the vertebrae) writes:
>The Perls of Perline?

Judging from the general reaction around here, that should be "The
Perils of Perling".

How about "Stalking the SysAdmin with Perl and Hatchet"?


"I know it's not Unix, but it's
*convenient*!"

Jay Skeer

unread,
Sep 6, 1989, 8:39:40 PM9/6/89
to
How about, _Mother of Perl_ ?
j'
--

Jerry Aguirre

unread,
Sep 7, 1989, 12:37:04 AM9/7/89
to
"Wisdoms of Perl"

Mitchell Wyle

unread,
Sep 8, 1989, 10:37:46 AM9/8/89
to
>"Wisdoms of Perl"

Enough already!! We don't need a discussion about the title of a book.
We need chapter topics; we need more examples. We need useful "sub"s.
Would someone with more free time than I have *PLEASE* start a perl
users' mailing list? Please?

Does anyone remember this perl program?

eval "exec nice -19 perl $0 $*"
if $running_under_some_shell;
# ---------------------------------------------------------------------------
# pi.perl computes pi (3.14...) about 5120 Digits
#
# W. Kebsch, July-1988 {uunet!mcvax}!unido!nixpbe!kebsch

$my_name = `basename $0`; chop($my_name);
$version = $my_name . "-1.2";

# some working parameter

$smax = 5120; # max digits
$lmax = 4; # digits per one array element
$hmax = 10000; # one array element contains: 0..9999
$smin = $lmax; # min digits
$mag = 7; # magic number

# subroutines

sub mul_tm # multiply the tm array with a long value
{
$cb = pop(@_); # elements(array)
$x = pop(@_); # value

$c = 0;
for($i = 1; $i <= $cb; $i++)
{
$z = $tm[$i] * $x + $c;
$c = int($z / $hmax);
$tm[$i] = $z - $c * $hmax;
}
}

sub mul_pm # multiply the pm array with a long value
{
$cb = pop(@_); # elements(array)
$x = pop(@_); # value

$c = 0;
for($i = 1; $i <= $cb; $i++)
{
$z = $pm[$i] * $x + $c;
$c = int($z / $hmax);
$pm[$i] = $z - $c * $hmax;
}
}

sub divide # divide the tm array by a long value
{
$cb = pop(@_); # elements(array)
$x = pop(@_); # value

$c = 0;
for($i = $cb; $i >= 1; $i--)
{
$z = $tm[$i] + $c;
$q = int($z / $x);
$tm[$i] = $q;
$c = ($z - $q * $x) * $hmax;
}
}

sub add # add tm array to pm array
{
$cb = pop(@_); # elements(array)

$c = 0;
for($i = 1; $i <= $cb; $i++)
{
$z = $pm[$i] + $tm[$i] + $c;
if($z >= $hmax)
{
$pm[$i] = $z - $hmax;
$c = 1;
}
else
{
$pm[$i] = $z;
$c = 0;
}
}
}

$m0 = 0; $m1 = 0; $m2 = 0;

sub check_xb # reduce current no. of elements (speed up!)
{
$cb = pop(@_); # current no. of elements

if(($pm[$cb] == $m0) && ($pm[$cb - 1] == $m1) && ($pm[$cb - 2] == $m2))
{
$cb--;
}
$m0 = $pm[$cb];
$m1 = $pm[$cb - 1];
$m2 = $pm[$cb - 2];
$cb;
}

sub display # show the result
{
$cb = pop(@_); # elements(array);

printf("\n%3d.", $pm[$cb]);
$j = $mag - $lmax;
for($i = $cb - 1; $i >= $j; $i--)
{
printf(" %04d", $pm[$i]);
}
print "\n";
}

sub the_job # let's do the job
{
$s = pop(@_); # no. of digits

$s = int(($s + $lmax - 1) / $lmax) * $lmax;
$b = int($s / $lmax) + $mag - $lmax;
$xb = $b;
$t = int($s * 5 / 3);

for($i = 1; $i <= $b; $i++) # init arrays
{
$pm[$i] = 0;
$tm[$i] = 0;
}
$pm[$b - 1] = $hmax / 2;
$tm[$b - 1] = $hmax / 2;

printf("digits:%5d, terms:%5d, elements:%5d\n", $s, $t, $b);
for($n = 1; $n <= $t; $n++)
{
printf("\r\t\t\t term:%5d", $n);
if($n < 200)
{
do mul_tm((4 * ($n * $n - $n) + 1), $xb);
}
else
{
do mul_tm((2 * $n - 1), $xb);
do mul_tm((2 * $n - 1), $xb);
}
if($n < 100)
{
do divide(($n * (16 * $n + 8)), $xb);
}
else
{
do divide((8 * $n), $xb);
do divide((2 * $n + 1), $xb);
}
do add($xb);
if($xb > $mag)
{
$xb = do check_xb($xb);
}
}
do mul_pm(6, $b);
do display($b);
($user,$sys,$cuser,$csys) = times;
printf("\n[u=%g s=%g cu=%g cs=%g]\n",$user, $sys, $cuser, $csys);
}

# main block ----------------------------------------------------------------

$no_of_args = $#ARGV + 1;
print("$version, ");
die("usage: $my_name <no. of digits>") unless($no_of_args == 1);
$digits = int($ARGV[0]);
die("no. of digits out of range [$smin\..$smax]")
unless(($digits >= $smin) && ($digits <= $smax));
do the_job($digits);
exit 0;

# That's all ----------------------------------------------------------------

Marc Rouleau

unread,
Sep 8, 1989, 4:16:30 PM9/8/89
to
wy...@ethz.UUCP (Mitchell Wyle) writes:
>
>Enough already!! We don't need a discussion about the title of a book.
>We need chapter topics; we need more examples. We need useful "sub"s.
>Would someone with more free time than I have *PLEASE* start a perl
>users' mailing list? Please?

Ok. The list address is

Internet: Perl-...@Virginia.EDU
USENET: ...!uunet!virginia!perl-users

and the service address is

Internet: Perl-User...@Virginia.EDU
USENET: ...!uunet!virginia!perl-users-request

Send requests to be added or deleted to the service address ONLY.

I don't have much time to put into this. I'm willing to handle updating
of the list and that's about it. If someone would like to compose a
welcome message, I'd be happy to send that out with each subscription;
otherwise, I'll just respond with a brief acknowledgment.

If you have trouble reaching the service address, send mail to

me...@uvaarpa.Virginia.EDU

-- Marc Rouleau

J Greely

unread,
Sep 8, 1989, 6:19:14 PM9/8/89
to
In article <6...@uvaarpa.virginia.edu> me...@uvaarpa.virginia.edu
(Marc Rouleau) writes:
[now there's a mailing list...]

How about an archive site? Anything perlish mailed to me will get put
into pub/perl on tut.cis.ohio-state.edu, which at this moment contains
source for 2.18 and 3.0b.

Perry Hutchison

unread,
Sep 9, 1989, 6:00:48 AM9/9/89
to
"Duke of Perl"

Trying once again to redirect this thread to comp.sources.d

0 new messages