Re: Inserting lines into text files, or howto "fix" vCards having no n: entry



Thank you. Your clue results in a helpful pointer to the Tie::File
module.

It will take me quite a bit to figure out the rest of the puzzle. If
anyone else has any clues regarding how I might use the Tie::File
module to accomplish this task, I'd appreciate it.

Please understand that I am a Perl novice and the following is the best
I can do to describe where I'm trying to go with this. I've got to use
some plain English pseudocode where I've got no idea how to write the
Perl stuff in order to convey myself. I imaging it would be something
like (assuming this processing is done before the vCard file is split
into multiple vCards):

use Tie::File

tie @array, 'Tie::File', $sourcefilename or die;

for (@array) {
If, in a given paragraph there are no lines beginning with "N:" or
"FN:" then {
$org = the line of this paragraph beginning with "ORG:"
$n = $org except we've replaced "ORG" with "N"
$fn = $org except we've replaced "ORG" with "FN"
Insert $n and $fn as two new lines just after the line of this
paragraph which begins with "VERSION:2.1"
}
}

How would I go about completing the "for" statement in proper Perl?

I'm providing an example vCard to complete the illustration, with the
first record (paragraph) being a record which should be ignored,
followed by three that should have "N:" and "FN:" lines inserted into
them:

BEGIN:VCARD
VERSION:2.1
N:LastName;FirstName
FN:FirstName LastName
TITLE:Title
ORG:Company
ADR;WORK:;;WorkAddress;WorkCity;WorkState;WorkZip;WorkCountry

BEGIN:VCARD
VERSION:2.1
ORG:1 Day Paint and Body
ADR;WORK:;;27592 Camino Capistrano;Laguna Niguel;CA
NOTE:7:30am-6pm Mon-Fri
TEL;WORK:(949) 582-1821
X-Palm-Custom1:http://www.1daypaint.com/
END:VCARD

BEGIN:VCARD
VERSION:2.1
ORG:2 Advanced Studios
ADR;WORK:;;65 Enterprise;Aliso Viejo;CA;92656
TEL;WORK:949.443.2112
TEL;FAX:949.330.7581
EMAIL:info@xxxxxxxxxxxxx
X-Palm-Custom1:http://www.2advanced.com/
END:VCARD

BEGIN:VCARD
VERSION:2.1
ORG:604 List
X-Palm-Custom1:www.party.net
END:VCARD

.



Relevant Pages

  • Re: ASCWC 91result
    ... Circulated novel with character to kill concealed ... I was worried about the 'circulated' aspect of this clue, ... Story of crime in international medical group, German section ... Stripes, for the English paragraph). ...
    (rec.puzzles.crosswords)
  • Re: Books on C/C++ for perl programmers
    ... Perl because others mentioned it (can't recall how I exactly got into ... each language, but I am actually studying Python ... I have been trying to learn Common Lisp for several years, ... person with clue. ...
    (comp.lang.perl.misc)
  • Re: Crimson Editor query
    ... hence it is safe to believe that some of the Perl-users ... I *did* give you a quick clue. ... a glib "did you have a Perl question" or a similarly useless response. ...
    (comp.lang.perl.misc)
  • Re: Net::DNS
    ... I thought that a had a clue of perl after using it intensively for years. ... I'm not shure anymore... ...
    (perl.beginners)
  • Abnormal behavior of print / syswrite
    ... print STDOUT $message; ... syswrite (Though I can't use syswrite even if it works coz of code of ... Not getting any clue what is wrong. ... Could anyone tell me what could be the problem (perl or non perl ...
    (perl.beginners)