regex - Substituting letters in an array -
#!/usr/bin/env perl utilize warnings; utilize strict; $input = "test"; @arr = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); @cip = ('%', '@', '!', '^', '*', '_', '+', '&', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', 'a', 'b', 'd', '$', '(', ')', '/', '|'); <do here> print $res;
the output should according arrays: b*ab
the problem don't know how there, tried using s// regex doesn't seem working.
you can replace char char using hash table, @arr elements keys, , @cip values. "\u$1" upper case on captured string.
use warnings; utilize strict; $input = "test"; @arr = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); @cip = ('%', '@', '!', '^', '*', '_', '+', '&', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', 'a', 'b', 'd', '$', '(', ')', '/', '|'); %h; @h{@arr} = @cip; (my $res = $input) =~ s/(.)/ $h{"\u$1"} /ge; print $res; output
b*ab arrays regex perl encryption
No comments:
Post a Comment