When i tried to extract name and number and print in a file then they are being repeated. I tried with and if condition to prevent the repeating with an regex at the start but not successful.
Like Naresh -> 8890328840
Naresh -> 8890328840
Naresh -> 8890328840
Naresh -> 8890328840
Naresh -> 8890328840
file.vsf structure is:
BEGIN:VCARD
VERSION:3.0
N:;Naresh;;;
FN:Naresh
TEL;TYPE=CELL;TYPE=PREF:+917734807608
END:VCARD
Code i tried is:
use strict; use warnings; my $filename = $ARGV[0]; my ($name, $number); open my $fh, "<", "$filename" or die "$!"; open my $fh2, ">", "list.txt" or die "$!"; while(my $line = <$fh>) { if( /!^\s*FN/ || /!^\s*TEL/ ) { next ; } elsif( $line =~ /^\s*FN:(\w+\s*\w*)\b/ ) { $name = $1; } elsif( $line =~ /^\s*TEL;TYPE=CELL;TYPE=PREF:([+|(?:91)]?\d{10})\b +/ ) { $number = $1; } printf $fh2 "%15s -> %d\n", $name, $number ; } close $fh2 or die "$!"; close $fh or die "$!";
I appreciate your time taken to read and answer. Thank u in advance.:)
In reply to How to extract Name and No from .vcf file. by shankonit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |