Now you can do anything you want with array @file.# -------------------------------------------------------------------- +----- # read array from file sub read_file { my ( $line ); if ( not open(FILE, $file_path) ) { &logging( "Can't open database file." ); die; } if ( $file_lock ) { flock(FILE, 1); } @file = (); while ( $line = <FILE> ) { chomp($line); push(@file, $line); } } <p>
# -------------------------------------------------------------------- +----- # write array back to file sub write_file { my ( $line ); if ( not open(FILE, ">".$file_path) ) { &logging( "Can't open database file." ); die; } if ( $file_lock ) { flock(FILE, 2); } foreach $line ( @file ) { print FILE "$line\n"; } close(FILE); }
if $file_lock is <> 0 then script will use file locking.
Li Tin O've Weedle
mad Tsort's philosopher
In reply to Re: Opening a file for reading or writing (was: Newbie)
by LiTinOveWeedle
in thread Opening a file for reading or writing (was: Newbie)
by padangboy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |