Schrift
Wiki:Tipp zum Debugging: use Data::Dumper; local $Data::Dumper::Useqq = 1; print Dumper \@var;
[thread]7592[/thread]

Dateihandle: Beliebige Anzahl von Zeilen weiter ...



<< >> 6 Einträge, 1 Seite
bloonix
 2006-01-06 15:39
#61521 #61521
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Hallo,

beim Auslesen einer Datei - oder einer Pipe - und dem Vor-
kommen eines bestimmten Strings weiß ich, dass darauf zwei
Leerzeilen folgen. Nun möchte ich die zwei Leerzeilen gerne
überspringen. Dafür habe ich mir folgendes überlegt ...

_Short_Cut_

Code: (dl )
1
2
3
4
5
6
7
8
9
10
while (<ORA_OUT>) {
  # -> Verarbeitung $_
  if (/^(ORA|SP2)-\d+:/) {
     # -> Verarbeitung $_
     # dann zwei Zeilen weiter
     <ORA_OUT> for 0 .. 1;
     next;
  }
  # -> Verarbeitung $_
}


Gibt es elegantere Methoden als die kurze for-Anweisung?
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.
Relais
 2006-01-06 15:52
#61522 #61522
User since
2003-08-06
2244 Artikel
ModeratorIn
[Homepage] [default_avatar]
ähm, was gefällt Dir an
Code: (dl )
1
2
<ORA_OUT>;
<ORA_OUT>; # Hoehoe.
nicht?

Es gibt da noch
Code: (dl )
$. += 2;
Erst denken, dann posten --
26. Deutscher Perl- u. Raku -Workshop 15. bis 17.04.2024 in Frankfurt/M.

Winter is Coming
bloonix
 2006-01-06 16:01
#61523 #61523
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
[quote=Relais,06.01.2006, 14:52]ähm, was gefällt Dir an ... nicht?[/quote]
Das ist voll ok. Es ist nur Unsicherheit/Unwissenheit.

Zum Beispiel kannte ich $. noch nicht. Meine Frage hat
sich also gelohnt. Danke :-)
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.
bloonix
 2006-01-06 16:24
#61524 #61524
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
[quote=Relais,06.01.2006, 14:52]
Code: (dl )
$. += 2;
[/quote]
ohne es zu testen ... wenn ich die letzten 200 Zeilen einer
Datei lesen möchte, funktioniert dann auch ...

Code: (dl )
1
2
seek(FILE,0,SEEK_END);
$. -= 200;


bisher habe ich es so gelöst:

Code: (dl )
1
2
3
4
5
6
7
   my @ind;
  my $i;
  for ($i = 0; <F>; $i++) {
     $ind->[$i] = tell F;
  }
  $i = $i > 200 ? $i-200 : 0;
  seek (F,$ind[$i],0);
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.
Relais
 2006-01-06 16:25
#61525 #61525
User since
2003-08-06
2244 Artikel
ModeratorIn
[Homepage] [default_avatar]
[quote=opi,06.01.2006, 15:01][quote=Relais,06.01.2006, 14:52]ähm, was gefällt Dir an ... nicht?[/quote]
Das ist voll ok. Es ist nur Unsicherheit/Unwissenheit.[/quote]
Das ist voll ok, das hilft, wachsam zu bleiben.

Ich finde Deine for-Idee eleganter (intelligenter?).
Erst denken, dann posten --
26. Deutscher Perl- u. Raku -Workshop 15. bis 17.04.2024 in Frankfurt/M.

Winter is Coming
ptk
 2006-01-07 20:47
#61526 #61526
User since
2003-11-28
3645 Artikel
ModeratorIn
[default_avatar]
$. manipulieren und damit Zeilen überspringen geht laut perldoc perlvar nicht:
Code: (dl )
1
2
You can adjust the counter by assigning to $., but this will
not actually move the seek pointer.


Zum Rückwärtsspringen benutze ich meist File::ReadBackwards. Oder tac und tail -r.
<< >> 6 Einträge, 1 Seite



View all threads created 2006-01-06 15:39.