[30414] in Perl-Users-Digest
Perl-Users Digest, Issue: 1657 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 18 21:09:44 2008
Date: Wed, 18 Jun 2008 18:09:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 18 Jun 2008 Volume: 11 Number: 1657
Today's topics:
Re: [regex] grep for chars in any order <bart.lateur@pandora.be>
Re: DRaw a blank on combinging two arrays (Jens Thoms Toerring)
Re: DRaw a blank on combinging two arrays <bart.lateur@pandora.be>
Re: DRaw a blank on combinging two arrays <bill@ts1000.us>
Re: extract all hotmail email addresses in a file and s <cartercc@gmail.com>
Re: extract all hotmail email addresses in a file and s <toe@lavabit.com>
Re: extract all hotmail email addresses in a file and s <jurgenex@hotmail.com>
Re: extract all hotmail email addresses in a file and s <nospam@nospam.invalid>
Re: extract all hotmail email addresses in a file and s <rui.maciel@gmail.com>
Re: extract all hotmail email addresses in a file and s (Kenny McCormack)
Re: grep for chars in any order <jl_post@hotmail.com>
Re: htmldoc...funny characters not going away <smallpond@juno.com>
Re: Learning Perl <g....c.e@gmail.com>
Re: Learning Perl <stuart.flowers@t-online.de>
Re: Learning Perl <elizabethbarnwell@gmail.com>
Re: Offsetting dates from the past in Date::Manip <smallpond@juno.com>
Re: Perl XML::Simple Accessing complex XML <zzapper@gmail.com>
Re: Reading whole file into memory. Parsing 'C' like fi <smallpond@juno.com>
Wrtiting to a file in LDIF format <akhilshri@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 18 Jun 2008 22:47:39 +0200
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: [regex] grep for chars in any order
Message-Id: <c0ti54ps9cc7gtsiuv05ilcrq9fde4jhlc@4ax.com>
Glenn Jackman wrote:
>At 2008-06-18 09:01AM, "Ben Bullock" wrote:
>> Great! That is better than the solution I posted. But I have an
>> improvement:
>>
>> /(?=.*a)(?=.*b)(?=.*c)/
>
>Nice. I wonder (without bothering to benchmark it) if anchoring the
>expression would be an optimization:
>
> /^(?=.*a)(?=.*b)(?=.*c)/
It would, in case it doesn't match. The latter will only try a match at
the start of the string, the former will try again at every character
position, which is is dead stupid, of course.
Be aware of the possibility of the string containing newlines.
/^(?=.*a)(?=.*b)(?=.*c)/s
--
Bart.
------------------------------
Date: 18 Jun 2008 20:29:14 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: DRaw a blank on combinging two arrays
Message-Id: <6bt9gqF3dkqu6U1@mid.uni-berlin.de>
Bill H <bill@ts1000.us> wrote:
> Earlier I was trying to combing 2 arrays and totally drew a blank on
> how to do it. I though it would be join but didn't seem to work. Can
> someone tell me what to look up in perldoc for it?
> I thought I could used something like @c = join(@a,@b); but just ended
> up with one long string.
It's not clear what you mean exactly with "combine to arrays", but
your attempt with join makes it look as you simply want to append
the elements of @b to that of @a and have the result in a third
array. And in that case the you're looking for too complicated a
solution, a simple
@c = ( @a, @b );
is all you need. If you instead want to append the elements from
@b to @a you would do
push @a, @b;
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: Wed, 18 Jun 2008 22:31:25 +0200
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: DRaw a blank on combinging two arrays
Message-Id: <l2si54hab47rc538obcafe4dbtk54vof34@4ax.com>
Bill H wrote:
>Earlier I was trying to combing 2 arrays and totally drew a blank on
>how to do it. I though it would be join but didn't seem to work. Can
>someone tell me what to look up in perldoc for it?
>
>I thought I could used something like @c = join(@a,@b); but just ended
>up with one long string.
Simple enough:
@c = (@a, @b);
or
@c = @a; # copy @a
push @c, @b; # add @b
--
Bart.
------------------------------
Date: Wed, 18 Jun 2008 17:45:33 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: DRaw a blank on combinging two arrays
Message-Id: <86bbe825-abaa-4969-990f-48bc0d2281a5@26g2000hsk.googlegroups.com>
On Jun 18, 4:29=A0pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> Bill H <b...@ts1000.us> wrote:
> > Earlier I was trying to combing 2 arrays and totally drew a blank on
> > how to do it. I though it would be join but didn't seem to work. Can
> > someone tell me what to look up in perldoc for it?
> > I thought I could used something like @c =3D join(@a,@b); but just ende=
d
> > up with one long string.
>
> It's not clear what you mean exactly with "combine to arrays", but
> your attempt with join makes it look as you simply want to append
> the elements of @b to that of @a and have the result in a third
> array. And in that case the you're looking for too complicated a
> solution, a simple
>
> =A0 @c =3D ( @a, @b );
>
> is all you need. If you instead want to append the elements from
> @b to @a you would do
>
> =A0 push @a, @b;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Regards, Jens
> --
> =A0 \ =A0 Jens Thoms Toerring =A0___ =A0 =A0 =A0j...@toerring.de
> =A0 =A0\__________________________ =A0 =A0 =A0http://toerring.de
Thanks Jens - yeah thats what I wanted to do and I just could not
figure it out - new it was simple but I was looking for something
complex instead of thinking simple!
Bill H
------------------------------
Date: Wed, 18 Jun 2008 13:36:08 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <7a59a1d7-ed71-4b2a-857b-26260934e8e5@y38g2000hsy.googlegroups.com>
On Jun 18, 4:06 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
> In your program, the match of /hotmail/ could occur on the left-hand size
> of the @ . For example,
>
> "my_other_account_is_hotm...@msn.com"
>
> Your code would mistakenly file this in the wrong place.
>
> Your code also does not satisfy the requirement that,
> "The hotmail addresses in the original file would be deleted"
> which requires that the original file be altered.
My code was meant to be a rough pseudocode, not a tested application.
I just banged something out to show the logic, not expecting that
anyone would mistake it for a fully tested and debugged application. I
would expect it to fail the first time, but at least the outline of
the logic is there, even if it isn't complete.
CC
------------------------------
Date: Wed, 18 Jun 2008 15:02:30 -0700 (PDT)
From: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= <toe@lavabit.com>
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <d6cf6b62-60fd-4888-b2c2-504835c0e9d4@34g2000hsh.googlegroups.com>
On Jun 18, 8:33=A0pm, Dennis <dcho...@gmail.com> wrote:
> 1. Strip out the " characters and just leave the email addresses on
> each line.
char const *const original =3D "\"bob@hotmail.com\"";
char buf[50];
strcpy(buf,original);
buf[strlen(original) - 1] =3D 0;
> 2. extract out the hotmail addresses and store it into another file.
Take the last 12 characters, make them all lowercase, and then compare
with "@hotmail.com".
I'm not big up on the file access functions, I usually just consult
the reference at dinkumware.com when I want to use them.
------------------------------
Date: Thu, 19 Jun 2008 00:25:02 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <3e9j5410dj66c87o8timk6i05qgv66acop@4ax.com>
Dennis <dchou4u@gmail.com> wrote:
>Hi, I have a text file that contents a list of email addresses like
>this:
>
>"foo@yahoo.com"
>"tom@hotmail.com"
>"jerry@gmail.com"
>"tommy@apple.com"
>
>I like to
>
>1. Strip out the " characters and just leave the email addresses on
>each line.
'perldoc perlop' and look for either tr/// in combination with the 'd'
option or s/// in combination with the 'g' option. Maybe in combination
with anchoring the RE.
Or you can use substr() to grab anything between the first and last
character, excluding both.
>2. extract out the hotmail addresses
perldoc -f grep
>and store it into another file.
perldoc -f open
>The hotmail addresses in the original file would be deleted.
perldoc -q "delete a line"
jue
------------------------------
Date: Wed, 18 Jun 2008 20:36:34 +0000 (UTC)
From: Antoninus Twink <nospam@nospam.invalid>
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <slrng5isei.s3l.nospam@nospam.invalid>
On 18 Jun 2008 at 20:01, cartercc wrote:
> On Jun 18, 3:33 pm, Dennis <dcho...@gmail.com> wrote:
>> I like to
>>
>> 1. Strip out the " characters and just leave the email addresses on
>> each line.
>> 2. extract out the hotmail addresses and store it into another file.
>> The hotmail addresses in the original file would be deleted.
>
> open INFILE, "<all_emails.txt";
> open HOTMAIL, ">hotmail_only.txt";
> open NOTHOTMAIL, ">not_hotmail.txt";
> while(<INFILE>)
> {
> $_ =~ s/"//g;
> print HOTMAIL if $_ =~ /hotmail/i;
> print NOTHOTMAIL if $_ != /hotmail/i;
> }
> close INFILE;
> close HOTMAIL;
> close NOTHOTMAIL;
Firstly, you mean !~ instead of !=. Secondly, referring to $_ all the
time is unnecessary. Try:
open INFILE, "< all_emails.txt";
open HOTMAIL, "> hotmail_only.txt";
open NOTHOTMAIL, "> not_hotmail.txt";
while(<INFILE>)
{
s/"//g;
if (/hotmail/i) {
print HOTMAIL;
} else {
print NOTHOTMAIL;
}
}
close INFILE;
close HOTMAIL;
close NOTHOTMAIL;
You might also like to include some error-checking, and avoid
hard-coding the paths.
------------------------------
Date: 18 Jun 2008 20:53:48 GMT
From: Rui Maciel <rui.maciel@gmail.com>
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <485975dc$0$25052$a729d347@news.telepac.pt>
On Wed, 18 Jun 2008 12:33:45 -0700, Dennis wrote:
> Hi, I have a
<snip />
Why are you cross-posting this to C and Perl newsgroups?
Rui Maciel
------------------------------
Date: Wed, 18 Jun 2008 21:22:36 +0000 (UTC)
From: gazelle@xmission.xmission.com (Kenny McCormack)
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <g3buas$hik$1@news.xmission.com>
In article <485975dc$0$25052$a729d347@news.telepac.pt>,
Rui Maciel <rui.maciel@gmail.com> wrote:
>On Wed, 18 Jun 2008 12:33:45 -0700, Dennis wrote:
>
>> Hi, I have a
><snip />
>
>Why are you cross-posting this to C and Perl newsgroups?
>
>
>Rui Maciel
I assume because he is interested in a C/Perl solution to his problem.
------------------------------
Date: Wed, 18 Jun 2008 16:16:31 -0700 (PDT)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: grep for chars in any order
Message-Id: <3a245d4b-1d57-457f-927a-2222f516278d@k37g2000hsf.googlegroups.com>
On Jun 18, 1:06 am, viki <viki...@gmail.com> wrote:
> How can I build regex that matches all characters of the string $STR
> in any order with .* added between any two characters: ?
> And without generating all N! transpositions (where N is length of
> $STR) ?
> Example.
> For $STR "abc", I want to match equivalent to:
> /(a.*b.*c)|(a.*c.*b)|(b.*a.*c)|(b.*c.*a)|(c.*a.*b)|(c.*b.*a)/
Dear Viki,
If you don't mind using several regular expressions (one for each
letter), you can easily write:
/a/ and /b/ and /c/
You can even put it in a Perl grep() statement (which I presume is
what you intend to use it for) like this:
my @firstList = ('cab', 'back', 'cat', 'crab', 'dog', 'baby');
my @secondList = grep { /a/ and /b/ and /c/ } @firstList;
In this way, @secondList would contain 'cab', 'back', and 'crab',
but not 'baby' (which would have been a false positive in your
previous example).
Of course, this approach uses one regular expression for each
letter that you're looking for (instead of just one last regular
expression), but depending on how you're writing your code, that may
be acceptable.
I hope this helps, Viki.
-- Jean-Luc
------------------------------
Date: Tue, 17 Jun 2008 17:57:56 -0400
From: smallpond <smallpond@juno.com>
Subject: Re: htmldoc...funny characters not going away
Message-Id: <a79f$48583377$14259@news.teranews.com>
hotkitty wrote:
> Hi,
>
> Am using htmldoc to turn webpages into pdf files. When using the gui
> application the pdf file turns out great. However, when using perl to
> call the program the pdf apostraphes, quotations get turned into
> symbols (apostraphes get turned into a-hat). Obviously its an encoding
> issue but I've used various methods like setting the character set
> like cpan says, uri::escape and even tried substituting the character
> for the symbol (=~ s/a-hat/'/g) to no avail. Any suggestions?
I am not seeing any perl code in your post that has to do with calling
htmldoc, which has a fairly extensive set of options controlling the
fonts and character sets. Look in the documentation under "command line".
--S
** Posted from http://www.teranews.com **
------------------------------
Date: Wed, 18 Jun 2008 13:16:30 -0700
From: "Gordon Corbin Etly" <g....c.e@gmail.com>
Subject: Re: Learning Perl
Message-Id: <6bt8p0F3edvodU1@mid.individual.net>
Uri Guttman wrote:
>>>>>> "GCE" == Gordon Corbin Etly <g....c.e@gmail.com> writes:
> > Uri Guttman wrote:
> >>>>>>> "GCE" == Gordon Corbin Etly <g....c.e@gmail.com> writes:
> > > see you don't get it. it isn't broken behavior but behavior that
> > > shouldn't have been there to begin with. like my $x = 1 if 0 stuff
> > > which does something that was bad but not deprecated until
> > > recently.
> > I do get it. Maybe tell nose thumbing would allow us to understand
> > each other better.
> huh?? and you don't get it. otherwise you wouldn't have been defending
> the undefensible for so long. and i don't get that you even
> acknowledge you were wrong about it.
Ok, yes I was off with my initial assessment of defined() for
aggregates. I'm not above admitting that. I do think you could of gotten
your point across in a more diplomatic way and avoided all the extra
noise (which I'm also not above admitting may have partly been my fault
too for getting too worked up by it.)
I wasn't really disputing the documentation, though; I just feel it can
be useful to test weather an array or hash has been given a value since
it's inception, or if it has been run through the undef() function. I
can thing of a few scenarios where it maybe be useful to able to check
for such a state separately from being just empty, much like one might
test for undef vs. 0 or "".
--
G. C. Etly
------------------------------
Date: Wed, 18 Jun 2008 22:25:59 +0200
From: stuart <stuart.flowers@t-online.de>
Subject: Re: Learning Perl
Message-Id: <g3bqvp$rga$00$1@news.t-online.com>
brian d foy wrote:
> In article
> <dfa1a2b1-0455-4bf1-9cf8-9525335f1ed5@56g2000hsm.googlegroups.com>,
> Elizabeth Barnwell <elizabethbarnwell@gmail.com> wrote:
>
>> Here is a set of flashcards our developers have been using to learn
>> Perl with very good results:
>
[..]
>
> I guess the technology is okay, but I don't see the point of trying to
> learn a programming language without actually programming. Memorization
> isn't worth much when you should be able to look up anything you need
> at the same time you are programming.
I agree with brian (is agreement allowed in this thread?)
When I use Perl I have 4 xterms on the screen
1. File to be analysed (all my Perl programs analyse files)
2. The Perl program (in vi of course, but I guess we don't want to go there)
3. Here I run the program and read the errors
4. The research window. I normally end up with man perlfaq4 here, but often
its where I look at old programs that work, or other Perl manpages.
Summary, I don't remember anything parrot fashion, and therefore flashcards
wouldn't help me. What I need are old programs and the docs that come with
Perl. Thanks guys.
---
Stuart Flowers
------------------------------
Date: Wed, 18 Jun 2008 13:42:16 -0700 (PDT)
From: Elizabeth Barnwell <elizabethbarnwell@gmail.com>
Subject: Re: Learning Perl
Message-Id: <4c274097-dcbc-45dd-8330-b6d937f6de95@z72g2000hsb.googlegroups.com>
On Jun 18, 3:25=A0pm, stuart <stuart.flow...@t-online.de> wrote:
> brian d =A0foy wrote:
>
>
>
> > In article
> > <dfa1a2b1-0455-4bf1-9cf8-9525335f1...@56g2000hsm.googlegroups.com>,
> > Elizabeth Barnwell <elizabethbarnw...@gmail.com> wrote:
>
> >> Here is a set of flashcards our developers have been using to learn
> >> Perl with very good results:
>
> [..]
>
> > I guess the technology is okay, but I don't see the point of trying to
> > learn a programming language without actually programming. Memorization
> > isn't worth much when you should be able to look up anything you need
> > at the same time you are programming.
>
> I agree with brian (is agreement allowed in this thread?)
> When I use Perl I have 4 xterms on the screen
> 1. File to be analysed (all my Perl programs analyse files)
> 2. The Perl program (in vi of course, but I guess we don't want to go the=
re)
> 3. Here I run the program and read the errors
> 4. The research window. I normally end up with man perlfaq4 here, but oft=
en
> its where I look at old programs that work, or other Perl manpages.
>
> Summary, I don't remember anything parrot fashion, and therefore flashcar=
ds
> wouldn't help me. What I need are old programs and the docs that come wit=
h
> Perl. Thanks guys.
>
> ---
> Stuart Flowers
Hi Stuart, Thanks for your feedback!
Best,
Elizabeth
------------------------------
Date: Mon, 16 Jun 2008 10:08:14 -0400
From: smallpond <smallpond@juno.com>
Subject: Re: Offsetting dates from the past in Date::Manip
Message-Id: <39f30$485673d7$26702@news.teranews.com>
pwaring@gmail.com wrote:
> I'm trying to use Date::Manip to resolve strings which represent dates
> according to a known reference point - e.g. given a known date, what
> does "Friday" represent?. If I do something like this:
>
> my $date = ParseDate("Friday");
> print $date;
>
> I get the result I expect, i.e. 13/06/08 (assuming I changed the
> format to DD/MM/YY). However, the date used for as the reference point
> is always the current date, and I want to be able to put in an
> arbitrary date and have the reference resolved from there. For
> example, if I use this time last year, "Friday" should be resolved to
> a different date - 15/06/07. Does anyone know if it is possible to do
> this within Date::Manip? I've tried using DateCalc, but this gives me
> an offset from the current date, which isn't really what I want.
>
> Thanks in advance,
>
> Paul
>
> P.S. I'm only dealing with recent dates (1990-present), so there
> shouldn't be any problems with pre-1900 dates etc.
For Date::Manip, configure ForceDate to the base that you want to use.
** Posted from http://www.teranews.com **
------------------------------
Date: Wed, 18 Jun 2008 14:50:42 -0700 (PDT)
From: zzapper <zzapper@gmail.com>
Subject: Re: Perl XML::Simple Accessing complex XML
Message-Id: <c4019fc5-1507-465e-8e0b-a8e349b0eef6@f63g2000hsf.googlegroups.com>
On Jun 18, 8:33=A0pm, Jim Gibson <jimsgib...@gmail.com> wrote:
> In article
> <384b28cf-598d-4911-9612-8ec9e2013...@m44g2000hsc.googlegroups.com>,
>
>
>
> zzapper <zzap...@gmail.com> wrote:
> > On Jun 18, 1:39=A0pm, "John" <john1...@yahoo.com> wrote:
> > > "zzapper" <zzap...@gmail.com> wrote in message
>
> > >news:d4825f41-4e5b-4cbd-b8ee-2288c0cb0cc5@r66g2000hsg.googlegroups.com=
...
>
> > > > Hi
> > > > <companyname count=3D"1">
> > > > <property id=3D"55467" md=3D"2008-03-20" mc=3D"GBP" mp=3D"173000" >
> > > > <psumm><![CDATA[This 3 bedroom, ]]></psumm>
> > > > <a1>1 Bucket Way</a1>
> > > > <at>Stafford</at>
> > > > <ac>Staffordshire</ac>
> > > > <actry></actry>
> > > > <images>
> > > > =A0 =A0 <image id=3D"543">Property Image</image>
> > > > =A0 =A0 <image id=3D"545">Property Image</image>
> > > > </images>
> > > > </property>
> > > > </companyname>
>
> > > > I am trying to read the above (simplified) with XML::Simple with or
> > > > without ForceArray=3D1.
>
> > > > I can output everything EXCEPT I cannot find the Perl data syntax t=
o
> > > > access anything in <images> eg =A0543 or
> > > > the text "Property Image"
>
> > > > $data =3D $xml->XMLin("prop.xml", forcearray =3D> 1);
> > > > $ac=3D$data->{property}->{554674}->{ac}[0];
>
> > > > Desperate!!
> > > > zzapper
>
> > > Hi
>
> > > With ForceArray turned on.
>
> > > my $temp=3D$data->{property}->[0]->{images}->[0]->{image}->[0]{id}; #=
id of
> > > first image
> > > $temp=3D$data->{property}->[0]->{images}->[0]->{image}->[1]{id}; # id=
of
> > > second image
> > > $temp=3D$data->{property}->[0]->{images}->[0]->{image}->[0]{content};=
#
> > > Property Image of first image
> > > $temp=3D$data->{property}->[0]->{images}->[0]->{image}->[1]{content};=
#
> > > Property Image of second image
>
> > > Regards
> > > John
>
> > Hi John
> > Unfortunately this didn't work for me, the output was blank.
> > zzapper
>
> Try:
>
> $data->{property}->{'55467'}->{images}->[0]->{image}->{'545'}->{content}
>
> To figure these things out, use the Data::Dumper module to reveal the
> structure of the data returned by XMLin:
>
> print Dumper(\$data);
>
> --
> Jim Gibson
Great that worked.
I've now tried an alternative
$data =3D $xml->XMLin("prop.xml", KeyAttr =3D> {images =3D> 'image'});
Which works if don't use forcearray.
gives me
'images' =3D> {
'image' =3D> [
{
'content' =3D>
'Property Image',
'id' =3D> '2410543'
},
{
'content' =3D>
'Property Image',
'id' =3D> '2410544'
},
{
'content' =3D>
'Property Image',
'id' =3D> '2410545'
}
]
zzapper
------------------------------
Date: Tue, 17 Jun 2008 14:56:30 -0400
From: smallpond <smallpond@juno.com>
Subject: Re: Reading whole file into memory. Parsing 'C' like file efficently
Message-Id: <5c0df$485808ed$16805@news.teranews.com>
n_macpherson@sky.com wrote:
> I know there are a number of FAQs which disscourage reading whole
> files into memory rather than line by line.
>
> However my problem is as follows.
>
> I am reading a file which is a language which looks like (but isn't )
> C. I need to insert comments / documentation at various points in the
> file. However sometimes I don't know what I want to insert until I get
> well past the current line - for example
>
>
> for(i=0;i<64;i++)
> {
> // lots of code
> }
>
> Say my opening brace is on line 95 and my closing brace 195 I want to
> insert a comment
>
> // for loop ends line 195
>
> at line 94 (i.e immediately above the opening brace). The problem is
> that processing line by line I don't know until I get to line 195 what
> I have to change at line 9 so I have to store lines 94 to 195 in
> memory anyway
>
> Similarly if I read a function header, I want to insert some
> documentation before the function header
> so I don't believe processing the file line by line is the best
> solution here. As I will be inserting extra lines into the middle of
> an array I think I am going to need a module to do this.
>
> Memory won't be an issue - my largest file will only be 6000
>
> I've been away from Perl for a while but I seem to remember there was
> a module File::Tie which might be suitable.
>
> I'd be grateful if anyone has any suggestions - the people who will be
> using this don't normally use Perl so I'd like to avoid using any non-
> standard modules if possible
>
> Thanks
>
> Niall
1) Read the file into an array of lines.
2) Build a hash of your inserts, key=line number.
3) Write out the updated file inserting each new line as you get to it.
This way you don't have to modify the array which would change the
line indices.
** Posted from http://www.teranews.com **
------------------------------
Date: Wed, 18 Jun 2008 17:18:11 -0700 (PDT)
From: dakin999 <akhilshri@gmail.com>
Subject: Wrtiting to a file in LDIF format
Message-Id: <60d39cac-46fb-4c67-b6a8-6ea1b25f7423@s21g2000prm.googlegroups.com>
Hi, I am trying to write to a file elements of an array. The output I
want is simple LDIF format like this:
dn:uid=xxx,cn=yyy,cn=zzz,O=xyz,C=OO
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
Has some one done something like this using "sprintf" or any other
method?? . Any snippet will be really helpful....
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 1657
***************************************