Re: rename and move multiple files

2005-10-24 Thread perlwannabe
<>

>>
>> So I suppose I want to do a locate, rename, move.  1)  locate all
>> "output.txt" files on the hard drive; 2) rename each "output.txt" to
>> something unique, and 3) move each renamed file from its original
>> location
>> to a single directory.
>>
>> I have tried a few ways with no success.  Thanks for the help.
>
> UNTESTED (sorry I don't use Windows):
>
>
> my $dir = '/renoutput';
> mkdir $dir or die "mkdir '$dir' $!";
>
> my $count = 1;
>
> for my $file ( glob '/*/output.txt' ) {
> rename $file, "$dir/output" . $count++ . '.txt'
> or die "Cannot rename '$file' to '$dir/output$count.txt' $!";
> }
>
>

ARRG  OMG!!!  I had code that was very close to this... but I was
using the wildcard (*) in an attempt to rename the file.  Basically, where
you have " . . . "$count++ . '.txt' ..." I was using "$count++ .
'outp*.txt'. . ."  When I removed the wildcard, everything worked
perfectly.  I now have a directory named c:/renoutput with 522 files
numbered output1 through output 522.

Thanks a million.  Worked great and my project is close to getting done.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: rename and move multiple files

2005-10-24 Thread perlwannabe
<>

>> So I suppose I want to do a locate, rename, move.  1)  locate all
>> "output.txt" files on the hard drive; 2) rename each "output.txt" to
>> something unique, and 3) move each renamed file from its original
>> location
>> to a single directory.
>>
>> I have tried a few ways with no success.  Thanks for the help.
>>
>
> It's hard to imagine that you spend  multiple days looking at such an
> easy problem and can't come up with a single line of code to show the
> list. To get you started here's a solution of your problem in bash (you
> do have bash installed on your windows box ?)


WOW!  I didn't "show code" because I have about 4 or 5 different concepts
going, none of which worked.  However, I suppose this "easy problem"  was
too complex for my simple mind.  If you look at the archives, you will
notice that I seldom request help, and am always courteous and thankful
for the assistance.  Perhaps with a simple mind comes common courtesy, and
with a complex mind, such as yours, comes demeaning remarks and rampant
superiority.  I'll take the simple mind any day.


>
> Create a test environment:
> [EMAIL PROTECTED]:~/vuilbak$ for i in 1 2 3 4 5 6 7; do mkdir $i; touch
<>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




rename and move multiple files

2005-10-23 Thread perlwannabe
I have a file I download everyday, let's call it "output.txt."  The file
"output.txt" is saved in a directory by date, for example 10012005 (for Oct.
1, 2005).  I have a years worth of output files in my c:\ drive.  Now I have
to rename each output file so that I can copy all of the output to a single
directory.  It's a nightmare to do manually.  I really don't care what the
files are named as long as each file gets a unique name.  Imaging this:

C:\01012005
C:\01022005
C:\01032005
C:\01042005
.. . .

Now, each of those directories has a file in it called "output.txt."  I want
to get everyone of those "output.txt" and copy it to a single directory
(call it c:\renoutput) and each output will have a unique name.  So when I
do a "dir" of C:\RENOUTPUT is looks like:

output1.txt
output2.txt
output3.txt
output4.txt
.. . .

So I suppose I want to do a locate, rename, move.  1)  locate all
"output.txt" files on the hard drive; 2) rename each "output.txt" to
something unique, and 3) move each renamed file from its original location
to a single directory.

I have tried a few ways with no success.  Thanks for the help.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Getting info from website search.

2004-08-20 Thread perlwannabe
OK, I know my subject is not the best, but I couldn't think of anything
better.  Here is my situation:

There is a website that allows you to search a database by Name or Number.
 Once you search by name it will provide all kinds of information
(including dates) for the search parameters.  I want to be able to search
by date, which is not one of the options.

Here is the site:

