2009/10/18 Harry Putnam <rea...@newsguy.com>:

Hi,

I can't say I am absolutely sure what the error is referring to but I
can see where you might begin to look for clues.

> I'm not sure what these errors are telling me.
>
> The script is supposed to remove dups from .bash_history but not
> operate on the last 12 lines... just reprinting them.
>
> ./uniqbh.pl
>  Copying ./bash_history to ./bash_history-101809_020827
>  Unlinking ./bash_history
>  Copying /tmp/lPlN3goGnI.tmp ./bash_history
>  Operation "eq": no method found,
>        left argument in overloaded package File::Temp,
>        right argument has no overloaded magic at
>  /usr/lib/perl5/5.8.8/File/Copy.pm line 76, <BASH_HISTORY> line 18151.
>
> ------- 8< snip ---------- 8< snip ---------- 8<snip -------
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> # my $BashHistory = "$ENV{'HOME'}/.bash_history";
> my $BashHistory = "./bash_history";
> my $data = '';
> my %data;
> my $ext = '.tmp';
> ## Creat an honest to goodness random tmp file name


> require File::Temp;
> use File::Temp ();

Does this refer to the standard module or something else. If you are
(and I hope you are) using the standard File::Temp module then
substitute this:

> require File::Temp;
> use File::Temp ();

for this:

use File::Temp qw/ tempfile/;



>
> # [HP 101709_220324  Unlink is set to 1 by default .. that
> # means it will be unlinked when the object goes out of scope
> # so setting it to 0 means I have to delete (unlink) it manually
> my $tmpfile = new File::Temp( UNLINK => 0, SUFFIX => '.tmp' );
>
> open(TMPFILE,">$tmpfile") or die "Can't open $tmpfile: $!";
>
> ## Keep this many lines from being processed, but do include them
> ## in the final file.
> my $KeepLines = 12;
> my $ProcessLines = (count_lines($BashHistory) - $KeepLines);
>
> #####     BEGIN Body     #####     #####     #####
> open(BASH_HISTORY,"<$BashHistory")or die "Can't open $BashHistory: $!";
> while (<BASH_HISTORY>) {
>    chomp;
>  ## Process all but $KeepLines
>  if($. <= $ProcessLines){
>    ## finds unique input lines and prints them to a separate file
>    if ($data{$_}++ == 0) {
>      print TMPFILE $_ . "\n";
>    }
>  }elsif($. > $ProcessLines){
>    print TMPFILE  $_ . "\n";
>  }
> }
> close(TMPFILE);


> use File::Copy;

It might be best to put this at the top of your script with all the
other loadable modules your using.


> print "Copying $BashHistory to ".$BashHistory."-". PaddedDateStr()."\n";
> copy( $BashHistory, $BashHistory . "-" . PaddedDateStr() )
>                or die "Copy failed: $!";


To help narrow down the problem, I would change the above to

my $newname = $BashHistory . "-" . PaddedDateStr();
if (-e $BashHistory) {
    copy($BashHistory, $newname) or die "Can't copy $BashHistory ->
$newname: $!\n";
}
else {
   print "Can't find $BashHistory\n";
}

The error is being reported by File::Copy::copy, so it would be useful
to know that your passing to it as well as ensuring that the file
exists prior to asking for the file to be copied.

I suspect there is some un-foreseen interaction between File::Temp and
File::Copy. I wonder what version of perl you are using.

Hopefully this might provide some clues to what there error stem from.
Dp.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to