Strategy for diagnosing context-sensitive bug

2010-12-03 Thread Jonathan Pool
I'm seeking a strategy for diagnosing a bug that seems difficult to reduce to a simple reproducible case. The bug is that a hash element apparently becomes undef. When used as an argument to "split" or "index", it generates a "Use of uninitialized value" error. The mysterious thing about this

Re: A strange problem with array outside I/O

2010-12-03 Thread Odin Liu
Thanks to all. I have learned a lot tonight. Syntax sugar should be only used when I know clearly what happened. On Sat, Dec 4, 2010 at 12:34 AM, Jim Gibson wrote: > On 12/3/10 Fri Dec 3, 2010 8:26 AM, "Odin Liu" > scribbled: > > > Interesting. So if I need deal with an array of files, and I

Re: A strange problem with array outside I/O

2010-12-03 Thread Jim Gibson
On 12/3/10 Fri Dec 3, 2010 8:31 AM, "Odin Liu" scribbled: > No, actually I need deal with these files twice. So I need to keep the array > of these files. But after the first time dealing with these files, the array > of these files had been changed. Then you should modify your program so that

Re: A strange problem with array outside I/O

2010-12-03 Thread Jim Gibson
On 12/3/10 Fri Dec 3, 2010 8:30 AM, "Roche, Johnny" scribbled: > To my understanding, "$_" is the default input of the current running > script/program, hence, if you overwrite $_ in an inner loop, it will overwrite > $_ for the whole process. If you do not want to overwrite it, you'll need to

Re: A strange problem with array outside I/O

2010-12-03 Thread Odin Liu
Oh, it works! Thanks a lot. On Sat, Dec 4, 2010 at 12:29 AM, Shawn H Corey wrote: > On 10-12-03 11:26 AM, Odin Liu wrote: > >> Interesting. So if I need deal with an array of files, and I have to use >> the array after reading each file. I have to save another copy of the >> array? >> > > No, use

Re: A strange problem with array outside I/O

2010-12-03 Thread Uri Guttman
> "OL" == Odin Liu writes: OL> I consider $_ is a value-copy of the loop-element, but as shown in OL> a while loop inside a for loop, it seems that $_ is a reference of OL> the loop-element. it doesn't matter what you consider $_ to be. don't use it for loops. use a lexical variable wh

Re: A strange problem with array outside I/O

2010-12-03 Thread Uri Guttman
> "RJ" == Roche, Johnny writes: RJ> To my understanding, "$_" is the default input of the current RJ> running script/program, hence, if you overwrite $_ in an inner RJ> loop, it will overwrite $_ for the whole process. If you do not RJ> want to overwrite it, you'll need to assign $_

Re: A strange problem with array outside I/O

2010-12-03 Thread Shawn H Corey
On 10-12-03 11:40 AM, Odin Liu wrote: I consider $_ is a value-copy of the loop-element, but as shown in a while loop inside a for loop, it seems that $_ is a reference of the loop-element. The loop variable for a foreach loop is the actual element of the array. Consider: #!/usr/bin/perl u

Re: A strange problem with array outside I/O

2010-12-03 Thread Odin Liu
I consider $_ is a value-copy of the loop-element, but as shown in a while loop inside a for loop, it seems that $_ is a reference of the loop-element. On Sat, Dec 4, 2010 at 12:30 AM, Roche, Johnny wrote: > To my understanding, "$_" is the default input of the current running > script/program, h

RE: rtf files

2010-12-03 Thread Cristi Ocolisan
Hi Jim, Thanks for the tip. I searched CPAN prior to ask here and also I googled to find tutorials and everybody pointed me to RTF::Tokenizer. I use RTF::Writer to generate RTF files, but I need another module to append text to already generated *.rtf file by other user. I'll try also the modules

Re: A strange problem with array outside I/O

2010-12-03 Thread Shawn H Corey
On 10-12-03 11:30 AM, Roche, Johnny wrote: To my understanding, "$_" is the default input of the current running script/program, hence, if you overwrite $_ in an inner loop, it will overwrite $_ for the whole process. If you do not want to overwrite it, you'll need to assign $_ to a scalar be

RE: A strange problem with array outside I/O

2010-12-03 Thread Roche, Johnny
Shawn is absolutely right. If you don't care to save the array, then you can use $_. Johnny Roche Associate, Help Desk Harvard Management Company Tel: 617-720-6827 Fax: 617-878-6827 Email: roc...@hmc.harvard.edu -Original Message- From: Shawn H Corey [mailto:shawnhco...@gmail.com] Sent:

