Perl Tutorial - User Input - Tizag Tutorials

文章推薦指數: 80 %
投票人數:10人

A tutorial of PERL , standard input in PERL via the command prompt. ... stands for standard input. ... usr/bin/perl print "How old are you? PERL- standsforstandardinput.Itcanbeabbreviatedbyusingsimple<>.Bydeclaringascalarvariableandsettingitequaltowesetthevariableequaltowhateverwillbetypedbyouruseratthecommandprompt.Observe: AdvertiseonTizag.com whatismyage.pl: #!usr/bin/perl print"Howoldareyou?"; $age=<>; print"WOW!Youare$ageyearsold!"; Howoldareyou?: Don'tworryaboutthedisplaybeingalittleoffthemark,wewillcovertheformattinginthenextlesson.Fornowlet'spracticeretrievingsomeuserinputusingPERL. Let'stakethisexampleonestepfurtherandalsorequestthefavoritecolorofouruser. agencolor.pl: #!usr/bin/perl print"Howoldareyou?"; $age=<>; print"Whatisyourfavoritecolor?"; $color=<>; print"Youare$age,andyourfavoritecoloris$color."; Age'N'Color: Onceagain,ourformattingleavealittletobedesired,butthevariablesareworkingastheyshould,andfornowthisisallweneedtoknow. PERL-BeginningScripting Younowhavetheknowledgerequiredtocodesomemathematicalscriptslikethefollowing. circle.pl: #!usr/bin/perl print"Whatistheradiusofthecircle?"; chomp($r=<>); $diameter=(2*$r); $area=(3.14*($r**2)); $cir=($diameter*3.14); print"Radius:$r\nDiameter:$diameter\nCircumference:$cir\nArea:$area"; Circles!: GoBackContinueFoundSomethingWronginthisLesson?ReportaBugorCommentonThisLesson-YourinputiswhatkeepsTizagimprovingwithtime! WebReference HelpTizagGrow AdvertiseHere MoreTutorials! 2003-2008ErackNetwork|Copyright|PrivacyPolicy|AdvertisingInformation SitedesignbySeattleWebDesign



請為這篇文章評分?