Thread String Matching einer Zeile (3 answers)
Opened by Gast at 2008-12-14 05:25

Gast Gast
 2008-12-14 20:53
#117242 #117242
besser so:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use strict;
use warnings;

open my $in, '<', 'out1.txt' or die $!;
open my $out, '>', 'out.txt' or die $!;

while(my $line=<$in>)
{
  my @elemts=split(/\s+/,$line);
  if(@lements > 5)  
  {
    print $elemts[5]."\n";
  }
  else
  {
    print "keine Werte\n";
  }          
}
close($in);
close($out);


oder so:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use strict;
use warnings;

open my $in, '<', 'out1.txt' or die $!;
open my $out, '>', 'out.txt' or die $!;

while(my $line=<$in>)
{
  if($line=~/\A(?:[\d\.]+\s+){5}([\d\.]+)/)
  {
    print "$1\n";
  }
  else
  {
    print "keine Werte\n";
  }          
}
close($in);
close($out);

View full thread String Matching einer Zeile