Re: unlink help.

2003-10-29 Thread Anthony Saffer
Sara,

You're unlink() statement is correct and should work fine. What errors, if
any, are you getting?

Anthony

- Original Message -
From: Sara [EMAIL PROTECTED]
To: beginners-cgi [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Wednesday, October 29, 2003 12:44 PM
Subject: unlink help.


unlink *.bak;

how I am supposed to specify directory above?

for example I have to apply above unlink command to delete all backup files
in the Specified directory.

$dir = /home/path/to/dir

is it right?

unlink $dir/*.bak;

??

Any ideas?

Thanks,

Sara.



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



Question about Error

2002-09-18 Thread Anthony Saffer

Good Morning Everyone,

Got another question: I wrote my first Perl script last night and it seemed to be 
error free on Windows. But when I uploaded it to Linux (RH 7.3) it threw an error that 
I don't understand. From a Google search it seems there could be a number of problems 
and I am not experience enough to know which. The error I am getting is:

Nested quantifiers before HERE mark in  then it gives my regular expression 
followed by the first line of the file.

I THOUGHT this code was right. But obviously it isn't. Can someone tell me why line 29 
would be throwing this error or WHAT the error means? The entire code is below. Thanks 
again for all the help. This list has been a lifesaver.

Anthony

CODE:

my $PNdString = ;

sub process_files{
 open(FH,  $_) or die(Error! Couldn't open $_ for reading!! Program aborting.\n);
 open(MTH,  /home/losttre/sorted.txt) or die(Error! Couldn't open $MTH for 
reading!\n);
 open(OUTFILE,  temp.dat) or die (Couldn't open temp file! Aborting\n);
 
 MTH = MTH;
 fcontents = FH;
 
 foreach $matchitem (MTH){
  foreach $litem (fcontents){
   if($litem, /$matchitem/){
$PNdString =~ m/$litem/$matchitem/i;
print (OUTFILE $PNdString\n);
   }
   else{
print(OUTFILE $litem\n);
   }
  }

 } 
print Done\n;
}

find(\process_files, ARGV);




Re: Question about Error

2002-09-18 Thread Anthony Saffer

Apparantly not.
What the 'if' statement was SUPPOSED to do is to check if it had found a hit
and, if it did, replace the string. If it didn't, it is simply supposed to
write the line out to the temp file and move on. That is obviously NOT what
it is doing it seems. How would YOU structure this statement? Also, what
tool are you using to evaluate the code? I'm using Visual SlickEdit but it
would be nice to be able to do something like what you just did.

Thanks!
Anthony

- Original Message -
From: Nikola Janceski [EMAIL PROTECTED]
To: 'Anthony Saffer' [EMAIL PROTECTED]; Perl Beginners List
[EMAIL PROTECTED]
Sent: Wednesday, September 18, 2002 8:04 AM
Subject: RE: Question about Error


 Are you sure you know what this 'if' statement is doing?
 It always evaluates true. and the m/$litem/$matchitem/i shouldn't be in
 quotes.

 if($litem, /$matchitem/){  ## always true
  $PNdString =~ m/$litem/$matchitem/i;  ## not a pattern match if
it's
 in quotes
  print (OUTFILE $PNdString\n);
 }
 else{
  print(OUTFILE $litem\n);
 }

  -Original Message-
  From: Anthony Saffer [mailto:[EMAIL PROTECTED]]
  Sent: Wednesday, September 18, 2002 9:04 AM
  To: Perl Beginners List
  Subject: Question about Error
 
 
  Good Morning Everyone,
 
  Got another question: I wrote my first Perl script last night
  and it seemed to be error free on Windows. But when I
  uploaded it to Linux (RH 7.3) it threw an error that I don't
  understand. From a Google search it seems there could be a
  number of problems and I am not experience enough to know
  which. The error I am getting is:
 
  Nested quantifiers before HERE mark in  then it gives my
  regular expression followed by the first line of the file.
 
  I THOUGHT this code was right. But obviously it isn't. Can
  someone tell me why line 29 would be throwing this error or
  WHAT the error means? The entire code is below. Thanks again
  for all the help. This list has been a lifesaver.
 
  Anthony
 
  CODE:
 
  my $PNdString = ;
 
  sub process_files{
   open(FH,  $_) or die(Error! Couldn't open $_ for
  reading!! Program aborting.\n);
   open(MTH,  /home/losttre/sorted.txt) or die(Error!
  Couldn't open $MTH for reading!\n);
   open(OUTFILE,  temp.dat) or die (Couldn't open temp
  file! Aborting\n);
 
   @MTH = MTH;
   @fcontents = FH;
 
   foreach $matchitem (@MTH){
foreach $litem (@fcontents){
 if($litem, /$matchitem/){
  $PNdString =~ m/$litem/$matchitem/i;
  print (OUTFILE $PNdString\n);
 }
 else{
  print(OUTFILE $litem\n);
 }
}
 
   }
  print Done\n;
  }
 
  find(\process_files, @ARGV);
 
 

 --
--
 
 The views and opinions expressed in this email message are the sender's
 own, and do not necessarily represent the views and opinions of Summit
 Systems Inc.


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




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




Fully Commented Code..

2002-09-18 Thread Anthony Saffer

Hello Again All,

Perhaps if you all saw my logic during this script it would help you understand what I 
am trying to do and maybe see a bit better what is failing. Here is my code again, but 
fully commented...

Thanks!
Anthony

my $PNdString = ; # Setting it to blank

sub process_files{
   # First, I am opening all of my files
 open(FH,  $_) or die(Error! Couldn't open $_ for reading!! Program aborting.\n);
 open(MTH,  /home/losttre/sorted.txt) or die(Error! Couldn't open $MTH for 
reading!\n);
 open(OUTFILE,  temp.dat) or die (Couldn't open temp file! Aborting\n);
 
 MTH = MTH; #Assign the contents of sorted.txt to an array
 fcontents = FH; #Assign the contents of the $_ to an array (a dynamic filename)
 
# The two foreach loops below are for matching. I am wanting to pattern match
# every single element in FH to every single line in MTH. So if my MTH file has
# 3000 lines and my FH files 5000 every line in FH will be evaluated 3000 
times.

foreach $matchitem (MTH){ 
  foreach $litem (fcontents){
   if($litem, /$matchitem/){ # is there a match in this line?
$PNdString =~ m/$litem/$matchitem/i; #Yes? Replace!
 print (OUTFILE $PNdString\n); # Write the replace to our temp file
   }
   else{  # No match?
print(OUTFILE $litem\n); # Write the unaltered line to temp
   }
  }

 } 
print Done\n;
}




Final Code (I think it's gonna work!)

2002-09-18 Thread Anthony Saffer

Hello Everyone,

Here is the final code for my replacement script. I am about to test it out but I 
think it will work. Thanks to all who helped!!

#!/usr/bin/perl -w

use File::Find;

my $FileCount = 0;
my $LineCount = 0;

sub process_files {
   my $FinalString = ;
   my $ConvertedText = ;
   my $TotalReplacements = 0;

   open MASTER_FILE, /home/losttre/sorted.txt or die (Can't open file: sorted.txt! 
Aborting!\n);
   open TEMP_FILE,  tempfile or die(Can't open file: TEMPFILE! Aborting!\n);
   open THIS_FILE,  $_ or die(Can't open target file: $_! Aborting!\n);

   MATCH_KEYS= MASTER_FILE;
   MATCH_TARGETS = THIS_FILE;

   foreach $matchkey (MATCH_KEYS) {
  foreach $lineitem (MATCH_TARGETS) {
 if($lineitem =~ m/$matchkey/i){
$ConvertedText = lc($matchkey);
$FinalString = s/$matchkey/$ConvertedText/;
print TEMP_FILE $FinalString\n;
$LineCount++;
$TotalReplacements++
 }
 else{
print TEMP_FILE $lineitem\n;
$LineCount++;
  }
 }
  close(TEMP_FILE);
  close(THIS_FILE);
 # unlink(THIS_FILE)
  #rename(TEMP_FILE, THIS_FILE);
  $FileCount++;
   }
}

print Process starting...\n;
print Cycling through files. This might take some time.\n;
find(\process_files, ARGV);
print DONE!\n;
print FILES PROCESSED: $FileCount\n;
print LINES PROCESSED: $LineCount\n;
print REPLACEMENTS: $TotalReplacements\n;
print Exiting...;





Recognizing Directories...

2002-09-17 Thread Anthony Saffer

Hello Everyone,

I am writing a utility that needs to index the files contained within about 500 
directories (some nested). I want to provide the script with a top directory and have 
it recurse through everything underneath while indexing the files within each. I've 
searched Google and can't seem to find a way to do this. I know how to get all files 
within a directory but how do I RECOGNIZE my directories so I can descend into them to 
index?

Thanks in Advance,
Anthony Saffer



Yet another question...

2002-09-17 Thread Anthony Saffer

Hello Again Everyone,

I do apologize for all the newbie questions but I really have to get this program 
written today and this list is my only live resource besides Google. I'll try to 
keep my questions to a minimum.  But here is one more if you don't mind.

1. How do I ignore case in my program so that if the filename is named 'SUPER.GIF' yet 
it's called as 'super.gif' in my program I can match it?

Thanks in advance,
Anthony





One last question

2002-09-17 Thread Anthony Saffer

Hello AGAIN,

I have one final question that I think will set me free from this coding haze I've 
been in all day. Please look at the code below. Here is the idea I am trying to 
implement:

I have a text file with a list of about 56,000 filenames. Only the filenames are in 
this file.  I have another 30,000 or so .cfm and .htm files. I want to use File::Find 
to cycle through EVERY file in EVERY directory line by line (about 2 million lines in 
all). Evertime it comes across a reference to one of the 56,000 files I have in the 
list in the htm or cfm file it needs to replace it with a lowercase version of it. Not 
touching ANYTHING else.

I know it's going to take regular expressions. This is where I am totally lost. Could 
somone give me some hints. Please don't provide me with ready made code as I won't 
really learn that way. But an idea on what I need to do would be very helpful.

Thanks!
Anthony

CODE BELOW:
#!/usr/bin/perl -w
use strict;
use File::Find;

sub process_files{
 open($FH,  $_) or die(Error! Couldn't open $_ for reading!! Program aborting.\n);
 open($MATCH,  /home/losttre/match.txt) or die(Error! Couldn't open $MATCH for 
reading!\n);
 open($TEMP, ./temp.dat) or die (Couldn't open temp file! Aborting\n);
 
 MATCH = MATCH;
 fcontents = FH;
 
 foreach $lineitem (MATCH){
  foreach $lineitem2 (fcontents){
   if($lineitem == i/$lineitem2/){
#I ASSUME THIS IS WHERE MY MATCH WOULD HAPPEN AND I NEED TO REPLACE THE STRING
}
}

NOTE: Yes, I am aware there are a lot of syntax and other problems with this code. I 
can probably correct those but I am totally lost on the matching.







Thanks!!

2002-09-17 Thread Anthony Saffer

Just wanted to take the time to thank everyone who offered their help to me today in 
response to my silly questions. I leared a LOT about Perl today and the more I learn 
the more I like it.  Thanks again!!

Anthony



Simple one :-)

2002-09-17 Thread Anthony Saffer

print(OUTFILE, $PNdString\n);

This is line #19 in my code. When I run it I am told I cannot have a coma after the 
filehandle. Why not?? I thought this was standard Perl syntax?

Anthony