Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Useful syntax highlighting to illustrate variable interpolation?

by will_ (Scribe)
on Feb 07, 2011 at 10:52 UTC ( [id://886648]=perlquestion: print w/replies, xml ) Need Help??

will_ has asked for the wisdom of the Perl Monks concerning the following question:

I've used several syntax-highlighting text editors to write Perl code, and I'm always disappointed that they do not usefully highlight complex variables inside double quoted strings.

What's the simplest way to get syntax highlighting to match the actual interpolation behaviour of the perl interpreter?

e.g. vim 7.1 type this:

print "There are $sanity->{sane} lights"

The $sanity is a different colour, indicating it will be interpolated. But the ->{sane} is the same colour as the rest of the string, implying it will not be interpolated (but it will in fact be interpolated).

Shouldn't the whole of $sanity->{sane} be the same colour as an interpolated variable? That way one could know whether or not the syntax was actually correct for interpolation.

Perhaps there's a way to do this with syntax highlighting settings? But even Padre failed to highlight properly and I thought that was supposed to know the most about Perl internals.

Replies are listed 'Best First'.
Re: Useful syntax highlighting to illustrate variable interpolation?
by moritz (Cardinal) on Feb 07, 2011 at 11:00 UTC
Re: Useful syntax highlighting to illustrate variable interpolation?
by fisher (Priest) on Feb 07, 2011 at 11:01 UTC
    :version VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jul 12 2010 12:48:02)
    shows '->{sane}' in different color. You doing something wrong, maybe?

      I also tried with VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Sep 28 2010 11:05:08) but didn't see ->{sane} highlighted. I'm using the out-of-the-box default Perl syntax highlighting...

      Not for me, gvim_portable
      VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Aug 23 2009 16:31:33) " Last Change: 2007 March 13 " Location: http://www.van-laarhoven.org/vim/syntax/perl.vim
        Ah-ha!
        In my case the syntax file seems to be more fresh:
        fisher% cd /usr/share/vim/vim72/syntax/ fisher% head -7 perl.vim " Vim syntax file " Language: Perl 5 " Maintainer: Andy Lester <andy@petdance.com> " URL: http://github.com/petdance/vim-perl/tree/master " Last Change: 2009-09-2 " Contributors: Andy Lester <andy@petdance.com> " Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>
        This is vanilla packages from debian/squeeze (stable release starting from 5th feb 2011 =)
Re: Useful syntax highlighting to illustrate variable interpolation?
by Anonymous Monk on Feb 07, 2011 at 11:14 UTC
    The $sanity is a different colour, indicating it will be interpolated. But the ->{sane} is the same colour as the rest of the string, implying it will not be interpolated.

    Its hilighted the same as

    $sanity->{sane} = 4;

    Shouldn't the whole of $sanity->{sane} be the same colour as an interpolated variable? That way one could know whether or not the syntax was actually correct for interpolation.

    syntax hilighters aren't perl interpreters , they don't actually check syntax

    But even Padre failed to highlight properly and I thought that was supposed to know the most about Perl internals.

    Who decides what is proper?

      syntax hilighters aren't perl interpreters , they don't actually check syntax

      Well, they should do.

      Who decides what is proper?

      I knew someone was going to ask that. We decide!

      Proper is something that helps efficient coding. That tells me whether or not what I'm writing is what I intended to write.

      Proper syntax highlighting will tell me what the code is going to do before I run it.

      So, does anyone know how to 'fix' this problem?

        to fix this problem get the latest vim (or at least vim 7.2) and the latest syntax file for perl (at least last changed 2009-09-2).
Re: Useful syntax highlighting to illustrate variable interpolation?
by nextguru (Scribe) on Feb 07, 2011 at 23:09 UTC
    Highlighting worked as you were hoping in jEdit v4.4 on WinXP and FreeBSD for me.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://886648]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-20 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found