new way to code html?by Don Coyote (Pilgrim)
|on Nov 20, 2012 at 23:26 UTC||Need Help??|
ok nothing Ammazzingg here really, just a little bit neat. (And what the heck 1 vote to go for next level Scribe :D)
looking at simple package / subroutines I wrote a sub that had a print operation as its last argument. I called the sub from within a print.
the starting problem was that my print statements were all jumbled up with the print from the sub being evaluated then the print itself and finally a return of 1 or true from the call to the sub at the end of the print.
:( right so i eventually realise pass a scalar back! duh!
:) hooray this is how it is supposed to be! but as I say I was grappling with what was happenning so I tried wantarray ? : to see if maybe the caller of the sub had been expecting an array at some point. And something interesting happened. The sub evaluation returned the print as in the first attempt. So it was truly expecting an array afer being called from a print. Or was it? However, as the last statement was now a scalar, instead of returning true or 1, the scalar itself was also returned during the evaluation of the print statement. So it was also expecting a scalar??
At which point I hold my hands up and start thinking 'is this what they mean by a side effect?' and post the code
Still printing out the wrong way round, but the 1 is replaced with kerpow. So what is intersting is, how about I do..
I think this is why I like perl.
Unfortunately though, this doesnt nest too well when you start to add more elements. I do however seem to spend a lot of time previewing my posts here...