0% found this document useful (0 votes)
51 views

Perl Interview Questions

This document discusses the chomp function in Perl and how it works on different variable types. It notes that chomp removes trailing newline characters from scalar and array variables, and from the values of hash variables while leaving the keys unchanged. It provides an example of using a foreach loop to print each element of an array on its own line.

Uploaded by

Vikram Kamath
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Perl Interview Questions

This document discusses the chomp function in Perl and how it works on different variable types. It notes that chomp removes trailing newline characters from scalar and array variables, and from the values of hash variables while leaving the keys unchanged. It provides an example of using a foreach loop to print each element of an array on its own line.

Uploaded by

Vikram Kamath
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Perl interview Questions

Difference between the variables in which chomp function work?


Scalar: It is denoted by $ symbol. Variable can be a number or a string.
Array: Denoted by @ symbol prefix. Arrays are indexed by numbers.
The namespace for these types of variables is different. For Example: @add, $add.
Scalar variables can be either a number or a string
It doesnt matter if you want to chomp an array or a hash but it is safer to put the array or
hash inside the parentheses, otherwise the result could be one that you wouldnt expect.

If you chomp an array, all the trailing characters that match $/, from all the elements will be
removed. It returns the total number of characters removed.

In the case of hashes, only the values will be chomped, whereas the keys will remain
unchanged. It returns the total number of characters removed.

http://mpihowto.com/index.php/perl/perl-built-in-functions/perl-scalar-and-stringfunctions/perl-chomp-function
2. How can i display all array element in which each element will display on
next line in Perl ?

@array_declared=('ab','cd','ef','gh');
foreach (@array_declared) { print "$_\n"; }

You might also like