Been a long day with 'real life' issues I've been trying to use Perl to help me pretend they didn't happen... here's a base test I was thinking.

#!perl -T use Test::More tests => 9; use File::Copy qw(copy); use Tie::File; my $f = 't/sample.data'; my $wf = 't/write_sample.data'; copy($f, $wf); tie my @wfh, 'Tie::File', $wf; for (@wfh){ if (/sub seven/){ $_ =~ s/seven/xxxxx/; } } untie @wfh; #1 eval { open my $wfh, '<', $wf or die "Can't open test written file $wf: $!"; }; ok (! $@, "copy of test sample file ok" ); open my $wfh, '<', $wf or die $!; #2 eval { open my $fh, '<', $f or die "Can't open original test file $f: $!"; }; ok (! $@, "can open orig test file after tie/untie/copy" ); my @wf = <$wfh>; my @f = <$fh>; my $count = scalar @f; my @changes; #3 for (0..$count){ if ($wf[$_] and $wf[$_] ne $f[$_]){ push @changes, $wf[$_]; } } is ( scalar(@changes), 1, "search/replace does the right thing, in the + right spot" ); #4 eval { close $fh; }; ok (! $@, "no problem closing the original test read file" ); close $fh; #5 eval { close $wfh; }; ok (! $@, "no problem closing the test write file" ); close $wfh; #6 eval { unlink $wf }; ok (! $@, "no problem deleting the test write file" ); #7 eval { open my $wfh, '<', $wf or die "Can't open $wfh: $!"; }; ok ($@, "after unlink of test write file, it can't be opened" ); #8 is (@changes, 1, "search_replace on one line replaces only one line" ) +;

In reply to Re: "Unescaped left brace in regex is deprecated" by stevieb
in thread "Unescaped left brace in regex is deprecated" by stevieb

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.