http://207.156.115.73/patraffic/startsearch.aspx

If you select "Search by Name" it gives you input for a name and both a
start and end date.  I would like to use a wildcard in the name to give me
every person that received a ticket on July 23, 2004.  Any ideas on how to
formulate this in a command line?


I want to be able to find a way to pull all of the tickets issued on a
specific date (i.e. all tickets issued on 8/02/2004) Right now, the search
is useless to me because a date search is not an option eventhough the
date is available in the database.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Terminating script if file does not exist

2004-01-19 Thread perlwannabe
Basically the script runs and looks for a file in a certain directory.  If
the file is there, the script continues to run and process the file, but
if the file is not there the script should just exit.

Any ideas on how to do this?





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: problem with date routine THANKS!!

2003-10-02 Thread perlwannabe
Thank you for all of the responses to my date/time problem.  I have
rewritten the routine with the information and feel confident it is far,
far better than what I had.

Thanks...



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



problem with date routine

2003-10-01 Thread perlwannabe
I have a relatively simple script that needs to get two separate dates,
today's date, and yesterday's date.  The dates are in mmddyy format. 
Everything works great on days 2 - 31 of the month, but on the first of
the month yesterday's date is not correct.  For example, on October 1,
2003 the variable $dateyesterday was "13" when it needed to be 093003.
 Obviously, there is no 13.  Is there a way to deal with this problem
on the first day of every month?

Here is the script:


##  BEGIN SCRIPT  
my ($mday, $mon, $year) = (localtime)[3..5];
my $datetoday = sprintf ("%02d%02d%02d", ++$mon, $mday, $year-100);

print ("the value of datetoday is $datetoday\n");


my ($yesterdaymday, $yesterdaymon, $yesterdayyear) = (localtime)[3..5];
my $dateyesterday = sprintf ("%02d%02d%02d", ++$yesterdaymon,
$yesterdaymday-1, $yesterdayyear-100);
print ("the value of datetoday is $dateyesterday\n");

###  END SCRIPT  #




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Replacing variable data between fields - Revisited.

2003-09-29 Thread perlwannabe
> Perlwannabe wrote:
>>
>> I originally tried to do this, but it won't work.  The data doesn't
>> _always_ have a  before address, sometimes (although seldom) it
>> has a .  With grep I would miss the entire address.  However,
>> if I were to just select everything and replace it with nothing, that
>> would be the answer.  BTW...your solution above is right on the money
>> for about 98% of the file.  However, by simply scanning the line and
>> deleting everything between between HOW and NUMBER: that would give
>> me 100%.  Any ideas?
>
> You could try this:
>
> s/\tHOW.+?\sNUMBER:\s*\S+\t/\t/;

Hah!!! I got it.  FINALLY!!!  Thank you so much for the help.  It was a
simple  matter of using s/// instead of tr///.  I am not sure why, but
it works...The tr/// function does not work at all...Any ideas why?

s{ (?<=HOW) (.+?) (?<=NUMBER\t) } { ( $a = $1 ) =~ s/$a/ /; $a   }ex;




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Replacing variable data between fields - Revisited.

2003-09-28 Thread perlwannabe
> Perlwannabe wrote:
>>
>> I posted a problem to the mailing list with a similar question I had
>> some time ago regarding replacing data between fields.  Unfortunately,
>> I am having a difficult time with the problem.  I am including the
>> code and a sample of the data.  Could someone please give me a clue as
>> to why this is not working.  I have exhausted myself before
>> re-contacting the list.  When I run the code, the file remains exactly
>> the same and nothing is changed or
>> replaced.
>>
>>    BEGIN CODE  ##
>>  #!/usr/bin/perl
>> use warnings;
>> use strict;
>> use LWP::Simple;
>>
>> my $file10 = "C:/Test_Folder/test_data/input.txt";
>> #declare the input
>> file as the static file name
>> open(FILE,"<$file10") || die "Could not open file for reading!
>> $!";#open file for reading
>> open(TEMP,">$file10.tmp") || die "Could not open file for writing!
>> $!";#open file for writing
>> while(){   #begin while
>> s{ (?<=HOW) (.+?) (?=NUMBER:) } { ( $a = $1 ) =~ tr/\t/ /; $a
>>  }ex;
>> print TEMP $_;#print result to temp file
>> }#end while
>> #Close the files.  This should happen automatically, but the routine
>> is written for safety
>> close FILE || die "Could not close file! $!";
>> close TEMP || die "Could not close file! $!";
>> unlink $file10;
>> #remove the old file
>> rename("$file10.tmp",$file10) || die "The file could not be renamed!
>> $!";#rename the temp file to the old file's name
>>
>> #  END CODE #
>>
>> Here is a sample of the data file:
>>
>> Name:John SmithAddress: 1234 Sparrow Ave.HOW MANY
>> CHILDREN: 3NUMBER OF PETS: 2TYPE OF PETS: Fish,
>> DogFAVORITE NUMBER: 13City: New YorkState: New
>> YorkZip: 11011
>>
>> Obviously, I do not want all of the useless information between
>> Address and City.  I want to delete everything between HOW and NUMBER:
>> (including the HOW and NUMBER:)  So my file will look like this:
>>
>> Name:John SmithAddress: 1234 Sparrow Ave.City: New
>> YorkState: New YorkZip: 11011
>
>
> According to your data, this seems to work:
>
> while (  ) {
> print TEMP join '',
> grep /(?:^|\t)(?i:name|address|city|state|zip):/,  # fields to
> keep /(?:^|\t)[^:]+?:\s+[^\t]+/g;   # split
> the fields
> }

I originally tried to do this, but it won't work.  The data doesn't
_always_ have a  before address, sometimes (although seldom) it has a
.  With grep I would miss the entire address.  However, if I were
to just select everything and replace it with nothing, that would be the
answer.  BTW...your solution above is right on the money for about 98% of
the file.  However, by simply scanning the line and deleting everything
between between HOW and NUMBER: that would give me 100%.  Any ideas?

BTW...can you see why the original code I posted is not working?






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Replacing variable data between fields - Revisited.

2003-09-27 Thread perlwannabe
I posted a problem to the mailing list with a similar question I had some
time ago regarding replacing data between fields.  Unfortunately, I am
having a difficult time with the problem.  I am including the code and a
sample of the data.  Could someone please give me a clue as to why this is
not working.  I have exhausted myself before re-contacting the list.  When
I run the code, the file remains exactly the same and nothing is changed
or
replaced.

   BEGIN CODE  ##
 #!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;

my $file10 = "C:/Test_Folder/test_data/input.txt";   
#declare the input
file as the static file name
open(FILE,"<$file10") || die "Could not open file for reading!
$!";#open file for reading
open(TEMP,">$file10.tmp") || die "Could not open file for writing!
$!";#open file for writing
while(){   #begin while
s{ (?<=HOW) (.+?) (?=NUMBER:) } { ( $a = $1 ) =~ tr/\t/ /; $a 
 }ex;
print TEMP $_;#print result to temp file
}#end while
#Close the files.  This should happen automatically, but the routine is
written for safety
close FILE || die "Could not close file! $!";
close TEMP || die "Could not close file! $!";
unlink $file10;   
#remove the old file
rename("$file10.tmp",$file10) || die "The file could not be renamed!
$!";#rename the temp file to the old file's name

#  END CODE #


Here is a sample of the data file:

Name:John SmithAddress: 1234 Sparrow Ave.HOW MANY CHILDREN:
3NUMBER OF PETS: 2TYPE OF PETS: Fish, DogFAVORITE NUMBER:
13City: New YorkState: New YorkZip: 11011

Obviously, I do not want all of the useless information between Address
and City.  I want to delete everything between HOW and NUMBER: (including
the HOW and NUMBER:)  So my file will look like this:

