tag:blogger.com,1999:blog-11788780.post991813146212854373..comments2023-12-29T13:22:33.104-08:00Comments on JJinuxLand: Misspelled Variablesjjinuxhttp://www.blogger.com/profile/03270879497119114175noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-11788780.post-32974926292663616282008-11-19T12:22:00.000-08:002008-11-19T12:22:00.000-08:00> So it's not being treated as a string. It...> So it's not being treated as a string. It's just a coincidence really.<BR/><BR/>Thanks for setting me straight, Brandon :)jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-48455135299902292902008-11-19T10:10:00.000-08:002008-11-19T10:10:00.000-08:00IIRC, I think what you are seeing in Perl is that ...IIRC, I think what you are seeing in Perl is that FOO is filehandle portion of the glob *FOO. When you treat this in scalar context, you get its name (which happens to be what you typed).<BR/><BR/>That way, the following thing works:<BR/><BR/>$x = FH;<BR/>$line = <$x>;<BR/><BR/>$ perl<BR/>print FOO BAR;<BR/>Can't locate object method "FOO" via package "BAR" (perhaps you forgot to load "BAR"?) at - line 1.<BR/><BR/>So it's not being treated as a string. It's just a coincidence really.Brandon L. Golmhttps://www.blogger.com/profile/12579635831136709134noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-69549482757449623492008-11-19T09:07:00.000-08:002008-11-19T09:07:00.000-08:00> Variables (scalars) are prefixed by a $ in Pe...> Variables (scalars) are prefixed by a $ in Perl:<BR/><BR/>Ugh, silly me. And to think I used to code in Perl! Too many languages leads to too much confusion ;)<BR/><BR/>Thanks.jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-46620663134917941442008-11-19T09:03:00.000-08:002008-11-19T09:03:00.000-08:00aflury:> It's still a valid concern if you&...aflury:<BR/>> It's still a valid concern if you're using Perl constants.<BR/><BR/>Great comment.<BR/><BR/>anonymous:<BR/>> The Perl isn't a bug.<BR/><BR/>I didn't say it was a "bug". I just disagree with the design decision. I'm glad that the cases you showed work. The case that I showed and the case that Andrew showed don't. Thanks for the comment :)jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-71272175951284611622008-11-19T08:59:00.000-08:002008-11-19T08:59:00.000-08:00Mark:> Compiled languages are only a problem if...Mark:<BR/>> Compiled languages are only a problem if they lack true object-oriented features like metaclasses, reflection, and dynamic class loading (i.e., C, C++).<BR/><BR/>Great comment! Yes, reflection and dynamic class loading are two things I love dearly.jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-72993550379062405682008-11-19T08:57:00.000-08:002008-11-19T08:57:00.000-08:00greg:>In a compiled language? Isn't it more...greg:<BR/>>In a compiled language? Isn't it more a type issue that compiled vs interpreted one? <BR/><BR/>It's not just that I'm storing stuff in a hash, it's that I'm creating new local (or actually global) variables on the fly. In C, you can't read in the name of a local variable from STDIN and then define that global variable on the fly.jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-91998308298484937902008-11-19T08:52:00.000-08:002008-11-19T08:52:00.000-08:00> it isn't really silent. You'll get an...> it isn't really silent. You'll get an error in your logs:<BR/><BR/>Yes, but why would I look in the logs if it doesn't show an error on the screen? Do most PHP programmers tail -f their logs in a terminal window while developing? That would make sense, but I've never done it.jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-55750212072151253372008-11-19T08:51:00.000-08:002008-11-19T08:51:00.000-08:00> In general, the locals() is not modifiable in...> In general, the locals() is not modifiable in the way that globals() is. <BR/><BR/>Right you are!jjinuxhttps://www.blogger.com/profile/03270879497119114175noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-58579447209650057252008-11-19T07:02:00.000-08:002008-11-19T07:02:00.000-08:00The Perl isn't a bug. It is doing exactly what it ...The Perl isn't a bug. It is doing exactly what it was designed to do. You are feeding it a list. In your case a list that you concatenate together. Perl "sees" that and good or bad does the assumption that you actually meant to concatenate that together as a list.<BR/><BR/>my $FOO = 'hello';<BR/>print FOO;<BR/><BR/>Name "main::FOO" used only once: possible typo at p.pl line 2.<BR/>p.pl syntax OK<BR/><BR/>my $FOO = 'hello';<BR/>print $FO;<BR/><BR/>Name "main::FO" used only once: possible typo at p.pl line 2.<BR/>p.pl syntax OKAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-11788780.post-45021363932690994032008-11-19T06:13:00.000-08:002008-11-19T06:13:00.000-08:00In Java:Point obj = new Point(1, 2);String varname...In Java:<BR/><BR/>Point obj = new Point(1, 2);<BR/>String varname = "x";<BR/>Object x = obj.getClass().getField("x").get(pt);<BR/>System.out.println(x); // prints 1<BR/><BR/><BR/>In Objective-C:<BR/><BR/>id obj = [[[MyPoint alloc] initWithX:1 y:2] autorelease];<BR/>NSString varname = @"x";<BR/>id val = [obj valueForKey:varname];<BR/>NSLog(@"%@", val); // prints 1<BR/><BR/>Compiled languages are only a problem if they lack true object-oriented features like metaclasses, reflection, and dynamic class loading (i.e., C, C++).Mark Hugheshttps://www.blogger.com/profile/05325140104622317511noreply@blogger.comtag:blogger.com,1999:blog-11788780.post-80065127556529962762008-11-19T04:49:00.000-08:002008-11-19T04:49:00.000-08:00Why do you think you could never do: >>> ...Why do you think you could never do: <BR/><BR/>>>> var_name = 'a'<BR/>>>> locals()[var_name] = 'yep'<BR/>>>> print a<BR/>yep<BR/><BR/>In a compiled language? Isn't it more a type issue that compiled vs interpreted one? <BR/><BR/>If the language allows to store variables with different types in a list, I don't see why it won't work.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11788780.post-64418450066284979752008-11-19T02:11:00.000-08:002008-11-19T02:11:00.000-08:00It's still a valid concern if you're using...It's still a valid concern if you're using Perl constants.<BR/>$ perl -Mstrict -we 'use constant {FOO => "foo"}; print FO . "bar"'<BR/>FObarAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-11788780.post-43223714131192960012008-11-19T01:44:00.000-08:002008-11-19T01:44:00.000-08:00Variables (scalars) are prefixed by a $ in Perl:~$...Variables (scalars) are prefixed by a $ in Perl:<BR/><BR/>~$ perl -Mstrict -e 'print $FOO . "FOO"'<BR/>Global symbol "$FOO" requires explicit package name at -e line 1.<BR/><BR/>I believe in PHP it's similar.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11788780.post-39381192027676605832008-11-19T01:33:00.000-08:002008-11-19T01:33:00.000-08:00it isn't really silent. You'll get an error in you...it isn't really silent. You'll get an error in your logs:<BR/><BR/> PHP Notice: Use of undefined constant FO - assumed 'FO' in /data/sites/kai/warn.php on line 3Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11788780.post-78306507891184022132008-11-19T01:02:00.000-08:002008-11-19T01:02:00.000-08:00Python lint catches this type of error.Python lint catches this type of error.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11788780.post-63134900949449905112008-11-19T00:09:00.000-08:002008-11-19T00:09:00.000-08:00Your locals() example in Python only works because...Your locals() example in Python only works because in the interpreter, you have that<BR/><BR/>>>> locals() is globals()<BR/>True<BR/><BR/>In general, the locals() is not modifiable in the way that globals() is.Mike Hansenhttps://www.blogger.com/profile/01057721296272217731noreply@blogger.com