Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

File::CounterFile problems and hashes

by cecil36 (Monk)
on Oct 23, 2002 at 21:15 UTC ( #207532=perlquestion: print w/ replies, xml ) Need Help??
cecil36 has asked for the wisdom of the Perl Monks concerning the following question:

I'm rewriting a program that I use occasionally to track UPS shipments and have the status sent to a pager or e-mail address through a program that I use. My previous version used Lynx to fetch the package tracking info and dump the status to a file which was parsed and the pertinent info was sent out. This time, I'm sending out all the data (because of the limitations on hashes and the Business::UPS module. In running my code below on ActiveState Perl on a Win2000 box, I get the following error.

Can't use string "File::CounterFile" as a HASH ref while "strict ref" in use at E:/perl/lib/file/CounterFile.pm line 68.

Code is below
#!/usr/local/bin/perl use Business::UPS; use File::CounterFile; $counter = File::CounterFile->new("./msgid", "00000000"); $id = File::CounterFile->value; $filename = "pagemsg".$id; print "Enter in your UPS package tracking number: "; $track = <STDIN>; chomp($track); print "Enter in the receiver ID or e-mail address of the recipient"; $receiverID = <STDIN>; chomp($receiverID); print "Enter in the name of the messaging service, phone number (no da +shes or special characters), or Internet messaging server address (SN +PP, WCTP, or e-mail server address or IP address)"; $service = <STDIN>; chomp($service); %t = UPStrack("$track"); $t{error} and die "ERROR: $t{error}"; open (FILE, $filename); print FILE "MSG:\n"; print FILE "TO: $receiverID $service\n"; print FILE "CONTENTS: This package is $t{'Current Status'}\n"; # 'Del +ivered' or # 'In-transit' print FILE "Package route\n"; foreach $key (keys %t) { print FILE "KEY: $key = $t{$key}\n"; File::CounterFile->lock(); $counter->inc; File::CounterFIle->unlock(); }

Comment on File::CounterFile problems and hashes
Download Code
Re: File::CounterFile problems and hashes
by particle (Vicar) on Oct 23, 2002 at 23:39 UTC

    you should be locking and unlocking the File::CounterFile object, not the class.

    ## File::CounterFile->lock(); ## should be $counter->lock(); $counter->inc; ## File::CounterFIle->unlock(); ## should be $counter->unlock();

    i haven't tested, but this looks like the likely problem. the error message stems from the fact that a File::CounterFile object is a blessed hash reference, so perl is trying to use the string 'File::CounterFlie' as a reference to the object (a hash reference.)

    ~Particle *accelerates*

      Another problem.
      $counter = File::CounterFile->new("./msgid", "1"); $id = $counter->value(); $filename = "pagemsg".$id;
      I get a "Bad counter magic" error when the value is accessed. Am I accessing the counter file properly?

        i'm having trouble installing File::CounterFile. 'nmake test' is barfing badly on perl 5.6.1 build 626 for MSWin32. i get a 'bad counter magic' error from 't/basic.t'. until this is resolved, i can't help you debug File::CounterFile any more. perhaps i'll get a chance to look at the module later this week.

        ~Particle *accelerates*

        According to the File::CounterFile code unless the first line of the counter file is #COUNTER-1.0 you'll get the Bad counter magic error. Was the counter file created by File::CounterFile? If not remove the existing file and let the module do the rest.
        HTH

        _________
        broquaint

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://207532]
Approved by robartes
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-08-29 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (278 votes), past polls