in reply to file input output problem

against file which has hard link to another file

You actually only have one file on disk (uniquely identified by the device and inode values, see stat and lstat) with, in effect, two references to it in the directory table. You can have multiple hard links all pointing to the same file if you like. Any change to one will appear in all of them. However, deleting one of them will leave the others in place.

$ echo "hello world" > xxyyzz $ ln xxyyzz aabbcc $ ln xxyyzz ddeeff $ ls -li aabbcc ddeeff xxyyzz 45063 -rw-r--r-- 3 root root 12 Aug 7 23:36 aabbc +c 45063 -rw-r--r-- 3 root root 12 Aug 7 23:36 ddeef +f 45063 -rw-r--r-- 3 root root 12 Aug 7 23:36 xxyyz +z $ cat aabbcc hello world $ echo bye >> ddeeff $ cat xxyyzz hello world bye $ rm aabbcc $ ls -li aabbcc ddeeff xxyyzz aabbcc: No such file or directory 45063 -rw-r--r-- 2 root root 16 Aug 7 23:38 ddeef +f 45063 -rw-r--r-- 2 root root 16 Aug 7 23:38 xxyyz +z $

I hope this helps you.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: file input output problem
by convenientstore (Pilgrim) on Aug 07, 2007 at 23:26 UTC
    so bascially, my only option is
    ./perl.file done.txt > done.temp
    and then
    cat done.temp > done.txt
      If the file is relatively small you could just read all of it into memory and then overwrite the file after you have made your changes.
      #!/usr/bin/perl use strict; use warnings; my @contents; my $file = 'done.txt'; open IN, '<', $file or die "Could not open $file for reading."; while (<IN>) { $_ =~ s/yahoo/never/g; push @contents, $_; } close IN or die "Could not close $file after reading."; open OUT, '>', $file or die "Could not open $file for writing."; foreach my $line ( @contents ) { print OUT $line or die "Failed to write to $file ($line)." } close OUT or die "Could not close $file after writing.";