How to Work With User Input in Perl - Qualitest
文章推薦指數: 80 %
Perl is a language that is useful for scripting, file processing, and other forms of development. The command line can be used to gather a user's input and ... Insights TechnicalHub HowtoWorkWithUserInputinPerl HowtoWorkWithUserInputinPerl Introduction: Perlisalanguagethatisusefulforscripting,fileprocessing,andotherformsofdevelopment.Thecommandlinecanbeusedtogatherauser’sinputandcollectedbyPerl. Requirements: APerlInterpreter(shouldbenativeonLinux,ActiveStatePerlisonedistributionforWindows),andacommandlineinterface(CLI)suchascommandprompt/cmd.exeonWindowsorashellonLinux. Procedure: Setupyourtextfile(withfileextension.pl)asfollows,startingfromthefirstline: #!\usr\bin\Perl usestrict; usewarnings; my$data; ThefirstlineindicateswherethePerlinterpreterislocated.ThismaybeirrelevantonWindows,butwhetheritisincludedornot,thelocationwillbeusedonLinux.Thenextlinessignalwhatmodetorunin.Strictmodewithwarningswillthrowerrorsanddisplaywarningsifpresent.Thelastlineisdeclaringthelocationwheretheuserinputdatawillbestored. Followingthis,let’scollectuserinput: print“Pleaseentersomedata,thenpressEnter.\n”; $data=; chomp($data); Theabovelinesfirstprintamessagetothescreen,followedbyanewline(\n).Then,thedataiscollectedbytheenduserwhoisgivencontrolaftertheprompt.Followingthis,the chomp() functionwillremovethe \n newlineattheendofthedata,whetheritisthereornot. $datathencontainsthedataforfurtherusage,afterbeingcollectedby. share Newsletter Signuptoreceiveinsightfulcontent. HowtoWorkWithFilesinPerl readmore HowtouseregularexpressionsinPerlPart1:Syntax readmore
延伸文章資訊
- 1精簡扼要的Perl 課程講義(四):標準輸入輸出與檔案輸入輸出
標準輸入輸出. # 標準輸入輸出 # (1) STDIN, STDOUT, STDERR print "Enter your name:"; $input = <STDIN>; # 從STDIN...
- 2Perl Tutorial - User Input - Tizag Tutorials
A tutorial of PERL , standard input in PERL via the command prompt. ... <STDIN> stands for standa...
- 3Perl | STDIN in Scalar and List Context - GeeksforGeeks
- 4Taking Input in Perl - CodesDope
Taking command line arguments means to pass some argument (or give input) while calling this comm...
- 5How to Work With User Input in Perl - Qualitest
Perl is a language that is useful for scripting, file processing, and other forms of development....