For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2005 > Help for Newbie









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help for Newbie
umpty

2005-04-20, 3:56 pm

I am extracting certain info from a text file. I want to grab the
second line(without spaces) in the following text and push it into an
array. ( I know how to get it into an array, but my problem is telling
it to go to the next line.

---------------------------------------------------------------------------
13. Subject or Title of Occurrence:
Collapse of Contractor Employee while working out
----------------------------------------------------------------------------

This is what I have done to identify the line perusing through each
line

if (/Subject or Title of Occurrence:/)
{
do something;
}

Any help is appreciated.
Thanks,
umpty
Chris Cole

2005-04-21, 8:55 am

On Wed, 20 Apr 2005 09:28:44 -0700, umpty wrote:

> I am extracting certain info from a text file. I want to grab the
> second line(without spaces) in the following text and push it into an
> array. ( I know how to get it into an array, but my problem is telling
> it to go to the next line.
>
> ---------------------------------------------------------------------------
> 13. Subject or Title of Occurrence:
> Collapse of Contractor Employee while working out
> ----------------------------------------------------------------------------
>
> This is what I have done to identify the line perusing through each line
>
> if (/Subject or Title of Occurrence:/)
> {
> do something;
> }
>
> Any help is appreciated.
> Thanks,
> umpty


You could do something like this:

my $match = 0;
if (/Subject or Title of Occurrence:/)
{
$match = 1;
next;
}
if ($match) {
# put wanted data into array
last;
}

Warning this is untested and will probably only work with your very
specific example. I'll leave it to you see where the potential pitfalls
are (ie. how do you switch off the $match if you want to match multiple
items?).
HTH
Chris.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com