home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5543 < prev    next >
Encoding:
Text File  |  1992-08-27  |  1.5 KB  |  42 lines

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