File::Tie problem (newbie ?)

C

cmic

Hello

When I use 'abc' as the filename, it works. But if I use
'/home/cmic/abc', it throws
error : "Use of uninitialized value in print at a.pl line 8" and it
doesn't work.
NB Of course, abc has >100 valid lines !!

Anyone can explain ?

use warnings;
use Tie::File;

tie my @array, 'Tie::File', 'abc' || die $!;
print $array[3];

THX
 
X

xhoster

cmic said:
Hello

When I use 'abc' as the filename, it works. But if I use
'/home/cmic/abc', it throws
error : "Use of uninitialized value in print at a.pl line 8" and it
doesn't work.

Very mysterious. How can a 5-line program have an problem at line 8?

NB Of course, abc has >100 valid lines !!

How about /home/cmic/abc, does that also have >100 lines, valid or
otherwise?
Anyone can explain ?

use warnings;
use Tie::File;

tie my @array, 'Tie::File', 'abc' || die $!;
print $array[3];

THX

Xho
 
C

cmic

Hello

Oops. 'made a booboo.
The error was on line saying : print $array[n];

The problem happenned on a Redhat 9 (perl version ??)
However, I tried the same thing at home (Mandrake 10) and it seems to
work.
So I consider the problem closed, now.
Next time, I'll think twice

Thanks xhos....
 
G

Gunnar Hjalmarsson

Eric said:
This line doesn't do what you think it does. In particular, it will never
die.

Since you took the time to mention it, wouldn't it have been suitable to
explain _why_?

These are two ways to make the line behave as expected:

tie( my @array, 'Tie::File', 'abc' ) || die $!;

tie my @array, 'Tie::File', 'abc' or die $!;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top