> 在 2010-01-19二的 00:09 -0500,Perl Noob写道:
>> I have a data file with thousands of records.  The problem is that
>> the
>> records in the data file span two lines for each record.  I want to
>> write a perl script that makes each record a single line.  The file
>> looks like this:
>>
>
> HI,
>
> If you are using a regex, then may want to try the /m option.
> see perldoc perlre for details.
> I give the code below, it could work for me.
>
>
> use strict;
>
> local $/="RECORD1FIELD5\n";
>
> while(<DATA>) {
>     my @fields = /\w+/gm;
>     print "@fields\n";
> }
>
>
> __DATA__
> RECORD1FIELD1  RECORD1FIELD2     RECORD1FIELD3  RECORD1FIELD3
>           RECORD1FIELD4          RECORD1FIELD5
>
> RECORD2FIELD1  RECORD2FIELD2     RECORD2FIELD3  RECORD2FIELD3
>           RECORD2FIELD4          RECORD2FIELD5
>
>

Your example works if RECORD1FIELD5 is a constant value and is the
same as RECORD2FIELD5, it is not.  RECORD1FIELD5 is different from
RECORD2FIELD5 which will be different from RECORD3FIELD5.  There is
the problem.  I need to find a way to delete the \n at the end of the
first line of the record, but maintain the \n on the second line of
the record.

That way each record will be on a single line instead of spanning two
lines.





-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to