[10494] in Perl-Users-Digest
Perl-Users Digest, Issue: 4085 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 27 17:06:18 1998
Date: Tue, 27 Oct 98 14:00:23 -0800
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, 27 Oct 1998 Volume: 8 Number: 4085
Today's topics:
Re: ActiveState Perl: problem with PerlPacketManager: p (Jan Dubois)
Re: Amputated Perl Code gregghill@my-dejanews.com
command line problem <marx@idiom.com>
dynamic loading problem <phade@powerweb.de>
Re: File locations <rootbeer@teleport.com>
Re: File locations <killer@ath.forthnet.gr>
Re: Forcing perl to garbage collect droby@copyright.com
Help with Net::LDAPapi and packages. <jdubois@keane.com>
Re: LWP::UserAgent, how to get headers? <aas@sn.no>
Re: newbie needs help with file comparison loop 2 (Brand Hilton)
Re: newbie needs help with file comparison loop <barnett@houston.Geco-Prakla.slb.com>
Re: newbie needs help with file comparison loop (Larry Rosler)
Re: newbie needs help with file comparison loop <arnej@fc.hp.com>
Re: Not to start a language war but.. (Dave Kirby)
Re: OLE and EXCEL (Jan Dubois)
Re: Open an existing Microsoft Excell workbook and writ (Jan Dubois)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 27 Oct 1998 22:39:14 +0100
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: ActiveState Perl: problem with PerlPacketManager: ppm.pl (proxy/internet)
Message-Id: <363d3bc1.49765418@news3.ibm.net>
[mailed & posted]
rk <rkoch@sbs.de> wrote:
>I need to install the tk package for Active State Perl.
>Has anybody an idea, how this could work (or where else I could download
>the packages) ???
[snip]
>PPM> search
>Packages available from http://www.ActiveState.com/packages:
>
> <== No packages / no error displayed
>PPM>
>
>So, how can I get the packages?
Did you try just "install Tk". The "search" command may be broken. Also the
ActiveState server is rather temperamental; sometimes it works and sometimes
it doesn't. You might just try again later/next day etc.
-Jan
------------------------------
Date: Tue, 27 Oct 1998 20:09:58 GMT
From: gregghill@my-dejanews.com
Subject: Re: Amputated Perl Code
Message-Id: <7159am$dks$1@nnrp1.dejanews.com>
Justin Wilde wrote in message <362CFCDC.F4FA4367@openskies.com>...
>Looking in my perl error log, I see dozens of entries containing:
>
>"Missing right bracket at [path]\xxx.cgi line xxx, at end of line
>syntax error at [path]\xxx.cgi line xxx, at EOF
>Execution of [path]\xxx.cgi aborted due to compilation errors."
>
>Normally these scripts run fine, but it appears that occasionally they
>are cut short, often midway through a bracketed block of code. I assume
>this is what's happening because the line of code the perl compiler
>considers to be EOF is only partway through my file.
>
>What might cause this? The scripts are used only to process STDIN and
>display html pages. Concurrency wouldn't be an issue, would it?
>
>Any ideas would be greatly appreciated.
> Justin Wilde
> jwilde@openskies.com
>
>
I just found this article on Microsoft's site. I'm experiencing similar
symptoms, but I won't be able to test Microsoft's recommendations for a day or
two. If this helps, please post a reply.
Gregg
Process Launched with CreateProcess() May Terminate Prematurely
Last reviewed: February 24, 1998 Article ID: Q156484
The information in this article applies to:
Microsoft Windows NT Workstation version 4.0
Microsoft Windows NT Server version 4.0
Microsoft Internet Information Server version 3.0
SYMPTOMS
Cmd.exe, Perl.exe, or other console-mode applications may fail to initialize
properly and terminate prematurely when launched by a service using the
CreateProcess() or CreateProcessAsUser() APIs. The calling process has no way
of knowing that the launched console-mode application has terminated
prematurely.
In some instances, calling GetExitCode() against the failed process indicates
the following exit code:
128L ERROR_WAIT_NO_CHILDREN - There are no child processes to wait for.
MORE INFORMATION
Internet Information Server (IIS) may exhibit this problem intermittently when
processing CGI or Perl scripts. In this case the browser returns the following
error when executing CGI scripts:
CGI Error The specified CGI application misbehaved by not returning a
complete set of HTTP headers. The headers it did return are:.
Remote Command Service (RCMD) may also exhibit this problem. RCMD clients
experience connect and disconnect messages when they attempt to access a
server running RCMD service. This may be used as a test application to see if
another service is running into this problem.
Other third-party services (such as Patrol from BMC Software) are also known
to fail because of this problem.
RESOLUTION
To resolve this problem, please see the following articles in the Microsoft
Knowledge Base for more information:
ARTICLE-ID: Q142676
TITLE : Overcoming User32.dll Initialization Failure Errors
ARTICLE-ID: Q175687
TITLE : Win32k.sys Causes STOP 0x0000001e and 0x0000000a On SMP
Keywords : nt32ap ntconfig NTSrvWkst kbenv kbinterop
Version : WinNT:4.0
Platform : winnt
Issue type : kbprb
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 27 Oct 1998 15:23:23 -0600
From: "Marcus J. Foody" <marx@idiom.com>
Subject: command line problem
Message-Id: <363639CB.38CF@idiom.com>
Hello, I have a perl scipt that parses a text file and prints the parsed
data into 3 different files. I then take the three different parsed
files and bcp them into sybase tables. My problem is how do I call up
my bcp statement within my perl script?
thanks
marcus
------------------------------
Date: Tue, 27 Oct 1998 21:33:40 -0100
From: Frank Gadegast <phade@powerweb.de>
Subject: dynamic loading problem
Message-Id: <36364A44.8A73C9B1@powerweb.de>
Hi Folks,
still have the problem loading dynamic extensions.
A make test returns:
lib/sdbm...........Can't load '../lib/auto/SDBM_File/SDBM_File.so' for
module SDBM_File: dld_link(../lib/auto/SDBM_File/SDBM_File.so):
malformed input file at ../lib/DynaLoader.pm line 168.
o perl5.00502
o Linux 2.0.34 Rdhat 4.1
o gcc 2.7.2.1
o DLD 3.3
what the trick ?
Please reply by eMail.
Kind regards, Frank
--
Dipl.-Inform. Frank Gadegast mailto:frank@gadegast.de
PHADE Software - PowerWeb http://www.powerweb.de
Leibnizstr. 30, 10625 Berlin, Germany fon/fax: ++ 49 30 3128103
======================================================================
PowerWeb is WebPresenceProvider MPEG-1 Archive www.mpeg1.de
and hosts and sponsors ... KINOWEB www.kinoweb.de
------------------------------
Date: Tue, 27 Oct 1998 20:32:36 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: File locations
Message-Id: <Pine.GSO.4.02A.9810271156400.5534-100000@user2.teleport.com>
On Tue, 27 Oct 1998, Basile Laderchi wrote:
> i am trying' to built a perl script that accesses a file but the
> script insists on needing' the file in the C:\
It insists, does it? Show it who is the boss! My programs always do just
what I tell them to do.
> any ideas on how to convince the .pl or the server to make it look for
> the file in the cgi-bin directory or in the webserver root?
When you open() the file, specify the full path. Or, use chdir first. Hope
this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 27 Oct 1998 23:20:15 +0200
From: Basile Laderchi <killer@ath.forthnet.gr>
Subject: Re: File locations
Message-Id: <3636390F.ED37D1EB@ath.forthnet.gr>
Tom Phoenix wrote:
> > i am trying' to built a perl script that accesses a file but the
> > script insists on needing' the file in the C:\
> It insists, does it? Show it who is the boss! My programs always do just
> what I tell them to do.
> > any ideas on how to convince the .pl or the server to make it look for
> > the file in the cgi-bin directory or in the webserver root?
> When you open() the file, specify the full path. Or, use chdir first. Hope
> this helps!
The point is not to need to specify the whole path. and just tell the script
to find the files that it needs from the folder that the script is in or a
subfolder of it.
> --
> Tom Phoenix Perl Training and Hacking Esperanto
> Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
P.S.: when i put the whole path it worked
--
/------------------------\
| Killer Angel |
+------------------------+
| Killer@ath.forthnet.gr |
| ICQ 2870180 |
+------------------------+
| Alpha World |
| 32746.8S 99.3E 270 |
\------------------------/
------------------------------
Date: Tue, 27 Oct 1998 20:55:22 GMT
From: droby@copyright.com
Subject: Re: Forcing perl to garbage collect
Message-Id: <715bvq$hhc$1@nnrp1.dejanews.com>
In article <7152sn$tl$1@mathserv.mps.ohio-state.edu>,
ilya@math.ohio-state.edu (Ilya Zakharevich) wrote:
> [A complimentary Cc of this posting was sent to
> <droby@copyright.com>],
> who wrote in article <714l4c$f5o$1@nnrp1.dejanews.com>:
> > > Out of curiosity, what happens if you add:
> > >
> > > $i =~ s/./\0/g;
>
> > I was curious too, so I tried it. No go. In fact, it shows up twice with
or
> > without the clearing attempt. If you substitute $i = 'abc123' for $i = `cat
> > z.in`, it reduces to one, so I guess one of them is a temporary copy created
> > by the ``.
>
> Correct. Temporaries are not touched (until reused, or interpreter
> dies). But even if reused or forgotten, the string buffer is just
> free()ed or realloc()ed, which does not guarantie anything.
>
> > It might be that the s/./\0/g clears it but creates another
> > temporary copy in the process.
>
> No, it should not. An optimization should be triggered, and no new
> memory is going to be allocated.
>
Well then. Something's holding onto the value. At least in Perl5.00401.
Perhaps Perl isn't the best language for this level of paranoia. Wonder how
Python does.
<duck>
--
Don Roby
droby@copyright.com
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 27 Oct 1998 16:12:55 -0500
From: Joseph DuBois <jdubois@keane.com>
Subject: Help with Net::LDAPapi and packages.
Message-Id: <36363757.D3A993F6@keane.com>
This is a multi-part message in MIME format.
--------------D90C73BD67372661BF3DAEFC
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Well met,
I am currently using Net::LDAPapi (v 1.42) within our company. We
have it working fine. But we are writing more and more programs that
use the same code, so I want to create a package that has the
common set of code in it that we use for our company. I am
attaching the three scripts to this post.
The first one (ldap-get.pl) works fine and returns the results I
expect. The second one (ldap-get3.pl) runes (without errors),
but returns a msgid of 101 (which I believe is the end of values
indicator) on the first pass of the while loop.
Help is greatly appreciated.
The files are as follows:
====================================================
ldap-get.pl (Perl with code in subroutines - works fine)
ldap-get3.pl (Perl that uses my new package)
ldap.lib (Perl package for common routines)
-------------------------------------------------------
Joseph DuBois
mailto:jdubois@keane.com (Work) http://www.keane.com/
--------------D90C73BD67372661BF3DAEFC
Content-Type: application/x-perl;
name="ldap-get.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="ldap-get.pl"
#!/usr/bin/perl
$| = 1;
use Net::LDAPapi;
$data = "/webdisk/servers/extranet/data";
require 'ldap.inc';
$filter = $ARGV[0];
# Various Variable Declarations...
my($ld);
my($dn);
my($attr);
my($ent);
my($ber);
my(@vals);
my(%record);
my($rc);
my($result);
print qq(Checking for User with filter = [$filter]\n);
print qq(Return Value: ), &checkForDN($filter), qq(\n);
exit;
#--------------------------------------------------------------------
#--------------------------------------------------------------------
sub setupConnection {
print qq($ldap_server\n);
#
# Initialize Connection to LDAP Server
if (($ld = new Net::LDAPapi($ldap_server)) == -1)
{
return(-1);
}
#
# Bind as NULL User to LDAP connection $ld
if ($ld->bind_s($ROOTDN,$ROOTPW) != LDAP_SUCCESS)
{
$ld->unbind;
return(-2);
}
print qq(Here: $ld \n);
return($success)
}
#------------------------------------------------------------------
#------------------------------------------------------------------
sub checkForDN {
my($error) = -1;
my($attribute, $attribute_value) = "";
my(@pairs) = split(/=/, $filter);
if (@pairs)
{
if (@pairs == 1)
{
$attribute_value = $pairs[0];
}
else
{
$attribute = $pairs[0];
$attribute_value = $pairs[1];
}
}
else
{
return($error);
}
print qq(Here: $ld \n);
&setupConnection();
print qq(Here: $ld \n);
# This will set the size limit to $sizelimit from above. The command
# is a Netscape addition, but I've programmed replacement versions for
# other APIs.
$ld->set_option(LDAP_OPT_SIZELIMIT,$sizelimit);
# This routine is COMPLETELY unnecessary in this application, since
# the rebind procedure at the end of this program simply rebinds as
# a NULL user.
$ld->set_rebind_proc(&rebindproc);
#
# Specify Search Filter and List of Attributes to Return
my @attrs = ();
#
# Perform Search
my $msgid = $ld->search($BASEDN,LDAP_SCOPE_SUBTREE,$filter,\@attrs,0);
print qq(the $msgid was returned\n);
if ($msgid < 0)
{
$ld->unbind;
return($error);
}
# Reset Number of Entries Counter
my $nentries = 0;
# Set no timeout.
my $timeout = -1;
#
# Cycle Through Entries
$foundmatch = 0;
while (($rc = $ld->result($msgid,0,$timeout)) == LDAP_RES_SEARCH_ENTRY)
{
print qq(Result of Result call: $rc\n);
$nentries++;
for ($ent = $ld->first_entry; $ent != 0; $ent = $ld->next_entry)
{
print "Looking for $attribute with a value of $attribute_value\n";
if ($attribute eq "")
{
$found_attribute = ($ld->get_values("uid"))[0];
}
else
{
$found_attribute = ($ld->get_values($attribute))[0];
}
print "Found: $found_attribute\n";
if (lc($found_attribute) eq lc($attribute_value))
{
$foundmatch = 1;
}
}
$ld->msgfree;
}
print qq(Result of Result call: $rc\n);
if ($rc == LDAP_RES_SEARCH_RESULT && $ld->err != LDAP_SUCCESS)
{
print "result: " . $ld->errstring . "\n";
$ld->unbind;
return(-1);
}
$ld->unbind;
return($foundmatch);
}
#------------------------------------------------------------------
#------------------------------------------------------------------
sub rebindproc
{
return("","",LDAP_AUTH_SIMPLE);
}
--------------D90C73BD67372661BF3DAEFC
Content-Type: application/x-perl;
name="ldap-get3.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="ldap-get3.pl"
#!/usr/bin/perl
$| = 1;
use Net::LDAPapi;
require "ldap.lib";
$data = "/webdisk/servers/extranet/data";
$filter = $ARGV[0];
$ld = 0;
print qq(Checking for User with filter = [$filter]\n);
print qq(Return Value: ), &ldap'checkForDN($filter), qq(\n);
exit;
#------------------------------------------------------------------
#------------------------------------------------------------------
sub rebindproc
{
return("","",LDAP_AUTH_SIMPLE);
}
--------------D90C73BD67372661BF3DAEFC
Content-Type: text/plain; charset=us-ascii;
name="ldap.lib"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="ldap.lib"
###############################################################################
#
#
# MODULE NAME: ldap.lib
#
# MODULE OVERVIEW: Default set of routines for LDAP access at Keane
#
# USAGE: require "ldap.lib";
#
# Return Values: 1 = success
# -1 = error occured initilizing server
# -2 = error occured binding to server
# -3 = error
#
# MODULE REVISIONS:
# date initials description
# -------- -------- ---------------------------------------------
# 10/26/98 JMD Creation of script
#
###############################################################################
#
package ldap;
require "ldap.inc";
# Various Variable Declarations...
#$ld = 0;
my($dn);
my($attr);
my($ent);
my($ber);
my(@vals);
my(%record);
my($rc);
my($result);
$success = 1;
#--------------------------------------------------------------------
#--------------------------------------------------------------------
sub ldap'setupConnection {
print qq($ldap_server for $ROOTDN with password of $ROOTPW \n);
#
# Initialize Connection to LDAP Server
if (($ld = new Net::LDAPapi($ldap_server)) == -1)
{
return(-1);
}
#
# Bind as NULL User to LDAP connection $ld
if ($ld->bind_s($ROOTDN,$ROOTPW) != LDAP_SUCCESS)
{
$ld->unbind;
return(-2);
}
print qq(Here: $ld \n);
return($success)
}
#------------------------------------------------------------------
#------------------------------------------------------------------
sub ldap'checkForDN {
my($filter) = @_;
my($error) = -1;
my($attribute, $attribute_value) = "";
my(@pairs) = split(/=/, $filter);
if (@pairs)
{
if (@pairs == 1)
{
$attribute_value = $pairs[0];
}
else
{
$attribute = $pairs[0];
$attribute_value = $pairs[1];
}
}
else
{
return($error);
}
print qq(Here: $ld \n);
$return_value = &setupConnection();
print qq(RET: $return_value for $filter\n);
# This will set the size limit to $sizelimit from above. The command
# is a Netscape addition, but I've programmed replacement versions for
# other APIs.
$ld->set_option(LDAP_OPT_SIZELIMIT,$sizelimit);
# This routine is COMPLETELY unnecessary in this application, since
# the rebind procedure at the end of this program simply rebinds as
# a NULL user.
$ld->set_rebind_proc(&ldap'rebindproc);
#
# Specify Search Filter and List of Attributes to Return
my @attrs = ();
#
# Perform Search
print qq(About to search for $filter with a BaseDN = $BASEDN\n);
my $msgid = $ld->search($BASEDN,LDAP_SCOPE_SUBTREE,$filter,\@attrs,0);
print qq(the $msgid was returned\n);
if ($msgid < 0)
{
$ld->unbind;
return($error);
}
# Reset Number of Entries Counter
my $nentries = 0;
# Set no timeout.
my $timeout = -1;
print qq(Here: $ld \n);
#
# Cycle Through Entries
$foundmatch = 0;
while (($rc = $ld->result($msgid,0,$timeout)) == LDAP_RES_SEARCH_ENTRY)
{
$nentries++;
print '.';
for ($ent = $ld->first_entry; $ent != 0; $ent = $ld->next_entry)
{
print "Looking for $attribute with a value of $attribute_value\n";
if ($attribute eq "")
{
$found_attribute = ($ld->get_values("uid"))[0];
}
else
{
$found_attribute = ($ld->get_values($attribute))[0];
}
print "Found: $found_attribute\n";
if (lc($found_attribute) eq lc($attribute_value))
{
$foundmatch = 1;
}
}
$ld->msgfree;
}
print qq(Result of Result call: $rc\n);
if ($rc == LDAP_RES_SEARCH_RESULT && $ld->err != LDAP_SUCCESS)
{
print "result: " . $ld->errstring . "\n";
$ld->unbind;
return(-1);
}
$ld->unbind;
return($foundmatch);
}
#------------------------------------------------------------------
#------------------------------------------------------------------
sub ldap'rebindproc {
return("","",LDAP_AUTH_SIMPLE);
}
#--------------------------------------------------------------------
#--------------------------------------------------------------------
sub ldap'addUser {
my($entrydn, %ldap_modifications) = @_;
my($return_value) = 0;
$return_value = &ldap'setupConnection();
if ($return_value == $success)
{
if ($ld->add_s($entrydn,\%ldap_modifications) != LDAP_SUCCESS)
{
$return_value = -3;
}
else
{
print qq(<!-- Added User -->\n);
$return_value = $success;
}
}
$ld->unbind;
return($return_value);
}
#--------------------------------------------------------------------
#--------------------------------------------------------------------
sub ldap'updateUser {
my($entrydn, %ldap_modifications) = @_;
my($return_value) = 0;
$return_value = &ldap'setupConnection();
if ($return_value == $success)
{
if ($ld->modify_s($entrydn,\%ldap_modifications)!= LDAP_SUCCESS)
{
$return_value = -3;
}
else
{
print qq(<!-- Modified User -->\n);
$return_value = $success;
}
}
$ld->unbind;
return($return_value);
}
#--------------------------------------------------------------------
#--------------------------------------------------------------------
sub ldap'deleteUser {
my($entrydn) = $_;
my($return_value) = 0;
$return_value = &ldap'setupConnection();
if ($return_value == $success)
{
if ($ld->delete_s($entrydn) != LDAP_SUCCESS)
{
$return_value = -3;
}
else
{
print qq(<!-- Deleteded User -->\n);
$return_value = $success;
}
}
$ld->unbind;
return($return_value);
}
#
# Return Value for Perl Package
1;
--------------D90C73BD67372661BF3DAEFC--
------------------------------
Date: 27 Oct 1998 20:04:17 +0100
From: Gisle Aas <aas@sn.no>
Subject: Re: LWP::UserAgent, how to get headers?
Message-Id: <m3n26haksu.fsf@furu.g.aas.no>
cpierce1@cp500.fsic.ford.com (Clinton Pierce) writes:
> If I've made a request for a page using LWP::UserAgent, how can I
> get the _headers_ of the received information. Code snippet follows:
>
> sub open_url {
> my($url)=@_;
>
> my $ua=new LWP::UserAgent;
> $ua->proxy(['http'], 'http://workproxy.ford.com:8080/');
> $ua->agent('Getstuff/1.1');
>
> my $request=new HTTP::Request('GET', $url);
> $request->proxy_authorization_basic("userid", "password");
> $res=$ua->request($request);
>
> if (! $res->is_success) {
> warn "Error! " . $res->code . " ". $res->message;
> return(undef);
> }
>
> return( $res->content );
> }
>
> What I'm interested in is the "Content-type" returned, which describes
> the $res->content. Where can I get that?
Try the $res->content_type method. In general you can access any
response header with the $res->header("Some-Header-Name") method.
Some of the commonly used headers, like Content-Type, have convenience
methods.
Since you did not find this, how do you think the documentation could
be improved?
--
Gisle Aas
------------------------------
Date: 27 Oct 1998 19:56:14 GMT
From: bhilton@tsg.adc.com (Brand Hilton)
Subject: Re: newbie needs help with file comparison loop 2
Message-Id: <7158gu$9qv6@mercury.adc.com>
Oops... didn't read the problem statement carefully enough. Swap IN1
and IN2 everywhere after the opens.
In article <715857$9qv5@mercury.adc.com>,
Brand Hilton <bhilton@tsg.adc.com> wrote:
>How I'd do it, assuming I knew the data files weren't going to be too
>terribly big:
>
>
> #!/usr/local/bin/perl -w
> use strict;
>
> my $infile1 = 'doit.in1';
> open (IN1, $infile1) || die "Cannot open $infile1: $!";
>
> my $infile2 = 'doit.in2';
> open (IN2, $infile2) || die "Cannot open $infile2: $!";
>
> my $counter = 0;
>
> my %lines = map(($_, $counter++), <IN1>);
>
> foreach (<IN2>) {
> printf("%5d: %s", $lines{$_}, $_) if exists $lines{$_};
> }
>
>Or, if you need the output sorted by line number, replace the foreach
>with:
>
> print sort map sprintf("%5d: %s", $lines{$_}, $_),
> grep {exists $lines{$_}} <IN2>;
>
>What the heck, I'll even put parentheses in it so you can tell which
>things are parameters for which other things:
>
> print(sort(map(sprintf("%5d: %s", $lines{$_}, $_),
> grep(exists $lines{$_}, <IN2>))));
>
>Hope that helps somewhat. Of course, now you'll finish the
>assignment, and your boss will give you another, more difficult
>assignment, and they you'll really be in trouble. I strongly suggest
>you get a copy of Learning Perl, and start reading the copious online
>documentation that comes with your Perl distribution (man perl, or
>perldoc perl for non-Unix systems).
>
>--
> _____
>|/// | Brand Hilton bhilton@adc.com
>| ADC| ADC Telecommunications, ATM Transport Division
>|_____| Richardson, Texas
--
_____
|/// | Brand Hilton bhilton@adc.com
| ADC| ADC Telecommunications, ATM Transport Division
|_____| Richardson, Texas
------------------------------
Date: Tue, 27 Oct 1998 13:20:18 -0600
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: newbie needs help with file comparison loop
Message-Id: <36361CF2.3C7E345F@houston.Geco-Prakla.slb.com>
John Porter wrote:
>
> gsechen2@my-dejanews.com wrote:
> >
> > I have two data files both datafiles need to be read in. The first datafile
> > needs to be compared (line-by-line) to the second datafile. If a line of data
> > in the first datafile matches any line in the second data file I need it to
> > print the line and the line number.
<snip>
> $counter = 0;
> while ( <IN1> ) { # assigns to $_
> $line1 = $_;
> $counter++;
> $line2 = <IN2>;
>
> if ( $line1 eq $line2 ) {
> print "$counter: $line1";
> }
> }
<snip>
> hth,
> John Porter
John made some very good points about your code. One thing that John
didn't take into consideration (or maybe he did, but left it for an
exercise for the reader :-) is the possibility that the files are of
different line counts. Unless I miss my guess, it could matter,
especially when trying to read file2 if it has already reached eof.
Here's my attempt at it:
#!/usr/local/bin/perl -w
use strict;
use FileHandle;
my $fh0 = new FileHandle;
my $fh1 = new FileHandle;
if (scalar(@ARGV) != 2) {
print "Must include 2 files.\n";
exit 1;
} elsif ($ARGV[0] == $ARGV[1]) {
print "Must be 2 different files.\n";
exit 1;
}
open($fh0,$ARGV[0]) or die "Cannot access $ARGV[0]: $!\n";
open($fh1,$ARGV[1]) or die "Cannot access $ARGV[1]: $!\n";
my @firstFile = <$fh0>; my @secondFile = <$fh1>;
close($fh0,$fh1);
my $largest = scalar(@firstFile) > scalar(@secondFile) ?
scalar(@firstFile) : scalar(@secondFile);
for (my $i = 0; $i < $largest; $i++) {
last if (!defined($firstFile[$i]) or ! defined($secondFile[$i]));
if ($firstFile[$i] eq $secondFile[$i]) {
print $i+1, " ", $firstFile[$i];
}
}
print "\n\n__DONE!__\n\n";
__END__
Summary of above processing:
1. Some error checking
2. open the files
3. read the entire files into 2 arrays
4. close the files.
5. determine the number of lines in the larger of the two files.
6. iterate from 0 (beginning of array) to number of lines - 1 (index is
0 - 7 if there are 8 lines...)
7. If either array doesn't have a defined element, means we reached
eof, stop processing.
8. If the lines are equal, print the index + 1 to get the line number,
followed by a space, and the line.
Works for me, given your sample files.
HTH.
Dave
--
Dave Barnett Software Support Engineer (281) 596-1434
If you're born again, do you have two belly-buttons?
------------------------------
Date: Tue, 27 Oct 1998 12:47:32 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: newbie needs help with file comparison loop
Message-Id: <MPG.109fd13feecd7837989842@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <363623E7.7AFC@fc.hp.com> on Tue, 27 Oct 1998 12:49:59 -0700,
Arne Jamtgaard <arnej@fc.hp.com> says...
...>
> Okay, I can see a few problems here.
I can see a few problems in your response.
...
> 2) You're doing an assign (=) instead of a comparison (==)
> in your if statement. (You're also missing parens!)
Comparison of strings is done by 'eq', not '=='.
> Why not:
>
> Read the second file into a single string, and then step
> through the first file, line by line, and check for the
> presence of the line in the big string?
Why? This is an O(n ** 2) algorithm, and it will not be trivial to
determine what the line number of the match is, as was requested.
Use a hash, as others (and the FAQ in perlfaq5: "How can I tell whether
an array contains a certain element? ") have suggested.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 27 Oct 1998 14:31:42 -0700
From: Arne Jamtgaard <arnej@fc.hp.com>
Subject: Re: newbie needs help with file comparison loop
Message-Id: <36363BBE.51FA@fc.hp.com>
Larry Rosler wrote:
> In article <363623E7.7AFC@fc.hp.com> on Tue, 27 Oct 1998 12:49:59
> -0700, Arne Jamtgaard <arnej@fc.hp.com> says...
> > Okay, I can see a few problems here.
> I can see a few problems in your response.
> ...
> > 2) You're doing an assign (=) instead of a comparison (==)
> > in your if statement. (You're also missing parens!)
> Comparison of strings is done by 'eq', not '=='.
Yup. My bad.
> > Why not:
> > Read the second file into a single string, and then step
> > through the first file, line by line, and check for the
> > presence of the line in the big string?
> Why? This is an O(n ** 2) algorithm, and it will not be trivial to
> determine what the line number of the match is, as was requested.
The line number is for the line in the first file, at least from
what I read in his description and his code. This approach would
preserve that.
> Use a hash, as others (and the FAQ in perlfaq5: "How can I tell
> whether an array contains a certain element? ") have suggested.
I posted, then read your reply, to which I smacked my forehead.
You're absolutely right.
My approach would work, but yours is definitely much better.
Arne
------------------------------
Date: Tue, 27 Oct 1998 21:08:12 GMT
From: dkirby@see.sig.for.addr (Dave Kirby)
Subject: Re: Not to start a language war but..
Message-Id: <3638361e.11030167@read.news.global.net.uk>
On Sat, 24 Oct 1998 16:30:34 +0000, WMWilson <m.v.wilson@erols.com>
wrote:
> Not to start a language war but..
Fat chance!
>Just wondering why Perl is so much more popular than python...I've just
>started learning Perl and have somewhat of an interest in possibly
>giving Python a try as well, just to see which works better for me. It
>doesn't seem like there's as much Python info out there though, I don't
>even have any man pages (that I've found at least) for Python. What's
>the deal?
The answer is simple - perl was there first and found an ecological
niche that was virtually empty and filled it extremely well. When
python came along a few years later it had a far harder job since it
is aimed at a niche that largely overlaps with perl (but not totally)
so does not have the vacuum to fill that perl had. If python had been
an inferior language it would have withered and died years ago, but
instead it is flourishing - it is more or less at the same level of
support, awareness and growth that perl was when I started using perl
about 5 years ago, and I believe it will grow in a similar way over
the next 5 years.
> Is it harder, or just newer and hasn't quite been recognized
>yet, or something else?
It is newer, but definitely NOT harder. In fact of all the languages I
know it is the easiest to learn, IMHO far easier than perl or even
BASIC. A competent, experienced programmer can be writing useful code
in python in a matter of hours, and the code he or she writes will
generally be readable and well structured.
There has been a lot of debate in this thread saying that you can
write good or bad code in any language - that a bad programmer in
python will write worse code than a good programmer in perl. This is
true of course, but totally irrelevant. For someone who is equally
skilled in both languages their code will generally be more readable
in python. Of course this is a matter of opinion since anyone reading
their code who only knows perl will find the perl easier to read, and
vice versa, so YMMV. However I am sure that if I am given a program
in perl and the equivalent one in python (assuming both are written by
equally competent programmers) then I will generally find the python
one easier to read, despite the fact that I have programmed perl
extensively for years and python only for a few months.
> Also, from everything I've read Python is
>object-oriented, I've read a little about object-oriented programming,
>but all in all I haven't really been able to figure out what the big
>deal is, can someone clue me in on this.
Yes python is OO, and so is perl. However creating a class in perl is
frankly a pain in the ass, so a lot of people stick to procedural
programming in that language. If you want to learn OO techniques then
python is a good language to do it in.
I programmed for years in perl and I still like the language, but
since I discovered python I like the newer language better. For simple
text processing perl has the edge on convenience, but for anything
more complicated give me python any day.
Here are a few reasons why I prefer python (in no particular order):
* its cleaner and simpler. This makes it easier to learn, but it does
not sacrifice any power for that simplicity.
* better OO - see earlier comments.
* better cross platform support. Since I work in Windows/NT this is a
biggie. Although there are Windows versions of perl it is primarily a
UNIX tool and the Windows support is secondary. Python is truely cross
platform and with PythonWin I can create COM objects, do Active
Scripting, access the windows API & MFC etc.
* better interactive support. The interactive consol is a joy to use,
particularly via PythonWin or PTUI. You can try out code
interactively, including defining functions and classes, and
immediately see the result. This is great for learning the language
and for trying out new ideas.
* JPython. I can write java applets in python (or a python/java mix)
that can be downloaded and run in a browser. I can create a java
class and then subclass it in python, and if I want can compile the
new class and subclass it again in java.
There is a perl/java hybrid but I havn't used it (since AFAIK it is
not publicly available - you have to buy the perl kit from O'Reilly).
I also believe that it is not a pure java package - you still need the
perl runtime installed to execute programs written in it.
* Exceptions. These make error handling far easier and greatly
simplify the code.
* Easy embeding and extending. I can easily write extensions in C, C++
or other languages and they become a part of python. I can also embed
the interpreter in a C or C++ (or java with jpython) application to
give it scripting capabilities. These are possible in perl, but are
far more complex.
Of course there are disadvantages to python - no language is perfect.
The ones that come to mind are:
* Less mature. It has not been around as long as perl or had the same
growth that perl has enjoyed over the last few years. This is a root
cause of most of the following disadavantages, and will improve over
time.
* Less well documented. The core language is pretty well documented,
but some of the extension modules are not. There are also now dozens
of perl books but only two python books out (with at least two more on
the way).
* Less well supported. There are fewer python programmers out there,
and very few advertized job for them (in fact I have never seen any).
Learning python purely as a career move is not a sensible option
_at_the_moment_. This will change as python gains ground.
The fact that there are more perl programmers who have been using it
for longer also means that there is a huge library of existing perl
code, which has been neatly organised into the CPAN archive.
* Perl has better regex support. Regular expressions are built into
the core of the perl language, so many text processing tasks are
faster and simpler in perl. Python has a regular expression library
which is compatible with perl 5.004, but since it is a library it is
less convenient to use. Also parts of the library are still
implemented in python rather than C, so are markedly slower (though I
believe this will change in the next release). This, along with the
"while (<>)" construct make perl better for writing simple text
filtering programs.
* Block structuring by indentation. Some people hate this and some
people love it. I was put off of trying python for a long time because
of this, but after using it for a few days it seemed far more natural
than cluttering up the screen with curly braces. There is one caveat
though - you have to be careful not to mix indentation by tabs with
indentation by spaces. this can be a problem in a programming team
where everyone uses their own favourite editor. The compiler can warn
of inconsistent indentation, but it is still something you need to
keep an eye on.
The bottom line is that both languages are freely available - it just
costs some of your time to try them both and make up your own mind.
Dave K
-----------------------------------------------------------
The Python language -
why settle for snake-oil when you can have the *whole* snake?
dkirby@ <-figure this out, spambots!
bigfoot. My opinions are my own,
com but I'm willing to share.
------------------------------
Date: Tue, 27 Oct 1998 22:24:17 +0100
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: OLE and EXCEL
Message-Id: <363b3845.48873436@news3.ibm.net>
[mailed & posted]
"Geir Sjurseth" <geir_sjurseth@dell.com> wrote:
>Does anyone out there know how to open up an .XLS file read only? I just
>need to know the syntax for perl and the OLE module. I can open it up in
>the background, but it then asks me if I wanna type in the password. I
>would just like to automate this and have the perl script answer "Read Only"
>for me. Thanks in advance for any help.
Did you try the "obvious" method:
my $Book = $Excel->Workbooks->Open({FileName => $file, ReadOnly => 1});
This obviously works only with Win32::OLE and not with OLE.pm, because the
later doesn't support named parameters. You might try
my $Book = $Excel->Workbooks->Open($file, 0, 1);
The 2nd parameter is the UpdateLinks parameter. Look it all up in the
Microsoft Excel object model (Visual Basic reference).
-Jan
------------------------------
Date: Tue, 27 Oct 1998 22:24:16 +0100
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: Open an existing Microsoft Excell workbook and write to a particular cell
Message-Id: <363a3698.48444779@news3.ibm.net>
[mailed & posted]
"Majid Sharif" <majid.sharif@mci.com> wrote:
>Using Perl from a DOS promt, I'm trying to open an existing Microsoft Excell
>workbook and write to a particular cell. However, I'm receiving an error
>message of: "Can't call method "worksheets" without a package or object
>reference at cpexcel1.pl line 16.
You should use "perl -w" to run your problem. Win32::OLE gives much better
error messages in that mode :-)
>use strict;
>
>use Win32::OLE;
>
>my ($ex, $Row, $Column);
>
>$ex = new Win32::OLE 'Excel.Application' or die "oops\n";
>
>
># open an existing workbook
>
>$ex->Workbooks->Open( 'test.xls' );
You should provide the full path here. The current directory for Excel is
not the Perl script directory, but the default file directory. Either look
in the "Tools|Options" dialog where that is or do a
print $ex->{DefaultFilePath};
>
># write to a particular cell
>
>#$ex->Workbooks(1)->Worksheets('Sheet1')->Cells(1,1)->{Value} = "foo";
The Workbooks collection is probably empty, because the Open() method above
most likely failed. This means that $ex->Workbooks(1) returns C<undef>, and
calling the Worksheets() method on C<undef> fails with the above error
message. (I know you've commented out this statement, but the problem is the
same in the following ones too).
-Jan
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 4085
**************************************