[17795] in Perl-Users-Digest
Perl-Users Digest, Issue: 5215 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 28 18:10:40 2000
Date: Thu, 28 Dec 2000 15:10:18 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978045018-v9-i5215@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 28 Dec 2000 Volume: 9 Number: 5215
Today's topics:
Re: looking for a critique - Thanks <admin@j-enterprises.com>
Re: looking for a critique - Thanks (Tad McClellan)
Re: looking for a critique - Thanks <wescott@conterra.com>
Re: looking for a critique - Thanks nobull@mail.com
Re: looking for a critique - Thanks msalerno@my-deja.com
Re: looking for a critique - Thanks (Gary E. Ansok)
Loop is wrong (oh and it won't compile) <lmoran@wtsg.com>
Re: Loop is wrong (oh and it won't compile) <mischief@velma.motion.net>
Re: Loop is wrong (oh and it won't compile) <lmoran@wtsg.com>
Need help changing wrapped line to non-wrapped. <hinson@home.com>
Perl v4 and other bad things <bh_ent@my-deja.com>
Re: Perl v4 and other bad things (Chris Fedde)
Re: Perl v4 and other bad things <Mike.Wescott@crosstor.com>
Re: Problem with urlencoding <flavell@mail.cern.ch>
Re: Problems with Archive::Tar <stuart@numpty.www>
Re: Problems with Archive::Tar <tony_curtis32@yahoo.com>
Q: How do I check to see if a local TCP port is in use <mweatherford@aventail.com>
reading multi-line records <dkite@co.lenoir.nc.us>
Re: reading multi-line records (Tad McClellan)
Re: reading multi-line records <frank.buntschuh@specastro.com>
Re: Saving uploaded files w/CGI.pm -- Linux works great <micah@absolutely.geeks4christ.noorgspam!>
stripping leading and trailing blanks from a string dts@netkonnect.net
Re: stripping leading and trailing blanks from a string (Tad McClellan)
Re: Syntax for "eq" and "||" (Anno Siegel)
Re: Upload multi files with same source nobull@mail.com
Re: Upload multi files with same source <joe+usenet@sunstarsys.com>
Re: URL Testing Routine Problem jpeters@my-deja.com
Using Sendmail with Perl and CGI <g.soper@soundhouse.co.uk>
Re: want to fetch html files without LWP <bart.lateur@skynet.be>
Win32::ODBC - How to test for NULL? (MSSQL7) <mrd1968@my-deja.com>
XML Book recommendation rqd <derek@nospam.demon.co.uk>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 28 Dec 2000 19:03:00 GMT
From: GooglePlexed <admin@j-enterprises.com>
Subject: Re: looking for a critique - Thanks
Message-Id: <92g2ou$och$1@nnrp1.deja.com>
Did you know that you don't need a separate 'my' for each and every
variable:
my ($search,%pwlist,$count,$catalog) = ("em", , 1, 1);
?
--
j-enterprises.com...
custom software solutions for the enterprise
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 28 Dec 2000 12:43:30 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: looking for a critique - Thanks
Message-Id: <slrn94muu2.ghh.tadmc@magna.metronet.com>
GooglePlexed <admin@j-enterprises.com> wrote:
>Did you know that you don't need a separate 'my' for each and every
>variable:
>
>my ($search,%pwlist,$count,$catalog) = ("em", , 1, 1);
Did you know that the "1"s there will go into %pwlist, and
that $count and $catalog will be undef?
my ($search, $count, $catalog, %pwlist) = ("em", 1, 1);
%pwlist will be empty, but declared.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 28 Dec 2000 19:28:37 GMT
From: Mike Wescott <wescott@conterra.com>
Subject: Re: looking for a critique - Thanks
Message-Id: <osu27owdjf.fsf@eriadne.sc.rr.com>
msalerno@my-deja.com writes:
> Please be honest. I know that this script will accomplish what I need it
> to do, but I always like to read what other people would do to improve
> it.
In addition to comments other have made ...
> $pwlist{$count} = [$user,$comment];
Hmm, you're indexing this hash with a counter. I'd use an array in this
case. Or perhaps two:
$user[$count] = $user;
$comment{$count] = $comment;
With other changes to match.
> my $test = keys %pwlist;
Unused. Delete.
--
Mike Wescott
wescott@conterra.com
------------------------------
Date: 28 Dec 2000 20:18:08 +0000
From: nobull@mail.com
Subject: Re: looking for a critique - Thanks
Message-Id: <u9puic5mgv.fsf@wcl-l.bham.ac.uk>
tadmc@metronet.com (Tad McClellan) writes:
> msalerno@my-deja.com <msalerno@my-deja.com> wrote:
> > if (lc($user) =~ /\Q$search/ or lc($comment) =~ /\Q$search/ ) {
>
>
> I looks like you are using pattern matching when you do not need to.
I often use a highspeed hammer drill set to low speed with the hammer
action switched off. Sure I could often do the actual job marginally
quicker using using a smaller, cheeper, lighter low power non-hammer
drill but why clutte my workspace with two tools when I'm comfortable
with one?
> Is there some reason the code below won't work for you?
>
>
> if ( index( lc($user), $search) >= 0 or
> index( lc($comment), $search) >= 0 ) {
Perl is a natural language, and to my eye the following is more
natural:
if ( $user =~ /\Q$search/i or $comment =~ /\Q$search/i ) {
I've benchmarked it and using index() about twice as fast but IMHO
that's only justifiction for choosing it if you are optomising for
speed over readability.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 28 Dec 2000 20:41:18 GMT
From: msalerno@my-deja.com
Subject: Re: looking for a critique - Thanks
Message-Id: <92g8hd$tbo$1@nnrp1.deja.com>
In article <osu27owdjf.fsf@eriadne.sc.rr.com>,
Mike Wescott <wescott@conterra.com> wrote:
> msalerno@my-deja.com writes:
>
> > Please be honest. I know that this script will accomplish what I
need it
> > to do, but I always like to read what other people would do to
improve
> > it.
>
> In addition to comments other have made ...
>
> > $pwlist{$count} = [$user,$comment];
>
> Hmm, you're indexing this hash with a counter. I'd use an array in
this
> case. Or perhaps two:
>
> $user[$count] = $user;
> $comment{$count] = $comment;
>
> With other changes to match.
>
> > my $test = keys %pwlist;
>
> Unused. Delete.
>
> --
> Mike Wescott
> wescott@conterra.com
>
Actually, I have been working on that. I created the script so that the
user can enter a number rather than a username (UID's are not unique !).
Using the hash almost everything is finished, but when I try to
reference a record using the $catalog number, it pulls the wrong record!
They don't seem to match. I will be taking your advice.
Thanks to everyone who answered. It is appreciated.
Matt
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 28 Dec 2000 22:30:22 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: looking for a critique - Thanks
Message-Id: <92getu$l7m@gap.cco.caltech.edu>
In article <92fu7h$kd8$1@nnrp1.deja.com>, <msalerno@my-deja.com> wrote:
>Please be honest. I know that this script will accomplish what I need it
>to do, but I always like to read what other people would do to improve
>it.
>
>Thanks,
>Matt
>
>#!/usr/bin/perl -w
>use strict;
>
>open(PASSWD, "</etc/passwd2") || die "ERROR: Cannot open $!\n";
Excellent so far. In a longer script I like to include the filename
(with delimiters) in the error message ( die "Cannot open '$file': $!" ).
>my $search = "ern";
>my %pwlist;
I'm a bit confused about why you are using a hash here, when an array
would do it more efficiently. The only difference will be the sorting
of the output -- my version will have the output match the order the
records appear in the input file, where yours will have the tenth
matching record appear second (with the catalog number of 2).
my @pwlist;
>my $count = "1";
Not necessary in this version.
>my $catalog = "1";
Moved to the printout loop.
>while (<PASSWD>) {
> my($user, $comment) = (split /:/)[0,4];
> if (lc($user) =~ /\Q$search/ or lc($comment) =~ /\Q$search/ ) {
I would probably use
if ($user =~ /\Q$search/io or $comment =~ /\Q$search/io) {
although using index() would probably be faster. This version
will allow for uppercase letters in $search, as well. Possibly
there would be a small improvement in creating a single regexp
using qr//.
> $pwlist{$count} = [$user,$comment];
> $count++;
Using an array for storage, this becomes
push @pwlist, [$user, $comment];
> }
> }
Most people line the closing brace up with the while() or if() it
refers to -- or to the opening brace, if that's on a separate line.
As long as you're consistent, it's mostly a style issue.
>my $test = keys %pwlist;
Not necessary (even in your version).
>foreach (sort keys %pwlist) {
>print "Catalog # $catalog\tUser: $pwlist{$_}[0]\tComments:
>$pwlist{$_}[1]\n";
>$catalog++;
Using an array for storage, this becomes
foreach my $index (0..$#pwlist) {
my $catalog = $index + 1;
print "Catalog # $catalog\t",
"User: $pwlist[$index][0]\t",
"Comments: $pwlist[$index][1]\n";
}
(Of course, there are ways to write that last loop to get rid of
the $catalog variable entirely. Also, I might use printf to get more
consistent formatting.)
Not a bad script, though.
-- Gary Ansok
------------------------------
Date: Thu, 28 Dec 2000 15:10:11 -0500
From: Lou Moran <lmoran@wtsg.com>
Subject: Loop is wrong (oh and it won't compile)
Message-Id: <d57n4t4nnq3qhrn9urfu43khburoso0hdo@4ax.com>
--So someone was writing some code in Java to test for leap year.
They tried to explain it to me but I couldn't get it so I dashed off a
quick 10 line script and it worked great. Helped them out to see it.
--Then Java guy says, "Hey make it so it will know if the input is a
number or not.
--Things have gone South since. I did this once before I *think* the
regex is right but I can't tell b/c something is wrong and it won't
compile.
--I looked at the older code that did this and I haven't radically
changed things.
--any ideas why the below doesn't work and/or better (I hope the
formatting isn't horrible from my newsreader to yours)
thanks
____________________________________________________
#!/usr/bin/perl -w
use strict;
print "Leap Year?\n\n";
my $year = <STDIN>;
print "Enter a year: ";
chomp ($year);
if ($year < 1582) {
die "Year must be greater than 1581 because of
Clavius. \n\n";}
#check to make sure year entered is a number
my $is_valid = 0;
until ($is_valid) {
if ($year =~ m/^\d+$/) {
$is_valid = 1;
}elsif{
print "Invalid input, please enter an interger
over 1581 for your year.\n\n";
}elsif{ ($year % 4 == 0 && $year % 100 != 0 || $year %
400 ==0)
print "$year is a Leap Year.\n";
}else{
print "$year is not a Leap Year.\n";
}
}
lmoran@wtsgSPAM.com
print "\x{263a}"
------------------------------
Date: Thu, 28 Dec 2000 22:16:06 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Loop is wrong (oh and it won't compile)
Message-Id: <t4net6rr80eq91@corp.supernews.com>
Lou Moran <lmoran@wtsg.com> wrote:
> --So someone was writing some code in Java to test for leap year.
> They tried to explain it to me but I couldn't get it so I dashed off a
> quick 10 line script and it worked great. Helped them out to see it.
Cool. Inter-language discussion of a problem.
> --Then Java guy says, "Hey make it so it will know if the input is a
> number or not.
Good idea.
> --Things have gone South since. I did this once before I *think* the
> regex is right but I can't tell b/c something is wrong and it won't
> compile.
The problem I found is with syntax, not the regex. See below.
> --I looked at the older code that did this and I haven't radically
> changed things.
The small changes you made might be the syntax errors I'll mention
later.
> --any ideas why the below doesn't work and/or better (I hope the
> formatting isn't horrible from my newsreader to yours)
The formatting is horrible in my newsreader. Most programmers use
a fixed-width font in their newsreaders, and most use spaces for
indentation. Your indentation seems to use tabs instead of multiple
spaces.
##################### OP's code to marker ############################
> #!/usr/bin/perl -w
> use strict;
> print "Leap Year?\n\n";
> my $year = <STDIN>;
> print "Enter a year: ";
> chomp ($year);
> if ($year < 1582) {
> die "Year must be greater than 1581 because of
> Clavius. \n\n";}
> #check to make sure year entered is a number
> my $is_valid = 0;
> until ($is_valid) {
> if ($year =~ m/^\d+$/) {
> $is_valid = 1;
> }elsif{
> print "Invalid input, please enter an interger
> over 1581 for your year.\n\n";
> }elsif{ ($year % 4 == 0 && $year % 100 != 0 || $year %
> 400 ==0)
> print "$year is a Leap Year.\n";
> }else{
> print "$year is not a Leap Year.\n";
> }
> }
#################### end of OP's code ###############################
Blech. I don't like your indentation. I have always felt elsif should
line up with the if. You also used tabs instead of spaces, which makes
things turn out ugly sometimes when moved to systems with different
ideas about how tabs should be rendered.
Anyway, take a look at this, the error is in syntax, and I'll comment
where the problems are:
########### code to end of marker ##################################
until ($is_valid) {
if ($year =~ m/^\d+$/) {
$is_valid = 1;
##############################
### } elsif {
##############################
print "Invalid input, please enter an interger over 1581 for your year.\n\n";
##############################
### } elsif { ($year % 4 == 0 && $year % 100 != 0 || $year % 400 ==0)
##############################
print "$year is a Leap Year.\n";
} else {
print "$year is not a Leap Year.\n";
}
}
############### enxd of code #####################################
The marked lines both lack a test case for the 'elsif'. The latter seems
to have the curly which opens the execution block and the test case
reversed, while the former simply doesn't seem to have a test case at all.
} elsif {
} elsif ($year % 4 == 0 && $year % 100 != 0 || $year % 400 ==0) {
Please, always make sure you cut and paste into the group any code with which
you find fault, instead of rekeying it. If you did cut and paste the above code,
I understand why you are having errors.
Please also pay attention to the errors which you get when your programs
fail to compile. I got the following errors when compiling your code:
### output from running try2 : #####################################
syntax error at try2 line 16, near "elsif{"
syntax error at try2 line 19, near "}elsif"
Execution of try2 aborted due to compilation errors.
### end of output ##################################################
This should tell you there is a syntax error on (or at least near) line 16, and
again the same problem on line 19.
The logic errors I see are where you prompt for someone to enter a year to
be checked after the year has been read and that you use an until loop to
see if the year entered is valid, but do not allow the user to actually enter
a new value if the original is not valid.
Take a look at this section:
### code til marker ################################################
> print "Leap Year?\n\n";
> my $year = <STDIN>; ### reads input #############
> print "Enter a year: "; ### prompts for input #######
> chomp ($year);
> if ($year < 1582) {
> die "Year must be greater than 1581 because of
> Clavius. \n\n";}
### end of code ####################################################
You need to reverse those commented lines.
You also seem to suffer from a misconception of Perl semantics, because you
check for $year being less than 1582 before you check to see if it is all digits.
If it is not all digits, then the less-than ( '<' ) operator cannot be properly
used. You should make that check after you know the input is all digits. You
can then make your judgment about the validity of the input based upon both
criteria.
I changed just a couple of small details. I changed output formatting, just
to make the output look more reasonable to me. I also added some comments.
I find that if I put into the comments what I am trying to do, then code
according to the comments, I sometimes avoid errors in the first place.
If nothing else, your comments can help you find existing errors by
forcing you to explain to yourself what is happening. Of course, you need
to debug the code and not the comments, but if the comments and code do
not match, then I consider that a bug all by itself, as is mentioned
by Kernighan and Pike in _The_Practice_of_Programming_ ( Addison-Wesley
Pub Co; ISBN: 020161586X ).
Here is a program that has been trivially corrected and transformed
from the original, and has passed ad-hoc testing:
################### code to marker ##################################
#!/usr/bin/perl -w
use strict;
print "Leap Year?\n\n";
#check to make sure year entered is a number
my $is_valid = 0;
until ($is_valid) {
print "Enter a year: "; # prompt for input
my $year = <STDIN>; # read input
chomp ($year);
print("\n"); # end the line, so further output doesn't
# need to do so
if ($year =~ m/^\d+$/) { # test to make sure you have all digits
if ($year < 1582) { # test to make sure year is over 1581
print "Year must be greater than 1581 because of Clavius.\n";
} else {
$is_valid = 1;
}
}
if($is_valid == 0) {
print "Invalid input, please enter an integer over 1581";
print " for your year.\n\n";
} elsif ( $year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0 ) {
### Leap years are divisible by 4 but not by 100 unless also
### divisible by 400
print "$year is a Leap Year.\n";
} else {
print "$year is not a Leap Year.\n";
}
}
############### end of code #########################################
Here's my test data:
The program accepts 1600, 2000, 2400, and 16000 as leap years.
It does not accept 1700, 1800, 1900, or 2100.
It does accept 1586, 1560, 1980, 1984, 1988, 1992, and 1996 as leap years.
It does not accept 1582, 1669, 1981, 1982, 193, 1985, 1986, 1987, 1989, 1990,
1991, 1993, or 1999 as leap years.
I hope this helps.
Christopher
--
Christopher E. Stith
Try not. Do, or do not. The Force is binary. -- Yoda, The Empire Strikes Back (paraphrased)
------------------------------
Date: Thu, 28 Dec 2000 17:40:05 -0500
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: Loop is wrong (oh and it won't compile)
Message-Id: <g9gn4t0iao4mlj0kkjit5gtalr16vlcirm@4ax.com>
On Thu, 28 Dec 2000 22:16:06 -0000, in comp.lang.perl.misc you wrote:
{SNIP}
>The problem I found is with syntax, not the regex. See below.
>
>> --I looked at the older code that did this and I haven't radically
>> changed things.
>
>The small changes you made might be the syntax errors I'll mention
>later.
>
>> --any ideas why the below doesn't work and/or better (I hope the
>> formatting isn't horrible from my newsreader to yours)
>
>The formatting is horrible in my newsreader. Most programmers use
>a fixed-width font in their newsreaders, and most use spaces for
>indentation. Your indentation seems to use tabs instead of multiple
>spaces.
>
I was using ultraedit32 and I think you're right, it uses tabs instead
of spaces.
It was cut and pasted
{SNIP}
>
>Blech. I don't like your indentation. I have always felt elsif should
>line up with the if. You also used tabs instead of spaces, which makes
>things turn out ugly sometimes when moved to systems with different
>ideas about how tabs should be rendered.
>
>Anyway, take a look at this, the error is in syntax, and I'll comment
>where the problems are:
>
>
>
>########### code to end of marker ##################################
>
>until ($is_valid) {
> if ($year =~ m/^\d+$/) {
> $is_valid = 1;
> ##############################
> ### } elsif {
> ##############################
>
> print "Invalid input, please enter an interger over 1581 for your year.\n\n";
>
> ##############################
> ### } elsif { ($year % 4 == 0 && $year % 100 != 0 || $year % 400 ==0)
> ##############################
>
> print "$year is a Leap Year.\n";
> } else {
> print "$year is not a Leap Year.\n";
> }
>}
>############### enxd of code #####################################
>
>
>
>The marked lines both lack a test case for the 'elsif'. The latter seems
>to have the curly which opens the execution block and the test case
>reversed, while the former simply doesn't seem to have a test case at all.
>
>
>} elsif {
>
>} elsif ($year % 4 == 0 && $year % 100 != 0 || $year % 400 ==0) {
>
>
>
>Please, always make sure you cut and paste into the group any code with which
>you find fault, instead of rekeying it. If you did cut and paste the above code,
>I understand why you are having errors.
>
>Please also pay attention to the errors which you get when your programs
>fail to compile. I got the following errors when compiling your code:
>
>### output from running try2 : #####################################
>syntax error at try2 line 16, near "elsif{"
>syntax error at try2 line 19, near "}elsif"
>Execution of try2 aborted due to compilation errors.
>### end of output ##################################################
>
>
>This should tell you there is a syntax error on (or at least near) line 16, and
>again the same problem on line 19.
>
The one thing I sort of dislike about Perl is when it tells me a line
number I believe it. I find a lot of times that the problem is a line
or two above the line (like a missing semi colon or something. I
still use -w but think it's weird that it says the problem is one
place and it's really somewhere else.
>The logic errors I see are where you prompt for someone to enter a year to
>be checked after the year has been read and that you use an until loop to
>see if the year entered is valid, but do not allow the user to actually enter
>a new value if the original is not valid.
I have since moved things around, the problems were in fact with those
elseif 's
>
>Take a look at this section:
>
>
>### code til marker ################################################
>> print "Leap Year?\n\n";
>
>> my $year = <STDIN>; ### reads input #############
>> print "Enter a year: "; ### prompts for input #######
>> chomp ($year);
>> if ($year < 1582) {
>> die "Year must be greater than 1581 because of
>> Clavius. \n\n";}
>### end of code ####################################################
>
>
>You need to reverse those commented lines.
>
>You also seem to suffer from a misconception of Perl semantics, because you
>check for $year being less than 1582 before you check to see if it is all digits.
>If it is not all digits, then the less-than ( '<' ) operator cannot be properly
>used. You should make that check after you know the input is all digits. You
>can then make your judgment about the validity of the input based upon both
>criteria.
>
>I changed just a couple of small details. I changed output formatting, just
>to make the output look more reasonable to me. I also added some comments.
>
>I find that if I put into the comments what I am trying to do, then code
>according to the comments, I sometimes avoid errors in the first place.
>If nothing else, your comments can help you find existing errors by
>forcing you to explain to yourself what is happening. Of course, you need
>to debug the code and not the comments, but if the comments and code do
>not match, then I consider that a bug all by itself, as is mentioned
>by Kernighan and Pike in _The_Practice_of_Programming_ ( Addison-Wesley
>Pub Co; ISBN: 020161586X ).
{SNIP}
>I hope this helps.
>
Thanks,
That did help, seeing your correct code made me understand where my
until needed to be and of course you are right my error check was all
over the place.
thanks for helping out.
>Christopher
lmoran@wtsgSPAM.com
print "\x{263a}"
------------------------------
Date: Thu, 28 Dec 2000 20:59:49 GMT
From: Roger Hinson <hinson@home.com>
Subject: Need help changing wrapped line to non-wrapped.
Message-Id: <3A4BA94A.5AA7B24D@home.com>
Hi all,
I'm getting some output from a program that wraps the line if it
exceeds 101 characters. The output looks like this:
Work item name Level Start time Time used Backup
Files\ bad Size Catalog
-----------------------------------------------------------------------------------------------------
server.backup.somewhere.com:servername
9 12/24/00 12:01:42 0:25:45 Completed
951\ 0 48.4 MB Complete
server.backup.somewhere.com:server
9 12/24/00 13:01:27 0:12:58 Completed
173\ 0 303.3 MB Complete
What I want to do is put it back on one line. This is my first attempt
at programming and I've come up with this script.
#!c:/perl
# Open the daily log
$TESTFILE="c:/roger/perl/12242000.txt";
$OUTFILE="c:/roger/perl/12242000.log";
open FILEHANDLE, $TESTFILE;
open OUT, ">$OUTFILE";
while (<FILEHANDLE>) {
tr/\012/#/; #remove the new line and replace with a #
s/# / /ig; #if the resulting line has spaces after # take
them out
tr/#/\012/; #replace the remaining #'s with new lines
print OUT; #write the file
}
I've tried the script and it writes the file just as it was when I
started. I'm doing something wrong with the substitution, but I can't
figure out what.
Thanks for any help..
Roger
------------------------------
Date: Thu, 28 Dec 2000 20:33:55 GMT
From: Drew Myers <bh_ent@my-deja.com>
Subject: Perl v4 and other bad things
Message-Id: <92g83i$t42$1@nnrp1.deja.com>
I was asked to create a perl prog that would parse out various
information from multiple data files. Fine. I was asked to modify the
prog to output this information in a particular format. No problem,
with the help of this newsgroup. Now I have been asked to make this
prog run on 22 different boxes with perl 4.0.1.8 installed. Houston,
well you know the rest.
Anyone have any suggestions on modifying an existing, working perl
5.6.0 prog to work on perl 4.0.1.8? I would upgrade the existing perl
installations, but these are all HP machines and that would mean
purchasing (due to contract restrictions, we aren't allowed to use gcc)
22 ANSI C++ compilers from HP.
Yours in tears,
Drew Myers
perotsystems
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 28 Dec 2000 21:07:55 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Perl v4 and other bad things
Message-Id: <LYN26.507$B9.189437440@news.frii.net>
In article <92g83i$t42$1@nnrp1.deja.com>,
Drew Myers <bh_ent@my-deja.com> wrote:
>I was asked to create a perl prog that would parse out various
>information from multiple data files. Fine. I was asked to modify the
>prog to output this information in a particular format. No problem,
>with the help of this newsgroup. Now I have been asked to make this
>prog run on 22 different boxes with perl 4.0.1.8 installed. Houston,
>well you know the rest.
>
>Anyone have any suggestions on modifying an existing, working perl
>5.6.0 prog to work on perl 4.0.1.8? I would upgrade the existing perl
>installations, but these are all HP machines and that would mean
>purchasing (due to contract restrictions, we aren't allowed to use gcc)
>22 ANSI C++ compilers from HP.
>
You can use Perl but not GCC? How inconsistant. You can get 1 compiler
Install 5.6.0 on one box then copy the files to each machine. Alternately
you might want to see what is available to help you out at
http://devresource.hp.com/OpenSource/Tools.
Good luck
chris
--
This space intentionally left blank
------------------------------
Date: 28 Dec 2000 16:29:44 -0500
From: Mike Wescott <Mike.Wescott@crosstor.com>
Subject: Re: Perl v4 and other bad things
Message-Id: <ouy9x0mdyv.fsf@strange.cae.crosstor.com>
Drew Myers <bh_ent@my-deja.com> writes:
> [...]
> Anyone have any suggestions on modifying an existing, working perl
> 5.6.0 prog to work on perl 4.0.1.8? I would upgrade the existing perl
> installations, but these are all HP machines and that would mean
> purchasing (due to contract restrictions, we aren't allowed to use gcc)
> 22 ANSI C++ compilers from HP.
Simple perl programs are often easily backward compatible. That said,
however, you really ought to upgrade the machines. Why do you need a
unique C compiler for each machine? Can't you compile once and
distribute the results? Or better yet, why not get pre-compiled
binaries? A quick web search shows several versions of perl available,
some from HP itself.
--
Mike Wescott
mike.wescott@crosstor.com
------------------------------
Date: Thu, 28 Dec 2000 21:18:44 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Problem with urlencoding
Message-Id: <Pine.LNX.4.30.0012282112450.640-100000@lxplus003.cern.ch>
On Fri, 22 Dec 2000, Dr. Peter Dintelmann wrote:
> there is a URI::Escape module providing a function for
> this.
Indeed there is, and those who need to ask would be well-advised to
use it.
> Here is a quick "hack". Be careful! I did not test this
> code; I just wrote it down...
Why did you go and do that?
You seem to have given good advice with one hand, and taken it away
with the other. (No, I haven't reviewed the code; this isn't the kind
of thing one should do on the fly on usenet. Maybe the code is
perfect, but that isn't the point. There's a more-general principle
at stake, and security loopholes are lying in wait.)
------------------------------
Date: Thu, 28 Dec 2000 20:58:48 GMT
From: "Stuart" <stuart@numpty.www>
Subject: Re: Problems with Archive::Tar
Message-Id: <cQN26.67290$2L2.5633657@news3.cableinet.net>
"BUCK NAKED1" <dennis100@webtv.net> wrote in message
news:22475-3A49A547-20@storefull-246.iap.bryant.webtv.net...
> I think you forgot a line. "extract_archive" extracts and writes.
>
> Try this coding for the Archive/Tar part of your script.
>
> use Archive::Tar;
> $tar = Archive::Tar->new();
> $tar->extract_archive("blah.tar.gz",1);
>
> Tested and works for me.
>
> I hope this helps,
> --Dennis
>
Thanks for the reply,
I'm not sure I understand fully what you mean...
I tried this:
use Archive::Tar;
$compressedfilenew = Archive::Tar->new();
$compressedfilenew->add_files('$newfile');
$compressedfilenew->extract_archive('/home/servername/www/archives/access-lo
g.tar.gz' ,1);
And I don't get any compressed file at all...
I tried this:
use Archive::Tar;
$compressedfilenew = Archive::Tar->new();
$compressedfilenew->add_files('$newfile');
$compressedfilenew->extract_archive('/home/servername/www/archives/access-lo
g.tar.gz' ,1);
$compressedfilenew->write('/home/servername/www/archives/access-log.tar.gz'
,1);
And I still get a zero byte file!
It's getting to be quite frustrating!
Stuart
------------------------------
Date: 28 Dec 2000 15:02:49 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Problems with Archive::Tar
Message-Id: <87lmt0dzt2.fsf@limey.hpcc.uh.edu>
>> On Thu, 28 Dec 2000 20:58:48 GMT,
>> "Stuart" <stuart@numpty.www> said:
> I tried this:
> $compressedfilenew->add_files('$newfile');
> And I don't get any compressed file at all...
You don't have a file called '$newfile' which contains a gzipped tar
archive.
(i.e. lose the single quotes, they prevent variable interpolation).
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: Thu, 28 Dec 2000 22:47:11 GMT
From: none <mweatherford@aventail.com>
Subject: Q: How do I check to see if a local TCP port is in use or free?
Message-Id: <b25q4t0l89gt59mcplb6avlc79fgbftve3@4ax.com>
I am creating SSH tunnels from a localhost to a remote machine, and
want to check to see if a port # on localhost is free to be used to
make the tunnel. Is there a perl "Quickie" to do this?
If its not too much to ask, pls email reply also to:
mweatherford@aventail.com
Thanks!
Matt
------------------------------
Date: Thu, 28 Dec 2000 20:00:59 GMT
From: Doug Kite <dkite@co.lenoir.nc.us>
Subject: reading multi-line records
Message-Id: <92g65n$r9c$1@nnrp1.deja.com>
How do I set $/ so that it will read three lines for each record?
There are no blank lines separating records, and there is no consistent
text at the beginning of each record (like a header), and the records
are not all the same length.
Sample data follows (3 records):
UO-14
1 20437U 90005B 00362.20357791 .00000470 00000-0 19619-3 0 5856
2 20437 98.3860 62.5557 0011455 8.8249 351.3133 14.30607735570466
RS-10/11
1 18129U 87054A 00361.97069404 .00000149 00000-0 14658-3 0 8848
2 18129 82.9245 6.0084 0010119 242.2465 117.7666 13.72539066677015
STRV 1C
1 26610U 00072C 00348.77010174 .00000229 00000-0 00000-0 0 125
2 26610 6.3262 237.9809 7347700 194.4901 123.3033 1.99965837 563
Each record is three lines long, but there are no spaces, blank lines or
anything. Can $/ be set to grab a certain number of lines?
Thanks,
Doug
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 28 Dec 2000 13:22:29 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: reading multi-line records
Message-Id: <slrn94n175.gl6.tadmc@magna.metronet.com>
Doug Kite <dkite@co.lenoir.nc.us> wrote:
>How do I set $/ so that it will read three lines for each record?
You cannot use $/ for that.
>Can $/ be set to grab a certain number of lines?
No.
But you can easily manufacture 3-line chunks:
while (<>) {
$_ .= <>; # second line
$_ .= <>; # and a third
# have your way with the 3-line record
}
Fails miserably if the number of lines is not a multiple of 3 though...
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 28 Dec 2000 22:01:10 GMT
From: Frank Buntschuh <frank.buntschuh@specastro.com>
Subject: Re: reading multi-line records
Message-Id: <uk88k9pdp.fsf@specastro.com>
Doug Kite <dkite@co.lenoir.nc.us> writes:
> How do I set $/ so that it will read three lines for each record?
> There are no blank lines separating records, and there is no consistent
> text at the beginning of each record (like a header), and the records
> are not all the same length.
>
> Sample data follows (3 records):
> UO-14
> 1 20437U 90005B 00362.20357791 .00000470 00000-0 19619-3 0 5856
> 2 20437 98.3860 62.5557 0011455 8.8249 351.3133 14.30607735570466
> RS-10/11
> 1 18129U 87054A 00361.97069404 .00000149 00000-0 14658-3 0 8848
> 2 18129 82.9245 6.0084 0010119 242.2465 117.7666 13.72539066677015
> STRV 1C
> 1 26610U 00072C 00348.77010174 .00000229 00000-0 00000-0 0 125
> 2 26610 6.3262 237.9809 7347700 194.4901 123.3033 1.99965837 563
>
> Each record is three lines long, but there are no spaces, blank lines or
> anything. Can $/ be set to grab a certain number of lines?
>
> Thanks,
> Doug
Hi Doug - reading TLEs?
The usual method I use for TLEs is to open the file, and loop over it
with the following (allows for stray blank lines to sneak into the
file, which happens with some elset sources):
open IN, $tle_file or die "file open failed $!";
while(<IN>) {
next if /^\s*$/; # dump blank lines
$line = $_, next if !/^[12] /;
$line .= $_, next if /^1 /;
$line .= $_ if /^2 /;
# do stuff with the TLE here
}
If you are interested in the module I wrote for parsing and
manipulating TLEs (but not propagating the orbits), drop me a private
email.
Frank
------------------------------
Date: Thu, 28 Dec 2000 19:29:24 GMT
From: "Micah K Yoder" <micah@absolutely.geeks4christ.noorgspam!>
Subject: Re: Saving uploaded files w/CGI.pm -- Linux works great, Windows makes it look like crap!
Message-Id: <owM26.198931$U46.6128071@news1.sttls1.wa.home.com>
In article <slrn94mipu.quo.efflandt@efflandt.xnet.com>, efflandt@xnet.com
wrote:
>> # and the pic
>> my $filename = $query->param("pic_$MLS"); if ($filename) {
>> my $picno = GetNumPics($MLS) + 1; open
>> (OUTPICFILE,">$photodir/$MLS-$picno.jpg"); open (INPICFILE,
>> "<$filename");
>
> If "pic_$MLS" is your file upload field then $filename is a filename AND
> filehandle to it. So open(IMPICFILE...) is unnecessary and probably
> what is screwing you up. I don't have a Win box with Perl to test this
> on, but maybe you need to binmode $filename and read from $filename as a
> filehandle (read $filename instead of INPICFILE and dump all other
> statements about INPICFILE).
Interesting, because that's the way I *was* doing it and I thought maybe
that was screwing it up so I changed it to the regular filehandle. Both
methods had the same result -- worked great on Linux, last info under
'Doze.
Guess I'll change it back to that and re-check it...
Thanks,
Micah
------------------------------
Date: Thu, 28 Dec 2000 20:03:34 GMT
From: dts@netkonnect.net
Subject: stripping leading and trailing blanks from a string
Message-Id: <92g6ah$ri2$1@nnrp1.deja.com>
Hello
I am looking for the Perl equivalent of LTRIM/RTRIM in basic.
Is there a handy function or do I have to use a Perl regular expression?
TIA
dan
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 28 Dec 2000 13:24:57 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: stripping leading and trailing blanks from a string
Message-Id: <slrn94n1bp.gl6.tadmc@magna.metronet.com>
dts@netkonnect.net <dts@netkonnect.net> wrote:
> Subject: stripping leading and trailing blanks from a string
^^^^^ ^^^^^
perldoc -q strip
or
perldoc -q blank
"How do I strip blank space from the beginning/end of a string?"
>Is there a handy function or do I have to use a Perl regular expression?
^^^^^^^
You "have to" check the Perl FAQs *before* posting to the
Perl newsgroup. Shame on you.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 28 Dec 2000 19:18:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Syntax for "eq" and "||"
Message-Id: <92g3m7$sl1$1@mamenchi.zrz.TU-Berlin.DE>
The WebDragon <nospam@nospam.com> wrote in comp.lang.perl.misc:
>In article <3a486ebf.56fd$233@news.op.net>, mjd@plover.com (Mark-Jason
>Dominus) wrote:
> | If Damian's Quantum Superpositions thing goes into Perl 6, you'll be
> | able to write
> |
> | if ($in{'Contact_Country'} eq any("Australia","Canada","UK"))
> | {
> | ...
> | }
>
>indeed.. looks *quite* nice, but I've run into a few things in 5.004
>(MacPerl) that I've mailed him about and hope to see an update for
>soonish. (failing some test cases, etc)
This public complaint about Damian's maintenance is in very bad style.
I find it hard to believe you posted that, but I don't see how your
paragraph can be read otherwise.
Anno
------------------------------
Date: 28 Dec 2000 19:51:34 +0000
From: nobull@mail.com
Subject: Re: Upload multi files with same source
Message-Id: <u9snn85np5.fsf@wcl-l.bham.ac.uk>
efflandt@xnet.com (David Efflandt) writes:
> Since CGI.pm stores the file as a tmp file with the name of the uploaded
> file, the second instance of that same file likely overwrites the first
> instance.
IIRC CGI.pm used the name of the uploaded file as the name of the
_filehandle_ not the the name of the file. This was a poor-man's way
to have a single variable overloaded as a filename and as a symbolic
filehandle reference.
I use the past tense because recent versions of CGI.pm don't do this
any more. They use real overloading to make an object that is both a
filename and a proper filehandle reference.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 28 Dec 2000 15:14:02 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Upload multi files with same source
Message-Id: <m3n1dg8fsl.fsf@mumonkan.sunstarsys.com>
efflandt@xnet.com (David Efflandt) writes:
> On Thu, 28 Dec 2000, martinnitram@my-deja.com wrote:
> >
> > I used CGI.pm to handle upload file. Everything work fine at first,
> >even upload two files in a single form; but if user input same image
> >src in both fields (say, both input c:\image.gif), i found that only
> >the first one can upload successfully, while another one is zero in
> >file size.
What code did you use to arrive at your findings? There is no way
to know how you managed this without posting the offending perl,
HTML, and CGI.pm version. IIRC, there is an old, broken browser
that is capable of "compressing" duplicate file uploads, but modern
browsers should work fine.
> >
> > I tried use both open(FILEHANDLER) and FILE::COPY to save the file
> >(and tried both ASCII and Binary file), same error occoured. Anyone had
> >idea in that?
>
> Since CGI.pm stores the file as a tmp file with the name of the uploaded
> file,
No it does not. It creates a temp file in your TMP folder using a
mechanism akin to a poor-man's mkstemp(3).
% man CGI
[...]
When the form is processed, you can retrieve the entered
filename by calling param():
$filename = $query->param('uploaded_file');
Different browsers will return slightly different things
for the name. Some browsers return the filename only.
Others return the full path to the file, using the path
conventions of the user's machine. Regardless, the name
returned is always the name of the file on the user's
machine, and is unrelated to the name of the temporary
file that CGI.pm creates during upload spooling (see
below).
The filename returned is also a file handle. You can read
the contents of the file using standard Perl file reading
calls:
# Read a text file and print it out
while (<$filename>) {
print;
}
[...]
However, there are problems with the dual nature of the
upload fields. If you `use strict', then Perl will com-
plain when you try to use a string as a filehandle. You
can get around this by placing the file reading code in a
block containing the `no strict' pragma.
==================================================
#!/usr/bin/perl -wlT
#use strict;
use vars qw($file_1 $file_2);
$file_1 = "C:\image.gif"; # same name
$file_2 = "C:\image.gif"; # same name
open $file_1, "</tmp/file_1" or die $!;
open $file_2, "</tmp/file_2" or die $!; # closes /tmp/file_1 !
print while <$file_1>; # reads from /tmp/file_2 !
__END__
Create /tmp/file_[12] and see what happens if
you uncomment line 2. Symrefs are very "bad".
==================================================
The documentation continues:
More seriously, it is possible for the remote user to type
garbage into the upload field, in which case what you get
from param() is not a filehandle at all, but a string.
To be safe, use the upload() function (new in version
2.47). When called with the name of an upload field,
upload() returns a filehandle, or undef if the parameter
is not a valid filehandle.
$fh = $query->upload('uploaded_file');
while (<$fh>) {
print;
}
This is the recommended idiom.
It seems you are not using the recommended idiom, and also are not
using strictures. Hence you pay a price by discovering undocumented
misbehavior. Newer CGI.pm's behave better since $q->param returns
an overloaded filehandle object instead of a symref, but you'd have
to read the documentation (or the source :) to find out.
HTH.
--
Joe Schaefer
------------------------------
Date: Thu, 28 Dec 2000 22:16:45 GMT
From: jpeters@my-deja.com
Subject: Re: URL Testing Routine Problem
Message-Id: <92ge48$284$1@nnrp1.deja.com>
In article <92fgc9$8k9$1@nnrp1.deja.com>,
usctjd02@my-deja.com wrote:
> I'm trying to use the following script to give a basic status of URLs
> (up or down), however it fails on ssl sites. I've tried adding the
> SSLeay piece, but to no avail. I must be doing something dumb,
> assistance would be greatly appreciated...
>
> #!/usr/local/bin/perl
> use LWP::UserAgent;
>
> my $ua = new LWP::UserAgent;
>
> my $request = new HTTP::Request('GET', $ARGV[0]);
> my $response = $ua->request($request);
>
> if ($response-> is_success) {
> print "SITE IS UP\n";
> } else {
> print $response->error_as_HTML;
> }
Try something of the form:
use Net::SSLeay;
$port = "443";
$VAR_WEBHOST = "outlet.dell.com";
$uri = "/";
($page, $response, %reply_header) = Net::SSLeay::get_https(
$VAR_WEBHOST, $port, $uri,
Net::SSLeay::make_headers('User-Agent' => 'Foo bar')
);
print %reply_header, "\n";
print $page;
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 28 Dec 2000 22:06:36 +0000 (GMT)
From: Geoff Soper <g.soper@soundhouse.co.uk>
Subject: Using Sendmail with Perl and CGI
Message-Id: <4a342dd848g.soper@soundhouse.co.uk>
I am interested in using Sendmail through Perl in a CGI context. I see the
item in the FAQ about 'opening' Sendmail and writing headers and body into
it but would like more information on this. I have looked at
www.sendmail.org but after searching can't find information on the various
headers that I can use. I'm particularly interested in how to use the BCC
header (if I can).
Could somebody point me in the right direction?
Many thanks
--
Geoff Soper
g.soper@soundhouse.co.uk
Take a look at the Soundhouse page http://www.soundhouse.co.uk/
------------------------------
Date: Thu, 28 Dec 2000 20:38:41 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: want to fetch html files without LWP
Message-Id: <q29n4to4u61uab1h11lrg81g9j3426u9qa@4ax.com>
Bruce K wrote:
>Newby question here, but how do I install a module like LWP "in some
>private directory"? Pointers to FAQ, etc welcome!
perlfaq8
How do I keep my own module/library directory?
--
Bart.
------------------------------
Date: Thu, 28 Dec 2000 22:19:40 GMT
From: Mike Donaldson <mrd1968@my-deja.com>
Subject: Win32::ODBC - How to test for NULL? (MSSQL7)
Message-Id: <92ge9m$2a0$1@nnrp1.deja.com>
How can I determine the nullness of a value in the result
set of a query made through the Win32::ODBC package? E.g.
I select from a table with a nullable column and desire to
know if one of the fields is null. Currently, with
Win32::ODBC I cannot distinguish null fields from blank
(empty string) fields in a resultset. They are certainly
different beasts within the database itself. I would like
to accomplish this without changing the SQL statement
(e.g. adding "IsNull"). Sample script below.
I have scoured the Win32::ODBC doc and searched the Deja
archives for an answer to this and have come up with nothing.
Is there no hope of passing NULLness through the layers of
ODBC, Win32::ODBC, and perl?
My technical environment: MSSQL 7.0, perl 5.005_03 (ActiveState
build 522), NT 4.0, Microsoft SQL Server ODBC driver 3.70.08.20
Givens:
MSSQL7 table "tCustomer" created as follows:
CREATE TABLE tCustomer
(FirstName varchar (35) NULL)
The table contains a single row with:
FirstName=NULL (truly NULL)
The output of this script is:
FirstName is Empty String
I WANT the output of this script to be:
FirstName is NULL
Thanks!
-Mike. (mrd1968@my-deja.com)
use Win32::ODBC;
$db = new Win32::ODBC("DSN=Whatever;UID=;PWD=");
$sql = "SELECT FirstName FROM tCustomer";
die $db->Error() if $db->Sql($sql);
$db->FetchRow();
print "FirstName is Empty String\n" if ($db->Data("FirstName") eq "");
print "FirstName is Not Defined\n" if ( ! defined $db->Data
("FirstName"));
print "FirstName is Something\n" if ($db->Data("FirstName"));
#print "FirstName is NULL\n" if ( ?? WHAT CAN I DO HERE ?? );
$db->Close();
exit 0;
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 28 Dec 2000 19:06:42 +0000
From: Derek Fountain <derek@nospam.demon.co.uk>
Subject: XML Book recommendation rqd
Message-Id: <3A4B8F42.E481F6DC@nospam.demon.co.uk>
I asked this a few days ago but I don't think the posting got through.
Apologies if you see it twice...
I want to learn XML and want to use Perl as the base language. Can
anyone recommend a book on XML which uses either Perl for examples or at
least is language/OS neutral?
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 5215
**************************************