On 22/12/2012 11:15, punit jain wrote:
Hi,
I have a file like below : -
BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test1
REV:20101116T030833Z
UID:644938456.1419.
END:VCARD
From <>(S_______-000000000003) Tue Nov 16 03:10:15 2010
content-class: urn:content-classes:person
Date: Tue, 16 Nov 2010 11:10:15 +0800
Subject: test
Message-ID: <644938507.1420>
MIME-Version: 1.0
Content-Type: text/x-vcard; charset="utf-8"
BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test2
REV:20101116T031015Z
UID:644938507.1420
END:VCARD
My requirement is to get all text between BEGIN:VCARD and END:VCARD and all
the instances. So o/p should be :-
BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test1
REV:20101116T030833Z
UID:644938456.1419.
END:VCARD
BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test2
REV:20101116T031015Z
UID:644938507.1420
END:VCARD
I am using below regex :-
my $fh = IO::File->new("$file", "r");
my $script = do { local $/; <$fh> };
close $fh;
if (
$script =~ m/
(^BEGIN:VCARD\s*(.*)
^END:VCARD\s+)/sgmix
){
print OUTFILE $1."\n";
}
However it just prints 1st instance and not all.
Any suggestions ?
This is very simply done with Perl's range operator. See the program
below.
Rob
use strict;
use warnings;
open my $fh, '<', 'vcard.txt' or die $!;
while (<$fh>) {
print if /^BEGIN:VCARD/ .. /^END:VCARD/;
}
**output**
BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test1
REV:20101116T030833Z
UID:644938456.1419.
END:VCARD
BEGIN:VCARD
VERSION:2.1
EMAIL:te...@test.com
FN:test2
REV:20101116T031015Z
UID:644938507.1420
END:VCARD
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/