me wrote:
Hello all,

Hello,

I have been beating my head against the wall for a
while trying to extract some data.

Here is the following data:

<SNIP>
===================
Data 1: data1
Data 2: data2
Data 3: data3
Data 4: data4
Data 5:
data5 data5 data5 data5 data5 data5 data5 data5 data5 data5 data5 data5


====================
<SNIP>

My goal is to put all data after each colon into a
variable.

I don't have any problem with Data 1 through Data 4. My problem is when I get to Data 5:, I can't figure
out how to put the data into a variable.

I can think of three ways to do it.

Method one:

my @data;
while ( <FILE> ) {
    if ( /:\s*(.*)/ ) {
        push @data, $1;
        }
    else {
        $data[ -1 ] .= $_;
        }
    }


Method two:

my @data;
$/ = ':';
while ( <FILE> ) {
    s/.*://;
    s/^\s+//;
    s/\s+$//;
    next unless length;
    push @data, $_;
    }


Method three:

local $/;
my @data = map /^[^:]*:\s*([^:]+)$/gm, <FILE>;




John -- use Perl; program fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to