in reply to Re^3: copy line with character
in thread copy line with character

Your sample is too small to tell if this would work. You may be able to greatly simplify your code by defining the special variable $RECORD_INPUT_SEPARATOR ($/) to redefine 'line' as a 'logical block' of input. See perlvar
Bill

Replies are listed 'Best First'.
Re^5: copy line with character
by jalopez453 (Acolyte) on Nov 23, 2015 at 20:55 UTC

    Hi Bill, thank you... I was able to get my answer from Stevieb. But I do have another question if you don't mind. for my $find, I want the lines beginning with A or C.

    input sample: A123 A321 B123 B456 C321 C123 C654 output sample: A123 A321 C321 C123 C654

    Im sure my code is wrong below but that is what I am trying to accomplish, locating the lines beginning with A or C

    use strict; my $find = '^A' OR '^C'; open (NEW, ">", "output.txt" ) or die "could not open:$!"; open (FILE, "<", "Report.txt") or die "could not open:$!"; while (<FILE>) { print NEW if (/$find/); } close (FILE); close (NEW);
      Untested: my $find = qr/^(?:A|C)/;
      Sorry for my late reply. Others have already answered you latest question (use the syntax for a regular expression). You seem to have misunderstood my previous post. Stevieb's solution is correct and will work for almost any imaginable input. A much simpler solution may be possible depending on the format of the data file.
      Bill