It's generally good form to include specific examples of what strings you want to transform and what you want the results to be (see How (Not) To Ask A Question). The documentation for how to use regular expressions can be found at perlre, with a tutorial at perlretut. While it is certainly possible to do this in a one-liner, given your stated experience level, you probably want to open the file (I/O Operators), make changes and then write the info out. And, as ikegami states, I think that \$ in your regex looks hinky.

You'll probably want something like:

#!/usr/bin/perl use strict; use warnings; use Date::Format; my ($input_file, $output_file) = @ARGV; my $date = time2str("%Y-%m-%d", time); #print "\n\n$date\n\n"; ## works open my $input, '<', $input_file or die "Open failure on $input_file: +$!"; my @contents = (); while (defined (my $line = <$input>)) { $line =~ s/(\d\d\d\d-\d\d-\d\d)(-[a-z_]{5,30}\.zip)/$date$2/; push @contents, $line; } close $input; open my $output, '>', $output_file or die "Open failure on $output_fil +e: $!"; foreach my $line (@contents) { print $output $line; } close $output;

This code could certainly be improved, but it should be sufficiently step-by-step to provide a good idea of how to proceed. The script as written should be called with

> perl script.pl infile outfile

The input and output file names can be the same for in-place edits.


In reply to Re: Regexp substitution w/ variable value (again) by kennethk
in thread Regexp substitution w/ variable value (again) by Craig_B

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.