mayer@sono.uucp (Ronald &) (05/31/91)
Could someone please explain what's going on in these examples? % perl -e '@a = eval ("*\n"); print "@a\n";' [A bunch of random control characters which don't mean anything to me.] % perl -e '@a = eval ("*\n"); print "@a";' *main' In neither case is $@ set to anything. Even if the second case is supposed to mean something, I'm at a total loss to explain the first one. [BTW: sparc 1,SunOS 4.1, perl 4.0 patch 3] My guess: It's probably somehow related to this section of the manual, but I can't figure out how or why: > Since a *name value contains unprintable binary data, if it > is used as an argument in a print, or as a %s argument in a > printf or sprintf, it then has the value '*name', just so it > prints out pretty. Thanks, Ron Mayer sun!sono!mayer mayer@sono.uucp
mayer@sono.uucp (Ronald &) (05/31/91)
[In a recent mail message I asked people to explain this behavior:] > >% perl -e '@a = eval ("*\n"); print "@a\n";' >[A bunch of random control characters which don't mean anything to me.] > >% perl -e '@a = eval ("*\n"); print "@a";' >*main' > Thanks to a number of you for pointing out that *\n is a reference to a variable called "\n". The bunch of random characters occured from the print statement when I try to print a "\n" concatenated with the "unprintable binary data" contained in the *name value. # perl -e '$\ = "Almost another Perl hacker,"; print $\ ' Ron Mayer mayer@sono.uucp sun!sono!mayer [Note: mandantory "\n" after each $ Why does this JAPH return "Almost another Perl hacker," from csh and "> > Almost another Perl hacker,Almost another Perl hacker,$" from sh? [My guess: In sh the "\n" doesn't need to be '\' quoted, so from sh I'm actually setting '$\' instead of $"\n".] ]
allbery@NCoast.ORG (Brandon S. Allbery KF8NH) (06/04/91)
As quoted from <MAYER.91May30150835@porky.sono.uucp> by mayer@sono.uucp (Ronald &): +--------------- | % perl -e '@a = eval ("*\n"); print "@a\n";' | [A bunch of random control characters which don't mean anything to me.] | | % perl -e '@a = eval ("*\n"); print "@a";' | *main' | | My guess: It's probably somehow related to this section of the manual, | but I can't figure out how or why: | > Since a *name value contains unprintable binary data, if it | > is used as an argument in a print, or as a %s argument in a | > printf or sprintf, it then has the value '*name', just so it | > prints out pretty. +--------------- You are eval'ing something which Perl treats as an expression: a "type-glob" (or whatever the name du jour is) on the variable named "\n". (Which is illegal in most circumstances; it should be here as well. This is probably a bug.) So in the second case (easiest), you're getting back from print that it saw a *-expression on the variable "\n" (newline) in package main. The first example is more interesting: since the \n in the print causes an interpolation (the second is probably optimized out), print can't recognize that it was passed an *-expression and therefore prints out the actual symbol table entry: a binary value which is meaningless to mere mortals. ++Brandon -- Me: Brandon S. Allbery KF8NH: DC to LIGHT! [44.70.4.88] Internet: allbery@NCoast.ORG Delphi: ALLBERY uunet!usenet.ins.cwru.edu!ncoast!allbery