HDTenEightyP/NetNews huggingface dataset:
From: Rick Emerson <rick@ssg.com>
Subject: Re:  Includes in MS-DOS perl?
Reply-To: rick@ssg.com
Organization: The Internet
Date: Fri, 16 Oct 1992 15:59:09 GMT

| From: Rick Emerson <rick@ssg.com>
| Subject: Includes in MS-DOS perl?
| Date: Thu, 15 Oct 1992 14:57:51 GMT
| 
| I'm unable to include a package of subroutines (rfc822.pl) in my MS-DOS
| version of perl.  I've tried a number of variants of
|    #include <c:/waffle/bin/rfc822.pl>
| with slashs tilted foreward and backwards, with quotes around the string
| (with and without the surrounding <>).  I also tried -I c:/waffle/bin and
| even -I c:/waffle/bin/rfc822.pl.  I moved a copy of rfc822.pl into the
| sub-directory with perl.exe.  All have been fruitless.  The manpage shipped
| with this version of perl says the normal include should work - obviously,
| I'm missing something.  What?
|  

Thanks to everyone who replied.

The something I was missing is "require" (see p 169 of the camel book). 
Substituting
   require "rfc822.pl"
for 
   #include <rfc822.pl>
worked like a champ.  

Also, the default location for libraries for the MS-DOS versions of perl
seems to be \usr\local\lib - at least that worked for me.  Of course
   -I \foo\bar\bletch
will give an alternate location.

Rick


| Richard B. Emerson     | Replies may be sent to:                         |
| System Support Group   |                        rick@ssg.com             |
| 940 Delaware Avenue    |-------------------------------------------------+
| Lansdale, PA 19446 USA | "...don't forget to listen to the steady beat,  |
| Voice: 215.855.1607    |  don't forget to balance on your ready feet."   |
From: hhg1@gte.com (Hal German)
Newsgroups: comp.lang.perl
Subject: SAS versus Perl: an update
Date: 9 Oct 92 11:06:41 GMT
Followup-To: comp.lang.perl
Organization: GTE Labs

Just wanted to say that this was an interesting thread. I'd be curious to
see
someone's code where they piped a SAS program from perl or a perl program
from
SAS. My NESUG (Northeeast SAS Users Group) 90 paper talks about the
relationship
between SAS and command languages and proposes a model describing this. It
was
the starting point for my second book The Command Language Cookbook (which
has
a chapter on Perl.)

At the NESUG 92 conference, I had the previously posted paper (with
corrections) as a poster. A lot of people had never heard of Perl before
but were interested because of the price and the high portability factor. 

Hal German
hhg1@gte.com
Newsgroups: comp.lang.perl
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: Where do I find my packages?
Originator: tchrist@pixel.convex.com
Date: Mon, 12 Oct 1992 01:51:11 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: Convex Computer Corporation, Colorado Springs, CO
X-Disclaimer: This message was written by a user at CONVEX Computer
              Corp. The opinions expressed are those of the user and
              not necessarily those of CONVEX.

From the keyboard of sommar@enea.se (Erland Sommarskog):
:Is there some special place somewhere I can find the names of
:all packages in my script?

Run down all the keys in %_main{} and check their values
for magic best derived by checking out the debugger.

:The background problem: I have a general abort routine which I
:call instead of simply saying "die". Today it looks for a cleanup
:routine in the main and the locks packages if they are defined, 
:but it would be much more elegant if I could traverse the array 
:of packages, and call each cleanup routine I find.

Instead of looking through the symbol table, have each return
register an atexit() function to call.

:By the way, it would be a nice extention to the language if
:dies were trappable to faciliate when you need to do some
:cleanup before you exit.

Already happens.  It's called eval.  Do something like this:

        sub atexit { push(@_exit_subs, @_); }

        sub _cleanup { unlink $tmp; }

        &atexit('_cleanup');

        eval <<'End_Of_Eval';  $here = __LINE__;
        # as much code here as you want
        End_Of_Eval

        $oops = $@;  # save error message

        # now call his stuff
        for (@_exit_subs) {  do $_(); }

        $oops && ($oops =~ s/\(eval\) line (\d+)/$0 .
            " line " . ($1+$here)/e, die $oops);


Put the main code between the eval and End_Of_Eval. I'd just make a
function &main and call that myself, like:

    eval '&main()';

