-
#!/usr/bin/perl
-
-
@array = (1..1000);
-
-
sub total {
-
my($v1) = print @array;
-
}
-
-
my($output) = &total();
-
I'll figure it out. Don't need your help. Thanks. Since the array is just
@array = (1..1000);
print @array;
or
some bs, this thing sucks.
Just because I was in a coding mood: -
#!/usr/bin/perl
-
-
use strict;
-
use warnings;
-
-
my @array = (1..10);
-
my $sum = 0;
-
-
foreach my $num (@array){
-
$sum = $sum + $num;
-
}
-
-
print("The sum is: $sum\n");
-
Please notice the pragmas at the beginning, "use strict;" and "use warnings;". You want to use those at the beginning of every Perl script you write. They will save you a ton of headache.
Regards,
Jeff
5 27480
Just because I was in a coding mood: -
#!/usr/bin/perl
-
-
use strict;
-
use warnings;
-
-
my @array = (1..10);
-
my $sum = 0;
-
-
foreach my $num (@array){
-
$sum = $sum + $num;
-
}
-
-
print("The sum is: $sum\n");
-
Please notice the pragmas at the beginning, "use strict;" and "use warnings;". You want to use those at the beginning of every Perl script you write. They will save you a ton of headache.
Regards,
Jeff
That helps a bunch. Man I still got a lot to learn. That little trick
$1 = $1 + $other didn't know you could do that. Yah man thanks again since I actually got so pissed, I broke something. At least I don't own a gun.
-
#!/usr/bin/perl
-
-
use strict;
-
use warnings;
-
-
my @array = (1..1000);
-
my $sum = 0;
-
-
foreach my $num (@array){
-
$sum = $sum + $num;
-
}
-
-
sub total {
-
my($v1) = print $sum;
-
}
-
-
-
my($output) = &total();
-
print "$output\n";
-
Happy as a clown. Only thing is, I'm right when I say the foreach is not a subroutine, it's a loop. Yah so this is correct.
-
use List::Util 'sum';
-
$sum=sum(@array);
-
Thank You, I will try one too. So kind of you both to help me. Really appreciate that.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paul |
last post by:
The following code:
<?php
header("Content-Type: text/plain");
$numbers = array(3.714, 0.7142857142857143, 9.667, 6.333, 7, 6, 8, 2, 3,
-2, 0, -6.6, 2.25, 4.333, -8, 3, 3.141592654, 5.5, 6.5,...
|
by: Ole |
last post by:
Goodday everybody,
i want to create an array that represents data, that has to
be transferred to a pdf doc ( iTextSharp ).
The problem is, that i seem too loose my faith. Namely, ( i have...
|
by: inkexit |
last post by:
I need help figuring out what is wrong with my code. I posted here a
few weeks ago with some code about creating self similar melodies in
music. The coding style I'm being taught is apparently a...
|
by: Michael |
last post by:
Hi,
I am trying to pass a function an array of strings, but I am having trouble
getting the indexing to index the strings rather than the individual
characters of one of the strings.
I have...
|
by: Steve |
last post by:
here's a quirk i can't seem to handle, just hack. since call-time
by-reference is depreciated and i don't want to enable it in the php.ini,
i'm kind of stuck when i want to pass userdata as an...
|
by: Nightfarer |
last post by:
Hello.
I have a big trouble using System.Array class (it's the first time I use it) for a software I'm developing.
I have a form with a textbox(numbers) and one button (done).
Once the number...
|
by: David TG |
last post by:
Hiya!
I would like to take a partial slice of a fairly complex array. The
source looks something like
array
(
==array
(
==NN
|
by: tuananh87vn |
last post by:
Hi ! can anyone help me with the following topic:
Find All Duplicates in a List of Numbers - Array implementation - -InitializeTree()
-AddNode()
-Add into...
|
by: jabernet |
last post by:
Is it possible in the new DB2 9.5 to use the content of an array in an
IN expression?
Say we have the ddl:
CREATE TYPE Numbers AS Integer ARRAY;
CREATE tab1 AS (
id integer,
numbers...
|
by: niner |
last post by:
I have been working on the following code for about 6 hours now. I am attempting to write a program in Java that finds the highest, lowest, sum, and mean of an array. The program should also end...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |