Other journalers seem to have weekly quizzes, so here is my take on that. The first "Show brian he's a dumbass" question of the week:
If you can see the problem in less than five minutes, you are better than me.
print "$ARGV[$.] $_";
Re:I'll take a stab at it
brian_d_foy on 2003-01-21T05:24:18
1) No points awarded.
2) Yes, the preceding line was while(){. Bonus points awarded.
3) Nope. Platinum points still available.
4) The Global Thermonuclear War points are still available.
5) Actually, this is unrelated to my post on line counting. It comes from another program I was working on today.
open(IN, $ARGV[0]) or die "$ARGV[0]: $!";
while ( <IN> ) {
print "$ARGV[$.] $_\n";
}
What I'm pondering while looking at this, and without virtue of perlvar, is whether there's some other way that $. is side-effected.
Re: What's wrong with this line of Perl?
dws on 2003-01-21T05:37:35
Oh. I see. You were trying to print lines from all files in @ARGV, preceded by the filename. Unfortunately, $. is incremented after each line read, and the magic <> form of read is destructive on @ARGV anyway.Re: What's wrong with this line of Perl?
brian_d_foy on 2003-01-21T05:48:43
1) Points awarded. I was trying to prefix lines with their file name and line number. The line should have been "$ARGV\[$.] $_" so the "[" is not treated as the start of an array indexy thingy. I typically print values between square brackets so I can notice any whitespace that might be there.
2) Bonus points already awarded to gizmo_mathboy. The preceding line used the diamond operator <> which I forgot to entity encode in my last response.
3) Platinum and Global Thermonuclear War points still available.Re: What's wrong with this line of Perl?
dws on 2003-01-21T06:02:27
Hm... for Platinum, I guess "use strict;".For GTW, @ARGV, $ARGV, $., and $_
Re: What's wrong with this line of Perl?
brian_d_foy on 2003-01-21T06:07:09
No points.:(
# Print filename before line
perl -pe '$_="$ARGV: $_"' file
For question 5: $/ and $\ would directly influence the operation. I don't think that any special variables are affected by it (apart from the stringification of $..
Re: What's wrong with this line of Perl?
brian_d_foy on 2003-01-21T17:20:00
You are right on my intent, but points have already been awarded.
Re: What's wrong with this line of Perl?
brian_d_foy on 2003-01-21T17:21:03
No, that was not the line, although I have never thought to do that. Interesting...
close ARGV if eof
;
print "${ARGV}[$.] $_";
Re:Line after
brian_d_foy on 2003-01-21T18:11:44
Nope, no close ARGV.
Maybe it is time for another hint: it is nothing tricky or unusual.
$ARGV, @ARGV, *ARGV (or does that just count as 1 since you can get to them all through *ARGV?), $_, $.
Re:Global Thermonuclear attempt
brian_d_foy on 2003-01-21T18:14:06
Nope, still missing a lot. No points awarded.
(Actually, I bet you really have a blank line before the while loop, but that you're not being that evil in the nature of your question.)
Global Thermonuclear War Bonus:
Re:One more stab at it
brian_d_foy on 2003-01-21T22:25:10
Double bonus: nope, the preceding line was the while(). nothing tricky.
Global Thermonuclear War bonus: i think that is pretty close---I had not actually considered $|. Still, at least one is missing.:) Re:One more stab at it
dws on 2003-01-22T02:35:48
Platinum. I meant Platinum. Aaaarg.Re:One more stab at it
dws on 2003-01-22T06:01:02
Bah. Never mind. I misread Platinum as being the one "before" the one before your line.