--tom
-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist

    "It is easier to port a shell than a shell script."
		--Larry Wall
Newsgroups: comp.lang.perl
From: rstory@elegant.com (Robert Story)
Subject: Re: Perl and sco unix (??)
Summary: perl config.sh available for SCO UNIX 3.2.2
Date: Fri, 9 Oct 1992 17:09:39 GMT
Organization: Elegant Communications Inc.
Keywords: sco unix config.sh


Last week I posted a query with regerd to getting perl configured and 
running for SCO UNIX 3.2.2.

Chris Hare <chare@unilabs.unilabs> sent me his config.sh for ODT.  By
using this as a basis I was able to get perl up and running and passing
the 'make test' suite.

If anyone would like my config.sh, please feel free to e-mail me for it.

                               -Robert.


-- 
 _________________________________________________________________________
 Robert.Story@Elegant.COM                      Elegant Communications Inc.
 Tel: +1 416 362 9772                        4 King Street West Suite 1101
 Fax: +1 416 362 8324                     Toronto, Ontario; CANADA M5H 1B6
Newsgroups: comp.lang.perl
From: deeken@iti.informatik.th-darmstadt.de (Hans-Christoph Deeken)
Subject: Re: Perl for BSD
Date: Thu, 8 Oct 1992 17:00:58 GMT
Organization: TU Darmstadt
Keywords: perl,pc,bsd

In article <1692@enst.enst.fr>, tardieu@artemis.enst.fr (Samuel Tardieu) writes:

> Did anyone already port Perl on this system ? Or are the binaries downloadable ? 

Yes, I did. No, not yet. :-)

I have perl 4.0pl35 up and running on my system. It passes all but one test
(lib/big, concerning big numbers or so).
If I ever find the time, I send the patches to Larry Wall and put the binaries
& patches on agate. But I can't predict when this will happen, since my BSD
machine doesn't see me very often at the moment. :-(

So take this as a "It can be done" message. ;)


> Thanks for all.
> -- 
>      Samuel TARDIEU  -  Telecom Paris  -  tardieu@enst.fr  -  (1) 45-81-71-97

So long,
Hannes
-- 
Hans-Christoph Deeken                                        (Glenlivet on IRC)
Inst. fuer theoret. Informatik		(deeken@iti.informatik.th-darmstadt.de)
TH Darmstadt, Germany          (I don't speak for THD, they don't speak for me)
        "Whisky ist fluessiges Sonnenlicht --- George Bernard Shaw"
From: mwm@bugtussle.mpk.ca.us (Mike Meyer)
Newsgroups: comp.lang.perl
Subject: Re: Why I am glad I know perl
Date: 13 Oct 92 23:10:26 GMT
Article-I.D.: bugtussl.MWM.92Oct13161026
	<1992Oct7.153432.17541@walter.cray.com>
Organization: Anterior Technology, Menlo Park, CA USA
NNTP-Posting-Host: bugtussle.mpk.ca.us
In-reply-to: hens@snipe.cray.com's message of 7 Oct 92 15:34:32 CDT

In article <1992Oct7.153432.17541@walter.cray.com> hens@snipe.cray.com (Tom Stephens) writes:


   Soooooo correct.  When I did sys admin I *always* did ls -l * before doing a rm *.

Actually, the sequence (for CShell users) is:

	# ls -l <pattern>
	# rm !$


	<mike
From: mark@coombs.anu.edu.au (Mark)
Newsgroups: comp.lang.perl
Subject: perl util sites.
Date: 14 Oct 92 13:25:23 GMT
Organization: Australian National University
NNTP-Posting-Host: 150.203.76.2
Keywords: FTP perl reference
Organisation: Wassat?!

What do you guys think of the idea of a site that was a depository for
perl scripts. If you wanted something in perl you could zip over there and
see if it had been invented yet. 

alt.sources is good but people dont always bother to post the tiny useful
scripts; more the larger packages.

any comments?

