Monday, June 9, 2014

[Solved] PERL Programming Challenge

Fancy your PERL programming skills ? Take this challenge and answer these simple 5 questions on PERL.
Update : Added solutions


  1. How do I eliminate the newline character from the input variable $age in PERL ?
      • chomp($age);

  2. Write a PERL one-liner to convert tab spaces in a file called tabs.txt to one space each
      • perl -pe 's/\t/ /g' tabs.txt;

  3. How do you empty the contents of an array called : myarray in PERL?
      • $#myarray = -1;

  4. How do I append a new line containing the text “Get water” before the 3rd line of a file : todo.txt using PERL ?
      • perl -pe 'print "Get water\n" if $. == 3’ todo.txt;

  5. How do you download the contents of a URL with PERL ?
      • By using LWP.pm [ Perl Module ]
      • use LWP::Simple;
      • $webdata = get ‘http://your-website.com';

No comments:

Post a Comment