shankonit has asked for the wisdom of the Perl Monks concerning the following question:
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.:)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to extract Name and No from .vcf file.
by GrandFather (Saint) on Aug 03, 2015 at 05:36 UTC | |
|
Re: How to extract Name and No from .vcf file.
by kevbot (Vicar) on Aug 03, 2015 at 05:45 UTC | |
|
Re: How to extract Name and No from .vcf file.
by pme (Monsignor) on Aug 03, 2015 at 05:25 UTC | |
|
Re: How to extract Name and No from .vcf file.
by shankonit (Acolyte) on Aug 03, 2015 at 05:46 UTC | |
by pme (Monsignor) on Aug 03, 2015 at 05:56 UTC | |
|
Re: How to extract Name and No from .vcf file.
by vinoth.ree (Monsignor) on Aug 03, 2015 at 05:49 UTC |