[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-AnyPerl] key=value lines hard wrap in input



On Fri, Nov 10, 2000 at 02:15:29PM -0800, Paul Corr wrote:
> 
> Folks,
> 
> I have lines of input that begin with a key= and then the value. Since it
> is from a file generated by a reporting system, it has an upper limit of
> characters per line and it wraps. I'm wondering if anyone can shed light
> on getting the wrapped line to go with the key. I know
> there are three ways to set the input record separator, $/ --
> newline(default);
> ""(paragraph mode); and 'undef'(file slurp mode). I'm wondering how
> to implement.

The input record separator will not help you here, because your input has
no well-defined record separator.


my $curr_key = '';

while (<>) {

  chomp;

  if (/=/) {

    my($key, $value) = split /\s*=\s*/, $_, 2;
    $hash{$key} = $value;
    $curr_key = $key;

  } else {

    $hash{$curr_key} .= " $_";

  }

}


Ronald


==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org