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


In reply to Re: Writing to a file by kcott
in thread Writing to a file by victorz22

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.