home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!sunic!dkuug!uts!id.dth.dk!ej
- From: ej@id.dth.dk (Erik Johansen)
- Newsgroups: comp.lang.perl
- Subject: Re: Fast String Operations?
- Message-ID: <1992Aug26.080304.29886@id.dth.dk>
- Date: 26 Aug 92 08:03:04 GMT
- References: <1992Aug25.151625.3134@IDA.ORG>
- Organization: Department of Computer Science
- Lines: 43
-
- 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!).
-
- >So, I read in a series of lines from a file. If I find 2 pipe
- >symbols adjacent to each other, "||", in the input string, I want
- >to insert either a ~ or a -1 depending on the type of that field,
- >which I get from the @name array.
-
- Here is my rewriting of your code:
-
- #!/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);
-
- %defaults = (1, '-1', 2, "~"); # Specify defaults for each of your types
- @strings = split(/\|/, $string);
- for $count ( 0..8 )
- {
- $strings[$count] = $defaults{ $name[$count] } if $strings[$count] eq '';
- }
- $string = join("|", @strings);
-
- print "$string\n";
-
-
- - Erik
-
-
- --
- ---
- Erik Johansen E-mail: ej@id.dth.dk
- Institute for Computer Science, Copenhagen, Denmark
-