Author |
Message |
Marc #1 / 13
|
 How to enclose scalar for readability?
Is there a way to enclose a scalar variable for both readability and parsing reasons? For example: print "This is the two variables I want $together$here" Is there some way to enclose these so they are not together and will print ok still. Especially if I have a variable named $together and maybe one called $togethe (and I want the "r" to print between $togethe and $here)
|
Tue, 14 Oct 2003 02:25:57 GMT |
|
 |
Greg Bac #2 / 13
|
 How to enclose scalar for readability?
: For example: : : print "This is the two variables I want $together$here" : : Is there some way to enclose these so they are not together and will : print ok still. Especially if I have a variable named $together and : maybe one called $togethe (and I want the "r" to print between $togethe : and $here) Use curly braces: print "${togethe}r${here}"; Note that the braces around $here aren't strictly necessary, but they seem to provide balance. YMMV. Greg -- Lisp requires an unhealthy relationship with the lambda calculus that leads to proposing the dog of food instead of feeding the dog. -- The Programmers' Stone
|
Tue, 14 Oct 2003 02:31:04 GMT |
|
 |
Anno Sieg #3 / 13
|
 How to enclose scalar for readability?
Quote:
> : For example: > : > : print "This is the two variables I want $together$here" > : > : Is there some way to enclose these so they are not together and will > : print ok still. Especially if I have a variable named $together and > : maybe one called $togethe (and I want the "r" to print between $togethe > : and $here) > Use curly braces: > print "${togethe}r${here}"; > Note that the braces around $here aren't strictly necessary, but they > seem to provide balance. YMMV.
Side note: It's interesting that this construct is not a case of the ${ BLOCK } dereferencing syntax. While the latter would work for ${togethe}, it would involve the bareword "togethe" (hmm, how to quote a bareword?) and a symref to $togethe. The behavior against warnings and strict shows that it is special-cased. Anno
|
Tue, 14 Oct 2003 02:47:36 GMT |
|
 |
Andrew J. Perr #4 / 13
|
 How to enclose scalar for readability?
Quote:
> Is there a way to enclose a scalar variable for both readability and > parsing reasons?
braces. Quote: > For example: > print "This is the two variables I want $together$here"
print "These are the two variables I want ${together}${here}." -- ---------------------------------------------------------------------- Andrew J Perrin - Ph.D. Candidate, UC Berkeley, Dept. of Sociology (Soon: Asst Professor of Sociology, U of North Carolina, Chapel Hill)
|
Tue, 14 Oct 2003 04:34:29 GMT |
|
 |
Samuel Thoma #5 / 13
|
 How to enclose scalar for readability?
Quote:
> Use curly braces: > print "${togethe}r${here}";
or: print "we are all $togethe" . 'r' . $here; -- /\ Sam Thomas / \ Ext 1161 / ** \ /______\
|
Tue, 14 Oct 2003 04:43:47 GMT |
|
 |
Greg Bac #6 / 13
|
 How to enclose scalar for readability?
: : > Use curly braces: : > : > print "${togethe}r${here}"; : : or: : print "we are all $togethe" . 'r' . $here; TMTOWTDI: print "we're all $ta", 'rs in the dope ', "$how!"; Greg -- Since I was running Windows, I did the normal thing you do when you encounter problems: I rebooted. -- Simson Garfinkel
|
Tue, 14 Oct 2003 05:19:31 GMT |
|
 |
Bart Lateu #7 / 13
|
 How to enclose scalar for readability?
Quote:
>> print "${togethe}r${here}"; >> Note that the braces around $here aren't strictly necessary, but they >> seem to provide balance. YMMV. >Side note: It's interesting that this construct is not a case of >the ${ BLOCK } dereferencing syntax. While the latter would work >for ${togethe}, it would involve the bareword "togethe" (hmm, how >to quote a bareword?) and a symref to $togethe. The behavior >against warnings and strict shows that it is special-cased.
Plus: it works for lexicals, too. As Anno should know: symbolic references, don't. -- Bart.
|
Tue, 14 Oct 2003 05:27:38 GMT |
|
 |
Bart Lateu #8 / 13
|
 How to enclose scalar for readability?
Quote:
>print "This is the two variables I want $together$here" >Is there some way to enclose these so they are not together and will >print ok still. Especially if I have a variable named $together and >maybe one called $togethe (and I want the "r" to print between $togethe >and $here)
"${togethe}r" but this works, too: "$together\Er" -- Bart.
|
Tue, 14 Oct 2003 05:28:26 GMT |
|
 |
Abiga #9 / 13
|
 How to enclose scalar for readability?
in <URL::">
// // >print "This is the two variables I want $together$here" // > // >Is there some way to enclose these so they are not together and will // >print ok still. Especially if I have a variable named $together and // >maybe one called $togethe (and I want the "r" to print between $togethe // >and $here) // // "${togethe}r" // // but this works, too: // // "$together\Er" Really? Now, where is that documented? Or did you typo? Abigail
|
Tue, 14 Oct 2003 05:42:18 GMT |
|
 |
Bart Lateu #10 / 13
|
 How to enclose scalar for readability?
Quote:
>// but this works, too: >// >// "$together\Er" >Really? Now, where is that documented? Or did you typo?
"r" too much. The "\E" provides a break, but doesn't insert anything by itself. -- Bart.
|
Tue, 14 Oct 2003 06:06:11 GMT |
|
 |
Anno Sieg #11 / 13
|
 How to enclose scalar for readability?
Quote:
> >> print "${togethe}r${here}"; > >> Note that the braces around $here aren't strictly necessary, but they > >> seem to provide balance. YMMV. > >Side note: It's interesting that this construct is not a case of > >the ${ BLOCK } dereferencing syntax. While the latter would work > >for ${togethe}, it would involve the bareword "togethe" (hmm, how > >to quote a bareword?) and a symref to $togethe. The behavior > >against warnings and strict shows that it is special-cased. > Plus: it works for lexicals, too. As Anno should know: symbolic > references, don't.
Oh, right. This shows that it doesn't just exempt the bit from warnings and strictures and otherwise relies on the ${ BLOCK} mechanism. Anno
|
Tue, 14 Oct 2003 06:17:48 GMT |
|
 |
nob.. #12 / 13
|
 How to enclose scalar for readability?
Quote:
> >// but this works, too: > >// > >// "$together\Er" > >Really? Now, where is that documented? Or did you typo? > "r" too much. > The "\E" provides a break, but doesn't insert anything by itself.
So does "${['']}" but I wouldn't consider using it or "\E" this way to be an aid to _readability_ as per the subject of this thread :-) -- \\ ( ) . _\\__[oo
. l___\\ # ll l\\ ###LL LL\\
|
Wed, 15 Oct 2003 01:41:55 GMT |
|
 |
Michael LaGal #13 / 13
|
 How to enclose scalar for readability?
Quote: > Is there a way to enclose a scalar variable for both readability and > parsing reasons? > For example: > print "This is the two variables I want $together$here" > Is there some way to enclose these so they are not together and will > print ok still. Especially if I have a variable named $together and > maybe one called $togethe (and I want the "r" to print between $togethe > and $here)
$togethe="a"; $here="e"; print "This is the two variables I want $togethe" . "R" . "$here"; This prints: This is the two variables I want aRe
|
Mon, 20 Oct 2003 10:03:33 GMT |
|
|