in reply to Re: how to delete part of the line?
in thread how to delete part of the line?

Minor niggle: bichonfrise74: At line 5, didn't you mean "...and print "$1/" while...?

This scales nicely (as do the other replies above) for a source file (which OP calls a "result file") which includes only elements of a single data set. But IMO, the actual problem is likely under-spec'ed.

Yes, I may be overthinking this but I can't help but wonder if we're giving the "X" answers where what OP is seeking may be the "Y" answers, but isn't getting them because the problem is less than fully stated.

Here's my train of thought: it seems to me that the phrase "result file" may imply that it contains sets of (previously selected) data from multiple sources (multiple rows of a DB table, for example) in which case one might expect that there will be a delimiter - - express or implied - - between the sets.

OP's ellipsis beg the question.

Suppose the source looks like this:

__DATA__ line1=10 line2=30 line3= I am a monk ine4=false line5=20 line6=42 line7= But I haven't read perlretut and I should have! line8=true line8=34 line9=67 line10=Coder line11=false

Is this one set of 12 items or three sets of 4 items each. And what if the data continues with an inconsistent set such as:

line12=00 line2=11 line3= line4=questionable

Hence, yskmonk, you may wish to enlighten us with details. Did one of the fine answers above solve your problem or does your question need refinement/more specifics?

Update: If the original question (data has since undergone a major transformation, which is still insufficiently particular) relates to sets of data, each comprising 4 lines, then one answer might be:

my @outfile = ( "line1=10", "line2=30", "line3= I am a monk", "line4=false", "line5=20", "line6=42", "line7= But I haven't read perlretut and I should have!", "line8=true", "line8=34", "line9=67", "line10=Coder", "line11=false", ); my @quads; while (@outfile) { my $line; for (1..4) { # presumption: each data set is made up +of 4 consecutive lines * my $line_from_outfile = shift (@outfile); $line_from_outfile =~ /line\d+=(.*)/; $line .= $1 . "/" ; } push @quads, $line; $line = ""; } for my $quad(@quads) { print $quad . "\n"; # to console; writing to file "final.txt" is +left as an exercise for OP }

* Season Line 19 to taste.