# From what Anonymous monk writes, it seems the task is: # replace a field (in double quotes) of a comma # separated record in a file called guidpair.txt with # something else. # He gives me the line, the text of the last field, and # the replacement text which he somehow gets from another # file. # The line # "Web","rad","INPUT","onclick","746B97B8-486A-094F-9426292F0C0BB644 F +","" # should be # "Web","rad","INPUT","onclick","5C1DAEF0-9386-44a5-B92A-31FE2C79236A" +,"" # # Given that information, the program could look like this: my $infile = 'guidpair.txt'; my $tempfile = "$infile.new"; # =================================================== # CAVEAT: if $infile.new exists, it will be clobbered # XXX Better use File::Temp here? # =================================================== open(I,"<$infile") or die "Can't open $infile: $!\n"; open(O,">tempfile") or die "Can't write $tempfile: $!\n"; while(<I>) { if (/"Web","rad","INPUT","onclick","746B97B8-486A-094F-9426292F0C0 +BB644 F",""/) { s/746B97B8-486A-094F-9426292F0C0BB644 F/5C1DAEF0-9386-44a5-B92 +A-31FE2C79236A/; } print O; } close(I) or die "Can't close input file $infile: $!\n"; close(O) or die "Can't close temp file $tempfile: $!\n"; rename($tempfile,$infile) or die "Can't rename $tempfile to $infile: $!\n"; __END__
This might be of no help at all, but your specs aren't clear. One way to make them clear is to write down your requirements into the program file as comments as accurate as possible. The clearer they are, the easier it is to translate them into code.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: how to match the pattern by using regexp for the below task by shmem
in thread how to match the pattern by using regexp for the below task by Anonymous Monk

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.