Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > file access trouble

Reply
Thread Tools

file access trouble

 
 
Chuck
Guest
Posts: n/a
 
      04-07-2004
I am a new user to perl - trying to teach myself enough perl to do a
specific task to be used in conjunction with other software I have
developed.

I am a software developer and use a web site for distribution of the
software. The download folder of this web site uses password protection via
..htpasswd

I created another windows based program that creates the .htpasswd file
locally - each of my software users has their own username and password to
download updates to the software - what I need to do with perl is to loop
through the local .htpasswd file that is created by the other windows app
and crypt() the password. I have already done this by looping through the
local .htpasswd file in my windows based code and copying the password to be
encrypted to the local clipboard on the computer that I use to maintain my
user list. Then I call perl from within my windows based code, get the data
from the clipboard, crypt() the password, and then copy it back to the
clipboard, then get the clipboard data in my windows based code, and update
the local .htpasswd file with the encrypted string for the password. Then
after the process is done I use FTP to upload the .htpasswd file to the
protected folder on the web server. This all works great but I want to loop
through the entire file using perl rather that calling perl for each record
in the file - this is rather slow because perl needs to be loaded for each
record in the local .htpasswd file rather than only loading once.

I have been through several tutorials and did google searches to see if I
could determine why my perl script is not working but could not get it to
work. I ran the script though the perl debugger and made sure there were no
errors in the script that the debugger could find. I am using wperl.exe so
the console window does not show but have also used perl.exe.

I have been working on this for a couple of days but figured that some help
from the perl experts could expedite this for me. Any suggestions or
pointers will be greatly appreciated.

The script runs without any error messages but does not appear to read data
from the already existing .htpasswd file and it does not create the new
..htpasswd2 file that I rename to the original file name after the loop is
finished - this is my script;

use strict;
use warnings;

my $text1;
my $text2;

my $OldFile = "c:\\cwicweb\\exec\\commpay\\shared data\\.htpasswd";
my $NewFile = "c:\\cwicweb\\exec\\commpay\\shared data\\.htpasswd2";

open(OLD, '<', $OldFile) or die "$!\n";
open(NEW, '>', $NewFile) or die "$!\n";