Mark.
From: majidi@rwja.umdnj.edu (Masoud Majidi)
Newsgroups: comp.lang.perl
Subject: playing with pointers (beginner's question)
Date: 15 Oct 92 13:52:47 GMT
Organization: Robert Wood Johnson Medical School, Piscataway NJ

I have been learning perl from the camel book for the past month or so
and apparently that book doesn't cover the pointers in any extent.
Is there any book that covers some of the more advanced features
of perl? 

I have a list of words, say ("cat", "dog", "cat", "cat") and I need
to create an assosiate array such that:
$table{"cat"} be a pointer to (0, 2, 3) i.e. pointer to indices of "cat"
and $table{"dog"} be a pointer to (1). I wrote the following code which
doesn't work and I appreciate it if someone could give me a hand in fixing
it.

for ($i = 0; $i <= $#words; $i++) {
	if (defined $table{$words[$i]}) {
		*ary = $table{$words[$i]};
		push (@ary, $i);
		$table{$words[$i]} = *ary;
	}
	else {
		@ary = ($i);
		$table{$words[$i]} = *ary;
	}
}

Thanks in advance,

Masoud Majidi (majidi@umdnj.edu)
Newsgroups: comp.lang.perl
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: Recursive 'walk' into dir
Originator: tchrist@pixel.convex.com
Date: Wed, 7 Oct 1992 09:10:14 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: Convex Computer Corporation, Colorado Springs, CO
X-Disclaimer: This message was written by a user at CONVEX Computer
              Corp. The opinions expressed are those of the user and
              not necessarily those of CONVEX.

From the keyboard of dat91uni@ludat.lth.se (Urban Nilsson):
:
:Yo !
:
:I'm a total newbie to perl (well i've tried it for a week or so) !
:and would like to get some help in constructing a program that
:takes away (deletes) all backupfiles at my account.
:
:It wouild be nice if it did a recursive walk into the sub directories ...
:
:Is this possible in perl ?!? if so please show me how !

Sure, here are two approaches.

The first is to use the find program to do your work for you:

    #!/usr/bin/perl
    #
    # Given the name of a from directory and a to directory, make a copy
    # of the from directory rooted in the to directory, but make all the
    # *files* in the copy symbolic links.

    sub usage { die "usage: $0 olddir newdir\n"; }
    &usage unless @ARGV == 2;
    for (($srcdir, $dstdir) = @ARGV) {
	-d && next;
	warn "$0: $_ is not a directory\n";
	&usage;
    } 

    chdir $srcdir || die "can't cd to $srcdir: $!";
    open(FIND, "find . -print |") || die "can't fork: $!";
    <FIND>;  # skip dot
    while (<FIND>) {
	chop;
	next unless ($dev, $ino, $mode) = lstat($_);
	$mode &= 07777;
	s!^./!!;
	if (-d _) {
	    mkdir("$dstdir/$_", $mode)
		|| die "couldn't mkdir $dstdir/$_: $!";
	} else {
	    symlink("$srcdir/$_","$dstdir/$_")
		|| die "couldn't symlink $srcdir/$_ to $dstdir/$_: $!";
	} 
	
    } 
    close FIND || die "find exited nonzero";

The second is to do the find yourself:

    #!/usr/bin/perl
    #
    # Given the name of a from directory and a to directory, make a copy
    # of the from directory rooted in the to directory, but make all the
    # *files* in the copy symbolic links.

    sub usage { die "usage: $0 olddir newdir\n"; }
    &usage unless @ARGV == 2;

    for (($srcdir, $dstdir) = @ARGV) {
	-d && next;
	warn "$0: $_ is not a directory\n";
	&usage;
    } 

    chdir $srcdir || die "can't cd to $srcdir: $!";

    require 'find.pl';

    &find('.');

    sub wanted {
	(($dev, $ino, $mode) = lstat($_)) || return 0;
	$mode &= 07777;
	return 1 if $name eq '.';
	$name =~ s!^\./!!;
	if (-d _) {
	    mkdir("$dstdir/$name", $mode)
		|| die "couldn't mkdir $dstdir/$name: $!";
	} else {
	    symlink("$srcdir/$name","$dstdir/$name")
		|| die "couldn't symlink $srcdir/$name to $dstdir/$name: $!";
	} 
	1;
    } 

--tom

-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist

    "The road to hell is paved with melting snowballs."
		--Larry Wall in  <1992Jul2.222039.26476@netlabs.com>
Newsgroups: comp.lang.perl
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: FAQ ? : Sun RPC's in perl wanted
Originator: tchrist@pixel.convex.com
Date: Wed, 7 Oct 1992 19:14:55 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: Convex Computer Corporation, Colorado Springs, CO
X-Disclaimer: This message was written by a user at CONVEX Computer
              Corp. The opinions expressed are those of the user and
              not necessarily those of CONVEX.

