perl push的用法及子程式傳回值的反思
文章推薦指數: 80 %
這在Perl 中是一條通用規則:如果去掉括弧含義不變,那括弧就是可選的◇。
和pop 相反的操作是push,它可以將一個元素(或者一列元素)加在數組的末尾 ...
International-English
International
English
Country/Site
中国站-简体中文
Cart
Console
LogInSignUp
TopicCenter
About
Products
Solutions
Pricing
Marketplace
Partners
ContactSales
Submit
首頁>
開發者>
Perl
perlpush的用法及子程式傳回值的反思
最後更新:2018-12-08
來源:互聯網
上載者:User
創建阿里雲帳戶,並獲得超過40款產品的免費試用版;而企業帳戶則可以享有總值$1200的免費試用版。
立即註冊!
pop操作將數組的最後一個元素取出並返回:
@array=5..9;$fred=pop(@array);#$fred得到9,@array現在為(5,6,7,8)$barney=pop@array;#$barneygets8,@array現在為(5,6,7)pop@array;#@array現在為(5,6)(7被丟棄了)最後一個例子中,pop使用在"inavoidcontext",也就是說沒有存放其傳回值的地方。
這樣使用pop是合法的。
如果數組為空白,那pop什麼也不做(因為沒有元素可以移出),並返回undef。
你可能已注意到pop後可以使用或者不使用括弧。
這在Perl中是一條通用規則:如果去掉括弧含義不變,那括弧就是可選的◆。
和pop相反的操作是push,它可以將一個元素(或者一列元素)加在數組的末尾:◆受過相應教育的人將發現,這是同義反覆。
push(@array,0);#@array現在為(5,6,0)push@array,8;#@array現在為(5,6,0,8)push@array,1..10;#@array現在多了10個元素@others=qw/90210/;push@array,@others;#@array現在又多了5個元素(共有19個)push的第一個參數或者pop的唯一參數必須是陣列變數。
複製代碼代碼如下:#!/bin/perl
subabove_average
{
$number=@_;
foreach$how(@_)
{
$total=$total+$how;
}
$the_average=$total/$number;
foreach(@_)
{
if($_>$the_average)
{
push(@larger,$_)#這裡不用賦值,數組元素的添加,直接用push就好了
}
}
@larger;#子程式的傳回值,一定要有,剛開始沒有寫
}
print"pleaseinputseveralnumbers,andyouwillgetthenumberwhichislargethantheiraverage\n";
@the_number_input=
本網站不對文章的準確性,完整性或可靠性或其任何翻譯作出任何明示或暗示的陳述或保證。
如對該文章有任何疑慮或投訴,請傳送電郵至[email protected]並提供相關疑慮或投訴的詳細說明。
職員會於5個工作天內與您聯絡,一經驗證之後,即會刪除該侵權內容。
相關關鍵詞:
perlpushexample
perlhasharraypush
pushcommandinperl
pushinperl
perlpushpop
pushfunctioninperl
perl
Perl中use和require用法對比分析_perl
01-18
Perl變數的作用my,our,local和全域變數_Perl
08-21
Perl語言中的$_和@_
08-23
perl中chomp的使用介紹(chop和chomp函數區別)
12-08
Perlsplit字串分割函數用法指南
12-08
perl文本輸出對齊
12-06
/
LearnMoreBuyNow
/
LearnMoreBuyNow
/
LearnMoreBuyNow
聯繫我們
該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。
如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至:
[email protected]
進行舉報並提供相關證據,工作人員會在5個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。
熱門內容
Perlsplit字串分割函數用法指南
Perl中use和require用法對比分析_perl
Perl變數的作用my,our,local和全域變數_Perl
perl中chomp的使用介紹(chop和chomp函數區別)
perl文本輸出對齊
Perl語言中的$_和@_
perlpush的用法及子程式傳回值的反思
Perl語言及其優缺點簡介
Perl變數:陣列變數
perl中seek函數的用法
熱門主題
ECS鏡像
RDS索引優化
RDS分區索引
雲上的資料移轉
Web漏洞防護
物理專線
線上與離線資料分離
Kubernetes叢集
AFreeTrialThatLetsYouBuildBig!
Startbuildingwith50+productsandupto12monthsusageforElasticComputeService
GetStartedforFree
SalesSupport
1on1presaleconsultation
Chat
ContactSales
After-SalesSupport
24/7TechnicalSupport
6FreeTicketsperQuarter
FasterResponse
OpenaTicket
AlibabaCloudoffershighlyflexiblesupportservicestailoredtomeetyourexactneeds.
LearnMore
Acomprehensivesuiteofglobalcloudcomputingservicestopoweryourbusiness
PaymentMethodsWeSupport
About
About
AboutAlibabaCloud
PricingModels
Products
Customers
Partners
Startups
ApsaraConference
AlibabaCloudSummit
Promotions
Promotions
FreeTrial
StarterPackage
SimpleApplicationServer
AffiliateProgram
Explore
Explore
Technology
KnowledgeBase
ChinaGateway
ICPLicenseSupport
GettingStarted
Blog
Marketplace
Training&Certification
Support
Support
ContactSales
SubmitaTicket
After-SalesSupport
ReportAbuse
Feedback
Forum
PricingCalculator
Resources
Resources
DocumentationCenter
AlibabaCloudMVP
Security&Compliance
PressRoom
WHOIS
SiteMap
Products&Solutions
ElasticComputeService
CDN
Anti-DDoS
ObjectStorageService
eCommerce
WebHosting
Security
HotContent
JapanSite
ECSDocumentation
HowtogetDomains
SoftwareInfrastructure
LearningPath
NewUsers
Recommended
TopicCenter
CloudComputing
Industries
Developers
WebDeveloping
Tutorials
PHPTutorials
BrowsebyLetter
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
0-9
Careers
AboutUs
PrivacyPolicy
Legal
NoticeList
Links
AlibabaGroup
TaobaoMarketplace
Tmall
Juhuasuan
AliExpress
Alibaba.com
1688
Alimama
Fliggy
YunOS
AliTelecom
Amap
UCWeb
Umeng
Xiami
DingTalk
Alipay
©2009-2022CopyrightbyAlibabaCloudAllrightsreserved
//intl.aliyun.com
//intl.aliyun.com/why-alibaba-cloud
//intl.aliyun.com/product
//intl.aliyun.com/solution
//intl.aliyun.com/chinaconnect
//intl.aliyun.com/icp
//intl.aliyun.com/pricing
//intl.aliyun.com/trust-center
//intl.aliyun.com/free-trial/enterprise
//intl.aliyun.com/startup
//intl.aliyun.com/partner
0.0.9homon:page_57074_9135018350_Uscv9dq6oXpK
延伸文章資訊
- 1Perl push Function - Tutorialspoint
Perl push Function · Description. This function pushes the values in LIST onto the end of the lis...
- 2Perl | push() Function - GeeksforGeeks
push() function in Perl is used to push a list of values onto the end of the array. push() functi...
- 3push - Perldoc Browser
Starting with Perl 5.14, an experimental feature allowed push to take a scalar expression. This e...
- 4Manipulating Perl arrays: shift, unshift, push, pop - Perl Maven
The push function can add one or more values to the end of an array. (Well, it can also add 0 val...
- 5Perl push()用法及代碼示例- 純淨天空
Perl中的push()函數用於將值列表推送到數組的末尾。 push()函數通常與pop結合使用以實現堆棧。 push()函數不取決於作為列表傳遞的值的類型。這些值可以是alpha-numeric。