Name:John SmithAddress: 1234 Sparrow Ave.City: New
YorkState: New YorkZip: 11011



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Replacing variable data between fields

2003-09-09 Thread perlwannabe
> On Tuesday, September 9, 2003, at 08:58  PM, perlwannabe wrote:
>


>> I know it involves using the s/// operator to both strip the tabs and
>> replace with  but the problem is that it requires using an array
>> for
>> each address...and that is what is creating problems for me.
>>
>> Thanks...
>
> Hmm, let me think out loud a little.
>
> I think I see a pattern, so let's first change all of them to spaces.
> That's easy enough:
>
> s/\t/ /g;
>
> Now, if we switch all the spaces that are supposed to be tabs to tabs,
> we're done, right.  I bet we can handle that.  What about:
>
> s/ ([A-Za-z]:) /\t$1\t/g;
> # and...
> s/^([A-Za-z]:) /$1\t/;# The first one is a special case
>
> # or, most complex...
>
> s/(^| )([A-Za-z]:) / length($1) ? "\t$1\t" : "$1\t" /eg;
>
> You may have to adjust it a little if any of my assumptions are wrong,
> but it should be close to what you need, I think.  Does that help any?


Yes, but the problem is that there is a mix of numbers and letters in the
address.  There is a response to the list that was right on the money. 
But, your example definitely put me on the right track in dealing with a
more complex s/// operator.  Thanks!




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Replacing variable data between fields

2003-09-09 Thread perlwannabe


>> I know it involves using the s/// operator to both strip the tabs and
>> replace with  but the problem is that it requires using an array
>> for each address...and that is what is creating problems for me.
>
>
> s{ (?<=Address:\t) (.+?) (?=\tCity:) }
>  { ( $a = $1 ) =~ tr/\t/ /; $a   }ex;


WOW!!! Perfect...Thank you.  I went directly to the manual to find out
exactly what everything does.  Magnificent!  I gotta admit, I don't know
what everything does, but it does it well.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Replacing variable data between fields

2003-09-09 Thread perlwannabe
I have a text file that has various addresses in different formats.  I
need to remove any items that are not part of the address so the output is
standard.  Here is an example of the input file:

Address:1234MockingbirdLaneCity:GrotonState:CT
Address:2933HummingbirdSt.City:GrotonState:CT
Address:4321SparrowAve.City:GrotonState:CT
. . .

What I want to do is get all of the data between Address: and City: and
strip the  and replace with spaces.  The only problem is that the
data between Address: and City: changes.  What I want in the end is:

Address:1234MockingbirdLaneCity:GrotonState:CT
Address:2933HummingbirdSt.City:GrotonState:CT
Address:SparrowAve.City:GrotonState:CT

(notice that any  in the address itself is now a  with  both
before and after the address.)

I know it involves using the s/// operator to both strip the tabs and
replace with  but the problem is that it requires using an array for
each address...and that is what is creating problems for me.

Thanks...



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Deleting a line that contains certain text

2003-09-06 Thread perlwannabe
OK, I have a new problem.  I need to delete an entire line that contains
certain text.  I have done an extensive search and had no luck finding an
adequate answer.  Yes, I also saw the FAQ that just refers me to
Tie::file.  The most promising solution was:

perl -ni.bak -e 'print unless /FOO/;' input.txt

but when I run that line from the c:\ I get the following error:

Can't find string terminator "'" anywhere before EOF at -e line 1.

Also, I would like to run this from within a script instead of from the
command line.

BTW...using PERL 5.8.0 on Windows2000 Pro



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: search replace

2003-09-06 Thread perlwannabe
> Hi ,
>
> How do I search replace text in a file from a perl script. i.e. by
> opening the file in write mode and then do a search replace.
>
> I don't want to do a command line search replace.

Use the s/// operator...as follows:

