Hello I need help with perl script I'm writing. we have an input file that contains following:

variable=value;
variable2=value2;
.
.
.

However sometimes following thing happens - one of the variable might have its value written in more lines:

variable=value;
variable=value value

value value value

value

;
variable2=value2;
.
.
.

Question: Can you please recommend a good way to read the value spread over more lines? Is there a way to say: start reading from here and finish when you reach ';' character? thank you!

The input record separator (see perlvar) determines how much input to read for each input record. It is newline by default. Change it to semicolon followed by newline and each time perl reads the file it will read up to the next semicolon followed by newline, which is what you want.

#!/usr/bin/perl
use strict;
use warnings;

$/ = ";\n";#Now semicolon followed by newline character indicates end of input rec

while (<DATA>){
    chomp;
    my ($name, $value) = split(/=/);
    print "$name => $value\n";
}

__DATA__
variable=value;
variableX=value value

value value value

value

;
variable2=value2;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.