设为首页 收藏本站
查看: 715|回复: 0

[经验分享] perl FAQ(zz)

[复制链接]

尚未签到

发表于 2015-12-26 09:26:05 | 显示全部楼层 |阅读模式
1. Why do you write a program in Perl?
  Ans : Easy to use and fast execution since perl script undergoes only two phases like compile phase and run phase.
2. What is the difference between chop & chomp functions in perl?
  Ans : Chop removes last character.
Chomp removes new line character.
3. What is a hash?
  Ans : It is array having attributes andvalues.
4. How would you replace a char in stringand how do you store the number of replacements?
  Ans : By using Translation operator(tr///). Number of replacements can be obtained by assigning wholeexpression to scalar variable.
5. How do you open a file forwriting?
  Ans : open HANDLER, “<filename” or die $!;
6. What is the difference between for& foreach?
  Ans : Only syntax differs.
7. What purpose does each of the followingserve: -w, strict, - T ?
  Ans : List out the warnings if any in perlprogram.
8. Explain the difference between use andrequire?
  Ans : "use" the controler will go to thatfile during run time and come back to original program at the sametime if we consider the "require" the         wholefile will get copied at the place where it is required.
9. Explain the difference between my andlocal?
  Ans : The variables declared with "my" canlive only within the block it was defined.
The variables declared with "local" can live within the block andhave its visibility in the functions called within thatblock.
10. Which is the shebang inperl?
  Ans : #! /usr/bin/perl
11. Name the two phases of execution ofPERL program?
  Ans : Compiler phase and Runphase.
12. Which is the default variable inPERL?
  Ans : $_
13. How to check the syntax of the scriptwithout executing the program?
  Ans : #! /usr/bin/perl -c
14. How to get the versionPERL?
  Ans : #! /usr/bin/perl -v
15. Which is the command used to changethe base of a number to another base?
  Ans : sprintf
16. Which is the command used to removethe new line character?
  Ans : chomp();
17. How we can get ASCII value ofcharacter?
  Ans : Ord();
18. What is QW in list and why it isused?
  Ans : QW is quote word which mainly usedto avoid complexity in lists.
19. Give an example to show how the mapwill be used for list?
  Ans : print ( map lc ,A,B,C);
20. How array differs from list
  Ans : Array is obtained by assigning listto variable.
21. $#arrayname signifies
  Ans : Last index of an array.
22. How we can get the size of anarray?
  Ans : By assigning an array to any scalarvariables.
23. What are the functions of followingcommands:
a. push    b. pop    c. shift    d. unshift
  Ans : a. push = updates the values at theend of an array.
b. pop = takes out the last element of an array.
c. shift =takes out the first element of an array.
d. unshift = updates the values at the beginning of anarray.
24. Give an example to show how splicingwill be done?
  Ans : @num = (1,2,3,4,5);
@val = (6,7);
splice (@num ,4,0,@val);
25. How we can access the individualvalues of hash?
  Ans : Using {}
26. How to find the number of keys andvalues in hash?
  Ans : Using key words Keys andValues.
27. Which is the function used to deletethe value of specified key?
  Ans : undef
28. Which is the function to delete bothkey and related value?
  Ans : delete
29. What & specifies inPERL?
  Ans : Bitwise and
30. Which is the binding operater inPERL?
  Ans “ =~”
31. What are the functions of followingkeywords
a. last    b.next    c.redo
  Ans : a. last : used to exit from thestatement block.
b. next : used to skip the rest of the statements block and startthe next iteration.
c. redo : causes perl to restart the current statementblock.
32. List the regular expressions inPERL?
  Ans : m// , s/// ,tr///
33. How to pass an arguments tosubroutines?
  Ans : Through variable @_.
34. Which is the default variable thatwill be having argument value that is passed tosubroutine?
  Ans : @_
35. What happens if a PATTERN is of nullstring?
  Ans : Last successfully executed regularexpression is used.
36. $value=~tr/SEARCHLIST/REPLACEMENTLIST/in this expression what will be the variable $valuehaving?
  Ans : SEARCHLIST
37. $value=~tr/SEARCHLIST/REPLACEMENTLIST/how to find out the number of replacements in thisexpression?
  Ans : By assigning this expression toanother variable like
$count=($value=~tr/SEARCHLIST/REPLACEMENTLIST/)
38. How to complement the the search listin Translation operator?
  Ans : Using c modofier
39. How we can match the metacharacters inpattern matching?
  Ans : m/\metacharacter/
40. $var=~/\d/ What does itmatch?
  Ans : Matches any digit.
41. $var=~/\W/ it is equivalent to
a. [a-z]     b.[a-zA-Z]     c.[^0-9a-zA-Z]    d. [0-9]
  Ans : C
42. Which is the character that will beused to match white space?
  Ans : \s
43. What is the difference between \u and\U?
  Ans : \u changes next character touppercase.
\U changes following characters to uppercase.
44. What is the difference betweenfollowing expressions
$var=~/w[^aoi]nder/ &$var=~/^w[aoi]nder/
  Ans : first one will look for W followedby something that is none of 'a' , 'o' , or 'i'
second one will matches at the begining of the line.
45. $txt=~/((T/N)est(ing|er))/) What arethe values of following variables
$txt ,    $1,    $2,    $3
  Ans : $1 = Testing, $2=T,$3=ing
46. What are Quantifiers?
  Ans : Quantifiers says how many timessomething may match.
47. Which of the following matches zero ormore times
a. *     b. +   c. ?   d.{}
  Ans : a
47. How we can find out number ofarguments sent from command line?
  Ans : Assigning @ARGV to any scalarvariables.
48. What are the difference in writingscript in C and PERL?
  Ans : There we don't have a muchdifference between PERL and shell script.
As of my knowledge both are good in there own way of workenvironment.
As consern to speed & performance the PERL is ahead of shell.
---Perl is very good at text processing like we have regularexpressions.
---Shell scripts are mainly inteded for sys-admin tasks.
49. How we can use a Linux commands inPERL?
  Ans : By writing linux command in ``operater.
50. Write a script to set an environmentvariables?
  Ans : $var = `setenv $VAR path`;
51. How we can use foreach loop foraccessing the content of file?
  Ans : foreach (< HANDLER>) {
command1;
command2;
....... }
52. Write a script to list all unknowndirectories of another directory?
  Ans : chdir(dir name);
$var = `find . -type d -name “*” | tee list `;

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-156423-1-1.html 上篇帖子: Perl 中的 s/// 操作符 下篇帖子: Perl链接数据库
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表