[Sderby] PERL

trw dLogical trw at dlogical.co.uk
Thu Nov 13 15:53:45 GMT 2003


Mike

Guess you need to figure out where you want to split the line.

The problem you have is that you cannot do a straight split due to the
continual . in the data.

the split command is (@data) = split (/\./, $_);

but this will give you all the data into and array and drop all the .

However if you know that you always want the data in the first two elements
of the array you could do.

$first_bit = $data[0];
$secon_bit = $data[1];

$fred = @data;

for ($i = 2; $i < $fred; $i++)
{
    $last_bit .= $data[$i];
}

#####

This will then give you the three lots of data into individual scalars to
output.

There is probably a better way but if stuck send me the data file and Ill
have a look for you.


Trevor Ward
dLogical Limited

T:     01283 760469
E:     trw at dlogical.co.uk
W:     www.dlogical.co.uk

-----Original Message-----
From: sderby-bounces at mailman.lug.org.uk
[mailto:sderby-bounces at mailman.lug.org.uk]On Behalf Of Mike Hemstock
Sent: 13 November 2003 14:57
To: South Derby LUG General Mailing List
Subject: [Sderby] PERL


Folks,

A quick question.  I am trying to write a PERL script to open a file, read
values from it and rebuild those vaules into another file to be used by a
piece of software.  An extract from the file is below:

a.adams.DADIESO SEC. SCH. - DADIESO.
a.adigah.ACHISCO.
a.agyapong-ntra.OPON MEM SEC. SCH..
a.amoah.EFUTU SEC. TECH.

The first part of the line is an initial, the second is a surname and the
third is a school.  I can read the data into a variable line by line, but
want I can't figure out how to do it take that line and extract the three
pieces of information and assign them to a variable eg. after reading the
first line into $_ I would then like:

$initial = "a"
$surname = "adams"
$school = "DADIESO SEC. SCH. - DADIESO"

I'd also like to drop the . off the end of each line.  Some lines have two
dots but that's OK, just need to drop one of them.

Many thanks,
Mike who can't code very well!


_______________________________________________
Sderby mailing list
Sderby at mailman.lug.org.uk
http://mailman.lug.org.uk/mailman/listinfo/sderby
Web site: http://sderby.lug.org.uk/
wiki: http://www.sderby.lug.org.uk/cgi-bin/wiki.pl
Join us on IRC: irc.lug.org.uk #sderby




More information about the Sderby mailing list