$_ =~ s/oldtext/newtext/gi;

this will replace all occurrences of "oldtext" with "newtext".

You should visit the perlfunc at perl.com to get all of the variables and
syntax of s///

HTH

Perlwannabe



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



How to replace variable spaces with a tab - Please Help

2003-09-06 Thread perlwannabe
I have a text file that is a mess.  It contains various fields with lots
of spaces between the fields.  The amount of spaces differs from field to
field.  Here is a sample of the file:

<8sp>NAME:<13sp>JOHN
SMITH<22sp>RANK:<3sp>CAPTAIN<15sp>WIFE:<6sp>POCAHONTAS...

What I would like to have after processing the file is a tab delimited
file like:

NAME:JOHN SMITHRANK:CAPTAINWIFE:POCAHONTAS...

I have been experimenting with the s/// and had some success.  The only
problem is that I have about 30 of the s/// statements to try and deal
with all of the  in the file.  I know this is not efficient.

What I want to do is replace any repeating spaces (two or more) with a
tab.  I know the examples below do not work but am just giving it as
"pseudocode" of replacing repeating spaces (between 2 and 50) with a tab:

s/[2..50]/\t/gi;

or maybe hex value (hex 20 is the space character)

s/\x20[2..50]/\t/gi;

Thanks.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



How to download a .pdf file from a website

2003-08-25 Thread perlwannabe
There is a .pdf file on a website that I would like to download on a daily
basis.  The site puts up a new .pdf file everyday and I would like to
write a simple script to download the file to my computer.

The URL basically adds the name of the file with the date, i.e.

http://www.samplesite.com/files/August23.pdf

all I want to do is get the file.  Obviously the .pdf will change to
August24.pdf on the 24th.  I looked all over and the stuff available looks
way to sophisticated for what I want (i.e. mywebget).  I just want a
simple script to download the file.

Seems easy enough, but tough to find information on how to do it.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Still need unlink help!! God help me. - Revisited

2003-08-14 Thread perlwannabe
> This works - i've tried it...
>
> print 'Deleted ' , unlink (<*997*>) , ' files.\n';
>
> good luck
> Duncan

Yes, it does.  But it does not work when reading from a variable.

my $temp = '*997*';
print 'Deleted ' , unlink (<$temp>) , ' files.\n';

This very simple variation of your example does not work.

The problem is that I have to read from a file and put the value from the
file into a variable.  Although your "hard coded" example does work, it
doesn't work for a value read in from an external file and into a
variable.  Any other ideas?  I am all ears and out of ideas.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Help with Unlink please

2003-08-14 Thread perlwannabe
> Steve Grazzini wrote at Wed, 06 Aug 2003 23:38:00 -0400:
>
>> On Wed, Aug 06, 2003 at 11:49:20PM -0400, perlwannabe wrote:
>>> I have made the script as simple as possible and cannot get
>>> unlink to work.
>>>
>>> unlink ("c:\testdir\*030977*.*") || die "unlink failed: $!";
>>
>> You'd need to expand the wildcards yourself:
>>
>>   my $pat = 'c:\testdir\*030977*.*';
>>   foreach (glob($pat)) {
>>   unlink or warn "Couldn't unlink '$_': $!";
>>   }
>
> Or if you want to write it as a one liner,
> you can exploit that unlink also takes a list as its arguments:
>
> unlink glob "c:/testdir/*030977*.*" or die "No files unlinked: $!";

Neither of these worked.  I am beginning to think that there is something
wrong with ActivePerl and WinXP.

Try this.  Make a sample text file named "testfile.txt" and put it in
directory "c:\testdir\"

then try this script...don't add anything like use File::glob and see if
it works:

my $test = ("c:\\testdir\\testfile.txt");
unlink glob ($test) || die "unlink failed: $!";

This simple little script does not delete testfile.txt from my machine.  Why?



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Still need unlink help!! God help me.