while (<OLD>) {
$text1 = substr($_,0,5);
$text2 = crypt(substr($_,5,,substr($_,13,2));
print NEW "$text1 $text2 /n";
}

close OLD or die "$!\n";
close NEW or die "$!\n";
rename($NewFile,$OldFile) or die "$!\n";

The files do not need to be locked as only one person will be running this
script at any given time.

--

regards,

Chuck
CommPay Software


 
Reply With Quote
 
 
 
 
Tore Aursand
Guest
Posts: n/a
 
      04-07-2004
On Wed, 07 Apr 2004 10:24:19 -0500, Chuck wrote:
> my $text1;
> my $text2;


You don't need these.

> my $OldFile = "c:\\cwicweb\\exec\\commpay\\shared data\\.htpasswd";
> my $NewFile = "c:\\cwicweb\\exec\\commpay\\shared data\\.htpasswd2";


No need for double quotes here. Save yourself trouble by doing this:

my $OldFile = 'c:/cwicweb/exec/company/shared data/.htpasswd';
my $NewFile = 'c:/cwicweb/exec/company/shared data/.htpasswd2';

> while (<OLD>) {
> $text1 = substr($_,0,5);
> $text2 = crypt(substr($_,5,,substr($_,13,2));
> print NEW "$text1 $text2 /n";
> }


Could have been written as:

while ( <OLD> ) {
my $text1 = substr( $_, 0, 5 );
my $text2 = crypt( substr($_, 5, , substr($_, 13, 2) );
print NEW "$text1 $text2 \n";
}

Other than that, I don't see any "errors" in your script. Are you sure
there aren't any error messages?


--
Tore Aursand <>
"A teacher is never a giver of truth - he is a guide, a pointer to the
truth that each student must find for himself. A good teacher is
merely a catalyst." -- Bruce Lee
 
Reply With Quote
 
 
 
 
Bob Walton
Guest
Posts: n/a
 
      04-10-2004
Chuck wrote:

> I am a new user to perl - trying to teach myself enough perl to do a
> specific task to be used in conjunction with other software I have
> developed.
>
> I am a software developer and use a web site for distribution of the
> software. The download folder of this web site uses password protection via
> .htpasswd
>
> I created another windows based program that creates the .htpasswd file
> locally - each of my software users has their own username and password to
> download updates to the software - what I need to do with perl is to loop
> through the local .htpasswd file that is created by the other windows app
> and crypt() the password. I have already done this by looping through the
> local .htpasswd file in my windows based code and copying the password to be
> encrypted to the local clipboard on the computer that I use to maintain my
> user list. Then I call perl from within my windows based code, get the data
> from the clipboard, crypt() the password, and then copy it back to the
> clipboard, then get the clipboard data in my windows based code, and update
> the local .htpasswd file with the encrypted string for the password. Then
> after the process is done I use FTP to upload the .htpasswd file to the
> protected folder on the web server. This all works great but I want to loop
> through the entire file using perl rather that calling perl for each record
> in the file - this is rather slow because perl needs to be loaded for each
> record in the local .htpasswd file rather than only loading once.
>
> I have been through several tutorials and did google searches to see if I
> could determine why my perl script is not working but could not get it to
> work. I ran the script though the perl debugger and made sure there were no
> errors in the script that the debugger could find. I am using wperl.exe so
> the console window does not show but have also used perl.exe.
>
> I have been working on this for a couple of days but figured that some help
> from the perl experts could expedite this for me. Any suggestions or
> pointers will be greatly appreciated.
>
> The script runs without any error messages but does not appear to read data
> from the already existing .htpasswd file and it does not create the new
> .htpasswd2 file that I rename to the original file name after the loop is
> finished - this is my script;
>
> use strict;
> use warnings;
>
> my $text1;
> my $text2;
>
> my $OldFile = "c:\\cwicweb\\exec\\commpay\\shared data\\.htpasswd";
> my $NewFile = "c:\\cwicweb\\exec\\commpay\\shared data\\.htpasswd2";
>
> open(OLD, '<', $OldFile) or die "$!\n";
> open(NEW, '>', $NewFile) or die "$!\n";
>
> while (<OLD>) {
> $text1 = substr($_,0,5);
> $text2 = crypt(substr($_,5,,substr($_,13,2));
> print NEW "$text1 $text2 /n";


\----------------------------^


> }
>
> close OLD or die "$!\n";
> close NEW or die "$!\n";
> rename($NewFile,$OldFile) or die "$!\n";

....

Seems to work OK for me, copied verbatim (AS Perl build 806 on Windoze
98SE). You might want to consider fixing the /n above that looks like
you probably intended a \n.

--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl

 
Reply With Quote
 
Chuck
Guest
Posts: n/a
 
      04-11-2004
Bob,

Tried your suggestion - did not make any difference - my script does not
create the NEW file. Using ActiveState latest version.

--

regards,

Chuck
CommPay Software

"Bob Walton" <invalid-> wrote in message
news:...
> Chuck wrote:
>
> > I am a new user to perl - trying to teach myself enough perl to do a
> > specific task to be used in conjunction with other software I have
> > developed.
> >
> > I am a software developer and use a web site for distribution of the
> > software. The download folder of this web site uses password protection

via
> > .htpasswd
> >
> > I created another windows based program that creates the .htpasswd file
> > locally - each of my software users has their own username and password

to
> > download updates to the software - what I need to do with perl is to

loop
> > through the local .htpasswd file that is created by the other windows

app
> > and crypt() the password. I have already done this by looping through

the
> > local .htpasswd file in my windows based code and copying the password

to be
> > encrypted to the local clipboard on the computer that I use to maintain

my
> > user list. Then I call perl from within my windows based code, get the

data
> > from the clipboard, crypt() the password, and then copy it back to the
> > clipboard, then get the clipboard data in my windows based code, and

update
> > the local .htpasswd file with the encrypted string for the password.

Then
> > after the process is done I use FTP to upload the .htpasswd file to the
> > protected folder on the web server. This all works great but I want to

loop
> > through the entire file using perl rather that calling perl for each

record
> > in the file - this is rather slow because perl needs to be loaded for

each
> > record in the local .htpasswd file rather than only loading once.
> >
> > I have been through several tutorials and did google searches to see if

I
> > could determine why my perl script is not working but could not get it

to
> > work. I ran the script though the perl debugger and made sure there were

no
> > errors in the script that the debugger could find. I am using wperl.exe

so
> > the console window does not show but have also used perl.exe.
> >
> > I have been working on this for a couple of days but figured that some

help
> > from the perl experts could expedite this for me. Any suggestions or
> > pointers will be greatly appreciated.
> >
> > The script runs without any error messages but does not appear to read

data
> > from the already existing .htpasswd file and it does not create the new
> > .htpasswd2 file that I rename to the original file name after the loop

is
> > finished - this is my script;
> >
> > use strict;
> > use warnings;
> >
> > my $text1;
> > my $text2;
> >
> > my $OldFile = "c:\\cwicweb\\exec\\commpay\\shared data\\.htpasswd";
> > my $NewFile = "c:\\cwicweb\\exec\\commpay\\shared data\\.htpasswd2";
> >
> > open(OLD, '<', $OldFile) or die "$!\n";
> > open(NEW, '>', $NewFile) or die "$!\n";
> >
> > while (<OLD>) {
> > $text1 = substr($_,0,5);
> > $text2 = crypt(substr($_,5,,substr($_,13,2));
> > print NEW "$text1 $text2 /n";

>
> \----------------------------^
>
>
> > }
> >
> > close OLD or die "$!\n";
> > close NEW or die "$!\n";
> > rename($NewFile,$OldFile) or die "$!\n";

> ...
>
> Seems to work OK for me, copied verbatim (AS Perl build 806 on Windoze
> 98SE). You might want to consider fixing the /n above that looks like
> you probably intended a \n.
>
> --
> Bob Walton
> Email: http://bwalton.com/cgi-bin/emailbob.pl
>



 
Reply With Quote
 
Bob Walton
Guest
Posts: n/a
 
      04-11-2004
Chuck wrote:

> Bob,
>
> Tried your suggestion - did not make any difference - my script does not
> create the NEW file. Using ActiveState latest version.
>
>


Well, here is the exact source I ran (verbatim with yours except for the
file names and better die messages), along with the exact output:

D:\junk>type junk444.pl
use strict;
use warnings;

my $text1;
my $text2;

my $OldFile = "d:/junk/junk444.txt";
my $NewFile = "d:/junk/junk444a.txt";

open(OLD, '<', $OldFile) or die "Oops, couldn't open $OldFile, $!";
open(NEW, '>', $NewFile) or die "Oops, couldn't open $NewFile, $!";

while (<OLD>) {
$text1 = substr($_,0,5);
$text2 = crypt(substr($_,5,,substr($_,13,2));
print NEW "$text1 $text2 /n";
}

close OLD or die "$!\n";
close NEW or die "$!\n";
rename($NewFile,$OldFile) or die "$!\n";

D:\junk>type junk444.txt
asdflkjsdflkjsdflksdflkjsdflkj
weroiuwqeroiuweroiwueroiuwerqweoiu
xcvzxcvmnzxcvxzcvxzcvzxcmbnxczvmnbw

D:\junk>perl junk444.pl

D:\junk>type junk444.txt
asdfl sdT3lI5wcQc1Y /nweroi weI0TeB.6rg/o /nxcvzx xzOM.vGz4CsCs /n
D:\junk>ver

Windows 98 [Version 4.10.2222]


D:\junk>perl -v

This is perl, v5.8.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2002, Larry Wall

Binary build 806 provided by ActiveState Corp. http://www.ActiveState.com
Built 00:45:44 Mar 31 2003


Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.


D:\junk>

The junk444a.txt file does not appear, since it was renamed over top of
the original junk444.txt file, which is now gone.

HTH.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl

 
Reply With Quote
 
Chuck
Guest
Posts: n/a
 
      04-15-2004
Bob,

I got my script working - there was a problem with my path settings. Thanks
for the help.

--

regards,

Chuck

"Bob Walton" <invalid-> wrote in message
news:...
> Chuck wrote:
>
> > Bob,
> >
> > Tried your suggestion - did not make any difference - my script does not
> > create the NEW file. Using ActiveState latest version.
> >
> >

>
> Well, here is the exact source I ran (verbatim with yours except for the
> file names and better die messages), along with the exact output:
>
> D:\junk>type junk444.pl
> use strict;
> use warnings;
>
> my $text1;
> my $text2;
>
> my $OldFile = "d:/junk/junk444.txt";
> my $NewFile = "d:/junk/junk444a.txt";
>
> open(OLD, '<', $OldFile) or die "Oops, couldn't open $OldFile, $!";
> open(NEW, '>', $NewFile) or die "Oops, couldn't open $NewFile, $!";
>
> while (<OLD>) {
> $text1 = substr($_,0,5);
> $text2 = crypt(substr($_,5,,substr($_,13,2));
> print NEW "$text1 $text2 /n";
> }
>
> close OLD or die "$!\n";
> close NEW or die "$!\n";
> rename($NewFile,$OldFile) or die "$!\n";
>
> D:\junk>type junk444.txt
> asdflkjsdflkjsdflksdflkjsdflkj
> weroiuwqeroiuweroiwueroiuwerqweoiu
> xcvzxcvmnzxcvxzcvxzcvzxcmbnxczvmnbw
>
> D:\junk>perl junk444.pl
>
> D:\junk>type junk444.txt
> asdfl sdT3lI5wcQc1Y /nweroi weI0TeB.6rg/o /nxcvzx xzOM.vGz4CsCs /n
> D:\junk>ver
>
> Windows 98 [Version 4.10.2222]
>
>
> D:\junk>perl -v
>
> This is perl, v5.8.0 built for MSWin32-x86-multi-thread
> (with 1 registered patch, see perl -V for more detail)
>
> Copyright 1987-2002, Larry Wall
>
> Binary build 806 provided by ActiveState Corp. http://www.ActiveState.com
> Built 00:45:44 Mar 31 2003
>
>
> Perl may be copied only under the terms of either the Artistic License
> or the
> GNU General Public License, which may be found in the Perl 5 source kit.
>
> Complete documentation for Perl, including FAQ lists, should be found on
> this system using `man perl' or `perldoc perl'. If you have access to the
> Internet, point your browser at http://www.perl.com/, the Perl Home Page.
>
>
> D:\junk>
>
> The junk444a.txt file does not appear, since it was renamed over top of
> the original junk444.txt file, which is now gone.
>
> HTH.
> --
> Bob Walton
> Email: http://bwalton.com/cgi-bin/emailbob.pl
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very annoying error: Access to the path is denied. ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity Jay ASP .Net 2 08-20-2007 07:38 PM
i have no trouble to send , ihave trouble reciving mail --any ideas John Penney Computer Support 4 08-29-2006 08:45 PM
403 Forbidden: You were denied access because: Access denied by access control list Southern Kiwi NZ Computing 6 03-19-2006 05:19 AM
How do I let people access the internet via an access point but not allow them access to my network yar Wireless Networking 4 09-21-2004 03:48 AM
trouble with caching or caching the trouble Hypo ASP .Net 6 08-01-2003 07:11 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57