home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!decwrl!sgi!wdl1!wdl39!mab
- From: mab@wdl39.wdl.loral.com (Mark A Biggar)
- Subject: Re: Fast String Operations?
- Message-ID: <1992Aug25.215959.549@wdl.loral.com>
- Sender: news@wdl.loral.com
- Organization: Loral Western Development Labs
- References: <1992Aug25.151625.3134@IDA.ORG>
- Date: Tue, 25 Aug 1992 21:59:59 GMT
- Lines: 40
-
- In article <1992Aug25.151625.3134@IDA.ORG> rlg@IDA.ORG (Randy garrett) writes:
- >I'm looking for the fastest way to perform the following operation.
- >Basically, this is a conversion of one database format to another.
- >If I have a NULL field, indicated by 2 pipe symbols next to
- >each other, I want to insert either a -1 or a ~ between the
- >two pipes, depending upon whether the type of that field
- >is a integer or a character. I know the type of the field
- >because I've already pre-filled that array with the correct
- >types from the Data Dictionary (Thanks Sybase to Perl Interface!).
-
- I probabily make more sense to use split for this, modifiy your code like so:
-
- >#!/usr/local/bin/perl
- ># Walk thru a string; if find "||" insert either a ~ or a -1
- ># depending on value of @name
- >
- >$string = "a|bcd||g||i|||";
- >@name = (1,2,1,1,2,1,2,1);
- >
- >$count = 0; # index into @name
-
- @string = split(/|/,$string);
- foreach $s (@string) {
- $s = ($name[$count++] == 1 ? -1 : '~') if $s eq '';
- }
- $string = join('|', @string);
-
- >print "$string\n";
-
- The foreach could be written as a grep() but I think this was is more
- understandable.
-
- --
- Perl's Maternal Uncle
- Mark Biggar
- mab@wdl1.wdl.loral.com
-
-
-
-
-