me wrote:
Hello all,

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

Here is the following data:

<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.

#!/usr/bin/perl

use strict;
use warnings;

my %data;

my $cache;
while (defined( my $line = <DATA> )) {
    chomp( $line );
    if ( $line =~ /\w+:/ || eof(DATA) ) {
        $cache .= $line if eof(DATA);
        my( $k, $v ) = split( /:/, $cache, 2 );
        $data{$k} = $v;
        $cache = '';
    }
    $cache .= $line;
}

use Data::Dumper;
print Dumper( \%data );


__DATA__ 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

--
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