From the keyboard of peter@micromuse.co.uk (Peter Galbavy):
:This is more then likely an FAQ - but I cannot find an answer:
:
:Is there an implmentation of Sun RPC's in perl (a perl API more than
:anything) ?

Here's a hard-coded hack for a rup inplementation.


    #!/usr/local/bin/perl

    die "usage: $0 hostname\n" unless @ARGV;

    $pat = 'S n C4 x8';

    $stream = 1;
    $datagram = 2;

    $inet = 2;

    $tcp = 6;
    $udp = 17;


    ($name,$aliases,$port) = getservbyname('sunrpc','udp');

    for $host (@ARGV) {

	if ($host =~ /^\d+\./) {
	    @bytes = split(/\./,$host);
	}
	else {
	    ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($host);
	    die "Can't lookup $host\n" unless $name;
	    @bytes = unpack("C4",$addrs[0]);
	}

	$this = pack($pat,$inet,0,    0,0,0,0);
	$that = pack($pat,$inet,$port,@bytes);

	socket(S,2,$datagram,$udp) || die "socket: $!\n";
	bind(S,$this) || die "bind: $!\n";
	connect(S,$that) || die "connect: $!\n";

	select(S); $| = 1; select(stdout); $| = 1;

	print S pack("N13", 1956, 0, 2, 100000, 2, 5, 0, 0, 0, 0, 100001, 3, 1);

	read(S, $_, 32767);

	@r = unpack("N" . length($_)/4, $_);
	#print join(' ', @r), "\n";
	printf("%-30s %4.2f %4.2f %4.2f\n",
		$name,$r[26]/256, $r[27]/256, $r[28]/256);

	if ($r[0] != 1956) {
	    die "xid error\n";
	} elsif ($r[1] != 1) {
	    die "Not a reply!\n";
	} elsif ($r[2] == 1) {
	    if ($r[3] == 0) {
		    die "Rejected - RPC_MISMATCH\n";
	    } elsif ($r[3] == 1) {
		    die "Rejected - AUTH_ERROR\n";
	    } else {
		    die "Rejected - unknown code\n";
	    }
	} else {
	    print '', (("SUCCESS", "PROG_UNAVAIL", "PROG_MISMATCH", "PROC_UNAVAIL",
		    "GARBAGE_ARGS")[$r[5]]), "\n";
	}

	close S;

    }


--tom
-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist

Justice is incidental to law and order.
                -- J. Edgar Hoover
Newsgroups: comp.lang.perl
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: Visual
Originator: tchrist@pixel.convex.com
Date: Fri, 9 Oct 1992 15:52:04 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: Convex Computer Corporation, Colorado Springs, CO
X-Disclaimer: This message was written by a user at CONVEX Computer
              Corp. The opinions expressed are those of the user and
              not necessarily those of CONVEX.

From the keyboard of tm8t+@andrew.cmu.edu (Tod McQuillin):
:tchrist@convex.COM (Tom Christiansen) writes:
:> From the keyboard of djd@csg.cs.reading.ac.uk (David J Dawkins):
:> :I don't know about anyone else, but I would sure like to know what 
:> :Larry, Tom and Randall *look* like :-}
:> :
:> :You guys been digitised? 
:> 
:> Nope, but I've been digitized.
:
:Come on, Tom, surely you're aware that it's us Americans who revised
:certain spellings, not the brits.  Don't make fun of the poor guy.

Just teasing.  I've a friend at Oxford who swears by the -ize spellings
for some esoteric reasons I don't recall.

:But if you have a picture, post it!  (Maybe in
:alt.binaries.pictures.utilities?)  I'd certainly post it on my office
:wall.

