[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Skrive til en bestemt position i en fil i perl



In article <sslug@sslug>, Troels Liebe Bentsen wrote:
>  Så var Jonas så lidt hurtiger til at læse sin perldoc end jeg var, men her er 
>  der et eksempel på hvordan du bruger det:
>  
>  open FILE, "+</tmp/minfil" or die ("Could not open file");
>  # Seek to minus 4 from end.
>  seek FILE, -4, 2;
>  print(tell(FILE). "\n");

mmm og så printer den at cursoren eller pointeren eller hvad vi vil
kalde det, er det rigtige sted. Og så skriver den filen forfra i stedet
for at skrive fra det sted jeg seeker hen. Og så fatter jeg ingenting ;)

>  my $buff;
>  # Read 4 bytes.
>  read(FILE,$buff,4);
>  print "buff:$buff\n";

>  
>  # Seek back the 4 bytes from current pos.
>  seek(FILE, -4, 1);
>  
>  # Replace stuff.
>  $buff =~ s/CCC/DDD/;
>  print FILE $buff;
>  print(tell(FILE). "\n");
>  
>  close FILE;

Det lyder til gengæld smart. Jeg burde nok faktisk skrive det hele
tilbage til at arbejde direkte på filen. Det du laver her må kunne
bruges, også når jeg skal ændre i en værdi eller slette en blok. På en
eller anden klog måde.

Men nu virker det (den vigtigste del af det) med XML::DOM så jeg venter
lige. Men performance er ikke imponerende. 

-- 
Hanne Munkholm <sslug@sslug>

BOFH excuse of the day: Backbone adjustment



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:43 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *