in reply to Writing to a file

G'day victorz22,

Here's how I might have tackled this (pm_1189607_read_replace_write.pl).

#!/usr/bin/env perl -l use strict; use warnings; use autodie; use File::Spec; my ($infile, $outfile) = qw{pm_1189607_input pm_1189607_output}; my %new_path_for = ( 'old/path/to/some/' => 'new/path/to/some/', 'another/old/path/to/some/' => 'another/new/path/to/some/', 'one/more/old/path/to/some/' => 'one/more/new/path/to/some/', ); { open my $in_fh, '<', $infile; open my $out_fh, '>', $outfile; while (<$in_fh>) { chomp; my ($vol, $dirs, $file) = File::Spec::->splitpath($_); $dirs = $new_path_for{$dirs} if exists $new_path_for{$dirs}; print $out_fh File::Spec::->catpath($vol, $dirs, $file); } }

Sample run:

$ cat pm_1189607_input old/path/to/some/file another/old/path/to/some/file one/more/old/path/to/some/file path/to/keep/as/is/file $ pm_1189607_read_replace_write.pl $ cat pm_1189607_output new/path/to/some/file another/new/path/to/some/file one/more/new/path/to/some/file path/to/keep/as/is/file $

[Over the past fortnight or so, you've posted much the same question repeatedly: this has already been noted, more than once, in responses to your earlier posts. You appear to be ignoring not just the advice given, but also requests for additional information that would help us to help you. You're under no obligation to take our advice or answer our questions; however, if you choose that course of action, you're really just wasting your time and ours with these multiple postings.]

— Ken