Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Bad name after xxxx'

by KyussRyn (Acolyte)
on Jan 25, 2011 at 03:45 UTC ( #884038=perlquestion: print w/replies, xml ) Need Help??

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

Dear Monks,

I am having a minor problem with a "Bad name After" error. I am using Strawberry Perl 5.12.1 on Windows XP. here is some dummy cope:
01: #!c:\Perl\bin\perl 02: use warnings; 03: use strict; 04: use CGI ':standard'; ED: use constant CONSTANT1 => '../'; ED: use constant CONSTANT2 => '../'; 05: my $htmlPage = CGI->new; 06: 07: print "\n<p>ID/&#65418;&#65439;&#65405;&#65436;&#65392;&#65412;&#6 +5438;&#12434;&#24536;&#12428;&#12383;&#26041;&#12399;"; 08: print $htmlPage->a( { -href => CONSTANT2 09: , -target => '_self' }, '&#12371;&#12385;&#12425;' ); 10: print "</p>\n<p>"; 11: print $htmlPage->a( { -href => CONSTANT1 12: , -target => '_self' }, '&#21033;&#29992;&#35215;&#32004;' + ); 13: print "</p>";

On Line 12 I get an error saying "Bad name after _self'". I have read that perl used to allow pkg'$var and this is still supported so I have tried:
12: , -target => ''_self'' }, '&#21033;&#29992;&#35215;&#32004 +;' ); 12: , -target => "_self" }, '&#21033;&#29992;&#35215;&#32004;' + ); 12: , -target => "'_self'" }, '&#21033;&#29992;&#35215;&#32004 +;' );
These other alternatives provide variations of the error. I am pretty certain also that it is not the Japanese characters causing the problem either, as I have tested the same characters in other places.

Now I say this is not a major problem as the code builds and runs fine, but I am still getting this error message and would like to understand why.

Thank you in advance for any help you can give.

Kind regards,
P.S. The hashed codes are japanese characters.

I am using Eclipse with EPIC, and the pages are coded into UTF-8 through the interface. I tried out the use utf8; line, and that created a recursion error. I have also retyped the troubled lines, copied it from Line 10, and used the same word as well, but to no avail.

Replies are listed 'Best First'.
Re: Bad name after xxxx'
by GrandFather (Saint) on Jan 25, 2011 at 04:08 UTC

    What are 'CONSTANT1' and 'CONSTANT2'? In your sample code these two bare words are the things that generate 'Bareword "CONSTANT2" not allowed while "strict subs" in use' type errors. No trivial variations on the code you provide give the error you report, at least with Perl 5.10.1.

    True laziness is hard work
Re: Bad name after xxxx'
by ikegami (Pope) on Jan 25, 2011 at 04:54 UTC

    I have read that perl used to allow pkg'$var and this is still supported

    "'" is allowed as an alternate to "::", so $pkg::var could be (very unwisely) written as $pkg'var. Writing pkg'$var could definitely result in the error you get. But I don't see that in the code, so why do you bring it up?

    The hashed codes are japanese characters.

    No, there are no Japanese characters in the iso-8859-1 character set. You are not giving Japanese characters to perl. Perhaps you meant to include "use utf8;" to indicate your source is encoded using UTF-8 rather than iso-8859-1?

      I tried using the "use utf8;" line and it created a recursion error. As mentioned above I am using EPiC for eclipse and have the pages encoded to UTF-8 through the interface. Also the output to the HTML pages that the script is creating is handling the characters fine.

      If you still think that it is a UTF-8 error, I am assuming I would need to copy all of my code out to say notepad, use the UTF-8 line, and then paste back in. If there is an easier way would be happy to hear as it will save me a few files of code to not do this for.

      As for the $pkg'var comment, I just wanted to ensure readers that I was aware of this and that this wasn't the cause.
Re: Bad name after xxxx'
by fullermd (Priest) on Jan 25, 2011 at 04:21 UTC

    Works for me on *nix on everything form 5.6 to 5.12 with no errors (after putting something in for the CONSTANT's). Any change you've got some weird unprintable character in it somehow? What are you using for an editor?

    The various forms of multiple quoting you have wouldn't work, except the one using a plain doublequote ". That should work, but single quote is also fine. The issue with single quotes acting like package names is when they look like part of the variable; e.g., if you had $x = "$users's coat".

      This is the closest to a solution of the replies so far, I am using Eclipse with EPIC package installed. When I save the file the previously mentioned error appears.
      #!c:\Perl\bin\perl use warnings; use strict; use CGI ':standard'; use constant CONSTANT1 => '../'; use constant CONSTANT2 => '../'; my $htmlPage = CGI->new; print $htmlPage->a( { -href => CONSTANT2 , -target => '_self' }, '&#12371;&#12385;&#12425;' + ); print "</p>\n<p>"; print $htmlPage->a( { -href => CONSTANT1 , -target => '_self' }, '&#21033;&#29992;&#35215;& +#32004;' ); print "</p>";
Re: Bad name after xxxx'
by JavaFan (Canon) on Jan 25, 2011 at 12:28 UTC
    Your code snippets compiles and runs fine.

    Care to post a piece of code that actually acts like you describe it?

      The code I posted in response to fullermd has a sample of the code that comes up with the error.

      To restate my problem, the code compiles and runs on the system I am testing it on, but in the eclipse EPIC environment it marks the specific line with a bad name error. I just thought to test the script from the command line and it works fine with no error calls.

      I would like to know or be given direction as to why this is occuring to learn more about the proper way to code with perl.

        Well, it looks like perl to me any all the perl's on my system, and it sounds like it's working fine for you with perl. So I'd say you're coding perl properly.

        So it sounds like you really have an EPIC problem; maybe it has a bug in its parsing somehow. 's beyond me; I've never used anything Eclipse-ish. I don't know what support channels exist there, but you could see if someone there knows what's up.

        You could also try fiddling the code around a bit and see if you can find something that's making it's confused. Perhaps it doesn't like the commas at beginning of line? Try changing something like

        print $htmlPage->a( { -href => CONSTANT2 , -target => '_self' }, '&#12371;&#12385;&#12425;' + );


        print $htmlPage->a( { -href => CONSTANT2, -target => '_self' }, '&#12371;&#12385;&#12425;' ) +;

        instead (comma moved to the end of the first line rather than start of the second). Or put it all together on one line. Eliminate the -href, and try with just the -target, and vice versa.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://884038]
Approved by GrandFather
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2021-01-16 08:19 GMT
Find Nodes?
    Voting Booth?