-----Original Message----- From: Pedro Soto [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 04, 2007 8:50 AM To: Andrew Curry Cc: beginners@perl.org Subject: Re: spliting
Well, Sorry if I was not clear enough. I want to read lines from a file and I need to split the line into characters. I know you can use the split function from perl to do this, but I have not space or commas or dots in between. So the file looks like(e.g): line1 ADCBFSDSSDDFFGTESDFGG line2 BGCDFGYRTEDGHHJJJKKKKL etc I want to know how can I separate this characters as I need to retrieve for example the character number 5 in line 1 and character 45 in line 2 and so on. Cheers, P On 04/09/07, Andrew Curry <[EMAIL PROTECTED]> wrote: > > Just to clarify you have a file which is basically 1 string but you know > every 60 characters is a new set of data? > > -----Original Message----- > From: Pedro Soto [mailto:[EMAIL PROTECTED] > Sent: 04 September 2007 13:29 > To: beginners@perl.org > Subject: spliting > > Hi, > I have a file with lines of 60 characters each. I would like to split > every > line into its 60 characters, but there is not any delimiter between them. > Something like: ABCDEFGHIJK etc. > Is there anyway to do it? > Many thanks in advance, > Cheers, > P. Soto > > [>>] Several ways are available... You may wish to read about substr & unpack - if you have a "fixed length record" #! /usr/local/bin/perl use strict; while (my $data=<DATA>){ print substr($data,4,1), "\n" if $. == 1; my @a = unpack('a44aa21', $data) if $. == 2; print $a[1], "\n" if $. == 2; } __DATA__ ADC>F<DSSDDFFGTESDFGGADCBFSDSSDDFFGTESDFGGADCBFSDSSDDFFGTESDFGGADC BGCDFGYRTEDGHHJJJBGCDFGYRTEDGHHJJJBGCDFGYRT>D<HHJJJBGCDFGYRTEDGHHJ 123456789+123456789+123456789+123456789+123>5<789+123456789+123456 Hope this gives you some ideas... jwm -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/