Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: How do I prevent unwanted print output from an eval?

by duggles (Acolyte)
on Aug 26, 2008 at 21:35 UTC ( #706985=note: print w/replies, xml ) Need Help??


in reply to Re: How do I prevent unwanted print output from an eval?
in thread How do I prevent unwanted print output from an eval? (RESOLVED! eval NOT THE PROBLEM!)

It's not cgi - it's in a cmd window on WinXP.
I hope this helps to explain the problem...
This is the cryptogram being worked on
$test_crypt="NK JNK YJ YAK ZPCCTK GDKQ YAK YNJ NJVQY PUSKUYPJUQ JR AMZ +GUPYL - VJZGUYPX TJSK GUC DMUOJNCKV. -- GUCVK ZGMVJPQ" The correct translation:<br> "WE OWE TO THE MIDDLE AGES THE TWO WORST INVENTIONS OF HUMANITY - ROMA +NTIC LOVE AND GUNPOWDER. -- ANDRE MAUROIS"

After finding the most productive letter patterns in the quote, the eval translates the quote trying one word at a time, testing to see if valid words can be made out of the rest of the quote using that translation. None of that work is being sent to the screen, just the results at the bottom of the loop. Small case letters have been translated for the test. Upper case letters are the original as they are $test_crypt.
The first shown here tries "inventions" and is successful in verifying all the rest of the words can be solved using the translation (in this example: $key = "inventions" $word = PUSKUYPJUQ)
eval "\$test_crypt =~ tr/$key/$word/"; # TRANSLATE USING THIS KEY
Screen output:
Ne oNe to tAe ZiCCTe GDes tAe tNo NoVst inventions oR AMZGnitL - VoZGn +tiX Tove GnC DMnOoNCeV -- GnCVe ZGMVois

(The next line is a normal print statement which I DO want to print at the bottom of the loop.)
inventions 12==2=1=2= 80

The second word in the quote is then tried. In this case we start with $key = "something" $word = PUSKUYPJUQ and progress through $key = "gunpowder $word = PUSKUYPJUQ and on to the end
In the above loop there was only one match to try. In this next one there's a pretty good list of words to test. This next block is generated by each successive execution of the eval statement in the loop.
hn thn Yt YAn ZPiiTn GsnQ YAn Yht htgQY PmSnmYPtmQ tR AoZGmPYL - gtZGm +YPX TtSn Gmi something -- Gmign ZGogtPQ to ato Ya YAo ZPiiTo GeoQ YAo Yta tanQY PuSouYPauQ aR AdZGuPYL - naZGu +YPX TaSo Gui education -- Guino ZGdnaPQ ru eru Ye YAu ZPooTu GduQ YAu Yre resQY PnSunYPenQ eR AaZGnPYL - seZGn +YPX TeSu Gno dangerous -- Gnosu ZGasePQ ru eru Ye YAu ZPffTu GwuQ YAu Yre relQY PnSunYPenQ eR AoZGnPYL - leZGn +YPX TeSu Gnf wonderful -- Gnflu ZGolePQ st rst Yr YAt ZPiiTt GatQ YAt Ysr sryQY PvStvYPrvQ rR AdZGvPYL - yrZGv +YPX TrSt Gvi adversity -- Gviyt ZGdyrPQ il ail Ya YAl ZPnnTl GclQ YAl Yia iayQY PrSlrYParQ aR AeZGrPYL - yaZGr +YPX TaSl Grn certainly -- Grnyl ZGeyaPQ vr ovr Yo YAr ZPeeTr GdrQ YAr Yvo voyQY PsSrsYPosQ oR AiZGsPYL - yoZGs +YPX ToSr Gse discovery -- Gseyr ZGiyoPQ mt smt Ys YAt ZPiiTt GgtQ YAt Yms mshQY PlStlYPslQ sR AoZGlPYL - hsZGl +YPX TsSt Gli goldsmith -- Gliht ZGohsPQ br hbr Yh YAr ZPooTr GnrQ YAr Ybh bhsQY PiSriYPhiQ hR AeZGiPYL - shZGi +YPX ThSr Gio neighbors -- Giosr ZGeshPQ re ore Yo YAe ZPiiTe GfeQ YAe Yro rosQY PcSecYPocQ oR AaZGcPYL - soZGc +YPX ToSe Gci factories -- Gcise ZGasoPQ ga nga Yn YAa ZPwwTa GhaQ YAa Ygn gnyQY PmSamYPnmQ nR AeZGmPYL - ynZGm +YPX TnSa Gmw hemingway -- Gmwya ZGeynPQ lu elu Ye YAu ZPooTu GmuQ YAu Yle lesQY PrSurYPerQ eR AaZGrPYL - seZGr +YPX TeSu Gro marvelous -- Grosu ZGasePQ cn ucn Yu YAn ZPiiTn GpnQ YAn Ycu cugQY PoSnoYPuoQ uR ArZGoPYL - guZGo +YPX TuSn Goi producing -- Goign ZGrguPQ hn chn Yc YAn ZPiiTn GsnQ YAn Yhc hcgQY PaSnaYPcaQ cR AeZGaPYL - gcZGa +YPX TcSn Gai searching -- Gaign ZGegcPQ ln eln Ye YAn ZPiiTn GtnQ YAn Yle legQY PaSnaYPeaQ eR ArZGaPYL - geZGa +YPX TeSn Gai traveling -- Gaign ZGrgePQ et met Ym YAt ZPnnTt GatQ YAt Yem emsQY PgStgYPmgQ mR ArZGgPYL - smZGg +YPX TmSt Ggn arguments -- Ggnst ZGrsmPQ hn thn Yt YAn ZPiiTn GbnQ YAn Yht htgQY PeSneYPteQ tR ArZGePYL - gtZGe +YPX TtSn Gei breathing -- Geign ZGrgtPQ ag hag Yh YAg ZPrrTg GdgQ YAg Yah aheQY PsSgsYPhsQ hR AiZGsPYL - ehZGs +YPX ThSg Gsr discharge -- Gsreg ZGiehPQ ae lae Yl YAe ZPccTe GmeQ YAe Yal aldQY PsSesYPlsQ lR AiZGsPYL - dlZGs +YPX TlSe Gsc misplaced -- Gscde ZGidlPQ ra era Ye YAa ZPssTa GuaQ YAa Yre relQY PiSaiYPeiQ eR AnZGiPYL - leZGi +YPX TeSa Gis universal -- Gisla ZGnlePQ an lan Yl YAn ZPiiTn GcnQ YAn Yal alsQY PmSnmYPlmQ lR AoZGmPYL - slZGm +YPX TlSn Gmi complains -- Gmisn ZGoslPQ tr utr Yu YAr ZPeeTr GcrQ YAr Ytu tusQY PmSrmYPumQ uR AoZGmPYL - suZGm +YPX TuSr Gme computers -- Gmesr ZGosuPQ mt smt Ys YAt ZPiiTt GltQ YAt Yms mshQY PcStcYPscQ sR AoZGcPYL - hsZGc +YPX TsSt Gci locksmith -- Gciht ZGohsPQ nc inc Yi YAc ZPaaTc GocQ YAc Yni niyQY PsScsYPisQ iR AbZGsPYL - yiZGs +YPX TiSc Gsa obstinacy -- Gsayc ZGbyiPQ ie nie Yn YAe ZPzzTe GoeQ YAe Yin indQY PgSegYPngQ nR ArZGgPYL - dnZGg +YPX TnSe Ggz organized -- Ggzde ZGrdnPQ be mbe Ym YAe ZPllTe GseQ YAe Ybm bmdQY PrSerYPmrQ mR AcZGrPYL - dmZGr +YPX TmSe Grl scrambled -- Grlde ZGcdmPQ tr atr Ya YAr ZPuuTr GsrQ YAr Yta taeQY PgSrgYPagQ aR AiZGgPYL - eaZGg +YPX TaSr Ggu signature -- Gguer ZGieaPQ tn etn Ye YAn ZPiiTn GcnQ YAn Yte tegQY PmSnmYPemQ eR AoZGmPYL - geZGm +YPX TeSn Gmi competing -- Gmign ZGogePQ re tre Yt YAe ZPiiTe GceQ YAe Yrt rtsQY PuSeuYPtuQ tR AoZGuPYL - stZGu +YPX TtSe Gui countries -- Guise ZGostPQ we owe Yo YAe ZPddTe GgeQ YAe Ywo worQY PnSenYPonQ oR AuZGnPYL - roZGn +YPX ToSe Gnd gunpowder -- Gndre ZGuroPQ . . . . . mn omn Yo YAn ZPiiTn GwnQ YAn Ymo mogQY PlSnlYPolQ oR AeZGlPYL - goZGl +YPX ToSn Gli welcoming -- Glign ZGegoPQ lc plc Yp YAc ZPaaTc GwcQ YAc Ylp lpeQY PrScrYPprQ pR AoZGrPYL - epZGr +YPX TpSc Gra workplace -- Graec ZGoepPQ gunpowder ========= 169 inventions 12==2=1=2= 80 bottom of foreach key in $aword_score hash

All failed except "gunpowder".

The point is there is no print statement and there appears to be no error to be reported. It just looks like the results of the eval are being printed to the screen. As I mentioned in a reply to a previous answer, this is executing in a cmd window on a Windows machine. Thanks for your help! Doug
Life is short, but it's wide -- Chuck Pyle

Replies are listed 'Best First'.
Re^3: How do I prevent unwanted print output from an eval?
by ikegami (Pope) on Aug 26, 2008 at 22:30 UTC

    It just looks like the results of the eval are being printed to the screen.

    It makes no sense for that eval to do so, and I can't reproduce it. The following produces no output to the screen.

    use strict; use warnings; my $test_crypt = "NK JNK YJ YAK ZPCCTK GDKQ YAK YNJ NJVQY PUSKUYPJUQ J +R AMZGUPYL - VJZGUYPX TJSK GUC DMUOJNCKV. -- GUCVK ZGMVJPQ"; my $key = 'something'; my $word = 'PUSKUYPJUQ'; eval "\$test_crypt =~ tr/$key/$word/";

    So far, we've only received unverifiable claims on your part. Please provide us the means of reproducing your results.

    The code is too convoluted, long and poorly written to post

    Yet you're sure it's eval's fault...

      First an apology: I'm sorry to have troubled all of you. I appreciate very much the opportunity to come here for help and now that I've found the problem, I am indeed contrite!

      Second and explanation:
      I found it... I thought I had commented out all of my print statements but there was just one in a subroutine that I did not notice was being called and it was printing the $test_crypt variable. The subroutine call was a bit further down in the code and I simply didn't see it.

      Third a thank you:
      Thanks for all of your inputs. This one was particularly enlightening. I just put these few lines in a subroutine and surrounded it with print statements and it was immediately obvious that the print was coming from somewhere else. I didn't ever really say that I was sure it was eval's fault, I did consider it a suspect, but your reply coupled with some of the others helped me pin it down. I have to confess that I was a bit slighted after yesterday's replies sort of talked down to me a bit, but now I realize that it was well-deserved!!! ;-)

      A sincere thanks to all of you!! I'll try to improve my postings (and testing methods) when I need help again.

      Doug
        jeez... another screwup... I didn't notice that I wasn't logged in so the above reply from anonymous monk actually came from me (duggles)

        sorry...

        Life is short, but it's wide -- Chuck Pyle
Re^3: How do I prevent unwanted print output from an eval?
by jethro (Monsignor) on Aug 26, 2008 at 22:45 UTC

    You say "(The next line is a normal print statement which I DO want to print at the bottom of the loop.)". I would have liked to see that print statement. And a lot more. We can't help you with code we can't see

    You seem so dead set on that eval line as the culprit (or some modules) that you discount any other code to have something to do with it. Big mistake. Or you don't want to show the code. In that case you have to use the perl debugger and single step through your loop. You will see exactly which statement produces this unwanted output

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://706985]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-07-19 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (414 votes). Check out past polls.

    Notices?