CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: General Discussions: General Questions:
Good afternoon!

 



ryanthelion91
New User

Nov 21, 2016, 1:59 PM

Post #1 of 3 (21253 views)
Good afternoon! Can't Post

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.


Laurent_R
Veteran / Moderator

Nov 22, 2016, 1:10 PM

Post #2 of 3 (21242 views)
Re: [ryanthelion91] Good afternoon! [In reply to] Can't Post

Hi,

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.


ryanthelion91
New User

Nov 23, 2016, 8:29 AM

Post #3 of 3 (21237 views)
Re: [Laurent_R] Good afternoon! [In reply to] Can't Post

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

Code
#!/usr/bin/perl 
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)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives