Jerry Rocteur wrote:
>
> I've just searched the web and tried the archives but I'm not in luck
>
> I'm reading a parameter file:
>
> PARAM=value
> PARAM1=value2
>
> Etc. and this works great, but all of a sudden...I need multiple lines..
>
> For example:
>
> login=logname
> password=password
> ftpfiles="/var/opt/file1, /var/opt/file2, /var/opt/file3
>           /var/opt/file4, /var/opt/file5 f/var/opt/ile6,
>     /var/opt/file7"
> oracleftpport=2111
>
>
> The file names are relative and so quite long so I prefer to put one on each
line ?
>
> I've thought of slurping in paragraph mode but I'm really stuck for a good way
to do it..
>
> Perhaps a module ?
>
> Any ideas ?
>
> I can do this any other way, I just need to pass these parameters, I can do it
any way I want..
>
> I prefer not having two parameter files but ...

Hi Jerry

I started writing this in a single pass, but its a lot easier if you take two
passes - effectively converting from multi-line parameters to single-line ones.
I assume you're not expecting multi-megabyte parameter files? :)

It needs some tweaking, as your example has no comma separator after the first
line of the 'ftpfiles' parameter (do you want to check for this and add it, or
just insist on the param file being correct?); the leading whitespace is
retained, perhaps unnecessarily; and you may want to reconsider your double
quotes, as this code relies on everything not starting with 'name=' being a
continuation line and they may not be needed.

HTH,

Rob


use strict;
use warnings;

my @data;

while (<DATA>) {

  chomp;

  if (/^\w+=/) {
    push @data, $_;
  }
  else {
    $data[-1] .= $_;
  }
}

my %params = map { split '=', $_, 2 } @data;


__DATA__
login=logname
password=password
ftpfiles="/var/opt/file1, /var/opt/file2, /var/opt/file3
          /var/opt/file4, /var/opt/file5 f/var/opt/ile6,
    /var/opt/file7"
oracleftpport=2111

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