in reply to Re: Writing to file...
in thread Writing to file...
Update: the unlink before rename is not necessary.use strict; use warnings; my $dir = '.'; # for my $file (glob("$dir/*.seq")) # "glob" is not portable even amoungst *nix systems # and certainly not amoungst Windows systems. opendir(DIR,$dir) or die "unable to open directory $dir:$!"; foreach my $file ( grep{/\.seq$/ && -f $dir/$_}readdir DIR) { my $output_path = "$dir/$file.out"; my $input_path = "$dir/$file"; open (my $in, '<', $input_path) or die "Unable to open $input_path: $!"; open (my $out, '>', $output_path) or die "Unable to open $output_path: $!"; while (<$in>) { s/\^\^/\n^^/g; print $out $_; # oopps ; was missing... } close ($in); close ($out); unlink ($input_path) or die "unable to unlink $input_path: $!"; rename ($output_path, $input_path) or die "Unable to rename $output_path to $input_path:$!"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Writing to file...
by cdarke (Prior) on Jul 22, 2009 at 10:21 UTC | |
by Marshall (Canon) on Jul 22, 2009 at 12:43 UTC | |
|
Re^3: Writing to file...
by rovf (Priest) on Jul 22, 2009 at 11:26 UTC | |
by Marshall (Canon) on Jul 22, 2009 at 12:54 UTC | |
by rovf (Priest) on Jul 23, 2009 at 07:28 UTC | |
by Marshall (Canon) on Jul 24, 2009 at 20:40 UTC | |
|
Re^3: Writing to file...
by perl_n00b (Acolyte) on Jul 22, 2009 at 21:03 UTC | |
by toolic (Bishop) on Jul 22, 2009 at 21:37 UTC | |
by Marshall (Canon) on Jul 24, 2009 at 20:31 UTC | |
|
Re^3: Writing to file...
by perl_n00b (Acolyte) on Jul 22, 2009 at 21:22 UTC | |
by Marshall (Canon) on Jul 24, 2009 at 20:59 UTC | |
|
Re^3: Writing to file...
by perl_n00b (Acolyte) on Jul 23, 2009 at 00:27 UTC | |
by Marshall (Canon) on Jul 24, 2009 at 22:24 UTC |