perl STDIN

perl STDIN,第1张

概述#!/usr/bin/perl ##### #####<1> #####@@@get a line from keyboard, like shell read var print "What is your name? "; $name=<STDIN>; print "What is your father's name? "; $paname=<>; print "Hello respecte @H_404_6@#!/usr/bin/perl ##### #####<1> #####@@@get a line from keyboard,like shell read var print "What is your name? "; $name=<STDIN>; print "What is your father's name? "; $paname=<>; print "Hello respected one,$paname"; #####result #What is your name? Stack #What is your father's name? Tony #Hello respected one,Tony ##### #####<2> #####@@@Getting rID of trailing newline. Use chomp instead of chop. #####if there is only one char,it wouldn't be cutted. print "\n###chomp and chop functin for perl beginning!!!!\n"; print "Hello there,and what is your name? \n"; chop($name=<STDIN>); print "$name has been chopped a \n char. \n"; chop($name); print "$name has been chopped again. \n"; print "What is your age? \n"; chomp($age=<STDIN>); print "$age has been chomped a \n char. \n"; chomp($age); print "$age dIDn't chomped again.\n"; #####result: ####chomp and chop functin for perl beginning!!!! #Hello there,and what is your name? #mywords #mywords has been chopped a \n char. #myword has been chopped again. #What is your age? #mywords #mywords has been chomped a \n char. #mywords dIDn't chomped again. ##### #####<3> #####@@@Reading input in a requested number of bytes print "\n###read Syntax beginning !!!\n"; print "Describe your favorite food in 10 bytes or less.\n"; print "If you type less than 7 characters,press Ctrl-d on a line by itself.\n"; $number=read(STDIN,$inputvar,7); print "You just typed: $inputvar \n"; print "The number of bytes read was $number \n"; #####result: ####read Syntax beginning !!! #Describe your favorite food in 10 bytes or less. #If you type less than 7 characters,press Ctrl-d on a line by itself. #12345678 #You just typed: 1234567 #The number of bytes read was 7 ##### #####<4> #####@@@function getc print "Getting only one character of input!!! \n"; print "Answer y or n  \n"; $answer=getc; $restofit=<>; print "The getc function get the char is: $answer \n"; print "The characters left in the input buffer were: $restofit \n"; #####result: #Getting only one character of input!!! #Answer y or n  #y12345678redundancy #The getc function get the char is: y #The characters left in the input buffer were: #12345678redundancy ##### #####<5> #####@@@Assigning input to an array print "\n###Assigning input to an array beginning!!!!\n"; print "Tell me everthing about yourself. \n"; @all=<STDIN>; print "your input are displayed: \n@all"; print "The number of elements in the array are: ",$#all + 1," \n"; print "The first element of the array is : $all[0]"; #####result: ####Assigning input to an array beginning!!!! #Tell me everthing about yourself. #first x #second x #thrID x #fourth x #your input are displayed: #first x # second x #  thrID x #   fourth x #   The number of elements in the array are: 4 #   The first element of the array is : first x ##### #####<6> #####@@@assign input to a hash print "\n###Assign input to a hash beginning!!!!\n"; print "What is the name of course 101?\n"; $course_number=101; chomp ($course{$course_number}=<STDIN>); print %course,"\n"; print "print the values of key(101) is: $course{101}","\n"; #####result ####Assign input to a hash beginning!!!! #What is the name of course 101? #xx #101xx #print the values of key(101) is: xx ##### #####<7> #####@@@chop(List) and chomp(List) for array. print "\n###chop(List) and chomp(List) for array beginning!!!\n"; @line=("red","green","orange"); chop(@line);  #Chops the last character off each string in the List; print "\n@line"; @line=("red","orange"); chomp(@line); #Chomps the newline off each string in the List print "\n@line\n"; #####result: #re gree orang #red green orange

总结

以上是内存溢出为你收集整理的perl STDIN全部内容,希望文章能够帮你解决perl STDIN所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/langs/1293562.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存