LPM: Silly string question

Joe Hourcle oneiros at dcr.net
Fri Dec 10 15:12:22 CST 1999



On Fri, 10 Dec 1999, Steve Lane wrote:

>   print "Size: ${width}x$height.\n";
> 
> i'm tempted to try to explain the general rule here
> (something like "braces following a variable identifier
> character mean treat what's inside the braces as either
> a reference or a variable name"), but i'm not exactly
> sure if that's exactly correct.  anyway, it works.

>From my understanding of it, you're basically just specifying braces, as
they're generally implied to be from the identifier ($@%*&), to the
wherever it could be (greedy matching)

Braces are also useful for setting wierd precidence, as I think the
following should all give the contents of $width:

	$width

	${width}

	$foo = 'width'; ${$foo}

	${&foo}; sub foo { return 'width'; }

	
and as for shortening keystrokes, that's what single letter variable names
are for:
	print "Size: ${w}x$h\n";
So what if it creates annoying to maintain code, right?  I mean, a few
keystokes here, so what if it results in hours of work later, when you're
trying to remember what the variables are?

-Joe




More information about the Lexington-pm mailing list