Sie sind auf Seite 1von 3

Explain the difference between "my" and "local" variable scope declarations. ?

The variables declared with my() are visible only within the scope of the block which names them. They are not visible outside of this block, not even in routin es or blocks that it calls. local() variables, on the other hand, are visible to routines that are called from the block where they are declared. Neither is vis ible after the end (the final closing curly brace) of the block at all.

Given a file, count the word occurrence (case insensitive) open(FILE,"filename"); @array=<FILE>; $wor="word to be found"; $count=0; foreach $line (@array) { @arr=split (/s+/,$line); foreach $word (@arr) { if ($word =~ /s*$wors*/i) $count=$count+1; } } What is difference between "Use" and "require". In which case should "Use" be us ed and not "Require"? Use : 1. The method is used only for the modules(only to include .pm type file) 2. The included objects are varified at the time of compilation. 3. No Need to give file extension. Require: 1. The method is used for both libraries and modules. 2. The included objects are verified at the run time. 3. Need to give file Extension. what is a DataHash(). What does it mean? and for what purpose it is used??

"perl regular expressions are greedy" what does this mean? Perl regular expressions normally match the longest string possible. that is wha t is called as "greedy match" For instance:my($text) = "mississippi";$text =~ m/ (i.*s)/;print $1 . " ";Run the preceding code, and here's what you get:ississIt matches the first i, the last s, and everything in between them. But what if you want to match the first i to the s most closely following it? Use this code:my( $text) = "mississippi";$text =~ m/(i.*?s)/;print $1 . " ";Now look what the code produces:is

what are the benefits of having global and local variables? global variables can be called upon any where in the script. local variables are not valid outside the code blocks they are created in. Here is a Perl Problem that was posed to me. I was given one day time to solve. Unfortunately I did not know enough Perl to do it. And sadly, I did not get sele cted. However I wish to share this question with all. Please pose your answers o r programs on this forum for the benefit of all friends. Submitted by ilangocal.

What is hash in perl? A hash is and unordered set of key/value pairs that you access using strings (ke ys) as subscripts, to look up the scalar value corresponding to a given key. How do you connect to database in perl? There is DBI module.use DBI;my $dbh = DBI->connect('dbi:Oracle:orcl', 'username' , 'password',)where username and password is yours. THis is exmaple for oracle d atabase. Then preparing statement $stmt = $dbh->prepare(select * from table_name) And executing the statement $stmt->execute Is there any way to add two arrays together? Of course you can add two arrays together by using push function. The push funct ion adds a value or values to the end of an array. The push function pushes the values of list onto the end of the array. Length of an array can be increased by the length of list. I have a variable named $objref which is defined in main package. I want to make it as a Object of Class XYZ. How could I do it? use XYZ; my $objref= XYZ->new(); what is meant 'die' in a perl program? If the condition defined before the DIE statement is NOT met, the script will st op execution at that point, printing out the default error, if a custom error me ssage is not defined.

what's the purpose of -w.strict,-T? w option enables warning.use strict pragma is used then you should declare varia bles before there use

What happens when you return a reference to a private variable?

Perl keeps track of your variables, whether dynamic or otherwise, and doesn't fr ee things before you're done using them. What is CPAN ? What are the modules coming under this? CPAN ic Comprehencive Perl Archive Network. Its a repository contains thousands of Perl modules, source and documentation, and all under GNU/GPL or similar lice nce. you can go to www.cpan.org for more details. Some Linux distributions provi de a tool named "cpan" with wich you can install packages directly from CPAN

what's is the use of 'require' and what does this mean? Require is a call to an external essential script or module, without which the c urrent script/program will not proceed any further what is meant by 'chomp'? where do we require this ? chomp is used to eliminate the new line character. It can used in many different scenarios. For ex: excuteScript.pl firstArgument. $firstArg = $ARGV[0]; chomp $firstArg; --> to get rid of the carrige return.

what is meant by a 'pack' in perl? Pack Converts a list into a binary representation Takes an array or list of values and packs it into a binary structure, returning the string containing the structure

Das könnte Ihnen auch gefallen