2003-08-14 Thread perlwannabe

>>
>> The directory c:/testdir/ contains many files, but I want to delete
>> the files with any *item###*.* from the directory.  So if the
>> directory has 3000 files I want to delete every file that has item997
>> in it.
>>
>
> glob returns the relative path of the files so if you are in a
> different
>  directory (other than c:/testdir) executing the script, it will not
> find  the files. try fully qualify the path:
>
> #!/usr/bin/perl -w
> use strict;
>
> open(FH,"listitems.txt") || die $!;
> unlink map{chomp; glob "c:/testdir/*$_*.*" }  or die $!;
> close(FH);
>
> __END__
>
> or:
>
> [x]$ perl -lne 'unlink glob "c:/testdir/*$_*.*" or die $!'
> listitems.txt

This suggestion returned the error:

Died at testscript.pl line 4,  line 15.

I tried both the suggested methods without success. But, I mightuv found a
problem.  I tried all of these methods with no success and looked at the
input file "listitems.txt" and found something interesting when using a
hexeditor.  Each line ends with 0D0A, so in a hex editor the previous file
looks like:

item9970D0Aitem9960D0Aitem9990D0Aitem9830D0A

but when I look at the file with notepad it looks like:

item997
item996
item999
item983

Could this be the culprit?



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Still need unlink help!! God help me.

2003-08-14 Thread perlwannabe
Still having problem with unlink.  My original problem began with deleting
files from a list.  I seem to have fixed the problem reading the list but
the unlink does not work.

Here is the test script that I am working from:

my $file = 'listitems.txt';
open my $fh, $file or die "Cannot open $file: $!";
while($Line = <$fh>) {
chomp($Line);
my $del = "*$Line*.*";
my $complete = "c:/testdir/$del";
unlink glob $complete or die "unlink failed: $!";
}

A sample of the contents of the 'listitems.txt' file is:

item997
item996
item999
item983


The directory c:/testdir/ contains many files, but I want to delete the
files with any *item###*.* from the directory.  So if the directory has
3000 files I want to delete every file that has item997 in it.

So file "testitem997document.txt" will be deleted as well as
"real1tem997file.doc" as well as "killitem983.txt.doc".

The sample script I posted aboveis returning the following error:
unlink failed:  at testscript.pl line 7, <$fh> line 1.

Working in Windows XP and ActivePerl 5.8.0.  BTW...this is perl.beginners
so be kind and understanding. :-)



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Still need unlink help!! God help me.

2003-08-14 Thread perlwannabe
> On Fri, 8 Aug 2003 22:16:38 -0400 (EDT), perlwannabe wrote:
>> I tried both the suggested methods without success. But, I mightuv
>> found a problem.  I tried all of these methods with no success and
>> looked at the input file "listitems.txt" and found something
>> interesting when using a hexeditor.  Each line ends with 0D0A, so in a
>> hex editor the previous file looks like:
> okay... in ascii the hex of 0d0a works out to character #13 and #10
> which works out to CR and LF.
>
> CRLF is the normal Carriage Return Linefeed that is used to separate
> lines on windows.
>
> It seems that everybody here pointed you into the right direction...
> but there seems to be something else wrong than the provided code (or
> your code for that matter). It seems that the data you use is the
> problem.
>
> To really find out what the problem is... you need to learn how to
> debug your code. A starting point would be:
>
>   perldoc perldebtut
> or
>   perldoc perldebug
>
> you should type that on the dos/command prompt in windows.
>
> Add the following lines to your program under the perl location line:
>
>   use warnings;
>   use diagnostics;
>   use strict;
>
> It will check automatically for stractural errors that are often made
> and will give you (hopefully) meaningful error/warning messages.
>
> Another thing to do is to print everything to the screen.
>
> You define a variable? Print it.
> You use a variable? Print it before it's use and after it's use.
>
> BTW. Write at first in PSEUDOCODE and than translate it into perl. (I
> will add comments instead)
>


