[23126] in Perl-Users-Digest
Perl-Users Digest, Issue: 5347 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 12 18:06:05 2003
Date: Tue, 12 Aug 2003 15:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 12 Aug 2003 Volume: 10 Number: 5347
Today's topics:
Re: Can't see http_referrer in IE <hillmw@ram.lmtas.lmco.com>
Re: Can't see http_referrer in IE <ian@WINDOZEdigiserv.net>
Re: Can't see http_referrer in IE <hillmw@ram.lmtas.lmco.com>
Re: Can't see http_referrer in IE <ian@WINDOZEdigiserv.net>
Re: CGI::POST_MAX Question... <simonis@myself.com>
Re: creating a new file <tzz@lifelogs.com>
Re: creating a new file <tzz@lifelogs.com>
Re: FTP doesn't add Carriage Return from VMS to NT? (Mike O'Neal)
hash reference to object methods <bulk@thatproject.co.uk>
Re: hash reference to object methods <uri@stemsystems.com>
Re: hash reference to object methods <bulk@thatproject.co.uk>
Re: hash reference to object methods <uri@stemsystems.com>
Re: Help needed (Tad McClellan)
Re: Help needed <usenet@dwall.fastmail.fm>
Re: Help needed (JR)
Re: MLDBM <simonis@myself.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 12 Aug 2003 10:38:10 -0500
From: Michael Hill <hillmw@ram.lmtas.lmco.com>
To: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Can't see http_referrer in IE
Message-Id: <3F3909E2.74EF4D79@ram.lmtas.lmco.com>
Ian,
Can you tell us more about that? How would a custom header be sent?
Mike
"Ian.H [dS]" wrote:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> Whilst lounging around on Tue, 12 Aug 2003 12:52:14 -0500, "Michael
> Hill" <hillmw@charter.net> amazingly managed to produce the following
> with their Etch-A-Sketch:
>
> > I have a p[erl script that looks at the http_referrer for security
> > purposes, but when using the IE browser i can't see the
> > http_referrer from the pgm, i.e $env{http_referrer}. I can using
> > mozilla.
> > What's up with that. On some of my pgms I need to make sure they
> > are being referrered by a url on my site
> > and not executed standalone.
> >
> > Anyone familiar with this, or a workaround in IE?
> >
> > Mike
> >
>
> HTTP_REFERER _cannot_ be relied upon.
>
> Some windoze bolt-on "firewalls" block / change this.. I coded a
> small C++ app that sends a custom referrer header, and more on-topic,
> with LWP::Simple, you can define the referrer header.
>
> Regards,
>
> Ian
>
> -----BEGIN xxx SIGNATURE-----
> Version: PGP 8.0
>
> iQA/AwUBPzjqgWfqtj251CDhEQK28QCgsSUA2Oqyk1H9Ku7BlpJZtyjJ54EAni9z
> 3l3DsM+lt72/i2IsA+qmT17N
> =d7Cz
> -----END PGP SIGNATURE-----
>
> --
> Ian.H [Design & Development]
> digiServ Network - Web solutions
> www.digiserv.net | irc.digiserv.net | forum.digiserv.net
> Programming, Web design, development & hosting.
------------------------------
Date: Tue, 12 Aug 2003 16:04:52 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Can't see http_referrer in IE
Message-Id: <5g3ijvouprv25k15gi7geoho95hbg1b5u3@4ax.com>
Keywords: Remove WINDOZE to reply
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Whilst lounging around on Tue, 12 Aug 2003 10:38:10 -0500, Michael
Hill <hillmw@ram.lmtas.lmco.com> amazingly managed to produce the
following with their Etch-A-Sketch:
> Ian,
>
> Can you tell us more about that? How would a custom header be sent?
>
> Mike
Mike,
As an example, the small C++ app I coded was used to retrieve the
HEAD info of a server to report server name, version, modules etc..
just some "geekish toy" I coded as a small project while beginning to
learn C++. Here's a line from my access_log after a hit from my app:
hybris.digiserv.net - - [12/Aug/2003:16:57:21 +0100] "HEAD /
HTTP/1.0" 200 0 "WWS - Copyright (c) 2003, digiServ Network
[www.digiserv.net]"
You could do this direct through Perl I guess, by printing the header
and defining the referrer in that method (for the likes of a GET
request). I haven't actually tested this method as I primarily use
PHP for Web development and Perl for system scripting.
I can also block referrers in Outpost (windoze bolt-on "firewall"):
hybris.digiserv.net - - [12/Aug/2003:17:00:06 +0100] "GET /logo.jpg
HTTP/1.1" 200 34004 "Field blocked by Outpost
(http://www.agnitum.com)"
- From the docs for LWP::UserAgent:
$ua->get($url, Header => Value,...);
This is a shortcut for $ua->request(HTTP::Request::Common::GET(
$url, Header =E<gt> Value,... )). See HTTP::Request::Common.
As you can see, you could specify 'referer' as the header and
'hahaha!' as the value. Nothing "clever".. but just some points to
show that pretty much many headers can be "forged" and thus, an
unreliable method for anything secure. If it's only "vanity" reasons,
then it makes no difference really, as if you geta referrer value,
great.. if not.. oh well.. but if you site starts breaking because of
it, this may obviously be of some concern.
HTH =)
Regards,
Ian
-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0
iQA/AwUBPzkQH2fqtj251CDhEQIAMgCgsox3kgD6cgeJzFW83EW8CRO6JpIAn1M7
pRDxbxG/pykizFPHljA10fSU
=xd7v
-----END PGP SIGNATURE-----
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
------------------------------
Date: Tue, 12 Aug 2003 11:15:09 -0500
From: Michael Hill <hillmw@ram.lmtas.lmco.com>
To: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Can't see http_referrer in IE
Message-Id: <3F39128D.EBC84ADE@ram.lmtas.lmco.com>
If it can be reproduced by a pgm not in the domain then it doesn't make
much sense for me to use it.
Mike
"Ian.H [dS]" wrote:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> Whilst lounging around on Tue, 12 Aug 2003 10:38:10 -0500, Michael
> Hill <hillmw@ram.lmtas.lmco.com> amazingly managed to produce the
> following with their Etch-A-Sketch:
>
> > Ian,
> >
> > Can you tell us more about that? How would a custom header be sent?
> >
> > Mike
>
> Mike,
>
> As an example, the small C++ app I coded was used to retrieve the
> HEAD info of a server to report server name, version, modules etc..
> just some "geekish toy" I coded as a small project while beginning to
> learn C++. Here's a line from my access_log after a hit from my app:
>
> hybris.digiserv.net - - [12/Aug/2003:16:57:21 +0100] "HEAD /
> HTTP/1.0" 200 0 "WWS - Copyright (c) 2003, digiServ Network
> [www.digiserv.net]"
>
> You could do this direct through Perl I guess, by printing the header
> and defining the referrer in that method (for the likes of a GET
> request). I haven't actually tested this method as I primarily use
> PHP for Web development and Perl for system scripting.
>
> I can also block referrers in Outpost (windoze bolt-on "firewall"):
>
> hybris.digiserv.net - - [12/Aug/2003:17:00:06 +0100] "GET /logo.jpg
> HTTP/1.1" 200 34004 "Field blocked by Outpost
> (http://www.agnitum.com)"
>
> - From the docs for LWP::UserAgent:
>
> $ua->get($url, Header => Value,...);
> This is a shortcut for $ua->request(HTTP::Request::Common::GET(
> $url, Header =E<gt> Value,... )). See HTTP::Request::Common.
>
> As you can see, you could specify 'referer' as the header and
> 'hahaha!' as the value. Nothing "clever".. but just some points to
> show that pretty much many headers can be "forged" and thus, an
> unreliable method for anything secure. If it's only "vanity" reasons,
> then it makes no difference really, as if you geta referrer value,
> great.. if not.. oh well.. but if you site starts breaking because of
> it, this may obviously be of some concern.
>
> HTH =)
>
> Regards,
>
> Ian
>
> -----BEGIN xxx SIGNATURE-----
> Version: PGP 8.0
>
> iQA/AwUBPzkQH2fqtj251CDhEQIAMgCgsox3kgD6cgeJzFW83EW8CRO6JpIAn1M7
> pRDxbxG/pykizFPHljA10fSU
> =xd7v
> -----END PGP SIGNATURE-----
>
> --
> Ian.H [Design & Development]
> digiServ Network - Web solutions
> www.digiserv.net | irc.digiserv.net | forum.digiserv.net
> Programming, Web design, development & hosting.
------------------------------
Date: Tue, 12 Aug 2003 16:32:21 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Can't see http_referrer in IE
Message-Id: <2d5ijv4bn7i72r8eqr3m0ev7450a1njno4@4ax.com>
Keywords: Remove WINDOZE to reply
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Whilst lounging around on Tue, 12 Aug 2003 11:15:09 -0500, Michael
Hill <hillmw@ram.lmtas.lmco.com> amazingly managed to produce the
following with their Etch-A-Sketch:
> If it can be reproduced by a pgm not in the domain then it doesn't
> make much sense for me to use it.
>
> Mike
If you're tracking users from within your site (ie: not looking to
see if they came from foobar.com), you could use SESSIONs. Store the
current page as a 'current_page' session then on the next page, shift
that to 'last_page' and the new current page to 'current_page'. If
the 'last_page' session var doesn't contain your domain name, then
maybe you can act upon this. This would depend though, on whether a
user can make a direct hit to the page that requires the tracking,
ie:
http://domain.com/direct_hit.html
rather than coming from:
http://domain.com/
My Perl skills for Web scripting never reached SESSIONs, so I
couldn't explain how you'd do this with Perl, but if a viable option
for you, someone here migth be able to offer more assistance in that
area =)
Anyways... just some thoughts / ideas... =)
Regards,
Ian
-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0
iQA/AwUBPzkWk2fqtj251CDhEQITDwCg0jgiJBKC3F4+gVYWTCPgtM+2BD4AoMFv
XZTTdyr4QWR6ETc0nloi5XlK
=dqc1
-----END PGP SIGNATURE-----
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
------------------------------
Date: Tue, 12 Aug 2003 16:03:45 GMT
From: simonis <simonis@myself.com>
Subject: Re: CGI::POST_MAX Question...
Message-Id: <3F390FCA.1512641C@myself.com>
George Magklaras wrote:
>
(...)
> The
> questions I have are:
> 1)Does this happen at the very beginning of the POST operation, or
> right after the file has already occupied 4Mbytes of RAM/Disk space.
> What I want is to prevent the operation from the very beginning if the
> file exceeds 4Megs.
> 2)If the answer to the previous question is 'No, it happens at the
> end.', does someone now of a reliable (aka browser independent way) to
> 'probe' the size of the file-to-be-uploaded from the very beginning?
>
You'll probably find better answers in a group whose topic matter is
more relevant to these questions. comp.infosystems.www.authoring.cgi
might be a good fit.
-Ds
------------------------------
Date: Tue, 12 Aug 2003 13:07:21 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: creating a new file
Message-Id: <4ny8xy7qk6.fsf@lockgroove.bwh.harvard.edu>
On Tue, 12 Aug 2003, nap@illx.org wrote:
>#Open the 1st file,
>
> open(IN, "file1") or die "Can't open file1: $!\n";
>
>#search for the string
> while(<IN>) {
> if(/abc/) {
> #found 'abc' so open the 2nd file for writing
> open(OUT, ">file2") or die "Can't open file2: $!\n";
> print OUT "foo\n";
> close(OUT);
> }
> }
> close(IN);
>
> Have not tested this code,
Why not?
> but, hope that helps
I don't think it does. Also, you don't exit after the first ocurrence
of the search string as the original request said.
perl -n -e 'if (m/abc/) { open (OUT, ">file2"); exit; }' file1
Ted
------------------------------
Date: Tue, 12 Aug 2003 13:13:28 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: creating a new file
Message-Id: <4nu18m7q9z.fsf@lockgroove.bwh.harvard.edu>
On Tue, 12 Aug 2003, tadmc@augustmail.com wrote:
MJS <tabletdesktop@yahoo.com> wrote:
>
>> I need to write a script which when run will create a new text file
>> depending if there is another text file which contains certain
>> string e.g. [abc]. The file should be created on the strings first
>> occurance and the rest occurances, if any, should be ignored.
>>
>> Thanks in anticipation
>
>
> Anticipation of what?
>
> An answer?
>
> To what? You did not ask a question.
>
>
>
> What part are you stuck on?
>
> Show us the code you have so far, and we will help you fix it.
For the record, although I provided an answer to correct Nick's
nonfunctional one (that irked me worse than the original post), I
agree with your sentiment. It was especially galling that MJS said "I
need to write a script" but then sat back "in anticipation."
Ted
------------------------------
Date: 12 Aug 2003 12:37:56 -0700
From: mjoneal@bpa.gov (Mike O'Neal)
Subject: Re: FTP doesn't add Carriage Return from VMS to NT?
Message-Id: <594ddf47.0308121137.b802c17@posting.google.com>
I have the solution, at least for my situation! This fix comes with
no warranty, expressed, implied or otherwise, but for those who
experience the problem I related (carefully go back and read my
original problem,) this seems to resolve it. I have only tried this
with version 5.8.0, so it may work differently or not at all with
other versions. It may not even work with this version, so don't
trust me...
Locate the A.pm module in the perl\lib\net\FTP directory on the pc.
Comment out the (octal) substitution line (it's the only one like it)
as follows:
# $readbuf =~ S/\015\012/\n/sgo;
It appears that this substitution is not needed and is causing the
trouble. I can now transfer ASCII files from VMS systems to my Win2K
box, and the CORRECT CR/LF is present on the Windows systems. Hurah!
Remember, use this fix at your own risk, since I don't know what I'm
talking about.
------------------------------
Date: Tue, 12 Aug 2003 21:24:18 +0100
From: Ben Jones <bulk@thatproject.co.uk>
Subject: hash reference to object methods
Message-Id: <X6c_a.2812$z7.458343@wards.force9.net>
Hi,
I'm farily new to oo perl, and wondered if either someone could help me with
the following problem, or suggest a less ugly way of doing it...
I am creating an object whose attributes are loaded from various data
sources. Various groups of attributes are loaded from specific sources,
but I don't want the overhead of loading attributes when client code hasn't
asked for it yet, and might not ever. I didn't want to write an accessor
for each, so I thought I's use AUTOLOAD. My AUTOLOAD method checks to see
if the hash attribute exists, and if it doesn't, calls a private method to
load the correct one. The first solution I thought of to accomplish this
was to use a hash, with the attribute sought being the key, and the value
being a ref to the apporpriate method. So in non oo, something like this:
sub _load_attrs {
my $attr = shift;
my %attr_lookup = ( 'attr1' => \&method1,
'attr2 => \&method2);
}
...etc
But this confuses me in oo - how do I do the refs, and how do I deference
them?
My initial thought would be:
sub _load_attrs {
my ($self, $attr) = @_;
my %attr_lookup = ( 'attr1' => \$self->_load_group1,
'attr2' => \$self->_load_group2);
}
...etc
Is that right? If it is, how do I deference the methods? Or is this
incredibly wrongheaded?
------------------------------
Date: Tue, 12 Aug 2003 20:54:42 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: hash reference to object methods
Message-Id: <x7n0ee61gt.fsf@mail.sysarch.com>
>>>>> "BJ" == Ben Jones <bulk@thatproject.co.uk> writes:
BJ> Hi, I'm farily new to oo perl, and wondered if either someone
BJ> could help me with the following problem, or suggest a less ugly
BJ> way of doing it...
just as a contrast to the doofus thread, note the good subject, good
background info and a respectful question.
BJ> I am creating an object whose attributes are loaded from various
BJ> data sources. Various groups of attributes are loaded from
BJ> specific sources, but I don't want the overhead of loading
BJ> attributes when client code hasn't asked for it yet, and might not
BJ> ever. I didn't want to write an accessor for each, so I thought
BJ> I's use AUTOLOAD. My AUTOLOAD method checks to see if the hash
BJ> attribute exists, and if it doesn't, calls a private method to
BJ> load the correct one. The first solution I thought of to
BJ> accomplish this was to use a hash, with the attribute sought being
BJ> the key, and the value being a ref to the apporpriate method. So
BJ> in non oo, something like this:
this sounds like a fine idea. but the first question is how much work is
it really to get all those attributes at construction time? if they
require slow things like file reads or DB access or page fetches and you
may never use them, your idea makes sense.
BJ> sub _load_attrs {
BJ> my $attr = shift;
BJ> my %attr_lookup = ( 'attr1' => \&method1,
BJ> 'attr2 => \&method2);
BJ> }
for methods you can just use the method name and call them.
my %attr_lookup = ( 'attr1' => 'method1'
'attr2 => 'method2');
my $method = $attr_lookup{ $attr } ;
$self->$method() ;
that is called late binding (among other names). one of perl's nice OO
features is generating method calls on the fly. note that this is NOT
the same as symbolic references which are evil.
now how you handle the AUTOLOAD will also make a difference. using
AUTOLOAD to access attributes will be slow. it should autogenerate
accessor methods on demand as well as initializing the attributes. then
the next time the accessor is called, it will have an installed method
and be initialized.
a simple (untested) version is this:
sub AUTOLOAD {
my $self = shift ;
my $attr = $AUTOLOAD ;
$attr =~ s/.*://;
*{$attr} = sub {
$_[0]->{$attr} = $_[1] if @_ > 1 ;
return $_[0]->{$attr}
} ;
goto &{$attr} ;
}
add your call to the initializer method before the magic goto call at
the end.
note how an intelligent question gets an intelligent answer with
examples and more. too bad doofus will never get help here again because
he got killfiled by too many.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 12 Aug 2003 22:13:25 +0100
From: Ben Jones <bulk@thatproject.co.uk>
Subject: Re: hash reference to object methods
Message-Id: <YQc_a.2837$z7.461808@wards.force9.net>
Uri Guttman wrote:
>>>>>> "BJ" == Ben Jones <bulk@thatproject.co.uk> writes:
>
> BJ> Hi, I'm farily new to oo perl, and wondered if either someone
> BJ> could help me with the following problem, or suggest a less ugly
> BJ> way of doing it...
>
> just as a contrast to the doofus thread, note the good subject, good
> background info and a respectful question.
Although in my case a seemingly well-formed question is partly a lucky
accident ;)
> this sounds like a fine idea. but the first question is how much work is
> it really to get all those attributes at construction time? if they
> require slow things like file reads or DB access or page fetches and you
> may never use them, your idea makes sense.
A *lot* of work, for a particular class of attributes, that are loaded from
a particularly slow script, accessing a particularly slow database, neither
of which I have much control over. And I have reason to expect that not
every user of the module will care to use them. In fact the script I was
writing this module for definitely won't always. Client code that chooses
to access them gets an overhead measured in seconds...
> for methods you can just use the method name and call them.
>
> my %attr_lookup = ( 'attr1' => 'method1'
> 'attr2 => 'method2');
>
>
> my $method = $attr_lookup{ $attr } ;
>
> $self->$method() ;
>
> that is called late binding (among other names). one of perl's nice OO
> features is generating method calls on the fly. note that this is NOT
> the same as symbolic references which are evil.
Of course! As always with elegant solutions, it looks so damned obvious
now.
<rest snipped and saved>
> note how an intelligent question gets an intelligent answer with
> examples and more.
And may I note an extremely speedy response. Thanks for your help, you've
saved a good deal of head-scratching.
------------------------------
Date: Tue, 12 Aug 2003 21:41:07 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: hash reference to object methods
Message-Id: <x7k79i5zbg.fsf@mail.sysarch.com>
>>>>> "BJ" == Ben Jones <bulk@thatproject.co.uk> writes:
BJ> A *lot* of work, for a particular class of attributes, that are
BJ> loaded from a particularly slow script, accessing a particularly
BJ> slow database, neither of which I have much control over. And I
BJ> have reason to expect that not every user of the module will care
BJ> to use them. In fact the script I was writing this module for
BJ> definitely won't always. Client code that chooses to access them
BJ> gets an overhead measured in seconds...
there are other solutions too. those slow attributes can be handled by
delegation methods, i.e. they are complete objects contained inside the
main object. then methods on the main object just call methods on the
contained object which then instantiates itself. there is even a module
to help with handling of delegation.
BJ> And may I note an extremely speedy response. Thanks for your
BJ> help, you've saved a good deal of head-scratching.
to save your scalp from more irritation, get and read the book Object
Oriented Perl by damian conway. guaranteed to help you out in many ways
when doing any OO perl.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 12 Aug 2003 10:45:17 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help needed
Message-Id: <slrnbji2sd.2v9.tadmc@magna.augustmail.com>
Learner <kernel_learner@yahoo.com> wrote:
> Subject: Help needed
Subject needed.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 12 Aug 2003 15:55:00 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Help needed
Message-Id: <Xns93D5793929C2dkwwashere@216.168.3.30>
Learner <kernel_learner@yahoo.com> wrote:
> I want to do this.
Please put the subject of your post in the Subject header. "Help
needed" is not very informative. "Comparing directory trees" or
something similar would be better.
> Traverse two directory trees
use File::Find;
>(similar trees) and do a diff for the
> files in those subdirectories.
perldoc -q "difference of two arrays"
That's one approach, anyway.
--
David Wall
------------------------------
Date: 12 Aug 2003 14:16:57 -0700
From: jrolandumuc@yahoo.com (JR)
Subject: Re: Help needed
Message-Id: <b386d54b.0308121316.169557d1@posting.google.com>
kernel_learner@yahoo.com (Learner) wrote in message news:<42dfbbc2.0308120647.420c2fe4@posting.google.com>...
> I want to do this.
>
> Traverse two directory trees (similar trees) and do a diff for the
> files in those subdirectories.
> I am not able to execute ls *.C using system it does not work right.
> What I want to do is get a list of the files in one directory. Then
> look for that same name in the other directory and do a diff between
> those two..but I seem to be hopelessly lost!!
>
> Here's a snippet of my code which works so far..but I am not able to
> furhter it:
>
> ...
> while(@SUBDIRS1)
> {
> $Sub = shift(@SUBDIRS2);
> push(@Dir1,$DIRECTORY1.$Sub);
>
> $Sub = shift(@SUBDIRS1);
> push(@Dir2,$DIRECTORY2.$Sub);
> }
>
> #
> # STEP 2.
> # Now go through each directory get a list of
> # .C .cpp .H .h files and then do diff!
> #
> while(@Dir2)
> {
> $dir2 = shift(@Dir2);
> $dir1 = shift(@Dir1);
> print "******\n";
> print "$dir2 \n";
> print "$dir1 \n";
> print "******\n";
>
>
> system("find $dir2 -name '*.C'");
> system("find $dir1 -name '*.C' | xargs ls -l");
>
> system("find $dir2 -name '*.cpp' | xargs ls -l");
> system("find $dir1 -name '*.cpp' | xargs ls -l");
>
> system("find $dir2 -name '*.h' | xargs ls -l");
> system("find $dir1 -name '*.h' | xargs ls -l");
>
> system("find $dir2 -name '*.H' | xargs ls -l");
> system("find $dir1 -name '*.H' | xargs ls -l");
> }
Here are a couple of possible solutions (neither are elegant or
optimized, but they at least give you something on which to improve).
To improve the efficiency of the first method, consider using a
recursive means of grabbing file names within a given directory and
its subdirectories (this is available within this newsgroup-search for
"faster than File::Find," or something such as that). Also, you can
write some very simple Perl code to compare two files, instead of
using the UNIX diff (or perhaps a Perl module already exists that
would save you the trouble of even having to write such code; if not,
see the last script included in my response for an example-this script
compares files between two directories-not subdirectories, though). I
don't know which would be faster. I imagine a more elegant solution
will be placed in response to your request-I look forward to seeing
it!
Anyway, good luck.
JR
### First possible solution
#!/perl
use strict;
use File::Find;
use warnings;
use diagnostics;
my %th; # Temp hash to hold path+file name
my $d1 = 'old/test2'; # Dir 1 path
my $d2 = 'old/test3'; # Dir 2 path
find \&findFiles, $d1; # Traverse dir 1
my %h1 = %th; # Record dir one file names
%th = (); # Clear temp hash
find \&findFiles, $d2; # Traverse dir 2
my %h2 = %th; # Record dir two file names
sub findFiles {
if (-f) { # Ferret out non-files
my $tv = $File::Find::name; # Use temp var to record
# path+file name
$tv =~ s/^.*\/(.*)$/$1/; # Remove from temp var the
# file name path
$th{$tv} = $File::Find::name; # Record the name as the key,
# and the value
# as the path + the file name
}
}
my $df = 'dFile.txt'; # Diff out file
open F, ">$df" or die "Cannot open $df: $!";
for (keys %h1) {
if (exists($h2{$_})) { # File name does exist in both hashes
my @d = `diff $h1{$_} $h2{$_}`; # Compare path+file name in UNIX
if (@d) { # Print result, if any
print F "Diff on $h1{$_} : $h2{$_}\n";
print F `diff $h1{$_} $h2{$_}`;
print F "-------------------------\n\n";
}
}
}
close F or die "Cannot close $df: $!";
### Second possible solution (brute-force)
#!/perl
use strict;
use File::Find;
use warnings;
use diagnostics;
## Get file names from directories
my (@compare, @tmpFileNames, $dir1, $dir2, @file1, @file2);
$dir1 = 'old/test2';
$dir2 = 'old/test3';
find \&findFiles, $dir1;
my @dir1 = @tmpFileNames;
@tmpFileNames = ();
find \&findFiles, $dir2;
my @dir2 = @tmpFileNames;
sub findFiles { push @tmpFileNames, $File::Find::name if -f; }
## Look for matches and compare when found
my $diffFile = 'diffFile.txt';
open OUTFILE, ">$diffFile" or die "Cannot open $diffFile: $!";
for my $d1 (@dir1) {
my $tmpD1 = $d1; # $d1 contains full path+name
$tmpD1 =~ s/^.*\/(.*)$/$1/; # $tmpD1 contains name
for my $d2 (@dir2) {
my $tmpD2 = $d2; # ''
$tmpD2 =~ s/^.*\/(.*)$/$1/; # ''
## A match has been found
if ($tmpD1 eq $tmpD2) {
my @diff = `diff $d1 $d2`;
if (@diff) {
print OUTFILE "Diff on $d1 : $d2\n";
for (@diff) {
print OUTFILE $_;
}
print OUTFILE "-----------------\n\n";
}
}
}
}
close OUTFILE or die "Cannot close $diffFile: $!";
#####
use strict;
### This script compares the contents of files with matching names,
### but in different directories.
### Written: July 8, 2003
my $directory1 = "production";
my $directory2 = "production_2";
my(@firstFile, @secondFile, $firstFile, $secondFile);
## Open primary directory
opendir DIR1, "$directory1" or die "Cannot open first directory: $!";
while ($firstFile = readdir(DIR1)) {
next if (-e $firstFile); # Only process real files
## Check for file existence in secondary directory
my $existsInSecondaryFile = secondDir($firstFile);
## If primary file name was found in the secondary directory,
## capture file contents of primary and secondary directory
## files, respectively, that matched
if ($existsInSecondaryFile eq 'found') {
## Capture primary file contents
open FILE1, "$directory1/$firstFile"
or die "First file open failed: $!";
@firstFile = ();
while (<FILE1>) {
chomp;
next if /^\s*$/; # Skip blank rows
s/\s+$//; # Remove any trailing spaces
push @firstFile, $_;
}
close FILE1 or die "First file close failed: $!";
## Capture secondary file contents
open FILE2, "$directory2/$firstFile"
or die "Second file open failed: $!";
@secondFile = ();
while (<FILE2>) {
chomp;
next if /^\s*$/; # Skip blank rows
s/\s+$//; # Remove any trailing spaces
push @secondFile, $_;
}
close FILE2 or die "Second file close failed: $!";
compare(\($firstFile, @firstFile, @secondFile));
}
}
closedir DIR1 or die "Cannot close first directory: $!";
## Sub to compare primary and secondary files
sub compare {
my ($fileName, $fileRef1, $fileRef2) = (shift, @_, @_);
my %seen; # Comparison hash
$seen{$_} = 1 for @$fileRef2; # Load hash w/ contents of file 2
## Iterate through first file, checking for elements in file
## but not in comparison hash
for (@$fileRef1) {
if(!exists($seen{$_})) {
print join "", "Some elements of the following row\n",
"are in \"$$fileName\" on $directory1,\n",
"but not \"$$fileName\" on $directory2.\n",
"\"$_\"\n\n";
}
}
%seen = (); # Empty comparison hash
$seen{$_} = 1 for @$fileRef1; # Load hash w/ contents of file 1
## Iterate through second file, checking for elements in file
## but not in comparison hash
for (@$fileRef2) {
if(!exists($seen{$_})) {
print join "", "Some elements of the following row\n",
"are in \"$$fileName\" on $directory2,\n",
"but not \"$$fileName\" on $directory1.\n",
"\"$_\"\n\n";
}
}
}
## Sub to check secondary directory for a given
## file from the primary directory
sub secondDir {
my $firstFile = shift;
## Search for file name in secondary directory
opendir DIR2, "$directory2"
or die "Cannot open second directory: $!";
while ($secondFile = readdir(DIR2)) {
if ($firstFile eq $secondFile) { # File was found in
# secondary directory
return "found";
last;
}
}
closedir DIR2 or die "Cannot close second directory: $!";
}
------------------------------
Date: Tue, 12 Aug 2003 16:00:14 GMT
From: simonis <simonis@myself.com>
Subject: Re: MLDBM
Message-Id: <3F390EF7.63A954C5@myself.com>
Jeff Mott wrote:
>
> Is there a wrapper to perform encryption on an MLDBM database? Since
> file permissions is a Unix-only feature, I'd prefer not to rely on
> that. Data encryption would appear to be the only cross platform way
> to keep the data secure. Unless someone has any better ideas...?
Not sure how this is related to Perl.
>
> Also, am I able to lock this type of database? I did some testing and
> it does not appear to force other processes to wait. Thus all the
> usual race conditions and possibilities for corrupting the data
> emerge.
Is this like what you need:
http://search.cpan.org/author/CHAMAS/MLDBM-Sync-0.30/Sync.pm ??
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5347
***************************************