How to push the 1) find content, 2) replaced content and 3)count

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to push the 1) find content, 2) replaced content and 3)count



I need to find greek characters and replace that corresponding values and its replaced counting numbers: (I need to do get this from more 100 replacements)



This is my coding:


use strict;
use warnings;

my @grkChars = qw(alpha beta gamma);
my $eachGrk = join "|", @grkChars; #Greek Characters

my $str = 'Trp $mathbfR^a$ locates alpha beta distantly $mathrmR^a$ from $mathitR^a$ cys25 in both gamma and cathepsin K, with alpha high and moderate $mathbbR^1H$ strengths, respectively. The protein $mathdsR^a$ modification $mathdsR^1H$ largely beta affects the binding sites and stability gamma of the gamma peptides, and the effects depend on alpha the elemental compositions of the peptides';

my $count = $str=~s\($eachGrk)\$1g && print "Content: $&n";

print "Total Count: $countn";



My Output:


Content: alpha
Total Count: 1



Expected output is:


alpha changed to alpha and count 3
beta changed to beta and count 2
gamma changed to [gamma] and count 3



Could you please someone will advice on this one. Thanks in advance.





How do you expect your program to print changed to if there is no code to do that? :)
– simbabque
Aug 10 at 11:01


changed to





How do you create the different replacements alpha, beta, and [gamma]?
– Borodin
Aug 10 at 11:12


alpha


beta


[gamma]





@simbabque: That's correct. I didn't mentioned in the code. But we have an output for the user end to expose the report like that only.
– ssr1012
Aug 10 at 11:19





I'm voting to close this question as "too broad" because there is no proper specification and the sample code doesn't come close to doing what has been described in comments.
– Borodin
Aug 10 at 11:51






"The replacement value's sometimes might be hard coded and getting values in *INI files means user input" So that information, together with proper details, need to be in your question.
– Borodin
Aug 10 at 11:52




1 Answer
1



Although you could do something like create an executable replacement that increments a hash field instead of a global $count variable. it is best to keep things simple. You need to replace the words individually if you want to count them individually. Forget creating a compound regex pattern and just iterate over the array of words


$count



Like this


use strict;
use warnings;

my @grkChars = qw/ alpha beta gamma /;

my $str = 'Trp $mathbfR^a$ locates alpha beta distantly $mathrmR^a$ from $mathitR^a$ cys25 in both gamma and cathepsin K, with alpha high and moderate $mathbbR^1H$ strengths, respectively. The protein $mathdsR^a$ modification $mathdsR^1H$ largely beta affects the binding sites and stability gamma of the gamma peptides, and the effects depend on alpha the elemental compositions of the peptides';

my $total = 0;

for my $grk ( @grkChars )

next unless my $count = $str =~ s\($grk)\$1g;

printf "\%s changed to \%s and count %dn", $1, $1, $count;
$total += $count;


print "Total Count: $totaln";





Please printf "\%s changed to \%s and count %dn", $1, $1, $count; In this line if the second $1 might be different content then how can I print the replaced value.
– ssr1012
Aug 10 at 11:24


$1





@ssr1012: Then you put the different content in its place.
– Borodin
Aug 10 at 11:26





As per the requirement I have raised the question. However simply I want to know in perl s($grk)\$1g we can get finding value ($grk) = $1 how can we get replacement value in \$1??? Might be stupid question but I want to know there is any chance to get ?
– ssr1012
Aug 10 at 11:34


($grk) = $1


\$1





You had completely changed your question. Don't do that. I have rolled back your changes. If your question is inherently wrong then you should delete it. If you have a different question then ask a new question.
– Borodin
Aug 10 at 13:16





I couln't able to delete the question. Please suggest.
– ssr1012
Aug 10 at 13:44






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard