Listing a Windows file, getting creation date

2005-02-24 Thread Bret Goodfellow
Hi all,
 
I am very new to Perl.  I have had assembler and Rexx experience on a
mainframe. I would like to be able to use Perl to list a directory, get
the propeties of the files (eg. date created), and keep the newest 3.
The reason I want to do this is because I am running a UDB system that
creates weekly backups.  The backups never get deleted unless I do that
by hand.  I would like to keep the 3 newest UDB backups.  Any help, in
any direction, would be greatly appreciated.  Once I get started on
this, I think perl will make more sense to me.
 
The directory structure is:
 
UDB
   Backups
  Folder1
 udbbck01.bak
  Folder2
 udbbck02.bak
  Folder3
 udbbck03.bak
  |
  |
  |
  Folder(n-1)
  udbbck(n-1).bak
  Folder(n)
  udbbck(n).bak
 
Bret Goodfellow
Questar Gas,
S.L.C.,  UT


Perl error --> Global symbol requires...

2005-02-25 Thread Bret Goodfellow
I'm getting the following error in my code.  If I define $i as my $i
then everything works fine.  What's wrong?
 
# while1.pl
use strict ;
use warnings ;
 
$i = 1;
 
while ($i < 10) {
 print "I am at $i\n";
 i++;
}
# while1.pl
 
 
 
Global symbol "$i" requires explicit package name at
C:\BegPerl\while1.pl line 6


Any ideas on 'uninitialized value in lenth'?

2005-03-03 Thread Bret Goodfellow
Here's a simple perl script where I am listing out the contents of a
directory.  When it completes, the following error occurs.  How do I
eliminate this?
 
Use of uninitialized value in length at C:\BegPerl\deldir.pl line 23.
 
Below is the script:
 
#!/usr/bin/perl
# Dsrch1.plx
# use strict ;
use warnings ;
 
$directory = $ARGV[0]; 
 
opendir(DIR, $directory) or die "Can't open $directory\n" ;
$direntry = readdir(DIR);
 ($mtime) = stat($direntry);
###
# read entire directory contents and print out#
###
while (length($direntry) > 0) {
 
 print "$direntry - modify date: $mtime\n" ;
 $direntry = readdir(DIR);
}
 
closedir(DIR);


Invalid data-time stamps

2005-03-07 Thread Bret Goodfellow
Hi all,
 
I am attempting to list out the contents of a directory, and print the
last time accessed.  The data-time is not correct though.  I am running
this code on a Windows XP workstation.  There doesn't seem to be a real
easy way to get the timestamps of directories.  H   Here is the
code:
 
# deldir4.pl
use strict;
# use warnings;
use File::Find;
 
my $DIRHANDLE;
my $file;
my $write_secs;
 
opendir $DIRHANDLE, "$ARGV[0]" or die "Can't open directory handle: $!";
 
 while ($file = readdir $DIRHANDLE) {
  $write_secs = (stat($file))[9];
  printf "file %s updated at %s\n", $file,
 scalar localtime($write_secs);
  } 
 
closedir $DIRHANDLE;
 
I get the following output:
 
C:\BegPerl>deldir4.pl c:\db2_backup\udbt.0\db2\node\catn
file . updated at Wed Dec  1 10:53:32 2004
file .. updated at Tue Jan  1 00:00:00 1980
file 20050204 updated at Wed Dec 31 17:00:00 1969
file 20050228 updated at Wed Dec 31 17:00:00 1969
file 20050301 updated at Wed Dec 31 17:00:00 1969
file 20050302 updated at Wed Dec 31 17:00:00 1969
file 20050304 updated at Wed Dec 31 17:00:00 1969
file dir.lst updated at Wed Dec 31 17:00:00 1969
file march.txt updated at Wed Dec 31 17:00:00 1969
 
C:\BegPerl>
 


Testing for a '\' in a string

2005-03-09 Thread Bret Goodfellow
Hi all,
 
