File::Tie problem (newbie ?)

Discussion in 'Perl Misc' started by cmic, Feb 22, 2006.

  1. cmic

    cmic Guest

    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
    --
    cmic want-to-be-perl-hacker :cool:)
    cmic, Feb 22, 2006
    #1
    1. Advertising

  2. cmic

    Guest

    "cmic" <> wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Feb 22, 2006
    #2
    1. Advertising

  3. cmic

    cmic Guest

    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....
    --
    cmic
    cmic, Feb 22, 2006
    #3
  4. cmic

    Eric Bohlman Guest

    "cmic" <> wrote in news:1140623379.173024.193500
    @o13g2000cwo.googlegroups.com:

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


    This line doesn't do what you think it does. In particular, it will never
    die.
    Eric Bohlman, Feb 24, 2006
    #4
  5. Eric Bohlman wrote:
    > cmic wrote:
    >>
    >>tie my @array, 'Tie::File', 'abc' || die $!;

    >
    > 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 $!;

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Feb 24, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonathan Weekes

    Tie to change line in file

    Jonathan Weekes, Sep 14, 2003, in forum: Perl
    Replies:
    0
    Views:
    486
    Jonathan Weekes
    Sep 14, 2003
  2. Carlo Filippini

    Tie a file handle to a variable

    Carlo Filippini, Sep 29, 2003, in forum: Perl
    Replies:
    1
    Views:
    437
  3. Carlo Filippini

    Tie a file handle to a variable

    Carlo Filippini, Sep 29, 2003, in forum: Perl
    Replies:
    3
    Views:
    626
    Kris Wempa
    Oct 1, 2003
  4. SpecialK

    Tie a file to a hash

    SpecialK, Feb 19, 2004, in forum: Perl
    Replies:
    1
    Views:
    461
    Ben Morrow
    Feb 19, 2004
  5. botfood

    tie() with DB_File not tie()ing ?

    botfood, Apr 24, 2006, in forum: Perl Misc
    Replies:
    23
    Views:
    445
    botfood
    Apr 26, 2006
Loading...

Share This Page