Home: General Discussions: General Questions:
Good afternoon!

New User

Nov 21, 2016, 1:59 PM

Views: 24455
Good afternoon!

Hi, I'm new here, and also completely new to coding.
Forgive me if I've put this in the wrong place, but what I'm trying to do is make a scalar variable sum itself. So for example, I've transliterated words into numbers, and now I want the transliterated numbers to sum themselves. If this issue has already been addressed, please forgive my missing it! Thankyou for any help you can give me.

Veteran / Moderator

Nov 22, 2016, 1:10 PM

Views: 24444
Re: [ryanthelion91] Good afternoon!


sorry, I don't understand your question. Can you please show what you mean by "transliterated words into numbers" (please show your code), et explain what you want to sum exactly.

New User

Nov 23, 2016, 8:29 AM

Views: 24439
Re: [Laurent_R] Good afternoon!

Hey, so I figured out what I was trying to do. I'll put some code here:

use 5.010;
use List::Util qw(sum); # This function sums our array in line 15
use strict;
use warnings;
say "Awaiting input: ";
my $text = <STDIN>;
chomp $text;
my $textsaver = $text;
$text=~ tr/abcdefghijklmnopqrstuvwxyz/12345678912345678912345678/;
$text=~ tr/ABCDEFGHIJKLMNOPQRSTUVWXYZ/12345678912345678912345678/;
my @wnums = split / /, $text;
foreach my $wnums(@wnums) {
my @lnums = split(//, $wnums);
my $wtotal = sum @lnums;
print " $wtotal ";

(This post was edited by FishMonger on Nov 23, 2016, 9:53 AM)