How to enclose scalar for readability? 
Author Message
 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  
 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  
 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  
 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  
 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  
 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  
 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  
 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  
 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  
 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  
 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  
 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  
 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  
 
 [ 13 post ] 

 Relevant Pages 

1. Readability & Languages HOWTO

2. code optimization and readability

3. Three cheers for the readability of c.l.p.misc

4. How to parse a csv-file with optionally enclosed fields

5. perldb.el for Emacs 19 [enclosed]

6. How to defeat lexical scoping in enclosed block?

7. Variable names enclosed within curly braces

8. how to get text enclosed by matching () ?

9. How to extract text enclosed by...

10. Enclosing a binary within perl

11. Enclosed code causes SIGSEGV in 5.002

12. Status of next perl tk release? -- Enclosed patch

 

 
Powered by phpBB® Forum Software