I am trying to evaluate a string, and determine if the last charater of
the string has a backslash '\' .  The piece of code I am using doesn't
appear to work.  What I've found with this peice of code is that if the
string does contain a \, then the following code still adds another
slash.  If there is not backslash in the string, the the code appears to
work fine by adding a backslash.  Any ideas?
 
   print "Deleting old directory $dir_no: $Dir_name\n";
   $arg_length = length($ARGV[0]);
   $arg_lastchar = substr($ARGV[0], $arg_length-1, 1);
   print "last char is: $arg_lastchar\n";
   
   # add a \ if one was not present in argument   #
   
if ($arg_lastchar ne '\\' or $arg_lastchar ne '/') {
$Dir_name = '\\' . $Dir_name;
print "Adding \\ to: $Dir_name\n";
   }


Why am I getting data from Current Directory?

2005-03-11 Thread Bret Goodfellow
I am writing a script to list out a directory's contents, showing the
number of days since modified.  The problem I am having is that the
script doesn't list out the "modified time" unless I change to the
directory being listed.  If I change to the directory I want to list,
then all works okay.  Is there a way to fix this script so that I don't
have to run the script from the current directory?
 
use strict;
use warnings;
use File::find;
use File::stat;
 
my $arg_length;
my $arg_lastchar;
my $arg_string;
my $Len;
 
$arg_length = length($ARGV[0]);
$arg_lastchar = substr($ARGV[0], $arg_length-1, 1);
$arg_string = $ARGV[0];
 
print "Argument: $arg_string\n";
print "length: $arg_length\n";
print "last character: $arg_lastchar\n";
 
print "Contents of $arg_string\n";
opendir DH, $arg_string or die "Couldn't open directory: $arg_string
$!";
 

#
# Read one file at a time into $_
#

#
while ($_ = readdir(DH)) {
 next if $_ eq "." or $_ eq "..";
 next if -d $_ ;
#
# append upto 30 blanks after the file name #
#
 print $_, " " x (30-length($_)); 
 print " age of file: ";  # age of file
 
 $Len = index(-M $_, ".");
 
 print substr(-M $_, 1, $Len-1);
 print "\n";
}



RE: Why am I getting data from Current Directory?

2005-03-11 Thread Bret Goodfellow
The File::Find::name didn't seem to make any difference.  I still have
to be in the directory that I want to search. Hmmm.

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, March 11, 2005 3:13 PM
To: Bret Goodfellow; beginners@perl.org
Subject: RE: Why am I getting data from Current Directory?


Bret Goodfellow wrote:
> I am writing a script to list out a directory's contents, showing the 
> number of days since modified.  The problem I am having is that the 
> script doesn't list out the "modified time" unless I change to the 
> directory being listed.  If I change to the directory I want to list, 
> then all works okay.  Is there a way to fix this script so that I 
> don't have to run the script from the current directory?
> 
> use strict;
> use warnings;
> use File::find;
> use File::stat;
> 
> my $arg_length;
> my $arg_lastchar;
> my $arg_string;
> my $Len;
> 
> $arg_length = length($ARGV[0]);
> $arg_lastchar = substr($ARGV[0], $arg_length-1, 1); $arg_string = 
> $ARGV[0];
> 
> print "Argument: $arg_string\n";
> print "length: $arg_length\n";
> print "last character: $arg_lastchar\n";
> 
> print "Contents of $arg_string\n";
> opendir DH, $arg_string or die "Couldn't open directory: $arg_string 
> $!";
> 
> ##
> ##
> #
> # Read one file at a time into $_
> #
>

> #
> while ($_ = readdir(DH)) {
>  next if $_ eq "." or $_ eq "..";
>  next if -d $_ ;
> #
> # append upto 30 blanks after the file name #
> #
>  print $_, " " x (30-length($_));
>  print " age of file: ";  # age of file
> 
>  $Len = index(-M $_, ".");
Change the $_ to $File::Find::name ( Fully qualified name of
file ) Is in the doc. Wags ;)
> 
>  print substr(-M $_, 1, $Len-1);
>  print "\n";
> }



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Passing command line arguments

