SPUG: parsing a config file

Scott Blachowicz sab at rresearch.com
Mon Jan 10 21:36:58 CST 2000


On Mon, Jan 10, 2000 at 06:13:56PM -0800, Todd Wells wrote:
> Well, this method has worked out great, but I'm having a problem as a result
> of this parentheses/square brackets issue.  
> 
> Here's the deal, if I feed this data to the routine:
>     Domain = {
>         servers = (beluga,toddw2,150.215.141.11);
>         status = Enabled;
>     };
> 
> Then I get this data structure:
> 
> $config = HASH(0x2ff098)
> 	'Domain' => HASH(0x282a0c)
> 		'servers' => 'beluga'
> 		'status' => 'Enabled'
> 		'toddw2' => '150.215141.11'

I bet it's interpreting that

	150.215.141.11

as two floating point numbers separated by a concatenation operator.

> Would it better if I turn those parens into brackets?  Or do you have some
> other trick up your sleeve?

Turning them into brackets would turn the contents into an anonymous
reference to a hash (curly braces) or an array (square brackets)...and
that's not what you want.

Maybe a substitution to specifically turn IP addresses (or things that
might look like them) into quoted strings?

	# Put double quotes around a sequence of 4 blocks of digits
	# separated from each other by dots. (followed by some optional
	# white space and a comma or end-of-line char).
	$line =~ s/(\d+\.\d+\.\d+\.\d+)(\s*[,\)\r\n])/"$1"$2/g;

Or, more generally, a sequence of characters starting with an alphanumeric
and ending with an alphanumeric consisting of non-whitespace, non-commas,
non-paren chars?

Scott.Blachowicz at seaslug.org

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list