Try pattern matching for the following:
1) 10.111.23.11
2) /root/abc/cde/fgg/ac.xml --> Get file name without
extention.
3) /root/abc/ac.xml/fgg/ac.xml --> Get file name without
extention.
4) What does "DIE" meant in PERL?
5) chomp
6) "This is saturday" --> Print the weekday number.
7) 11-2-2009 --> Print the name of the month.
8) Reverse the string without using func in C.

Answer Posted / guest

my $str="This is testing of string reverse";
print scalar reverse $s

chomp is used to remove the trailing new line.
If we give chomp list then it will remove the trailing new
line in all the elements of the list.

die function is used for handling the errors in Perl.
It terminates the program immediately after printing the
message passed to the die function.
die("testing of die");
It will print the message "testing of die" on screen and
terminates the program.

Pattern Matching
----------------
[code]

my $str="10.111.23.11";
my $file="/root/abc/cde/fgg/ac.xml";
my $file1="/root/abc/ac.xml/fgg/ac.xml";
if($str=~/[0-9]{2}\.[0-9]{3}\.[0-9]{2}\.[0-9]{2}/)
{
print "Pattern $& get matched\n";
}
if($file1=~s/\/(.*)\/(.*)\.(.*)/$2/)
{
print "File Name is $file1\n";
}
print strftime("%B",0,0,0,11,2-1,2009);

[/code]

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is q (single q) operator in perl?

534


How do I send e-mail from a Perl/CGI program on a Unix system?

586


Explain the different types of data perl can handle.

491


What is the function of virtual documents in cgi programs?

522


There are two types of eval statements i.e. Eval expr and eval block. Explain them.

480






What value is returned by a lone `return;’ statement?

562


Explain cpan?

529


how to create a flat file database as shown below s.no name age city phone 0 hema 22 Calcutta 4312542 1 hema 21 Bangalore 2344345 2 ganesh 25 delhi 2445454 3 kartik 45 pune 4312121 4 santosh 25 Hyderabad 2254231 5 kumar 25 mysore 2344567 6 gita 34 mangalore 6532123 7 gita 32 pune 2213456 Q1.print the details of the person who r from bangalore q2.Replace the city name managlore to pune q3.prints no of person having name gita and hema q4.print how many are of age 25.

1671


What are stdin, stdout and stderr?

515


How does polymorphism work in perl? Give an example.

479


How do I debug a perl program?

516


What is perl? What is the basic command to print a string in perl?

480


What is -> symbol in perl?

568


How to convert strings into an array in perl?

515


Which feature of perl provides code reusability?

569