Home Download Buy Blog Forum Support

Perl bug with split

Perl bug with split

Postby youradds on Fri Dec 07, 2012 4:27 pm

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: Select all
  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;

   }


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

Code: Select all
split /,/


If I change it to:

Code: Select all
split |,|


...then it works fine.. but thats not ideal ;)

Any ideas?

TIA

Andy
youradds
 
Posts: 8
Joined: Fri Dec 07, 2012 4:24 pm

Re: Perl bug with split

Postby youradds on Mon Apr 08, 2013 7:49 am

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

Code: Select all
   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 :( (especially when I have a copy of NotePad++, which works just fine for me - without all these color syntax issues). Please advise.

Cheers

Andy
Attachments
bug.png
bug.png (41.45 KiB) Viewed 1161 times
youradds
 
Posts: 8
Joined: Fri Dec 07, 2012 4:24 pm

Re: Perl bug with split

Postby skuroda on Mon Apr 08, 2013 8:00 am

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? ;)

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.|);
}


FWIW, here is the sample from the first post.

  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;

}
skuroda
 
Posts: 676
Joined: Fri Oct 05, 2012 8:11 am

Re: Perl bug with split

Postby youradds on Fri Apr 12, 2013 10:51 am

Hi,

Thanks for the reply. For some reason I didn't get a reply though.. thus the delay in replying :)

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 :)

Sublime Text 2\Packages\Perl\Perl.tmLanguage

Code: Select all
   <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
youradds
 
Posts: 8
Joined: Fri Dec 07, 2012 4:24 pm

Re: Perl bug with split

Postby skuroda on Fri Apr 12, 2013 6:58 pm

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.
skuroda
 
Posts: 676
Joined: Fri Oct 05, 2012 8:11 am

Re: Perl bug with split

Postby youradds on Fri Apr 19, 2013 7:36 am

Hi,

Thanks :)

I have actually come across a "genuine" bug this time though (I think ;))

Code: Select all
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:

Code: Select all
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:

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


Cheers

Andy
youradds
 
Posts: 8
Joined: Fri Dec 07, 2012 4:24 pm

Re: Perl bug with split

Postby skuroda on Fri Apr 19, 2013 8:09 am

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

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


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.

my $save_folder = $folder_images . "/" . (reverse split //, $vin)[0] . 
"/" . (reverse split //, $vin)[1];
skuroda
 
Posts: 676
Joined: Fri Oct 05, 2012 8:11 am

Re: Perl bug with split

Postby youradds on Fri May 03, 2013 8:04 am

And another one :)

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

print "Foo";


Seems like the single " tag breaks the code after it. Removing the quote works, but obviously I need to remove that =)
youradds
 
Posts: 8
Joined: Fri Dec 07, 2012 4:24 pm

Re: Perl bug with split

Postby youradds on Fri May 03, 2013 8:05 am

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

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


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.

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


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)
youradds
 
Posts: 8
Joined: Fri Dec 07, 2012 4:24 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], Yahoo [Bot] and 30 guests