What does the command "use strict" do and why should you
use it?
Answers were Sorted based on User's Feedback
Answer / prabin kumar, xansa(ind) chenn
"Use strict" is one of the pragma used for checking the
variable scope and syntax. If you use this pragma means,
you need to specify the scope (my, local, our) for the
variable and use the exact usage of operators.
For eg. Checking equality $number = 1 and $char eq 'a'.
Is This Answer Correct ? | 22 Yes | 0 No |
Answer / savitha sridhar
strict is a pragma that can be used to enforce Strict
programming practices while you write your programs.
Eg: You can write a program like this:
$x=100
print $x
But if you use strict pragma, then you have to be very
specific while using variables
use strict;
my $x=100; ##look at the usage of scope like my,local,our
print $x;
Pragma usage can also be used as a toggle
use strict;
my $x=100;
print $x;
no strict; # to toggle strict to "No"
$y=200; ##no need to use scope as strict is disabled
print $y;
Is This Answer Correct ? | 17 Yes | 0 No |
How do I send e-mail from a Perl/CGI program on a Unix system?
How many data types are there in perl?
while (my ($key, $value) = each(%ENV)) { print "$key - $value\n"; } What does the above sample code produce? What function do you use for reading a list of files within a directory? my %hash = ( 'hi' => {'hello' => 'all'}, 'bye' => {'later' => 'gone'} ); print $hash{'hi'}; What is printed when the above code is executed? sub new { my $pkg = shift; my $test = {'name' => shift;}; ???? return $test; } Which one of the following replaces "????" in the above code in order to cause the function new to return an object of type "Test"? while (<STDIN>) { ???? print "$_\n"; } Which one of the following statements causes the above code to strip all whitespace from the end of all lines of input and to print the resulting lines to standard output while (my ($key,$value) = each(%hash)) { print "$key - $value\n"; delete $hash{$key}; } open(FILE,"<file.dat"); my $data = ''; { local $/ = undef; $data = <FILE>; } close(FILE); my $foo = 21; $foo <<= 5; $foo >>= 4; print $foo; @arr = (1,2,3); {local $" = "\n"; print "@arr\n"; } my $line = "Hello World"; substr($line,5,2) = "abc"; print $line; Why is sprintf rarely used in perl in comparison to similar (or the same) functions in other languages? my $subRef = sub {print shift;}; How is the subroutine above called with one parameter? How can the values of an associative array be placed in sorted order in a new array? What function is often necessary for building data structures to be passed to low-level routines such as ioctl and fcntl? sub foo { if (shift(@_) > 0) { shift; } } print foo(10,5); print foo(-10,5); What does the above sample for (my $i = 1; $i <= 3; $i++) { print 1..$i; print "\n"; } my $data = 5**3 * 12,2+2; print $data; sub foo { my $value = shift; if ($value) { print 1; shift; } else { return shift(@_) + 3; } } print foo(10,20); What is printed as the result of executing the above code? $var = 20; sub s1 { print "$var "; } sub s2 { local $var = 10; s1;} sub s3 { my $var = 30; s1;} s3; s2; s1; On systems that record file ownership, how may the owner of a file be identified? Which one of the following sets $y to be a copy of $x with every occurrence of foo changed to bar? Which one of the following is an array literal that represents a 4-element array containing the numbers 1, 4, 2, and 6? sub foo {2*shift || 'x';} printf ("%s %s %s", foo(5),foo(0),foo(-5)); What does the above sample code print? Suppose $x contains a number. Which one of the following statements sets $y to be a string containing the octal value of $x?
What is the difference between $array[1] and @array[1]?
Mention what is cpan?
What is cpan in perl?
Remove the duplicate data from @array=(“perl”,”php”,”perl”,”asp”)
What do the symbols $ @ and % mean when prefixing a variable?
What does the command "use strict" do and why should you use it?
What are the reasons that cookie server can’t handle multiple connections?
How to read a file into a hash array?
What are the purpose of close(), getc() and read() functions?