in reply to lack an adequate understanding of (at least) the seek function

While i do appreciate wanting to learn the intricacies of a particular tool, in this case i'd just get a different tool. Tie::File

use strict; use warnings; use Tie::File; tie my @file, 'Tie::File', 'messageTest.txt' or die "can't open\n"; my $MAX = 5; if (@file > $MAX) { @file = @file[0 .. $MAX - 1]; unshift @file, "new line"; }
Tie::File even has built-in flocking.

Thanks to Corion for alerting me that i linked to File::Array ... oops :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
  • Comment on Re: lack an adequate understanding of (at least) the seek function
  • Download Code

Replies are listed 'Best First'.
Re^2: lack an adequate understanding of (at least) the seek function
by o2bwise (Scribe) on May 23, 2005 at 21:11 UTC
    jeffa,

    Thanks!

    Man, that is too cool!

    o2
Re^2: lack an adequate understanding of (at least) the seek function
by o2bwise (Scribe) on May 24, 2005 at 18:17 UTC
    jeffa,

    This is REAL quick (and I am quite a beginner with OO Perl).

    I am wondering if the "complaint" I got for my code (which gave me the desired results) is benign.

    Here's the code:
    #!/usr/bin/perl -w use strict; use warnings; use Tie::File; my $MAXSAVE = 5; my $name = "Duane Wade"; my $subject = "My Career"; my $message = "No one ever thought I'd be this good."; my $myTieObject = tie my @messagesIn, 'Tie::File', 'messageTest2.txt' +or die "can't open\n"; $myTieObject->flock; unshift @messagesIn, "$name|$subject|$message"; if (@messagesIn > $MAXSAVE) { @messagesIn = @messagesIn[0 .. $MAXSAVE - 1]; } untie @messagesIn; 1;


    And here's the complaint:

    untie attempted while 1 inner references still exist at ./messageTest2.pl line 21 <FH> line 16.

    Line 21 is the untie line and Line 16 is the if statement.

    Other than that, I am all set and much obliged!

    Tony

      You are quite welcome o2bwise. The problem is that you are untie'ing the wrong thingy. Try this instead:

      untie $myTieObject;
      And there is no need to have 1; as the last line of a script. That's only necessary for modules. Cheers! :)

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
        Thanks, jeffa. I guess I was fooled by the tie being applied to the array coupled by the following in:

        http://search.cpan.org/~mjd/Tie-File-0.96/lib/Tie/File.pm#flock

        "The best way to unlock a file is to discard the object and untie the array."

        Man, I want to become a solid perl programmer. I was an engineer for several years in semiconductors and have been in software for ~6 years. I scripted (read: SCRIPTED) in perl for five of those.

        Say, I listened to the song you have posted. Not bad, but the title is much better, i.e. "the triplet paradiddle with a high-hat" - how can you beat that?

        If you like it, perhaps you might give a song called Serengetti (Grateful Dead off Shakedown Street) a try. All percussion where it gradually adds more and then removes it.

        Well, thanks again, jeffa...

        Cheers!

        o2