home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!centerline!noc.near.net!wpi.WPI.EDU!bigboote.wpi.edu!john
- From: john@sekrit.WPI.EDU (John Stoffel)
- Subject: Re: Fast String Operations?
- In-Reply-To: mab@wdl39.wdl.loral.com's message of Tue, 25 Aug 1992 21:59:59 GMT
- Message-ID: <JOHN.92Aug27094603@sekrit.WPI.EDU>
- Sender: news@wpi.WPI.EDU (USENET News System)
- Nntp-Posting-Host: sekrit.wpi.edu
- Organization: Worcester Polytechnic Institute
- References: <1992Aug25.151625.3134@IDA.ORG> <1992Aug25.215959.549@wdl.loral.com>
- Date: Thu, 27 Aug 1992 14:46:03 GMT
- Lines: 28
-
- >>>>> On Tue, 25 Aug 1992 21:59:59 GMT, mab@wdl39.wdl.loral.com (Mark A Biggar) said:
- >#!/usr/local/bin/perl
- >
- >$string = "a|bcd||g||i|||";
- >@name = (1,2,1,1,2,1,2,1);
- >
- >$count = 0; # index into @name
-
- Mark> @string = split(/|/,$string);
-
- This split won't work correctly because it will ignore the null fields
- at the end of $string. I played with this for a while, RTFM a few
- times and changed it to
-
- Mark> @string = split(/|/,$string,100);
-
- with the 100 forcing it to match even null fields. I was assuming
- that there were fewer than 100 records in a line.
-
- Mark> foreach $s (@string) {
- Mark> $s = ($name[$count++] == 1 ? -1 : '~') if $s eq '';
- Mark> }
- Mark> $string = join('|', @string);
- --
- Youth of today! Join me in a mass rally for traditional mental attitudes!
- -------------------------------------------------------------------------------
- john@wpi.wpi.edu | Work Station Specialist | Worcester Polytechnic Institute
- John Stoffel | 508-831-5512 (work) | Worcester, MA 01609
-