[17971] in Perl-Users-Digest
Perl-Users Digest, Issue: 131 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 24 06:08:21 2001
Date: Wed, 24 Jan 2001 03:05:11 -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: <980334311-v10-i131@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 24 Jan 2001 Volume: 10 Number: 131
Today's topics:
Re: Catching warnings from Getopt::Std <james@NOSPAM.demon.co.uk>
change tmp dir for file upload in cgi venkatmohan@my-deja.com
disk usage with perl <news@#nospam#althepal.com>
Re: disk usage with perl (Martien Verbruggen)
Re: ERROR: Bad arg length for Socket jce2000@my-deja.com
Free SQL server with perl? spcman@my-deja.com
Re: Free SQL server with perl? <comdog@panix.com>
Re: Getting past protected directories? <pads@ebost.com>
help! Capturing matched content in regex (with double-b <rog@clandestino.stanford.edu>
Re: help! Capturing matched content in regex (with doub (Rafael Garcia-Suarez)
Re: help! Capturing matched content in regex (with doub nobull@mail.com
Re: help! Capturing matched content in regex (with doub (Abigail)
Re: help! Capturing matched content in regex (with doub (Abigail)
How to do this regular expression? <tony@lis.co.jp>
Re: How to do this regular expression? (Bernard El-Hagin)
Re: How to do this regular expression? (Rafael Garcia-Suarez)
How to make Win32 Executables from Perl Scripts? <dissc@tsai.es>
Re: partition a large file into a number of small ones (Rich Lafferty)
Re: partition a large file into a number of small ones mcgowan@alum.mit.edu
Re: partition a large file into a number of small ones egwong@netcom.com
Re: Perl Crashes on my Win2k Box <gracenews@optusnet.com.au>
Re: Please help how to use Open3 tuoihong@my-deja.com
Re: Porting from VB to perl <krahnj@acm.org>
Re: printing to a printer? <gracenews@optusnet.com.au>
Re: regex substitution w/variable replacement <krahnj@acm.org>
Re: s/// inconsistency <uri@sysarch.com>
Re: s/// inconsistency (Ilya Zakharevich)
Re: s/// inconsistency (Martien Verbruggen)
Shareware: txt2pdf 4.3 <sanface@sanface.com>
Re: stability of threads + interpreter performance <time4tea@monmouth.com>
Re: Thanks Joe & Eric <joe+usenet@sunstarsys.com>
Trouble sorting array <davidwaters@bigfoot.com>
Type globs <cmon_209@hotmail.com>
Why do 'or' and '||' behave strangely different? <whumann@my-deja.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 24 Jan 2001 05:20:13 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Catching warnings from Getopt::Std
Message-Id: <ant2405131cbfNdQ@oakseed.demon.co.uk>
In article <u1sb6.150$GF2.6376@eagle.america.net>, Garry Williams
<URL:mailto:garry@zvolve.com> wrote:
>
> I seem to remember either an earlier version of the manual page or
> the Camel that *did* document the fact that an unknown switch would
> cause getopts() to return false. I have always relied on that.
>
> sub USAGE () { die "usage: ..."; }
> getopts('ab:') || USAGE;
>
> I checked perl 5.004_05 but it was the same as 5.6.0. I must remember
> the Camel, second edition. I'll check tomorrow.
Just had a look at Camels 2 and 3. On page 453 of Camel 2 it clearly
states: "getopts() returns false if it encounters errors during option
processing" as you remembered. Surprisingly, Camel 3 has taken a step
back in the amount of detail it gives and does not say anything about
the return value of getopts().
> Okay, I looked at the code, too. There *is* an explicit return of a
> truth value in the getopts() subroutine. It's the last statement in
> the subroutine
That's what I call an implicit return, but hey that's just semantics.
> This is the last statement of the subroutine:
>
> $errs == 0;
>
> So, the code guarantees that any invalid option scanned will result in
> a false value returned to the caller of getopts().
Now that you've made me think about it, I agree that this is very
deliberate, and given that the return value has been documented in at
least one authoritative source, it seems reasonable to use this
feature. Does anyone think that it would be unwise to do so?
> It's a shame that the manual page does not document this obviously
> deliberate behavior.
Perhaps whoever maintains Getopt::Std will make a point of updating
the documentation. After all, we wouldn't want a future maintainer to
think they could change it because it's not documented.
Anyway, thanks for the tip Garry.
--
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02
------------------------------
Date: Wed, 24 Jan 2001 08:57:19 GMT
From: venkatmohan@my-deja.com
Subject: change tmp dir for file upload in cgi
Message-Id: <94m5de$krg$1@nnrp1.deja.com>
Hi,
Is it possible to change the temporary directory where the files are
uploaded (through the input type file html form item).
By default it uploads to /var/tmp I want to change this directory to
some other directory.
CGI documentation instructs to set $ENV{TMPDIR}
But that doesn't works. I am using apache web server.
Thanks,
Venkat
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 24 Jan 2001 06:51:16 GMT
From: Alex Hart <news@#nospam#althepal.com>
Subject: disk usage with perl
Message-Id: <EXub6.9925$CP4.2393739@typhoon2.ba-dsg.net>
Is there a standard way to get disk usage of a directory across
platforms?
Currently, I use
$usage = (split /\s+/, `du -sk $user_path/uploads`)[0]
I know this won't work on windows, but is there any reason that this
would not work on all unix platforms?
Does someone know a platform that this won't work on? I'm willing to
assume a reasonably recent version of "du".
Thanks y'all.
--
- Alex Hart
------------------------------
Date: Wed, 24 Jan 2001 19:21:37 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: disk usage with perl
Message-Id: <slrn96t44h.n5q.mgjv@martien.heliotrope.home>
On Wed, 24 Jan 2001 06:51:16 GMT,
Alex Hart <news@#nospam#althepal.com> wrote:
> Is there a standard way to get disk usage of a directory across
> platforms?
No. But you can get some reasonably good approximations:
#!/usr/local/bin/perl -wl
use strict;
use File::Find;
@ARGV = ('.') unless @ARGV;
my ($num_blocks, $num_bytes);
foreach my $dir (@ARGV)
{
$num_blocks = $num_bytes = 0;
find (\&wanted, $dir);
print "$dir: $num_bytes bytes in $num_blocks blocks";
}
sub wanted
{
my ($bytes, $blocks) = ( (-l) ? lstat _ : stat _)[7,12];
$num_bytes += $bytes;
$num_blocks += $blocks;
}
Note that this doesn't follow symbolic links, deliberately. Also note
that I count both blocks and bytes. You can also ask stat what the
block size is on your file system, and multiply the second number by
that. You'll find out that those numbers almost never match up.
> Currently, I use
>
> $usage = (split /\s+/, `du -sk $user_path/uploads`)[0]
>
> I know this won't work on windows, but is there any reason that this
> would not work on all unix platforms?
I haven't yet seen a Unix where du -sk doesn't give output that would be
parseable by that, but I don't know for certain whther they all are the
same. You'd have to ask someone who knows all dialects of unix, probably
on a unix group.
> Does someone know a platform that this won't work on? I'm willing to
> assume a reasonably recent version of "du".
It's not really a Perl question, but a cross-platform unix question.
Maybe comp.unix.admin can be helpful. Post the question there, and wait
a week to see if anyone can come up with a counter-example.
Why don't you code something that _can_ use the platform informaiton to
figure out which external command to run.
Martien
--
Martien Verbruggen |
Interactive Media Division | Freudian slip: when you say one thing
Commercial Dynamics Pty. Ltd. | but mean your mother.
NSW, Australia |
------------------------------
Date: Wed, 24 Jan 2001 09:00:10 GMT
From: jce2000@my-deja.com
Subject: Re: ERROR: Bad arg length for Socket
Message-Id: <94m5io$kth$1@nnrp1.deja.com>
In article <x4sb6.79959$xW4.617877@news-server.bigpond.net.au>,
"John Boy Walton" <johngros.NOSPAM@bigpond.net.au> wrote:
>
> <jce2000@my-deja.com> wrote in message
news:94h1ht$6pi$1@nnrp1.deja.com...
> > Hi,
> >
> > I write a little perl program using Net::FTP and I receive this
> > message:
> >
> > Bad arg length for Socket::unpack_sockaddr_in, length is 0, should
be
> > 16 at /usr/lib/perl5/5.00503/i386-linux/Socket.pm line 295.
> The value you pass to Socket:unpack_sockaddr_in is undef. Trace its
source
> and find where you think you are assigning it a value but are not. I
make
> these errors all the time. (Asssigning a value incorrectly) ;-(
But my program is like this, I don't assign any value to Socket because
I use Net::FTP. And the error appears when I send some files, sometimes
appears after send 25 files or sometimes 46 files,...
#!/usr/bin/perl
use Net::FTP;
# Settings
$host = "ftp.domain.com";
$login = "login";
$passwd = "password";
$source_dir = "/home/jce";
$dest_dir = "/";
# Program
my $log_text,$text,$error=0;
if ($ftp = Net::FTP->new("$host"))
{
if ($ftp->login("$login","$passwd"))
{
if ($ftp->cwd("$dest_dir"))
{
@local_files= `ls $source_dir/*.txt`;
for($a=0;$a<=$#local_files;$a++)
{
chomp($local_files[$a]);
if ($ftp->put("$local_files[$a]"))
{
$text = "Uploaded: \"$local_files[$a]\"\n";
}
else
{
$text = "ERROR Uploading\n";
$error=1;
}
}
}
$ftp->quit;
}
else
{
$text = "Bad Login or password\n";
$error=1;
}
}
else
{
$text = "Error connecting to the host\n";
$error=1;
}
print $text;
######################################
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 24 Jan 2001 06:56:10 GMT
From: spcman@my-deja.com
Subject: Free SQL server with perl?
Message-Id: <94lua9$f05$1@nnrp1.deja.com>
Ive honestly been searching the net for over a week looking for a free
hosting site with SQL and Perl capabilities. I want to start to learn
SQL with Perl:DBI but i cannot find a free service. Im not yet ready
to buy a hosting plan that offers SQL. I tried Freedom2surf.com
(f2s.com) but the database server they have has been down and F2s sucks
all together. Can anyone lead me in the right direction. Thanks -
Spcman
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 24 Jan 2001 02:30:33 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: Free SQL server with perl?
Message-Id: <comdog-BB755A.02303324012001@news.panix.com>
In article <94lua9$f05$1@nnrp1.deja.com>, spcman@my-deja.com wrote:
> Ive honestly been searching the net for over a week looking for a free
> hosting site with SQL and Perl capabilities. I want to start to learn
> SQL with Perl:DBI but i cannot find a free service.
install freebsd, mysql, and perl on your own box. all of those
are free (except for the box unless you got it for the holidays). ;)
--
brian d foy <comdog@panix.com>
no longer for hire ;)
------------------------------
Date: Wed, 24 Jan 2001 11:05:05 -0000
From: "Patrick Daley" <pads@ebost.com>
Subject: Re: Getting past protected directories?
Message-Id: <980334011.14263.0.nnrp-12.c1edae65@news.demon.co.uk>
zawy <zawy@yahoo.com> wrote in message
news:3a6c3421.5251069@news.knology.net...
>
> How do I use Perl to enter my username and password on a Unix protected
directory (over ther internet)? LWP::Authen::Basic somewhere?
Take a look at 'Programming Web Clients in Perl' by O'Reilly. The book is
out of print but online.
http://www.oreilly.com/openbook/webclient/ch03.html
Scroll down to 'Authorization' for info on Basic Authentification.
Hope this helps.
--
Pads
------------------------------
Date: 23 Jan 2001 22:25:40 -0800
From: Roger Levy <rog@clandestino.stanford.edu>
Subject: help! Capturing matched content in regex (with double-byte chars)
Message-Id: <m3r91tjwkb.fsf@clandestino.stanford.edu>
Hi,
I'm having trouble with the following piece of code.
***************************
my $j = 1;
my %myhash;
while (<TARGET>) {
while (s/($my_regex)/$j/g) {
$myhash{$j} = $1;
}
}
***************************
Problem--
the substitution always matches in the right places, but $1 is always empty.
Background--
I am trying to match any of a list of Big5 (Chinese) characters, so
$my_regex is built up earlier as a join of a list of Big5 characters,
with "|" interpolated between them. With Big5 characters you have to
be careful: they are double-byte but the second byte can be basically
anything, so sometimes you get bytes like { and | that are actually
part of Chinese characters. I'm using Perl 5.x so it's not
double-byte savvy. However I treat $my_regex and escape the potential
metacharacters; at any rate, the substitutions in the while() loop are
happening at the right places, so I think that part is okay. But I'm
really confused as to why $1 always winds up empty! Is it not the
case that if you do
s/(1|2)//;
print $1;
then you'll get either 1 or 2 as output, depending on which one was
matched? It seems to me that the same thing should happen here...
Anyway I suspect I'm missing something really simple. Anyone
(especially those with double-byte regex experience) have any
suggestions?
Thanks
Roger
------------------------------
Date: Wed, 24 Jan 2001 09:12:37 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: help! Capturing matched content in regex (with double-byte chars)
Message-Id: <slrn96t752.ddo.rgarciasuarez@rafael.kazibao.net>
Roger Levy wrote in comp.lang.perl.misc:
> Hi,
>
> I'm having trouble with the following piece of code.
>
> ***************************
> my $j = 1;
> my %myhash;
>
> while (<TARGET>) {
> while (s/($my_regex)/$j/g) {
> $myhash{$j} = $1;
> }
> }
Apparently there's a little confusion here between the meanings of
/.../g and s/.../.../g.
/.../g is described in the perlop manpage: in scalar context, each
execution of /.../g finds the next match; hence, it's suitable for use
in a while() loop.
s/.../.../g (also described in perlop) replaces *all* occurences of the
pattern and returns the number of substitutions actually made -- 0 if
the pattern didn't match at all.
Hence, the first time the while loop is executed, all the substitutions
are made (if any). Then the while loop will be executed a second time,
but as there were no substitution left to be done, s///g will return 0
and $1 will be empty.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
package another; sub AUTOLOAD { $AUTOLOAD =~ /::(.*)/;"$1 @_"; }
package hacker; sub AUTOLOAD { $AUTOLOAD =~ /::(.*)/;"$1 @_,\n"; }
print Just another Perl hacker;
------------------------------
Date: 24 Jan 2001 08:35:19 +0000
From: nobull@mail.com
Subject: Re: help! Capturing matched content in regex (with double-byte chars)
Message-Id: <u9k87li8xm.fsf@wcl-l.bham.ac.uk>
Roger Levy <rog@clandestino.stanford.edu> writes:
> while (s/($my_regex)/$j/g) {
> $myhash{$j} = $1;
> }
> the substitution always matches in the right places, but $1 is always empty.
Read about the semantics of the s///g operator used in a scalar
context in perldoc perlop.
I suspect you read about the semantics of m//g in a scalar context and
then tried to infer the semantics of s///g. This doesn't work.
You can use the s///g itself as the looping construct.
s/($my_regex)/$myhash{$j} = $1; $j/eg;
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 24 Jan 2001 10:49:54 GMT
From: abigail@foad.org (Abigail)
Subject: Re: help! Capturing matched content in regex (with double-byte chars)
Message-Id: <slrn96tcqi.124.abigail@tsathoggua.rlyeh.net>
Roger Levy (rog@clandestino.stanford.edu) wrote on MMDCCIII September
MCMXCIII in <URL:news:m3r91tjwkb.fsf@clandestino.stanford.edu>:
## Hi,
##
## I'm having trouble with the following piece of code.
##
## ***************************
## my $j = 1;
## my %myhash;
##
## while (<TARGET>) {
## while (s/($my_regex)/$j/g) {
## $myhash{$j} = $1;
## }
## }
## ***************************
##
## Problem--
## the substitution always matches in the right places, but $1 is always empty.
Well, $my_regex is undefined, so in string context, it's "", which
means it always matches, and hence, $1 is empty. Had you used -w,
Perl would have told you so.
Abigail
--
perl -wle'print"Κυστ αξοτθες Πεςμ Θαγλες"^"\x80"x24'
------------------------------
Date: 24 Jan 2001 10:59:13 GMT
From: abigail@foad.org (Abigail)
Subject: Re: help! Capturing matched content in regex (with double-byte chars)
Message-Id: <slrn96tdc1.124.abigail@tsathoggua.rlyeh.net>
Rafael Garcia-Suarez (rgarciasuarez@free.fr) wrote on MMDCCIII September
MCMXCIII in <URL:news:slrn96t752.ddo.rgarciasuarez@rafael.kazibao.net>:
__ Roger Levy wrote in comp.lang.perl.misc:
__ > Hi,
__ >
__ > I'm having trouble with the following piece of code.
__ >
__ > ***************************
__ > my $j = 1;
__ > my %myhash;
__ >
__ > while (<TARGET>) {
__ > while (s/($my_regex)/$j/g) {
__ > $myhash{$j} = $1;
__ > }
__ > }
__
__ Apparently there's a little confusion here between the meanings of
__ /.../g and s/.../.../g.
__
__ /.../g is described in the perlop manpage: in scalar context, each
__ execution of /.../g finds the next match; hence, it's suitable for use
__ in a while() loop.
__
__ s/.../.../g (also described in perlop) replaces *all* occurences of the
__ pattern and returns the number of substitutions actually made -- 0 if
__ the pattern didn't match at all.
__
__ Hence, the first time the while loop is executed, all the substitutions
__ are made (if any). Then the while loop will be executed a second time,
__ but as there were no substitution left to be done, s///g will return 0
__ and $1 will be empty.
You can have the while loop executed multiple times (see below), and
if there are no matches, then 1) s/// returns false, so the while
block isn't executed, 2) $1 isn't set if there's no match.
$_ = 'aabbccddeeff';
my $i = 0;
while (s/(.)\1/x/g) {
print ++ $i, "\n";
}
__END__
1
2
3
4
Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))
------------------------------
Date: Wed, 24 Jan 2001 08:23:37 GMT
From: Anthony Mak <tony@lis.co.jp>
Subject: How to do this regular expression?
Message-Id: <94m3e6$jav$1@nnrp1.deja.com>
I want to search for a string NOT ended with a ';' mark.
So it should match:
string0 string string2
But not match:
string0 string string2 ;
I tried to defined the reg-exp as 'string.*^;' but this reg-exp does
not work.
I need your help. Please email answer to tony@lis.co.jp
Anthony Mak
-------------------------
Anthony Mak (Sydney, Australia)
anthony.mak@iname.com
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 24 Jan 2001 08:33:13 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: How to do this regular expression?
Message-Id: <slrn96t4q9.2q0.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 24 Jan 2001 08:23:37 GMT, Anthony Mak <tony@lis.co.jp> wrote:
>I want to search for a string NOT ended with a ';' mark.
>
>So it should match:
> string0 string string2
>
>But not match:
> string0 string string2 ;
$_ = "My string";
print "Yipee" if /[^;]$/;
>I need your help. Please email answer to tony@lis.co.jp
I'm sure you didn't mean that.
Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'
------------------------------
Date: Wed, 24 Jan 2001 09:33:47 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: How to do this regular expression?
Message-Id: <slrn96t8co.dh3.rgarciasuarez@rafael.kazibao.net>
Anthony Mak wrote in comp.lang.perl.misc:
> I want to search for a string NOT ended with a ';' mark.
If you want to test whether the last character of a string is a ';',
just do :
if ((substr $string, length($string) - 1) eq ';') { ... }
If not, please explain your problem more clearly.
> I tried to defined the reg-exp as 'string.*^;' but this reg-exp does
> not work.
'^' in a regexp means 'beginning of the string'.
You probably wanted [^;] : match any char except ';'.
See the perlre manpage for docs on the regexp syntax.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Wed, 24 Jan 2001 10:56:39 +0100
From: "Alberto" <dissc@tsai.es>
Subject: How to make Win32 Executables from Perl Scripts?
Message-Id: <94m810$5ul21@esiami.tsai.es>
Hi! I'm Newbie and I would like to know how can I make
Win32 executables from Perl Scripts. I'm trying with "perlcc"
but I get errors.
Thank U in advance,
- Alberto -
------------------------------
Date: 24 Jan 2001 06:20:47 GMT
From: rich@bofh.concordia.ca (Rich Lafferty)
Subject: Re: partition a large file into a number of small ones
Message-Id: <slrn96st2n.685.rich@bofh.concordia.ca>
[Crossposts trimmed -- comp.unix.shell left in for old times' sake]
In comp.lang.perl.misc,
Derek M. Flynn <dmf@cs.uchicago.edu> wrote:
> Y. Zhang wrote:
> > Hi,
> > I have a text file which is huge one (~270mb) with million lines. I
> > want to divide this file into small ones (50 mb or 4000 lines each). I
> > am use a unix osf system.
> >
> > Any advice is appreciated.
>
> man split
You can do it in Perl!
http://language.perl.com/ppt/src/split/index.html
-Rich
--
Rich Lafferty ----------------------------------------
Nocturnal Aviation Division, IITS Computing Services
Concordia University, Montreal, QC
rich@bofh.concordia.ca -------------------------------
------------------------------
Date: Wed, 24 Jan 2001 07:16:33 GMT
From: mcgowan@alum.mit.edu
Subject: Re: partition a large file into a number of small ones
Message-Id: <94lvgf$fpr$1@nnrp1.deja.com>
In article <slrn96st2n.685.rich@bofh.concordia.ca>,
rich@bofh.concordia.ca (Rich Lafferty) wrote:
> [Crossposts trimmed -- comp.unix.shell left in for old times' sake]
>
> In comp.lang.perl.misc,
> Derek M. Flynn <dmf@cs.uchicago.edu> wrote:
> > Y. Zhang wrote:
> > > Hi,
> > > I have a text file which is huge one (~270mb) with million lines. I
> > > want to divide this file into small ones (50 mb or 4000 lines each). I
> > > am use a unix osf system.
> > >
> > > Any advice is appreciated.
> >
> > man split
>
> You can do it in Perl!
at the great risk of getting tangential, why?
the offered solution is perfectly simple, straight-forward,
_and_ worked for 20 yrs before Perl was conceived.
I think it demeans Perl to offer it where there is
a simpler solution.
-- Marty McGowan
mcgowan@alum.mit.edu
mcfly@workmail.com M-F,9-5,EST
>
> http://language.perl.com/ppt/src/split/index.html
>
> -Rich
>
> --
> Rich Lafferty ----------------------------------------
> Nocturnal Aviation Division, IITS Computing Services
> Concordia University, Montreal, QC
> rich@bofh.concordia.ca -------------------------------
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 24 Jan 2001 07:52:31 GMT
From: egwong@netcom.com
Subject: Re: partition a large file into a number of small ones
Message-Id: <3Rvb6.18246$J%.1345149@news.flash.net>
In comp.lang.perl.misc mcgowan@alum.mit.edu wrote:
> In article <slrn96st2n.685.rich@bofh.concordia.ca>,
> rich@bofh.concordia.ca (Rich Lafferty) wrote:
>> Derek M. Flynn <dmf@cs.uchicago.edu> wrote:
>> > Y. Zhang wrote:
>> >
>> > man split
>>
>> You can do it in Perl!
>
> at the great risk of getting tangential, why?
> the offered solution is perfectly simple, straight-forward,
> _and_ worked for 20 yrs before Perl was conceived.
> I think it demeans Perl to offer it where there is
> a simpler solution.
http://language.perl.com/ppt/why.html
------------------------------
Date: Wed, 24 Jan 2001 16:53:06 +1000
From: "Jeffrey Grace" <gracenews@optusnet.com.au>
Subject: Re: Perl Crashes on my Win2k Box
Message-Id: <3a6e7bd8$0$16405$7f31c96c@news01.syd.optusnet.com.au>
"Steve Kemp" <skx@tardis.ed.ac.uk> wrote in message
news:Pine.GS4.4.21.0101231608560.23913-100000@tardis.tardis.ed.ac.uk...
> .. Here's a simple way of killing perl on Windows:
>
> perl -P [script.pl]
>
> It has caused me trouble on Windows before, using perl 5.005, and
> now 5.6.0 - which I built from source myself.
I tried the above, and got two lines of "bad command or file name", then it
exited without the perl script doing anything, didn't do anything as serious
as needing windows to forcably close it though. (ActivePerl 5.6.0 on win98)
ie:
[
C:\>perl -P test.pl
Bad command or file name
Bad command or file name
C:\>
]
But then again I removed Virtual C++ some time ago (co-incidently around the
time perl was installed ;-) ).
(what c preprocessor is it trying to run through?, my guesses at perldoc
keywords have pulled up anything, except "perl" which I gave-up after 50 or
so screens.)
--
Jeffrey Grace
~~~~~~~~~~~~~~~~~~~~
Queensland, Australia
------------------------------
Date: Wed, 24 Jan 2001 05:06:51 GMT
From: tuoihong@my-deja.com
Subject: Re: Please help how to use Open3
Message-Id: <94lnt7$a83$1@nnrp1.deja.com>
In article <YAsb6.155$GF2.6376@eagle.america.net>,
garry@zvolve.com (Garry Williams) wrote:
> On Wed, 24 Jan 2001 01:58:59 GMT, tuoihong@my-deja.com
> <tuoihong@my-deja.com> wrote:
> >I currently have a piece of code that looks like this:
> >
> > open (FTP, "|lftp $server\n";
> > print FTP "user $username $password\n";
> > print FTP "mkdir $remote_dir\n";
> > print FTP "lcd $upload_dir\n";
> > print FTP "mput *\n";
> > close (FTP);
> >
> >Currently ftp the files I need to ftp. However, I would like to
> >capture the output/error of the program "lftp" to LOG routine. I've
> >read the document on Open3 but not quite sure how to use it. If
> >someone can give some details on this, I would really appreciate it.
> >
> >I'm new to Perl so please help....
> >
> >(by the way useing Net::Ftp module is not an option).
>
> Why not? It's really what you want. (Well, Net::FTP is.)
>
> --
> Garry Williams
Because my manager claims its too slow. It's not my call.
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 24 Jan 2001 08:53:55 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Porting from VB to perl
Message-Id: <3A6E990C.7FE13FB1@acm.org>
bob wrote:
>
> I'm pretty sure that I'm going to get flamed for this, but what the
> hell.
> I've been stuck with the job of porting an XOR cipher routine from
> Visual Basic to perl. So far, its turned out to be nigh impossible, and
> I was wondering if anyone who is familliar with both languages might
> have an idea as to what is going wrong. While my knowledge of Visual
> Basic is little to none, I think I know enough to understand the logic
> of the program, but all of my attempts to port it to perl have been
> unsucessful to say the least. If you want to take a whack at it or have
> any suggestions, you can take a look at the visual basic code at
> http://members.fortunecity.com/fcsvenu/fullcode/encryptdec.html (I am
> porting the StrDecode function) and here is the perl code I have come up
> with so far:
>
> [code snipped]
>
Rather than comment on your code I'll give my interpretation.
#Function StrDecode( ByVal s As String, key As Long, salt As Boolean )
As String
#
# 'Written by Gary Ardell.
# 'free from all copyright restrictions
# 'Modified by Ben Baird in the following way(s):
# '- Converted all "Next i" statements
# ' to merely "Next" to speed up the code
# ' (Yes, that really does make a difference!)
# '
# Dim n As Long, i As Long, ss As String
# Dim k1 As Long, k2 As Long, k3 As Long, k4 As Long
#
# n = Len(s)
# ss = Space(n)
# ReDim sn(n) As Long
#
# k1 = 11 + (key Mod 233)
# k2 = 7 + (key Mod 239)
# k3 = 5 + (key Mod 241)
# k4 = 3 + (key Mod 251)
#
# For i = 1 To n
# sn( i ) = Asc( Mid( s, i, 1 ) )
# Next
sub StrDecode ($$$) {
my $s = shift;
my $key = shift;
my $salt = shift;
my $k1 = 11 + ( $key % 233 );
my $k2 = 7 + ( $key % 239 );
my $k3 = 5 + ( $key % 241 );
my $k4 = 3 + ( $key % 251 );
my @sn = map { ord } split //, $s;
my $n = @sn; # or my $n = length $s
# For i = 1 To n - 2
# sn( i ) = sn( i ) Xor sn( i + 2 ) Xor ( k4 * sn( i + 1 ) ) Mod
256
# Next
# For i = n To 3 Step -1
# sn( i ) = sn( i ) Xor sn( i - 2 ) Xor ( k3 * sn( i - 1 ) ) Mod
256
# Next
# For i = 1 To n - 1
# sn( i ) = sn( i ) Xor sn( i + 1 ) Xor ( k2 * sn( i + 1 ) ) Mod
256
# Next
# For i = n To 2 Step -1
# sn( i ) = sn( i ) Xor sn( i - 1 ) Xor ( k1 * sn( i - 1 ) ) Mod
256
# Next
for ( my $i = 0; $i < ( $n - 2 ); ++$i ) {
$sn[$i] ^= $sn[$i + 2] ^ ( $k4 * $sn[$i + 1] ) % 256;
}
for ( my $i = $n; $i > 1; --$i ) {
$sn[$i] ^= $sn[$i - 2] ^ ( $k3 * $sn[$i - 1] ) % 256;
}
for ( my $i = 0; $i < ( $n - 1 ); ++$i ) {
$sn[$i] ^= $sn[$i + 1] ^ ( $k2 * $sn[$i + 1] ) % 256;
}
for ( my $i = $n; $i > 0; --$i ) {
$sn[$i] ^= $sn[$i - 1] ^ ( $k1 * $sn[$i - 1] ) % 256;
}
# For i = 1 To n
# Mid( ss, i, 1 ) = Chr( sn( i ) )
# Next i
#
# If salt Then
# StrDecode = Mid(ss, 3, Len(ss) - 4)
# Else
# StrDecode = ss
# End If
$s = join '', map { chr } @sn;
return $salt ? substr $s, 2, $n - 4 : $s;
}
HTH
John
------------------------------
Date: Wed, 24 Jan 2001 17:05:19 +1000
From: "Jeffrey Grace" <gracenews@optusnet.com.au>
Subject: Re: printing to a printer?
Message-Id: <3a6e7eb4$0$16377$7f31c96c@news01.syd.optusnet.com.au>
"Jeff Helman" <jhelman@wsb.com> wrote in message
news:hves6tcd8k8vqf8nasgqjkjaf36lc4ph6e@4ax.com...
>
> For example, assuming an MS-Win32 environment, the following will work
> for a printer defined to the system as LPT1...
>
> open PRINTER, ">lpt1:";
> print PRINTER "Testing the printer.\n\f";
> close PRINTER;
>
> Note the form feed at the end of the line. Some configurations will
aha, that what the form feed is. ;-) (so obvious really wasn't it ;-) )
(this refers to a different but similiar thread)
if he's using *nix, the open line should be of the form: (though the printer
name may be different.)
open PRINTER, ">>/dev/lp"; # WARNING: un-tested code. (can't, on win32)
I normally append, but I haven't had any trouble opening for write before.
> not actually dump the page until a form feed is encountered, which may
> be your problem.
>
> Let us know what you tried and you'll be a thousand times more likely
> to get useful help.
>
> JH
------------------------------
Date: Wed, 24 Jan 2001 06:13:33 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: regex substitution w/variable replacement
Message-Id: <3A6E7378.A7518A50@acm.org>
rickroot@my-deja.com wrote:
>
> #!/usr/local/bin/perl
> $foo = "<A HREF=\"/stations/kdrkfmtop10\">Hot Movies</A>";
> $find = "/stations/(.{5,6})top10";
> ### put replace into a variable, escape the $1
> $replace = "/stations/\$1top5";
$repleft = '/stations/';
$repright = 'top5';
> $foo =~ s/$find/$replace/g;
$foo =~ s/$find/$repleft$1$repright/g;
> print "$foo\n";
John
------------------------------
Date: Wed, 24 Jan 2001 05:14:07 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: s/// inconsistency
Message-Id: <x7puhdwmzl.fsf@home.sysarch.com>
>>>>> "RM" == Roman Moeller <roman@topologix.de> writes:
RM> On 23-Jan-2001, mgjv@tradingpost.com.au (Martien Verbruggen) wrote:
>> $2 and $1 are just variables. They get used by Perl internally, but in
>> contexts like these they're the same as all the others.
RM> That was my fundamental misconception. I thought of them as
RM> something special for the regex machine, possibly due to the old
RM> \1 notation. I never thought of \1 being a variable, because it
RM> made only sense in the replacement string
\1 is not for the replacement string. it is meant to be a backreference
INSIDE the regex itself. it works in the replacement string more as
convenience and its use there is deprecated.
RM> foreach my $m (@matches) {
RM> eval '($s=$m)'." =~ s/$pat/$sub/;"; #still ugly
RM> After all, if everything I learned from this thread is correct,
RM> I'll have to bear the eval uglyness, because the command line
RM> parameters are inherently "symbolic references".
use the /e modifier (or /ee if needed) on the regex. it will clean up
the syntax a great deal.
and if you are passing in $1 from @ARGV that can be handled with /ee.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 24 Jan 2001 07:17:55 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: s/// inconsistency
Message-Id: <94lvj3$6a6$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Roman Moeller
<roman@topologix.de>],
who wrote in article <94lmd5$139$1@crusher.de.colt.net>:
> I need a file rename tool with the full power of perls regexes. So
> both the pattern as the substitution are commaand line parameters.
See rename (or rnm) in the ex/ directory of the Perl distribution, or
my pfind tool (on CPAN).
Ilya
------------------------------
Date: Wed, 24 Jan 2001 18:58:26 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: s/// inconsistency
Message-Id: <slrn96t2p2.n5q.mgjv@martien.heliotrope.home>
On Wed, 24 Jan 2001 04:42:29 GMT,
Roman Moeller <roman@topologix.de> wrote:
>
> On 23-Jan-2001, mgjv@tradingpost.com.au (Martien Verbruggen) wrote:
>> aware of. Once you tell us what that is, maybe we'll be able to tell you
>> whether you need to use ugly stuff, or whether you can use less ugly
>> stuff.
>
> Not so magical at all. I need a file rename tool with the full power of
> perls
> regexes. So both the pattern and the replacement string are command
> line parameters. Here's what I got so far
Ok. I suspect that you will have to accept a level of eval then. I'd go
for the /ee options, but I would be very careful in what I accepted as
user input for the right hand side of the substitution. Eval means that
any perl code will be executed, and that can contain some nasties.
If you follow Ilya's suggestion, and look at eg/rename in the perl
distribution, you'll find that that program takes a full perl
expression, which it evals for each argument. Eval might not be easy to
avoid.
Martien
--
Martien Verbruggen |
Interactive Media Division | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd. | no excuse - Lazarus Long
NSW, Australia |
------------------------------
Date: Wed, 24 Jan 2001 09:46:31 GMT
From: SANFACE Software <sanface@sanface.com>
Subject: Shareware: txt2pdf 4.3
Message-Id: <94m89n$mv0$1@nnrp1.deja.com>
txt2pdf is a very flexible and powerful PERL5 program
(5 penguins at LinuxBerg, 5 cows at TuCows Mac, BeOS and PSION).
It's a converter from text files to PDF format files.
Why do you need txt2pdf?
Most of your documents are text files
Usually, your reports from legacy applications, DBs, ERP applications,
datawarehouse are textual
txt2pdf is a PERL5 script, so you can use it in every operating systems
supported by PERL5,
if you prefer we distribute also executables for these OS:
Windows,Linux,Solaris,AIX,HP-UX,FreeBSD. Inside the Windows version a
VB GUI (Visual txt2pdf)
txt2pdf is a native converter, you don't need to pass through
PostScript format
txt2pdf is specific for text to PDF conversion, so
you can mark coloured (using PERL regular expression) frases in the
produced PDF files
you can mark bold, italic, bolditalic frases in the produced PDF files
you can add page number in every page
you can add text at the beginning and at the end of every file
you can add a border to every page
every word like http://... ftp://... mailto:... https://...
file:... ldap:... news:... will become an URL
you can create a link to a specific page within a PDF document
http://...pdfdocument#pdfmark
every word like mime:... will become a link that launch the correct
application and opens the file
you can use background and foreground layers
every predefined encodings, supported by the PDF format, is supported +
the Unix default
txt2pdf supports STDIN and STDOUT
EPD 1.0 support. You can use EPD inside background layer.
the fee for every licence is $85
SANFACE Software is going to give you a free licence for every good
idea or for every good modify
txt2pdf is shareware
The txt2pdf source code is our company core business.
We trust you.
You can test text2pdf and modify it.
You can't use a modify version of txt2pdf for production purpose. You
can't resell txt2pdf or a modify version of it without SANFACE Software
authorization.
You can't copy part of it to include in your source without SANFACE
Software authorization.
What's new in this version
Now it's possible to convert Windows files with blank inside the path
txt2pdf.cgi 3.0 it's free code in the contributed zone
http://www.infomotions.com/pstoepd/ PostScript To EPD is an on line
converter from
PostScript graphic file to EPD http://epd.sourceforge.net (a new
encapsulated vectorial
graphic format). In the same time you can convert your PostScript
graphic also to PDF, TIFF, JPEG.
We'd like to make a gallery with the best EPD: help us sending us your
best EPD!
Visual_txt2pdf 1.2 inside the Windows distribution (with new maximize
feature)
Test txt2pdf 4.3!
You can find it at http://www.sanface.com/txt2pdf.html
Don't forget txt2pdf 4.x PRO at
http://www.sanface.com/txt2pdfPRO.html
and txt2pdf PRO + Japanese at
http://www.sanface.com/txt2pdfPROj.html
--
SANFACE Software
Your technology glasses. We help you see your full potential.
http://www.sanface.com
mailto:sanface@sanface.com
WAP http://www.sanface.com/wap/
i-mode http://www.sanface.com/i/
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Mon, 22 Jan 2001 23:00:36 -0500
From: "James Richardson" <time4tea@monmouth.com>
Subject: Re: stability of threads + interpreter performance
Message-Id: <94lpp2$k40$1@slb6.atl.mindspring.net>
"Koen Bossaert" <not@defined.com> wrote in message
news:8jYa6.77$j4.10000@nreader2.kpnqwest.net...
> Can anyone tell me if it [perl threading] is stable enough to use in
business applications?
No.
Well, I wouldn't.
Theres quite a few caveats that you have to be aware of, and many extensions
dont cater for threaded perl.
IMHO if you have to be reassured that its stable enough, it probably isn't.
Remember you're the one whos going to be doing the
repairs if stuff crashes & burns.
You can check the Event module for possible alternative.
HTH
James
------------------------------
Date: 24 Jan 2001 01:07:50 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Thanks Joe & Eric
Message-Id: <m3hf2pqy89.fsf@mumonkan.sunstarsys.com>
"Ofir" <ofirb@jdc.org.il> writes (upside-down):
> Wow, that's a nice answer. NOT to my question though...;-)
[snipped irrelevant code; answer was supplied in original post,
and here it is again]
> Hi all,
>
> I want to be able to determine how many lines are in a file.
^^^^^
It's deja vu all over again:
% perldoc -q lines
> What is the way (subroutine) to check the total number of lines
> written in a file?
#!/usr/bin/perl -w
use strict;
{
my $bad;
sub friends {
*UNIVERSAL::AUTOLOAD = sub {
pop() -> (), $UNIVERSAL::AUTOLOAD, \& friends
};
++$bad % 2 ? sub { system "perldoc", "perldoc" } :
system "perldoc", "perl";
}
}
grab a Perl programmer's two best friends
__END__
--
Joe Schaefer
------------------------------
Date: Wed, 24 Jan 2001 10:34:31 GMT
From: David Waters <davidwaters@bigfoot.com>
Subject: Trouble sorting array
Message-Id: <94mb3o$omj$1@nnrp1.deja.com>
I have the following lines of text as separate elements in an array
(not necessarily in this order).
3,postcode,ro_address
3+,line_two,ro_address
2,accounts_type,companies_house_data
2,acc_ref_date,companies_house_data
2,acc_made_up_date,companies_house_data
2+,ro_address,companies_house_data
1+,companies_house_data,
I would like to sort the array in reverse order so it would be 3's then
2's then 1's. However, there are some lines which have a '+' after the
number which I would like to be at the top of each set of numbers.
so the result should be
3+,line_two,ro_address
3,postcode,ro_address
2+,ro_address,companies_house_data
2,accounts_type,companies_house_data
2,acc_ref_date,companies_house_data
2,acc_made_up_date,companies_house_data
1+,companies_house_data,
Can anyone help please?
Thanks
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 24 Jan 2001 10:47:50 GMT
From: CM <cmon_209@hotmail.com>
Subject: Type globs
Message-Id: <94mbsl$pgf$1@nnrp1.deja.com>
While aliasing a list into a subroutine I get problems when I use 'my'
but works allright with 'local'
@foo = ("here's", "a", "list");
&testsub (*foo);
sub testsub
{
local (*printarray) = @_; # THIS DOES NOT WORK IF
# IF REPLACED BY
# my (*printarray) = @_;
foreach $element (@printarray)
{
print ("$element\n");
}
}
If the 'local' is changed to 'my' the following error message is
displayed.
"Cant declare ref-to-glob cast"
Can somebody guide me thru this?
regards
CM
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 24 Jan 2001 10:49:34 GMT
From: Wolfram Humann <whumann@my-deja.com>
Subject: Why do 'or' and '||' behave strangely different?
Message-Id: <94mbvt$phd$1@nnrp1.deja.com>
Can anybody tell me why I can test for 'shift @x' returning undef
because the array is empty using '||' but not using 'or'?
Sample script:
1 #!/usr/local/bin/perl -w
2
3 use strict;
4
5 my @x = (" a ", " b ");
6
7 print shift @x or " 1 ";
8 print shift @x || " 2 ";
9 print shift @x or " 3 ";
10 print shift @x || " 4 ";
11 print "\n";
Reply:
Useless use of a constant in void context at /tmp/or-test line 7.
Useless use of a constant in void context at /tmp/or-test line 9.
Use of uninitialized value at /tmp/or-test line 9.
a b 4
I can't really make sense out of this...
Thanks,
Wolfram
Sent via Deja.com
http://www.deja.com/
------------------------------
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 V10 Issue 131
**************************************