On Jun 16, 9:33 pm, [EMAIL PROTECTED] (Rob Dixon) wrote:
> Dermot wrote:
> > Hi All,
>
> > I have data in a tab delimited format like this (tabs might be lost in
> > the formatting of the email).
>
> > A456/959        ScHe
> > M920/1123      He
> > D123/999        ChFl
> > D123/949        AnFl
> > S520/257   Sp
> > T510/106    TePeHe
> > T540/110    Te
> > T875/1010  TeSc
> > T875/1050  TeSc
>
> > I need to split the 2nd column. The string is to be split into 2
> > characters , so ChFl becomes 'Ch, Fl' . I can't seem to find a RE that
> > will split the data correctly. My best effort is below but is captures
> > everything into $f[0], there is no splitting at all. I also tried my
> > hand at a recursive subroutine but that caused a lot deep recursion
> > errors.
>
> > Can anyone offer a bit of advise here?
> > Thanx,
> > Dp.
>
> > #!/bin/perl
>
> > use strict;
> > use warnings;
> > use Text::Tabfile;
>
> > my $file = 'myfile.txt';
> > my $tabfile = new Text::TabFile;
> > $tabfile->open($file);
>
> > my @headers = $tabfile->fields;
>
> > while (my $row = $tabfile->read) {
> >    my $str = $row->{'code'};
> >    my @f = split(/(?=\b[A-Z][a-z]\b)/, $str);
> >    print qq($row->{'number'}, "$f[0]" "$str"\n");
>
> >    #print $row->{'number'},"\t";
> >    #for (@f) {
> >    #       print $_,',';
> >    #}
> >    #print "\n";
> > }
>
> I think you are better off using a simple global regex match Dermot.
>
>     my @f =$str =~ /[A-Z][a-z]+/g;
>
> That finds all instances of a capital letter followed by one or more lower 
> case
> letters.
>
> HTH,
>
> Rob- Hide quoted text -
>
> - Show quoted text -

U can use:
while(<FH>) {
if ($_ =~ /(.*?)(\t)(\w{2})(.*)/){
print "$3\n";
}


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to