[17874] in Perl-Users-Digest
Perl-Users Digest, Issue: 34 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 10 21:07:22 2001
Date: Wed, 10 Jan 2001 18:05:09 -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: <979178709-v10-i34@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 10 Jan 2001 Volume: 10 Number: 34
Today's topics:
Re: ASCII to integer conversion <cliff@*MYLASTNAMEHERE*.nl>
Re: ASCII to integer conversion (Martien Verbruggen)
Re: counting lines in a file <krahnj@acm.org>
Creating accounts on iis5 advanced server jlegay@my-deja.com
Re: data problems (David Efflandt)
Re: email attachments w/Sendmail using Perl? (David Efflandt)
Re: Licensing a program written perl? <diab.lito@usa.net>
Re: Licensing a program written perl? gungeek@my-deja.com
Re: Outputting special DOS characters in Windows (Damian James)
Re: Outputting special DOS characters in Windows gungeek@my-deja.com
Re: Please Recommed Encryption Module (Damian James)
Re: Please Recommed Encryption Module <grichard@uci.edu>
Re: Please Recommed Encryption Module <grichard@uci.edu>
Re: Problem with inserting data gungeek@my-deja.com
Problem... Src included... cputek1@my-deja.com
Re: RegEx question <ren.maddox@tivoli.com>
Re: replacing spaces with %20 (Damian James)
Re: replacing spaces with %20 (Greg Bacon)
socket send to client problem <anthonyc@mincom.com>
Re: system() method won't change directories! 2obvious@my-deja.com
Re: system() method won't change directories! <juex@deja.com>
Re: System() redirection failing in Win98, WinME gungeek@my-deja.com
would a regex be helpful here? <webqueen@my-deja.com>
Re: would a regex be helpful here? (Chris Fedde)
Re: would a regex be helpful here? <uri@sysarch.com>
Re: would a regex be helpful here? (Greg Bacon)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 10 Jan 2001 23:53:21 +0100
From: Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl>
Subject: Re: ASCII to integer conversion
Message-Id: <93iptp$6jn$1@news.news-service.com>
gls@byu.edu wrote:
>
> Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl> writes:
>
> > Abigail wrote:
> > >
> > > If you would know the very basics of Perl, you'd know how silly the
> > > question is.
> >
> > An why is this silly? I've just started programming in Perl and I have
> > encountered the exact same "problem" numerous times.
> >
> > For instance, suppose we have a string that contains an important value
> > we need for some other stuff. The only thing we know and can be certain
> > of, is that this value can be found directly *after* a fixed delimiter
> > (in this case a ","). Now everything directly following this number can
> > be literally anything, except numbers:
> >
> > $a_string = "Random string with a value from somewhere,1234m/s";
> > $a_number = substr( $a_string, index( $a_string, "," ) );
> >
> > Now we need to pass this number to another program:
> >
> > `a_program $a_string`;
>
> I am assuming that the above should be: `a_program $a_number`;
Yes it should. I also forgot "+ 1" in the substr(). That's what happens
when you post at 4am.
> I think that the problem here is that you are asking the wrong
> question. Do you ever use $a_number as a number, or do you only pass
> it to the back quotes? The back quotes will convert a number back to
> a string. Converting something to an integer just to convert it back
> to a string is kind of like finding the absolute value of a number by
> squaring it, then taking the positive square root, it works for the
> test case of -4, but does more work than is needed and may not work
> for different data.
The example is a bad example. I just want the number only for any
reason. Be it to store in a file, use for shelling, whatever.
> I believe the question that you would like answered is:
>
> < I have a line of data that contains a comma (,) followed by one or
> < more digits (plus other characters that I don't care about at this
> < point), how do I extract just the digits from the string? e.g. if
> < $a_string contains
> < "Random string 4321 somewhere,1234m/s", then how do I get just the
> < digits 1234 into $a_number?
Ehm, yes. Exactly. But didn't I ask that with:
>> For instance, suppose we have a string that contains an important value
>> we need for some other stuff. The only thing we know and can be certain
>> of, is that this value can be found directly *after* a fixed delimiter
>> (in this case a ","). Now everything directly following this number can
>> be literally anything, except numbers:
> If that is your real question, then there are a couple of answers that
> suggest themselves:
>
> ( $a_number ) = $a_string =~ /,(\d+)/;
>
> ( $a_number ) = $a_string =~ /,\s*(\d+)/;
>
> ( $a_number ) = $a_string =~ /,(\d*)/;
>
> if( $a_string =~ /,(\d+)/ ){
> $a_number = $1
> } else {
> die "wrong format";
> }
>
> $a_string =~ s/,(\d*)/$1/ and $a_number = $a_string or
> die "wrong format";
>
> are just a few.
Thanks.
> You probably would have received this answer sooner, but you kept
> insisting that you need to use the middle step of converting to an
> integer and many people are trying to point out that you don't need to
> do this. Also several of the docs that they have pointed you to
> should have started you down this path also.
Well, no. I thought I made it clear I was only interested in the digits.
I don't want an integer since I'm very well aware that Perl has no
typecasting. I was making a comparison to C where the easiest way is to
convert it to an integer first (atoi), then back to a string (sprintf).
Actually, I wasn't the one who asked the original question, but the
original post got no (useful) answer. So I insisted on one. And for some
reason that makes me a troll in the eyes of some. Fortunately they
kill-filtered me so they won't be back in this thread.
> hope this helps,
Yes it does and my sincere thanks for that. Now I got my answer it's
time to unsubscribe from comp.lang.perl.misc. Too many god-wannabees
here.
> --
> ---------------------------------------------------------------------
> Dr. Gregory L. Snow | Inertia makes the world go round,
> (Greg) | Love makes the trip worth taking.
> gls@byu.edu |
> ---------------------------------------------------------------------
------------------------------
Date: Thu, 11 Jan 2001 00:10:30 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: ASCII to integer conversion
Message-Id: <slrn95pudj.ghh.mgjv@verbruggen.comdyn.com.au>
On Wed, 10 Jan 2001 23:32:44 +0100,
Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl> wrote:
> Martien Verbruggen wrote:
>>
>> *plonk*
>
> Thanks. Now at least you will stay away from this thread. Oh wait, you
> won't read this... Oh well.
Actually, since I am now at work, and don't have my laptop with me,
which syncs the score files here and at home for me, I am reading it.
And I am baffled by your attitude. I really am. I spent a rather
lengthy post responding to _your_ initial question (not the OP's),
which, AFAICT, went quite a way towards explaining how the number
conversions worked. I didn't tell you about how to extract the number
from a string, I seem to recall that I had already seen a post that
explained that, but that's beside the point.
For me, the thread was over. The question of the OP had been answered,
in various ways, your question had been answered, and had received
quite some more explanation about what was going on that was really
requested.
Then you start whinging.
Just go back, read the whole thread in order, and contemplate about
your attitude. Do NOT take the attitude of some others into account,
because that doesn't matter. You assert that no one answered your
questions, or the OPs. Read again.
And now, you're really invisible.
Martien
--
Martien Verbruggen |
Interactive Media Division | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd. | from a rich salesperson.
NSW, Australia |
------------------------------
Date: Thu, 11 Jan 2001 00:34:02 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: counting lines in a file
Message-Id: <3A5D003C.795EE1FA@acm.org>
John Galt wrote:
>
> As a newbie to Perl, I'm always welcome to suggestions and improvements
> to my
> (simple and often error prone) programs. Please take my questions
> seriously.
>
> > > open FILENAME, $file or die "Cannot open $file for read: $!";
> >
> > The file name is in "$file" and the file handle is in "FILENAME"?
>
> Why not? Are you trying to say that they should be the same name, like
> $file
> and "FILE"?
No, I'm just saying that a filehandle name of "FILENAME" is a bit
misleading.
> > > $count=0 #so that it will return "0" if there are no
> > > #relevant lines
> >
> > my $count = 0;
>
> I know that the "my" part makes it a local variable, but what's the
> consequence if you don't use it? Does making it a local variable
> confine it to just the subroutine, or the program, or what? I've done
> a bit of research about this one after your comment, but I haven't
> been able to figure that out. Yes, I did forget a semicolon,
> sorry about the typos. I did add the little disclaimer that
> said it wasn't perfect.
If you use warnings and strictures this will help you catch errors like
misspelling a variable name.
my EXPR A my() declares the listed variables to be local
(lexically) to the enclosing block, file, or
eval(). If more than one value is listed, the
list must be placed in parentheses. See the
section on Private Variables via my() in the
perlsub manpage for details.
> > > for ( <FILENAME> ) {
> >
> > You probably meant 'while ( <FILENAME> ) {'
> >
> Why? Won't it have the same result?
In older versions of Perl for and foreach would create a temporary
array.
> >
> > > chomp;
chomp is not really needed for this ap.
> > > if ($_) {
> > What it the line has the digit 0 on a line by itself or only contains
> > whitespace?
> >
next if /^\s*$/;
or
next unless /\S/;
> > > if (!/#/){
next if /^\s*#/;
> >
> > This will skip lines like:
> > print "This is an example of the # character";
>
> Well, this one's debatable. I'm not sure what the OP meant... did he
> want to *not* count lines that only had comments (which is logical)
> or not count lines that had any comment (I don't see the purpose)?
> His posting seemed to reflect the latter, but the former makes more
> sense. I should have specified (this isn't an excuse... I did test
> for that possibility). Good point about the "0" though.
> > > Enjoy!
> > Counting errors.
>
> No - learning.
Good to see that you are learning.
John
------------------------------
Date: Wed, 10 Jan 2001 23:01:01 GMT
From: jlegay@my-deja.com
Subject: Creating accounts on iis5 advanced server
Message-Id: <93ipj7$n7l$1@nnrp1.deja.com>
I have been running Perl scripts from my Windows 2000 Professional box
for the past few months. I am using IIS 5.0. I have some forms on a
website that collects the data and sends it to the Perl Script. NO
problems.
I have now moved the site and scripts to a Windows 2000 Advanced Server
box and presto, I can't create user accounts anymore. I have tried
everything known to man but the script will not create accounts. Perl
is setup correctly on the server. Some of my other scripts do work on
the new server. The script to create accounts works if I run it via a
command prompt. This is the only Windows 2000 server on an NT 4.0
domain. The server is a stand alone.
Thanks for any advice.
Jeff
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 11 Jan 2001 01:44:54 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: data problems
Message-Id: <slrn95q40h.irc.efflandt@efflandt.xnet.com>
On Wed, 10 Jan 2001 02:39:57 -0000, Ben Graves <ben.graves@virgin.net> wrote:
>My web server reports the time incorrectly for the area I live, could
>someone tell me how to get the date and time and add six hours to this time.
>
>I thought I had it working but if the time is changed it doesn't update the
>date if the time goes past midnight.
Quite simple. Add 6 hrs worth of seconds to time with localtime()
function or add/subtract your full timezone offset for gmtime():
#!/usr/bin/perl -w
print scalar(localtime(6 * 3600 + time)), "\n";
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Thu, 11 Jan 2001 01:47:20 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: email attachments w/Sendmail using Perl?
Message-Id: <slrn95q454.irc.efflandt@efflandt.xnet.com>
On Wed, 10 Jan 2001, kevin thomason <kthomason@utsystem.edu> wrote:
>I'm looking for a MIME-capable perl module that will allow me to send emails
>w/attachments using Sendmail. Any ideas on where to find such a thing (if it
>exists)? Thanks :)
MIME::Lite works well for attachments (or with CGI.pm file uploads).
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Wed, 10 Jan 2001 23:29:49 GMT
From: Mario <diab.lito@usa.net>
Subject: Re: Licensing a program written perl?
Message-Id: <93ir92$oq8$1@nnrp1.deja.com>
In article <93ie16$brj$1@nnrp1.deja.com>,
bababozorg@aol.com wrote:
> I was wondering if there is a way to actually implement licencing in a
> perl program... what i mean is simply... if a customer buys this
> program written in perl, under one user license... is there anyway to
> stop him if he gives a copy of the program to his friend to use or
> something?
>
I was posting a similar message right now,I am working on this thing
since a couple of days and nothing good came to my mind.
As you said,the idea of an image stored on your server isn't so good
for 2 reasons:
-it's very easy to remove
-it allows you to track the not-licensed copies of your script,not to
prevent the duplication (then what? would you call a lawyer?).
I guess there isn't a secure or even just efficient way to prevent a
perl script from being duplicate.Maybe the topic is more "how to
maximize the skills required to remove the protection".
--
Mario
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Thu, 11 Jan 2001 00:41:31 GMT
From: gungeek@my-deja.com
Subject: Re: Licensing a program written perl?
Message-Id: <93ivfq$sg9$1@nnrp1.deja.com>
In article <93ilu1$jee$1@nnrp1.deja.com>,
bababozorg@aol.com wrote:
> So what you are simply saying is that ALL those comercial programs out
> there which are written in perl MUST give their program for free...
> only because PERL is a free distributed langauage??? and another
> thing... if your advice is SO commercial... that you bother sharing
> your experiences to people.. u better dont read this news group AT
Huh?
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 11 Jan 2001 00:05:06 GMT
From: damian@puma.qimr.edu.au (Damian James)
Subject: Re: Outputting special DOS characters in Windows
Message-Id: <slrn95pu7h.2gu.damian@puma.qimr.edu.au>
In article <20010110145320.04296.00004832@ng-fi1.aol.com>, Spiffy1two wrote:
>Greetings.
>
>I am working on a cgi script that opens a text file, formats the contents,
>prints those contents to a web page. The problem is, the text files contain
>special characters, such as ö, ä, Ö, and other German letters. They don't come
>out correctly into the browser. Each of them gets converted to something else.
> I suspect this has to do with different character maps in Windows and DOS.
Not Windows, the browser -- you need to find out about HTTP encoding.
This is not a Perl issue, but see below.
>Does PERL have some way of handling this, or am I out of luck? HTML "&"
>character codes will not work here, because it is not in the body of the web
>page.
This doesn't make sense. How do you print the contents to a web page,
such that they are not in the body of the web page? You need to say where
they are actually going, rather than where they are not.
Anyway, you might be interested in:
perldoc CGI
perldoc -f chr
perldoc -f pack
and you might be interested to see the output of this:
perl -e 'for (1..255) {print $_, "\t=\t", chr($_), "\n" }'
Cheers,
Damian
------------------------------
Date: Thu, 11 Jan 2001 00:36:33 GMT
From: gungeek@my-deja.com
Subject: Re: Outputting special DOS characters in Windows
Message-Id: <93iv6h$s4v$1@nnrp1.deja.com>
In article <20010110145320.04296.00004832@ng-fi1.aol.com>,
spiffy1two@aol.com (Spiffy1two) wrote:
> Greetings.
>
> I am working on a cgi script that opens a text file, formats the
contents,
> prints those contents to a web page. The problem is, the text files
contain
> special characters, such as ö, ä, Ö, and other German letters. They
don't come
> out correctly into the browser. Each of them gets converted to
something else.
> I suspect this has to do with different character maps in Windows
and DOS.
> Does PERL have some way of handling this, or am I out of luck?
HTML "&"
> character codes will not work here, because it is not in the body of
the web
> page.
>
If not in the body, where are you? Javascript function? META tag?
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 11 Jan 2001 00:15:57 GMT
From: damian@puma.qimr.edu.au (Damian James)
Subject: Re: Please Recommed Encryption Module
Message-Id: <slrn95purt.2gu.damian@puma.qimr.edu.au>
In article <m3hf37w022.fsf@mumonkan.sunstarsys.com>, Joe Schaefer wrote:
>"Gabe" <grichard@uci.edu> writes:
>
>> I want to encrypt credit card data and store it in a MySQL data. Is there a
>> de facto standard Perl module for this sort of thing?
>>
>See the Crypt::* collection on CPAN. There's a whole
>bunch to choose from (DES, MD5, Blowfish, etc.). Both
>symmetric and (one-way) hashing algorithms are there.
>
If you don't need strong encryption, MySQL has it's own crypt()
and encode() functions. See the MySQL documentation for details.
Cheers,
Damian
------------------------------
Date: Wed, 10 Jan 2001 16:27:03 -0800
From: "Gabe" <grichard@uci.edu>
Subject: Re: Please Recommed Encryption Module
Message-Id: <93iutb$hvr$1@news.service.uci.edu>
Hi Joe, thanks for the response.
I guess the problem is I don't know what the differences between DES, MD5,
and Blowfish are. What is used for what? They are all encryption
algorhithms? I can use any of them to encrypt and decrypt data? I know zilch
about security...
Thanks!
Gabe
Joe Schaefer <joe+usenet@sunstarsys.com> wrote in message
news:m3hf37w022.fsf@mumonkan.sunstarsys.com...
> "Gabe" <grichard@uci.edu> writes:
>
> > I want to encrypt credit card data and store it in a MySQL data. Is
there a
> > de facto standard Perl module for this sort of thing?
> >
> See the Crypt::* collection on CPAN. There's a whole
> bunch to choose from (DES, MD5, Blowfish, etc.). Both
> symmetric and (one-way) hashing algorithms are there.
>
> --
> Joe Schaefer
>
------------------------------
Date: Wed, 10 Jan 2001 16:27:54 -0800
From: "Gabe" <grichard@uci.edu>
Subject: Re: Please Recommed Encryption Module
Message-Id: <93iuuu$i06$1@news.service.uci.edu>
Hi Damian, thanks for responding.
What is strong encryption versus weak encryption? What makes MySQL weak and
others strong?
Thanks!
Gabe
Damian James <damian@puma.qimr.edu.au> wrote in message
news:slrn95purt.2gu.damian@puma.qimr.edu.au...
> In article <m3hf37w022.fsf@mumonkan.sunstarsys.com>, Joe Schaefer wrote:
> >"Gabe" <grichard@uci.edu> writes:
> >
> >> I want to encrypt credit card data and store it in a MySQL data. Is
there a
> >> de facto standard Perl module for this sort of thing?
> >>
> >See the Crypt::* collection on CPAN. There's a whole
> >bunch to choose from (DES, MD5, Blowfish, etc.). Both
> >symmetric and (one-way) hashing algorithms are there.
> >
>
> If you don't need strong encryption, MySQL has it's own crypt()
> and encode() functions. See the MySQL documentation for details.
>
> Cheers,
> Damian
>
------------------------------
Date: Thu, 11 Jan 2001 01:09:40 GMT
From: gungeek@my-deja.com
Subject: Re: Problem with inserting data
Message-Id: <93j14g$tn8$1@nnrp1.deja.com>
In article <3a5621e0@news-uk.onetel.net.uk>,
"Edd" <edd@texscene.com> wrote:
> I am using the below section of a code to insert data into an MySQL
table. I
> copied this from DBI documentation available at www.perldoc.com/DBI
>
> ------------CODE----------------------
>
> Shebank line, use DBI;, use strict etc...
> ...
> ...
> my $coname = "tex";
> my $address = "tex";
> my $second = "30 Tosson terrace";
> my $town = "EW";my $country = "UK";
> my $code = "GHG";
> my $title = "Mr.";
>
> my $sth = $dbh->prepare("INSERT INTO
> f1(coname,address,second,town,country,code,title) VALUES
(?,?,?,?,?,?,?)");
I think you want to open a file here. Are you uploading a CVS file to
your database?
open(CVS,'cvsfile.txt') or die "can't open file: $!";
while(<CVS>) {
> chop;
> ($coname,$address,$second,$town,$country,$code,$title) = split/,/;
> $sth->execute($coname,$address,$second,$town,$country,$code,$title);
> }
close CVS;
>
> ... CODE continues....
>
> When the code runs, it gets into a loop and enters alot of 'NULL's
into the
> fields concerned.
> I don't quite understand 'while (<>)' what does that do. Another
version
> from perldoc is
> 'while (<CVS>). What on earth is CVS. There is no explanation about it
> whatsoever. Can somebody enlighten me about this.
Those are good questions for perldoc
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 10 Jan 2001 23:49:37 GMT
From: cputek1@my-deja.com
Subject: Problem... Src included...
Message-Id: <93isee$prm$1@nnrp1.deja.com>
I keep getting the error Can't stat Foo/Bar: No such file or directory.
I don't see what is wrong with it. the line that I think is the
problem is line # 11 (find (\&Extention_Check,"Foo/Bar");) Now the
directory that I am running this from has sub dirs under
it. "c:\temp\Foo\Bar". I have also tried it on a unix box /tmp/Foo/Bar
but that didn't work either.
The find line that I used is pretty much copied from
http://www.perldoc.com/perl5.6/lib/File/Find.html
What I'm trying to do is crawl a dir tree looking for binary files.
move those files to a different directory. I'm not sure that anything
else in the code will work as I can't get past this problem to check it
out.
thanks In advance for your help.
-CMF
Here is the code. Again... thanks
#!/usr/local/bin/perl
$CUR_DIR=$ENV{'PWD'};
@extentions= (".exe",".dll",".jar",".tar",".class");
mkdir("temp",0777);
chdir("temp");
use File::Find;
$init_handle = "NULL";
open (outPut, ">Output.log");
print "Before";
find (\&Extention_Check,"Foo/Bar");
print "After";
close (outPut);
sub Extention_Check
{
print "During";
*name = *File::Find::name;
*dir = *File::Find::dir;
$ffile = $_;
foreach $exten (@extentions)
{
if ($ffile=~/$exten\b/i)
{
$Dir=~s/^\///;
@fields = split(/\//,$Dir);
foreach $Var (@fields)
{
print "$Var\n";
mkdir("$Var",0777);
chdir("$Var");
}
rename("$name","/temp/$name");
$init_handle = select outPut;
print "$name";
select STDOUT;
}
chdir("$CUR_DIR/temp");
}
}
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 10 Jan 2001 17:23:24 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: RegEx question
Message-Id: <m34rz7c7pv.fsf@dhcp11-177.support.tivoli.com>
rzilavec@tcn.net (Richard Zilavec) writes:
> On Wed, 10 Jan 2001 16:40:05 GMT, mike_solomon@lineone.net wrote:
>
> >$output = " Blah blah ";
> >$output =~ s/^\s*|\s*$//g;
>
> I stuck the above in a loop, and used time to get a ball park on how
> fast \s* compared to \s+:
>
> $output =~ s/^\s*|\s*$//g; # 25.52
>
> $output =~ s/^\s+|\s+$//g; # 14.75
>
> $output =~ s/^\s+(.+?)\s+$/$1/; # 8.56
Please don't:
* Use the time command as a benchmarking tool
* Post benchmark results without the supporting code
I'm not sure what you did to get that third example to be faster than
the first two -- it shouldn't be. In addition, it isn't even correct
as it will only remove leading and trailing spaces if *both* are
present.
Also, you left out the FAQ solution, which significantly outperforms
all of these.
Here is my off-the-cuff benchmark, which is notably deficient in test
cases. Also, I modified the MATCH version to, I believe, be correct,
but did not significantly test it. Notably, it will not remove
anything from a string consisting only of whitespace.
perl -MBenchmark -e 'timethese
{ OR_STAR => sub { $_ = " Blah blah "; s/^\s*|\s*$//g },
OR_PLUS => sub { $_ = " Blah blah "; s/^\s+|\s+$//g },
MATCH => sub { $_ = " Blah blah "; s/^\s*(.*\S)\s*$/$1/ },
TWO => sub { $_ = " Blah blah "; s/^\s+//; s/\s+$//; }
}'
And here is the sanitized output, sorted from slowest to fastest:
MATCH: 27462.62/s (n=144728)
OR_STAR: 37413.19/s (n=190059)
OR_PLUS: 44162.17/s (n=232293)
TWO: 64793.37/s (n=342109)
As expected, using two passes is significantly faster than any of the
other methods mentioned.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 10 Jan 2001 23:06:04 GMT
From: damian@puma.qimr.edu.au (Damian James)
Subject: Re: replacing spaces with %20
Message-Id: <slrn95pqos.1k.damian@puma.qimr.edu.au>
In article <93imh0$k1q$1@nnrp1.deja.com>, ^Jerry wrote:
>I'm using a perl script to show images from a folder, one at a time..
>it works perfect in Internet Explorer, but in Netscape, if the images
>have a space in their name, it won't work...
>
This is because whitespace is not legal in a URL. IE is too
forgiving.
>how can I replace the name of an image (in $image_name) to something
>like this%20is%20me.jpg ??
>
perldoc perlre
perldoc CGI
Cheers,
Damian
------------------------------
Date: Thu, 11 Jan 2001 00:33:49 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: replacing spaces with %20
Message-Id: <t5pvrde3ttbn28@corp.supernews.com>
In article <93imh0$k1q$1@nnrp1.deja.com>,
^Jerry <newsgroups@jhorn.cjb.net> wrote:
: how can I replace the name of an image (in $image_name) to something
: like this%20is%20me.jpg ??
What did you try?
Greg
--
Reality is for people who can't handle drugs.
------------------------------
Date: Thu, 11 Jan 2001 09:56:05 +1000
From: "Anthony Carbone" <anthonyc@mincom.com>
Subject: socket send to client problem
Message-Id: <93isqd$hb7$1@sol.mincom.oz.au>
I have a problem when I use a socket as a two way pipe. Using IO::Socket, I
typically set up a server process listening on the socket waiting for
clients to connect.
if ($Client = $Server->accept()) {
$Client->autoflush(1);
$request = <$Client>;
When a client connects and writes, I read in the information and send a
confirmation back to the waiting client on the same socket.
print $Client $data;
However, if the client disappears before I get a chance to write back, the
server program crashes out - Nasty. I've been trying to find a method that
will test the client handle to see if it is still a valid connection before
I do the write, but to no avail.
I've tried methods/functions within IO::Socket, IO::Handle, socket etc. The
closest I got was actually with function 'eof HANDLE', which fails if the
client handle is not vaild but BLOCKS if it is thus hanging the server
script.
Any suggestions ?
thanks in advanced.
anthonyc
------------------------------
Date: Wed, 10 Jan 2001 23:45:36 GMT
From: 2obvious@my-deja.com
Subject: Re: system() method won't change directories!
Message-Id: <93is6t$pi3$1@nnrp1.deja.com>
> ugly as sin too. if that is what you really want, do this:
>
> chdir $path ;
> exec $script ;
> die "can't exec $script $!" ;
>
> uri
Um, permit me to revise my original question. What I'm ACTUALLY trying
to do is execute another application (that's why I want to go the
c:\Program Files directory). The app takes command line arguments. If
I were running this app from the command line, I would do something
like this:
cd "c:\Program Files\Application"
Application /file="c:\WINDOWS\Desktop\File.txt"
I am looking for a way to call this app from inside my original script,
because the file it takes as an argument might vary, and I want to keep
tabs on it with a scalar:
cd "c:\Program Files\Application"
Application /file="$file"
A chdir() call would take care of the first line, but I don't know of
any way to start the second without resorting to a system() call. And
that won't work--thanks to Wyzelli, Tony, and RH I now know that each
system() call creates its own environment.
So what can I do? Is there a way to invoke more than one line in a
system() call? Any different/better suggestions? Please help me out.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 10 Jan 2001 17:34:11 -0800
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: system() method won't change directories!
Message-Id: <3a5d0d94$1@news.microsoft.com>
<2obvious@my-deja.com> wrote in message news:93is6t$pi3$1@nnrp1.deja.com...
> Um, permit me to revise my original question. What I'm ACTUALLY trying
> to do is execute another application (that's why I want to go the
> c:\Program Files directory). The app takes command line arguments. If
> I were running this app from the command line, I would do something
> like this:
>
> cd "c:\Program Files\Application"
> Application /file="c:\WINDOWS\Desktop\File.txt"
[...]
> So what can I do? Is there a way to invoke more than one line in a
> system() call? Any different/better suggestions? Please help me out.
Have you tried to write both commands into one line?
system 'cd "c:/Program Files/Application" & Application
/file="c:/WINDOWS/Desktop/File.txt"'
Of course this is not portable but probably that is the least of your
worries right now.
On the other hand: why do you need to cd to the Application folder in the
first place?
Can't you simply use an absolute path to call the application:
system 'c:/Program Files/Application/Application
/file="c:\WINDOWS\Desktop\File.txt"'
jue
------------------------------
Date: Thu, 11 Jan 2001 00:51:21 GMT
From: gungeek@my-deja.com
Subject: Re: System() redirection failing in Win98, WinME
Message-Id: <93j028$svi$1@nnrp1.deja.com>
In article <3a5db297.16255904@newshost.uwo.ca>,
murdoch@fisher.stats.uwo.ca (Duncan Murdoch) wrote:
> I'm using perl in Win98 and WinME. A system call that has a file
> redirection in it is failing every time. If I take away the
> redirection, I see the correct output on the screen.
>
> It's something like this:
>
> system("echo Hello!");
>
> works fine, and displays Hello!, but
>
> system("echo Hello! > c:\\temp.txt");
> system("echo Hello! > c:/temp.txt");
>
> both fail, and don't create the temp.txt file. I don't know if this
> is relevant or not, but this particular perl script is being called
> from another process, running in a DOS window.
>
> Is this a known problem? Is there a workaround?
>
This works for me
$x = `echo Hello!`;
open(OUTFILE,'>c:\temp.txt') or die "Couldn't open file $!";
print OUTFILE $x;
close OUTFILE;
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 10 Jan 2001 22:57:40 GMT
From: webqueen, queen of the web <webqueen@my-deja.com>
Subject: would a regex be helpful here?
Message-Id: <93ipcv$msi$1@nnrp1.deja.com>
Say I have an input like:
1,2,4,6-9,12,15-16,20
which I want to explode into:
1,2,3,6,7,8,9,12,15,16,20
in other words, convert each n-m into n,n+1,n+2..,m
I can write a script to do this manually, but I wonder is there any
regex functionality that might help me?
Hug,
WQ
--
WHEN THE CATS ARE HUNGRY...
RUN FOR YOUR LIVES!
Alone, only a harmless pet...
One Thousand Strong, They Become a Man-Eating Machine!
-- The Night of a Thousand Cats (1972)
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 10 Jan 2001 23:34:15 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: would a regex be helpful here?
Message-Id: <Xj676.844$B9.180110848@news.frii.net>
In article <93ipcv$msi$1@nnrp1.deja.com>,
webqueen, queen of the web <webqueen@my-deja.com> wrote:
>Say I have an input like:
>
>
> 1,2,4,6-9,12,15-16,20
>
>which I want to explode into:
> 1,2,3,6,7,8,9,12,15,16,20
>
>in other words, convert each n-m into n,n+1,n+2..,m
>
>I can write a script to do this manually, but I wonder is there any
>regex functionality that might help me?
>
>Hug,
>WQ
$a = "1,2,4,6-9,12,15-16,20";
$a =~ s/-/../g;
@a = eval"($a)";
print "@a\n"
--
This space intentionally left blank
------------------------------
Date: Thu, 11 Jan 2001 00:02:43 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: would a regex be helpful here?
Message-Id: <x7snmr3qho.fsf@home.sysarch.com>
>>>>> "CF" == Chris Fedde <cfedde@fedde.littleton.co.us> writes:
CF> webqueen, queen of the web <webqueen@my-deja.com> wrote:
>> 1,2,4,6-9,12,15-16,20
>>
>> which I want to explode into:
>> 1,2,3,6,7,8,9,12,15,16,20
CF> $a = "1,2,4,6-9,12,15-16,20";
CF> $a =~ s/-/../g;
CF> @a = eval"($a)";
CF> print "@a\n"
feh. you return a list and i think she wanted a string.
$a =~ s/(\d+)-(\d+)/join ',', $1 .. $2/ge ;
BTW the /e eval is very different than the string eval chris used. s///e
compiles the replacement code once at compile time. eval string compiles
the string every time at runtime.
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: Thu, 11 Jan 2001 00:38:15 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: would a regex be helpful here?
Message-Id: <t5q03nrt6ld49a@corp.supernews.com>
In article <93ipcv$msi$1@nnrp1.deja.com>,
webqueen, queen of the web <webqueen@my-deja.com> wrote:
: Say I have an input like:
:
:
: 1,2,4,6-9,12,15-16,20
:
: which I want to explode into:
: 1,2,3,6,7,8,9,12,15,16,20
:
: in other words, convert each n-m into n,n+1,n+2..,m
In addition to the other solutions, you may want to check out the
Set::IntSpan module, available on the CPAN. Visit the following:
<URL:http://www.cpan.org/modules/by-module/Set/>
Greg
--
It's only premarital sex if you're going to get married.
------------------------------
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 34
*************************************