2005-04-13 Thread Bret Goodfellow
I have a script that is reading input from ARGV.  The script is being
passed a file name as follows:
 
datefile.pl c:\program files\IBM\SQLLIB\DB2\db2diag.log
 
The problem I am running into is that the space is not recognized in the
argument.  All that I get passed to is is c:\program.  How do I get
the rest of the argument.  Below is a portion of the script.  Thanks.
 
 #***
 # check input parameter*
 #***
 $arg_length = length($ARGV[0]);
 $arg_lastchar = substr($ARGV[0], $arg_length-1, 1);
 $arg_string = $ARGV[0] ;
 print "Parameter argument is: $arg_string \n";



host id

2005-06-09 Thread Bret Goodfellow
Simple question to answer, I hope. I am running on an HP-UX system, and
would like to retrive the UNIX system's host-id (name of box). Is there
a function to do this?



finding needle in a haystack

2005-06-22 Thread Bret Goodfellow
All right, I know how to do this in REXX because there is a word()
function, but how do I do this in Perl.  I want to read in one record at
a time, that has space-delimited fields.  There may be multiple spaces
between the words.  I want to be able to get for example, the 4th word
of the record.  How do I do this?  Just for grins, my record looks like
this:
 
/dev/sun11/lvol13   1032192  377921  613445   38% /techsupp
 
 


RE: finding needle in a haystack

2005-06-22 Thread Bret Goodfellow


-Original Message-
From: Chris Devers [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 22, 2005 3:17 PM
To: Bret Goodfellow
Cc: Perl Beginners List
Subject: Re: finding needle in a haystack


On Wed, 22 Jun 2005, Bret Goodfellow wrote:

> All right, I know how to do this in REXX because there is a word() 
> function, but how do I do this in Perl.

The split() function is what you're looking for.

$ perldoc -f split

The perldoc gives this example:

A pattern matching the null string (not to be confused with a
null pattern "//", which is just one member of the set of pat-
terns matching a null string) will split the value of EXPR into
separate characters at each point it matches that way.  For
example:

print join(':', split(/ */, 'hi there'));

produces the output 'h:i:t:h:e:r:e'.

It shouldn't be hard to adapt this example to your needs.



-- 
Chris Devers

Thanks Chris,

This is what I actually did to resolve my issue:

@words = split(/ * /, $line)
Print "the third word is: $words[2]\n";

Bret Goodfellow



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Can't locate object method "driver"

2006-10-13 Thread Bret Goodfellow
I have implemented Nagios, and wanted to run this perl script to
interrogate my Oracle systems.  This really isn't a coding question, but
rather a setup or execution question.  I would like to understand why I
am getting the following error when I run check_oracle_instance.pl
natively from the linux shell:
 
serv:~ > ./check_oracle_instance.pl -u nagios -p password -c mwm -t
51/55
DBD::Oracle initialisation failed: Can't locate object method "driver"
via package "DBD::Oracle" at
/usr/lib/perl5/vendor_perl/5.8.3/x86_64-linux-thread-multi/DBI.pm line
731.
 
Perhaps the capitalisation of DBD 'Oracle' isn't right. at
./check_oracle_instance.pl line 157
serv:~ >
 
I'm sure some perl guru knows exactly what is wrong here, and could
point me in the right direction.
 
Cheers


How do I truncate or remove a trailing character

2007-08-01 Thread Bret Goodfellow
Okay, I know this has to be simple, but because I am trying to truncate
or remove a special character I've run into a roadblock.  Here's what I
want to do.  
 
$value = "12345)" ;
 
How do I change $value so that the trailing ")" is removed.  In
otherwords with the given example, how do I manipulate $value so that
its value is "12345"?  Please keep in mind that $value may be variable
in length, so I can't use substr($value, 0, 5).  Can split be used to do
this?  Stumped.