| 1 | package NKTI::general::char::split; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | # Create Action Split Character in string : | ||
| 7 | # ------------------------------------------------------------------------ | ||
| 8 | sub based_length { | ||
| 9 | |||
| 10 | # Declare parameter module : | ||
| 11 | # ---------------------------------------------------------------- | ||
| 12 | my ($self, $string, $length) = @_; | ||
| 13 | |||
| 14 | # Action Convert string to array based length of char : | ||
| 15 | # ---------------------------------------------------------------- | ||
| 16 | my $this_length = 'A'.$length; | ||
| 17 | # my @data = unpack("($this_length)*", $string); | ||
| 18 | my $len = "." x $length; | ||
| 19 | my @data = ($string =~ m/$len/g); | ||
| 20 | |||
| 21 | # Return Result : | ||
| 22 | # ---------------------------------------------------------------- | ||
| 23 | return @data; | ||
| 24 | } | ||
| 25 | # End of Create Action Split Character in string. | ||
| 26 | # =========================================================================================================== | ||
| 27 | |||
| 28 | # Create Module Split Charcter by Character : | ||
| 29 | # ------------------------------------------------------------------------ | ||
| 30 | sub based_char { | ||
| 31 | |||
| 32 | # Declara parameter module : | ||
| 33 | # ---------------------------------------------------------------- | ||
| 34 | my ($self, $string, $delimiter, $join) = @_; | ||
| 35 | |||
| 36 | # Declare variable for action split : | ||
| 37 | # ---------------------------------------------------------------- | ||
| 38 | my @split = split /$delimiter/, $string; | ||
| 39 | |||
| 40 | # Check IF $join eq 1 : | ||
| 41 | # ---------------------------------------------------------------- | ||
| 42 | if ($join eq 1) { | ||
| 43 | |||
| 44 | # Declare scalar for Placing result : | ||
| 45 | # ---------------------------------------------------------------- | ||
| 46 | my $str_data = ''; | ||
| 47 | |||
| 48 | # Prepare To While loop for Join result split : | ||
| 49 | # ---------------------------------------------------------------- | ||
| 50 | my $i = 0; | ||
| 51 | my $keys_split = keys (@split); | ||
| 52 | my $until_loop = $keys_split; | ||
| 53 | |||
| 54 | # While Loop for Join result split : | ||
| 55 | # ---------------------------------------------------------------------------------------- | ||
| 56 | while ($i < $until_loop) { | ||
| 57 | |||
| 58 | # Join Result split : | ||
| 59 | # ---------------------------------------------------------------- | ||
| 60 | $str_data .= $split[$i]; | ||
| 61 | |||
| 62 | # Auto Increment : | ||
| 63 | # ---------------------------------------------------------------- | ||
| 64 | $i++; | ||
| 65 | } | ||
| 66 | # End of While loop for Join result split. | ||
| 67 | # ======================================================================================== | ||
| 68 | |||
| 69 | # Return Result : | ||
| 70 | # ---------------------------------------------------------------- | ||
| 71 | return $str_data; | ||
| 72 | } | ||
| 73 | # End of check IF $join eq 1. | ||
| 74 | # ---------------------------------------------------------------- | ||
| 75 | |||
| 76 | # Check IF $join eq 1 : | ||
| 77 | # ---------------------------------------------------------------- | ||
| 78 | else { | ||
| 79 | |||
| 80 | # Return Result : | ||
| 81 | # ---------------------------------------------------------------- | ||
| 82 | return @split; | ||
| 83 | } | ||
| 84 | # End of check IF $join eq 1. | ||
| 85 | # ---------------------------------------------------------------- | ||
| 86 | } | ||
| 87 | # End of Create Module Split Charcter by Character. | ||
| 88 | # =========================================================================================================== | ||
| 89 | 1; | ||
| 90 | __END__ |