Sublime Forum

Perl bug with split

#1

Hi,

It seems there is a bug with Perl, which causes all the text to go yellow (as if its broken). Some example code:

[code] if (length($current_val) > 0) {

# has a linkid in here already...

 my @tmp = split /,/, $current_val;

 my $exists;
 foreach (@tmp) { $exists->{$_} = 1; }

 if (!$exists->{$linkID}) { push @tmp , $linkID; }
 $current_val = join(',', @tmp);

} else {

#cookie doesnt exist yet
 $current_val = $linkID;

}[/code]

The problem seems to be with the /,/ part:

 split /,/

If I change it to:

 split |,|

…then it works fine… but thats not ideal :wink:

Any ideas?

TIA

Andy

0 Likes

#2

No one interested in the last bug? Seems to be another one with Perl :frowning:

if ($DB->table('Bad_Link_Track')->count( { LinkID => $IN->param('ID') } )) { error(qq|Thanks for taking the time to report an error on a link, but this links has already been reported - so we won't add it again.|); }

The ’ in “won’t” seems to break it. Please see attached image.

It could well be that SubLime doesn’t like the qq|| syntax. Changing that to " " works fine (but isn’t good enough for me, as I don’t wanna have to resort to doing that each time)

If I can’t get these sort of bugs fixed up, there is no way I’m gonna fork out money for it :frowning: (especially when I have a copy of NotePad++, which works just fine for me - without all these color syntax issues). Please advise.

Cheers

Andy


0 Likes

#3

What syntax are you using? I just tried it in ST2 (with the built in perl syntax highlighting) and got the following. Perhaps you grabbed a syntax definition from an external source. If that’s the case, you can’t really blame the editor for displaying it incorrectly right? :wink:

[pre=#272822]if ($DB->table(‘Bad_Link_Track’)->count( { LinkID => $IN->param(‘ID’) } )) {
error(qq|Thanks for taking the time to report an error on a link, but this links has already been reported - so we won’t add it again.|);
}[/pre]

FWIW, here is the sample from the first post.

[pre=#272822] if (length($current_val) > 0) {

# has a linkid in here already...

 my @tmp = split /,/, $current_val;

 my $exists;
 foreach (@tmp) { $exists->{$_} = 1; }

 if (!$exists->{$linkID}) { push @tmp , $linkID; }
 $current_val = join(',', @tmp);

} else {

#cookie doesnt exist yet
 $current_val = $linkID;

}[/pre]

0 Likes

#4

Hi,

Thanks for the reply. For some reason I didn’t get a reply though… thus the delay in replying :smile:

I feel a bit stupid now! I took a look at the language it was using, and its actually trying to open .cgi files as Ruby. Can I change the association for .cgi to use Perl instead? (I’m guessing it just has .pl set). Ideally I wanna add .pm as well

Manually changing the syntax to Perl fixed up both those issues.

EDIT: Never mind -found it :smile:

Sublime Text 2\Packages\Perl\Perl.tmLanguage

<key>fileTypes</key> <array> <string>pl</string> <string>pm</string> <string>pod</string> <string>t</string> <string>PL</string> <string>cgi</string> </array>

TIA

Andy

0 Likes

#5

No problem. Rather than editing the tmLanguage file, you may want to select the bottom right (where the language is listed) and choose “Open all with current extension as…”. If you have some extension issues though (I don’t know that you should/will) you may want to try the ApplySyntax plugin. I don’t think there should be any issue, but just in case. The reason for this is, any subsequent updates to the Perl package will wipe out your modified tmLanguage file. Though, if you are using your own custom Perl package, this isn’t really an issue.

0 Likes

#6

Hi,

Thanks :smile:

I have actually come across a “genuine” bug this time though (I think :wink:)

my $save_folder = $folder_images . "/" . (reverse split //, $vin)[0] . "/" . (reverse split //, $vin)[1];

After the first:

split //

It doesn’t seem to like doing a split on // (i.e every character). Not a show stopper for me as I can just do:

my $save_folder = $folder_images . "/" . (reverse split /./, $vin)[0] . "/" . (reverse split /./, $vin)[1];

But I do prefer to use //

UPDATE - Actually, I can’t use .in the /./ … the only way I can get the syntax going ok is by putting the 2nd part on a new line:

my $save_folder = $folder_images . "/" . (reverse split //, $vin)[0] . "/" . (reverse split //, $vin)[1];

Cheers

Andy

0 Likes

#7

Here’s some confirmation for you (I think). My perl knowledge is practically non existent. Is this what yours looks like too?

[pre=#272822]my $save_folder = $folder_images . “/” . (reverse split //, $vin)[0] . “/” . (reverse split //, $vin)[1];[/pre]

Not that you want to, but you could play around with the tmLanguage file to try to fix it. Though it may be more trouble than it’s worth.

And just as a reference for anyone else coming to the thread, here is the “expected” highlighting.

[pre=#272822]my $save_folder = $folder_images . “/” . (reverse split //, $vin)[0] .
“/” . (reverse split //, $vin)[1];[/pre]

0 Likes

#8

And another one :smile:

[code]$new_filename =~ tr{&]ÀÂÄàâäÇçÉÊÈËéêèëÏÌÎïìîÖÔÒöôòÜÛÙüûùA-Z?!;«»()" }{ aaaaaacceeeeeeeeiiiiiioooooouuuuuua-z__________};

print “Foo”;[/code]

Seems like the single " tag breaks the code after it. Removing the quote works, but obviously I need to remove that =)

0 Likes

#9

[quote=“skuroda”]Here’s some confirmation for you (I think). My perl knowledge is practically non existent. Is this what yours looks like too?

[pre=#272822]my $save_folder = $folder_images . “/” . (reverse split //, $vin)[0] . “/” . (reverse split //, $vin)[1];[/pre]

Not that you want to, but you could play around with the tmLanguage file to try to fix it. Though it may be more trouble than it’s worth.

And just as a reference for anyone else coming to the thread, here is the “expected” highlighting.

[pre=#272822]my $save_folder = $folder_images . “/” . (reverse split //, $vin)[0] .
“/” . (reverse split //, $vin)[1];[/pre][/quote]

Hi - yeah, sure is. As you can see, after the first // the color goes all whacky (and carries on down the rest of the doc too)

0 Likes