in reply to How to extract Name and No from .vcf file.
Nice of you to use strictures, but pretty dumb to ignore the warnings they generate! Your "additional" test is doomed because it doesn't test the input line and the regular expressions are broken. The remaining code is doomed because you need to process each record as a unit, which is not what the code does. Instead consider:
use strict; use warnings; local $/ = 'END:VCARD'; while (my $record = <DATA>) { my ($name, $number) = $record =~ /FN:([^\n;]+).*\nTEL;[^\n]*PREF:([^\n;]+)/s; next if !defined $number; printf "%15s -> %s\n", $name, $number; } __DATA__ BEGIN:VCARD VERSION:3.0 N:;Naresh;;; FN:Naresh TEL;TYPE=CELL;TYPE=PREF:+917734807608 END:VCARD
Prints:
Naresh -> +917734807608
This code is not robust, but may help as a starting point for you.
|
|---|