how to extract pin_code,phone_number,year from text file using
regular expressions in perl



how to extract pin_code,phone_number,year from text file using regular expressions in perl..

Answer / Prabhakar Anand

In Perl, you can use regular expressions (regex) with the `m//` operator to match patterns in a string. Here's an example of how you might extract phone number, pin code, and year from a text file:

open(my $fh, '<', 'file.txt') or die "Couldn't open file!";

while (my $line = <$fh>) {
if ($line =~ /(d{6}) (d{10}) (d{4})$/ ) {
print "Phone Number: $2nPin Code: $1nYear: $3n";
}
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More CGI Perl Interview Questions

How to create a package?

1 Answers  


How to deleting an existing file in perl programming?

1 Answers  


How do find the length of an array?

0 Answers  


Explain the functioning of conditional structures in perl.

1 Answers  


What happens to objects lost in "unreachable" memory, such as the object returned by Ob->new() in `{ my $ap; $ap = [ Ob->new(), $ap ]; }' ?

1 Answers  


What is the difference between having a parenthesis after module name and without parenthsis after module name?? i.e Package::Module(); and Package::Module;

1 Answers  


What is subroutine in perl?

1 Answers  


What are the benefits of perl in using it as a web-based application?

1 Answers  


What's the difference between /^Foo/s and /^Foo/?

1 Answers  


How to access parameters passed to a subroutine in perl?

1 Answers  


What are the various perl data types based on the context?

1 Answers  


What is lexical variable in perl?

1 Answers  


Categories