Um, and is this a feature?  I can only shudder in anticipation of
what nefarious purpose this might be put to. :-(

I've always avoided the facesaver in the past.

But ok, fine, my picture is on convex.com:/pub/perl/tchrist.pbm.Z .

--tom

-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist

I've been told to keep my remarks relatively brief. I understand Quayle-hunting
season begins at noon.  --Dan Quayle to a crowd in Eau Claire, Wisc.
From: majidi@rwja.umdnj.edu (Masoud Majidi)
Newsgroups: comp.lang.perl
Subject: associating lists with strings
Date: 7 Oct 92 14:15:17 GMT
Organization: Robert Wood Johnson Medical School, Piscataway NJ

Dear netters,

Is there anyway to associate lists with strings other than creating a string
out of the lists (using join) and then using associative arrays? The problem
with storing lists as strings is efficiency and I was wondering if there were
any better solution.

Thanks in advance,

Masoud Majidi (majidi@umdnj.edu)
Newsgroups: comp.lang.perl
From: mcook@fendahl.dev.cdx.mot.com (Michael Cook)
Subject: Malformed cmd links
Organization: Motorola Codex, Canton, Massachusetts
Date: Sat, 10 Oct 1992 15:44:02 GMT

Perl says "Malformed cmd links" when my script finishes.  Has anyone seen this
before?  Any ideas what it might mean?

Michael.

--
This is perl, version 4.0

$RCSfile: perl.c,v $$Revision: 4.0.1.7 $$Date: 92/06/08 14:50:39 $
Patch level: 35
--
From: futor@llnl.gov (randy j futor)
Newsgroups: comp.lang.perl
Subject: Re: perl=>C ??
Date: 9 Oct 92 17:54:50 GMT
Followup-To: comp.lang.perl
Organization: CSo @ LLNL


 wisplan@vms.macc.wisc.edu (Shaun Abshere) wrote:
> 
> (not sure i want to know what 2000 lines of perl would look like in
> C, might give me nightmares, but one can ask...)

If my experiences with both can be combined into some kind of yardstick,
you will write a bare minimum of 5000 lines of C to get the same job done
that 2000 lines of perl are doing.  If the lines of perl are chock full of
idiom instead of being "translated C", I'd be willing to bet on a number
more like 7500 . . .
__
\/  -+-  randy  -+-  all generalizations are flawed  -+-  futor@llnl.gov
From: zh@nike.rz.uni-konstanz.de. (Z. Horvat)
Subject: Question:Perl & Sockets
Keywords: Sockets
Reply-To: zh@nike.rz.uni-konstanz.de.
Organization: RZ Univ. Konstanz
Date: Tue, 13 Oct 1992 14:14:59 GMT

I'm relatively new to perl and much more new to Socket programming.
If someone could enlighten me on the following, i would really be glad...

I'm trying to set up a "telnet"-connection to a remote host.
Basically, I would like to read in the output of the remote telnet session
and send some commands there.

This is what i've done so far :

require "sys/socket.ph";
$packstr = 'S n a4 x8';
$remotehost = "blah.bluh.foo.bar";
chop($localhost = 'hostname');

($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $port)  = getservbyname(23, 'tcp');
($name, $aliases, $type, $len, $localaddr) = gethostbyname($localhost) || die "$!";
($name, $aliases, $type, $len, $remoteaddr) = gethostbyname($remotehost) || die"$!";

$we_are_here = pack($packstr, &AF_INET, $port, $localhost);
$he_is_there = pack($packstr, &AF_INET, $port, $remotehost);

socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "Aaarrrrggghhh ... $!";
bind(S, $we_are_here) || die "Boooommmm $!";
connect(S, $he_is_there) || die "Alas!! $!";
...
... etc etc

The script fails on the line containing connect.

I have been looking in three different books with some source code examples (in C) and have been trying to understand socket programming, but it looks like this somehow won't go into my head. 

Thanks in advance


---------------------------------------------------
SYS337654 Could not locate coffee - Operator halted 
---------------------------------------------------

Z. Horvat
Rechenzentrum Universitaet Konstanz
++49-7531-88-2405

zh@nike.rz.uni-konstanz.de
rzhorv@nyx.uni-konstanz.de
From: mab@wdl39.wdl.loral.com (Mark A Biggar)
Newsgroups: comp.lang.perl
Subject: Re: Sorting associative arrays based on the value
Date: 12 Oct 92 17:17:25 GMT
Organization: Loral Western Development Labs

In article <1992Oct12.082906.24636@mel.dit.csiro.au> sfy@koel.mel.dit.CSIRO.AU (Shane Youl) writes:
>This may be a FAQ, but then again...
>
>I have an associative array $Table{$Name} = $Number which I would like
>to sort by $Number. I have been converting the associative array into an
>ordinary two-d array and using the SUBROUTINE option to sort, but I
>thought that there might be a more elegant solution.

@keys = sort {$Table{$a} <=> $Table{$b}} keys(%Table);

@keys is now an array of keys sorted by $Number.

--
Perl's Maternal Uncle
Mark Biggar
mab@dl1.wdl.loral.com
Newsgroups: comp.lang.perl
From: volf@ebs.eb.ele.tue.nl (Frank Volf)
Newsgroups: comp.lang.perl
Subject: Wanted: perl version of updatedb
Keywords: perl, find, updatedb
Date: 13 Oct 92 13:15:01 GMT
Organization: Eindhoven University of Technology, The Netherlands

Hi,

I'm looking for a perl program of the program updatedb which creates 
the find-database /usr/lib/find/find.codes
Has anyone written such a program??????
                    
    Thanks a lot,

                     Frank







Frank Volf (volf@eb.ele.tue.nl)
Eindhoven University of Technology
Digital Systems Group, Room EH11.24
P.O. 513, 5600 MB Eindhoven, The Netherlands
Newsgroups: comp.lang.perl,comp.unix.large
From: ras@sgfb.ssd.ray.com (Shaw)
Subject: Re: pass+group, Networked version of passwd/chfn/chsh/finger in Perl
Keywords: NIS, Perl, Larry Wall's passwd with NIS hooks
Organization: Raytheon Company, Portsmouth, RI
Date: Wed, 14 Oct 1992 20:57:40 GMT

Er, looks like I forgot to mention *WHERE* I posted it - alt.sources.

Ralph Shaw			<ras@ssd.ray.com>
Raytheon Company, Submarine Signal Division, Portsmouth, R.I.
From: rhb@bu-pub.bu.edu (Rick Broberg)
Newsgroups: comp.lang.perl
Subject: novice numerical question
Keywords: rounding
Date: 13 Oct 92 21:54:08 GMT
Organization: Boston University

I'm having difficulty with string to numeric rounding in a floating point
number.  How do I fix this problem?

	$delta = 0.001;


	print "delta is $delta\n";

	$sum = 0.0;
	$count = 0;

	while (1) {
      	  $count+=1;
      	  $sum = $count * $delta;
      	  print "count is $count, sum is $sum\n";
	}
	
I get:
delta is 0.0010000000000000000208
count is 1, sum is 0.0010000000000000000208
count is 2, sum is 0.0020000000000000000416
count is 3, sum is 0.0030000000000000000625
count is 4, sum is 0.0040000000000000000833

and so on; when I'd much rather get:

delta is 0.001
count is 1, sum is 0.001
count is 2, sum is 0.002
count is 3, sum is 0.003

and so on.   I don't just want it printed out to a field length
that will obscure the value, I need it to be exact (for a later string
match).

Please send responses to me directly.
 
Newsgroups: comp.lang.perl
From: mab@wdl39.wdl.loral.com (Mark A Biggar)
Subject: Re: question about perl patterns
Keywords: perl pattern matching
Organization: Loral Western Development Labs
Date: Mon, 12 Oct 1992 17:31:05 GMT

In article <kumar.718895215@phage.cshl.org> kumar@phage.cshl.org (Sanjay Kumar at Cold Spring Harbor Lab) writes:
>Is there an easy way to find the position of a regular expression
>match in a string?  I would like to do the equivalent of the
>index function, but use regular expressions rather than substrings.

Well you can say:

$str =~ /pattern/;
$substr = substr($str,length($`),length($&));

But it is usually much faster to just say:

$str =~ /pattern/;
$substr = $&;

or

$str =~ /(pattern)/;
$substr = $1;

When parsing up a string using RE's, it is almost always faster and easier
to use $`,$&,$' or () and $1,$2,... to decompose the string instead of using
character positions and substr.  Also if you're decomposing a string using known
positions and lengths, you should use unpack() instead of a sequence of
calls to substr or using wierd patterns like /(......)(.....)(......)/.

--
Perl's Maternal Uncle
Mark Biggar
mab@wdl1.wdl.loral.com

Newsgroups: comp.lang.perl
From: kumar@phage.cshl.org (Sanjay Kumar at Cold Spring Harbor Lab)
Subject: question about perl patterns
Summary: Is there an equivalent to index() that uses regular expressions?
Keywords: perl pattern matching
Organization: Cold Spring Harbor Laboratory
Date: Mon, 12 Oct 1992 13:06:55 GMT

Is there an easy way to find the position of a regular expression
match in a string?  I would like to do the equivalent of the
index function, but use regular expressions rather than substrings.

Sanjay Kumar
kumar@neb.com
.

Newsgroups: comp.lang.perl