Jerry Rocteur wrote:
>
> On Wed, Aug 02, 2006 at 12:15:23PM +0100, Rob Dixon wrote:
>
>>Jerry Rocteur wrote:
>>
>>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? :)
>
> NOT at all, a few lines at most.

A standard config file really, as I expected!

>>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,
>
> I can insist the format of the file be as I want it.
>
>>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.
>
> So I add a comma at the end and I remove the "

Not necessarily, it depends what you want. See below.

[snip code]
>
> I can already use the above script.. Thanks a lot.
>
> However.. How would it change if the " were not there I don't get that part
????

It depends entirely on how you want to write the code that relies on the results
of this front end processing. As it stands, the contents of the hash look like:

  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
  login         => logname

Now if you want to support quoted strings in general (so that a parameter value
can contain spaces, for instance) then keep them. But if they were there as a
first stab at supporting multi-line values then they're not necessary. As long
as you're happy that your file paths can't have embedded spaces, which is more
of a Windows than a Unix thing, then you can just do something like:

  my @ftpfiles = $params{ftpfiles} =~ /[^,"\s]+/g;

which puts into the array all sequences of characters that aren't commas,
quotes, or whitespace and leaves it containing:

qw(
  /var/opt/file1
  /var/opt/file2
  /var/opt/file3
  /var/opt/file4
  /var/opt/file5
  f/var/opt/ile6
  /var/opt/file7
)

(I assume the f/ is a mistake in your original data?)

In other words, leave the data as it is and it will be fine. Take out the commas
and quotes and it will also be fine. If you have problems encoding your data
unambiguously then you may need to add quotes or commas and change how the
contents of the parameter hash are processed, but the code to import that hash
should suffice as it is regardless.

> Thanks again, this is great.

You're very welcome. It's nice but all too rare to get feedback as to whether a
question has been answered satisfactorily, but please keep your posts on the
list so that others can benefit.

Cheers,

Rob

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