Re: A strange problem with array outside I/O

2010-12-03 Thread Jim Gibson
On 12/3/10 Fri Dec 3, 2010 8:26 AM, "Odin Liu" scribbled: > Interesting. So if I need deal with an array of files, and I have to use the > array after reading each file. I have to save another copy of the array? No. You need to learn where and when it is appropriate to use the default variable

Re: A strange problem with array outside I/O

2010-12-03 Thread Shawn H Corey
On 10-12-03 11:31 AM, Odin Liu wrote: No, actually I need deal with these files twice. So I need to keep the array of these files. But after the first time dealing with these files, the array of these files had been changed. Only if you try to use $_ twice. Use a lexical variable for all your

Re: A strange problem with array outside I/O

2010-12-03 Thread Odin Liu
No, actually I need deal with these files twice. So I need to keep the array of these files. But after the first time dealing with these files, the array of these files had been changed. On Sat, Dec 4, 2010 at 12:24 AM, Roche, Johnny wrote: > Would this satisfy your desired output? > > my @ins =

RE: A strange problem with array outside I/O

2010-12-03 Thread Roche, Johnny
To my understanding, "$_" is the default input of the current running script/program, hence, if you overwrite $_ in an inner loop, it will overwrite $_ for the whole process. If you do not want to overwrite it, you'll need to assign $_ to a scalar before entering the loop that will overwrite $_

Re: A strange problem with array outside I/O

2010-12-03 Thread Shawn H Corey
On 10-12-03 11:26 AM, Odin Liu wrote: Interesting. So if I need deal with an array of files, and I have to use the array after reading each file. I have to save another copy of the array? No, use a lexical variable for each loop: foreach my $file ( @ins ){ while( defined( my $line = <$in_fh>

Re: A strange problem with array outside I/O

2010-12-03 Thread Odin Liu
Interesting. So if I need deal with an array of files, and I have to use the array after reading each file. I have to save another copy of the array? Anyway, thanks for helping. On Sat, Dec 4, 2010 at 12:16 AM, Shawn H Corey wrote: > On 10-12-03 11:12 AM, Odin Liu wrote: > >> Still confusing. We

Re: rtf files

2010-12-03 Thread Jim Gibson
On 12/3/10 Fri Dec 3, 2010 5:11 AM, "Cristi Ocolisan" scribbled: > Hi all, > > > > Have anybody used RTF::Tokenizer module? > > I'm struggling to find out how to retrieve the content of tokens. > > > > What I'm trying to do is to open a file (*.rtf) that a user uploaded on > server add

RE: A strange problem with array outside I/O

2010-12-03 Thread Roche, Johnny
Would this satisfy your desired output? my @ins = @ARGV; foreach(@ins) { open IN, $_; my $fn = $_; while() { chomp; print "$fn\n"; } close IN; } Johnny Roche Associate, Help Desk Harvard Management Company Tel: 617-720-6827 Fax: 617

Re: A strange problem with array outside I/O

2010-12-03 Thread Shawn H Corey
On 10-12-03 11:12 AM, Odin Liu wrote: Still confusing. We know that inner loop's $_ overwrite the outer loop's $_ only in the inner loop. When the inner loop was over, the $_ would be it was in outer loop before the inner loop begin. Outer $_ would be restored by Perl automatically. But why this

Re: A strange problem with array outside I/O

2010-12-03 Thread Shawn H Corey
On 10-12-03 10:36 AM, Odin Liu wrote: Suppose file test.pl is: my @ins = @ARGV; foreach(@ins) { open IN, $_; # the three argument open is preferred. See `perlodc -f open`. open my $in_fh, '<', $_ or die "could not open $_: $!\n"; while() { while( defined( my $line = <$in_f

A strange problem with array outside I/O

2010-12-03 Thread Odin Liu
Hi, all Suppose file test.pl is: my @ins = @ARGV; foreach(@ins) { open IN, $_; while() { chomp; print "@ins\n"; } close IN; } and file case is: a b c When I run it in shell, using: $ perl test.pl case I thought it would be print: case

rtf files

2010-12-03 Thread Cristi Ocolisan
Hi all, Have anybody used RTF::Tokenizer module? I'm struggling to find out how to retrieve the content of tokens. What I'm trying to do is to open a file (*.rtf) that a user uploaded on server add a few information and save it. I'm on Linux so I cannot use modules that work only on Windo