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 |
How to create a package?
How to deleting an existing file in perl programming?
How do find the length of an array?
Explain the functioning of conditional structures in perl.
What happens to objects lost in "unreachable" memory, such as the object returned by Ob->new() in `{ my $ap; $ap = [ Ob->new(), $ap ]; }' ?
What is the difference between having a parenthesis after module name and without parenthsis after module name?? i.e Package::Module(); and Package::Module;
What is subroutine in perl?
What are the benefits of perl in using it as a web-based application?
What's the difference between /^Foo/s and /^Foo/?
How to access parameters passed to a subroutine in perl?
What are the various perl data types based on the context?
What is lexical variable in perl?