子例程 subroutine
#! /usr/bin/perl
use strict;
use warnings;
print "\n---------summation_STDIN_parameter----------\n";
sub total{
my $array_len = @_;
my $sum = 0;
foreach(0..$array_len){
$sum += $_[$_];
#sum += 1;
}
return $sum;
}
my @comma = qw{ 3 5 1 7 9};
my $dash = &total(@comma);
print "Sum is: $dash.\n";
print "Enter some numbers on seperate lines:";
my $dollar_sign = &total(<STDIN>);
print "Sum of those numbers is: $dollar_sign.";
print "\n---------summation_STDIN_parameter----------\n";
print "\n---------_sum_1..1000----------\n";
#my $dot_operator;
my $dot_operator = &total(1..1000);
print "Sum of 1..1000 is: $dot_operator.";
print "\n---------_sum_1..1000----------\n";
子例程 subroutine的更多相关文章
- 分析Tornado的协程实现
转自:http://www.binss.me/blog/analyse-the-implement-of-coroutine-in-tornado/ 什么是协程 以下是Wiki的定义: Corouti ...
- gcc g++ 参数介绍
C和C++ 编译器是集成的.他们都要用四个步骤中的一个或多个处理输入文件: 预处理 (preprocessing),编译(compilation),汇编(assembly)和连接(linking).源 ...
- 维多利亚的秘密 golang入坑系统
原文在gitbook,字字原创,版权没有,转载随意. 在写本文的前一天,2017维密在上海开始了. 为了纪念屌丝界的盛世,特为本节起名维多利亚的秘密.现在的社会,要想出名只有抓眼球.所以写份技术文章, ...
- Haskell语言学习笔记(72)Free Monad
安装 free 包 $ cabal install free Installed free-5.0.2 Free Monad data Free f a = Pure a | Free (f (Fre ...
- 维多利亚的秘密 golang入坑系列
原文在gitbook,字字原创,版权没有,转载随意. 在写本文的前一天,2017维密在上海开始了. 为了纪念屌丝界的盛世,特为本节起名维多利亚的秘密.现在的社会,要想出名只有抓眼球.所以写份技术文章, ...
- 【转载】 GNU GCC 选项说明
GCC 1 Section: GNU Tools (1) Updated: 2003/12/05 Sponsor: GCC Casino Winning Content NAME gcc,g++-GN ...
- gcc, g++ - GNU 工程的 C 和 C++ 编译器 (egcs-1.1.2)
总览 (SYNOPSIS) gcc [ option | filename ]... g++ [ option | filename ]... 警告 (WARNING) 本手册页 内容 摘自 GNU ...
- Routine Subroutine Coroutine 子程序 协程 子例程
https://en.wikipedia.org/wiki/Subroutine In computer programming, a subroutine is a sequence of prog ...
- perl学习之子例程
1.system function && user function system fucntion:chomp reverse print... user function: & ...
随机推荐
- 关于python语言使用redis时,连接是否需要关闭的问题
python操作完redis,需要关闭连接的吧,怎么关闭呢 1人赞 回复 君惜丶: redis-server会关闭空闲超时的连接redis.conf中可以设置超时时间:timeout 300 2017 ...
- UOJ #206. 【APIO2016】Gap【交互题】
参考:https://blog.csdn.net/clover_hxy/article/details/70767653 人生第一次交互题...不是很难但是思维和传统题差别挺大的(以及并不会本地测试= ...
- jacoco 的使用及与jenkins的集成
1.把jacocoagent.jar的包放入到dockerfile COPY jacocoagent.jar /opt/jacoco/lib/jacocoagent.jar 2.打完镜像,需要启动容器 ...
- 简单的AndroidStudio单元测试工程配置
转载: http://www.jianshu.com/p/03118c11c199
- python爬取网页图片(二)
从一个网页爬取图片已经解决,现在想要把这个用户发的图片全部爬取. 首先:先找到这个用户的发帖页面: http://www.acfun.cn/u/1094623.aspx#page=1 然后从这个页面中 ...
- [ZOJ1961]Let it Bead
Description "Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. ...
- ural1076 Trash 垃圾
Description You were just hired as CEO of the local junkyard.One of your jobs is dealing with the in ...
- 随机带权选取文件中一行 分类: linux c/c++ 2014-06-02 00:11 344人阅读 评论(0) 收藏
本程序实现从文件中随即选取一行,每行被选中的概率与改行长度成正比. 程序用一次遍历,实现带权随机选取. 算法:假设第i行权重wi(i=1...n).读取到文件第i行时,以概率wi/(w1+w2+... ...
- WinForm 里面关闭窗体的两个方法的区别 Form.coles()与Application,Exit()
- java getDocumentBase() 得到的文件夹路径
参考一个百度知道上的回答 举例说来,假设你的项目文件是xx,而这个xx文件夹是在D盘下的yy文件夹里,即项目文件的完整路径D:\yy\xx,则编译运行文件后,在xx文件夹里会产生名为build的文件夹 ...