adspace
how to extract pin_code,phone_number,year from text file using
regular expressions in perl
Answer Posted / 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 View All Answers
What is perl? What is the basic command to print a string in perl?
How do find the length of an array?
There is no strict data types in perl unlike in other high level languages like Java so wouldn't that be a problem if a code in perl is to be a written by a big team of 20+ members ?"
How to connect to SQL server through Perl?