Oliver,  thank you for the response.  I did indeed comment every single
variable, but deleted it from my sample script for simplicity.  I have
been wrestling with this problem for a while.  I did run your code and got
the following error:

C:\testdir>perl testfile.pl
listitems.txt
item997
*item997*.*
c:/testdir/*item997*.*
Uncaught exception from user code:
unlink failed:  at testfile.pl line 27,  line 1.


You mention a "perl location line"  what is that?  Is there something I
have to declare for the program to work?  I read something about
File::glob but I don't think that has anything to do with it.

BTW...I have also hard coded the location as follows:

$location = 'c:/testdir/*item997*.*';
unlink glob $location;

THIS WORKS!!! That is why this stupid problem is killing me.  I can write
a script that will get me the location 'c:/testdir/*item997*.*' by using
variables, but when I try to unlink the program bombs.  You can see by the
printout of your script that it is indeed returning
"c:/testdir/*item997*.*" for your variable $complete, but for whatever
reason, it won't unlink $complete.  It doesn't even continue to process
the remaining lines in the file, it bombs after reading the first line of
'listitems.txt'



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Help with Unlink please

2003-08-14 Thread perlwannabe
I am still struggling through the problem I was having earlier.  However,
I am a great deal further.  I cannot seem to get unlink to delete the
files from the directory.  I have made the script as simple as possible
and cannot get unlink to work.

unlink ("c:\testdir\*030977*.*") || die "unlink failed: $!";

returns an error of

unlink failed: No such file or directory at testunlink.pl line 3.

I know there is a file in the directory named "culinary_file_17030977_work"

I have even simplified further using a file "test.txt" and using

unlink ("test.txt");  this also failed.

I can use "del c:\testdir\*030977*.*" from the command line and the file
is deleted.

I am using Windows XP and ActivePerl 5.8.0.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Still need unlink help!! God help me. - Revisited

2003-08-14 Thread perlwannabe
In my zeal for making things simple I may have created a problem.  OK,
here is the lowdown:

the real file names I am trying to delete from the directory are rather
lengthy and complicated and look like:

partial_qn_ri_pub_default_asp__Online_qdisp_bn_03042997-0-0
partial_qn_ri_pub_default_asp__Online_qdisp_bn_03042995-0-0
partial_qn_ri_pub_default_asp__Online_qdisp_bn_03042882-0-0
. . .

I cut the names down in my previous posts to 'item997' for ease and
simplicity, this was a mistake on my part as I am a true "beginner."  It
appears that unlink does not like something in the real file name and is
having trouble deleting such a long file name.

If I drop to command prompt and type "del *997*.* the file
"partial_qn_ri_pub_default_asp__Online_qdisp_bn_03042997-0-0" is deleted. 
So I tried to use the unlink and it did not work.  However, I then renamed
the lengthy file name to "5item997.txt" and used the unlink to "*997*.*"
AND IT WORKED!!!

This means that there is something with the original filename (the really
long one) that the unlink command does not like...perhaps the length, or
the underscores, or the - (dashes), etc.

Sorry for the problem.  All of the previous responses worked and everyone
was helpful.  My description was lacking...a mistake I will not make
again.

Is there some magical command that unlink needs to delete such a long file
name?  Are there characters in the filename that is giving unlink a
problem?
Man, I am so close I can taste it.  Again, thank you for all of your help.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



How to replace a long string in a text file?

2003-08-12 Thread perlwannabe
Now that I have, with all of you helping, dealt with the unlink problem. 
I am now faced with a new problem.

I have a file, myfile.txt, that consists of various text items that are
repetitive.  I am trying to replace many of the repetitive items with a
place holder. Here is an example of myfile.txt:

This is a long file with sentences, paragraphs and returns.  Certain
portions of the file never change and are simply repetitive.  I would like
to replace all of the repetitive items with a placeholder...call it
placey."
_END FILE_

I would like to replace "This ... items" with "placey" so the above would
look like:

placey with a placeholder...call it "placey."

When attacking this problem I thought it would be best to use hex values
so as not to deal with returns, etc.  myfile.txt in hex is:

54 68 69 73 20 69 73 20 61 20 6C 6F 6E 67 20 66 69 6C 65 20 77 69 74 68 20
73 65 6E 74 65 6E 63 65 73 2C 20 70 61 72 61 67 72 61 70 68 73 20 61 6E 64
20 72 65 74 75 72 6E 73 2E 20 20 43 65 72 74 61 69 6E 20 70 6F 72 74 69 6F
6E 73 0D 0A 6F 66 20 74 68 65 20 66 69 6C 65 20 6E 65 76 65 72 20 63 68 61
6E 67 65 20 61 6E 64 20 61 72 65 20 73 69 6D 70 6C 79 20 72 65 70 65 74 69
74 69 76 65 2E 20 20 49 20 77 6F 75 6C 64 20 6C 69 6B 65 20 74 6F 20 72 65
70 6C 61 63 65 20 61 6C 6C 0D 0A 6F 66 20 74 68 65 20 72 65 70 65 74 69 74
69 76 65 20 69 74 65 6D 73 20 77 69 74 68 20 61 20 70 6C 61 63 65 68 6F 6C
64 65 72 2E 2E 2E 63 61 6C 6C 20 69 74 20 22 70 6C 61 63 65 79 2E 22

Here is the little script that I am working with and, obviously, is not
working:

my $filefirst = "c:/perl/myfile.txt";
open(FILE,"<$filefirst") || die "Could not open file for reading!  $!";
open(TEMP,">$filefirst.tmp") || die "Could not open file for writing!  $!";
# I have used the . . . to show that the entire hex string is really there
my $hextostr = '\x54\x68\x69\x73 . . . \x79\x2E\x22';
while(){
   $_ =~ s/$hextostr/placey/gi;
   print TEMP $_;
}


Perhaps I am attacking this problem wrong by using hex, but it seems
easier to use then text which has carriage returns, tabs, and spaces.

I hope this explains the situation.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Still need unlink help!! God help me. - THANK YOU!!

2003-08-11 Thread perlwannabe
To all of you who helped me with my unlink problem...THANK YOU!!!

I finally figured out that the problem was the input file.  There was an
extended ASCII character at the beginning of the file that could not be
seen until I looked at it with a hex editor.

I am learning the hard way.  But now the darn thing is finally working.

Again, Thank you all.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



deleting files from the directory from a file list. Please Help!

2003-07-25 Thread perlwannabe
Here is my problem.  I want to delete the files contained in a directory
from a list contained in a file.  Here is an example:

The input file is a regular text file in the following format (call it
myfile.txt);

item1
item2
item3
item4


What I want to do is look in a directory and delete any file in the
directory that contains any item on the list.  For example, lets say the
contents of the directory looks like this:

07/24/2003  01:27 AM 3,812 heresanitem1
07/24/2003  10:42 PM   912,126 heretoitem2
07/14/2003  12:19 AM   234 item3ishere
06/12/2003  10:25 PM34,049 leavemealone
06/12/2003  10:25 PM16,683 leavemealonetoo
07/22/2003  11:36 PM 1,825 yupitem4yup


I would like to read each line of the file from "myfile.txt" [getline() I
suppose] and then delete the files that have ANY MATCHING information from
the input file.  So if the input file has "item1" it will delete the file
"heresanitem1" as well as "alsoitem1aswell" from the directory.  So when I
run the script the sample directory above will look like this:

06/12/2003  10:25 PM34,049 leavemealone
06/12/2003  10:25 PM16,683 leavemealonetoo


This problem has been tough for me.  I have read everything I can get my
hands on concerning unlink but I cannot get this problem solved.  Any help
appreciated.







-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]