[13468] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 878 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 22 16:07:27 1999

Date: Wed, 22 Sep 1999 13:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <938030712-v9-i878@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 22 Sep 1999     Volume: 9 Number: 878

Today's topics:
    Re: "Pattern matching" (Larry Rosler)
    Re: (-d $filename) test <cassell@mail.cor.epa.gov>
    Re: (-d $filename) test (Randal L. Schwartz)
    Re: (-d $filename) test (Kragen Sitaker)
        An experienced opinion please <dbwallace@iprimus.ca>
    Re: Array length <makkulka@cisco.com>
    Re: Arrays?!? (Kragen Sitaker)
    Re: automatic news poster script <cassell@mail.cor.epa.gov>
    Re: Checking for space <delete.the.nospam.kayec@gov.ns.ca>
    Re: DBD::Sybase, Using Stored Procs with output vars <mpeppler@peppler.org>
    Re: image upload using form (JeffM)
    Re: image upload using form (Alan Curry)
    Re: image upload using form (Steve van der Burg)
    Re: image upload using form (Kragen Sitaker)
        latest "stable" perl for alpha (Walter Tice USG)
    Re: memory use of children <elaine@chaos.wustl.edu>
    Re: memory use of children <ltl@rgsun5.viasystems.com>
    Re: memory use of children <ltl@rgsun5.viasystems.com>
    Re: memory use of children <elaine@chaos.wustl.edu>
    Re: Need a simple script <cassell@mail.cor.epa.gov>
    Re: newbie question...well kindof <cassell@mail.cor.epa.gov>
    Re: newbie question...well kindof (Kragen Sitaker)
    Re: Optimizing processing of text files (Andy Squires)
    Re: Optimizing processing of text files <ltl@rgsun5.viasystems.com>
    Re: printf mask? (Larry Rosler)
    Re: printf mask? (Kragen Sitaker)
    Re: Redirect STDERR <cassell@mail.cor.epa.gov>
    Re: Regex and my <xwu@micropat.com>
    Re: Regex and my (Kragen Sitaker)
    Re: REQ: tell-a-friend script (J. Moreno)
    Re: REQ: tell-a-friend script <tchrist@mox.perl.com>
    Re: sort depth <aqumsieh@matrox.com>
        sorting like numbers an array of strings <mortuno@iname.com>
    Re: sorting like numbers an array of strings (Andrew Johnson)
    Re: sorting like numbers an array of strings (Sean McAfee)
    Re: You should be admired <cassell@mail.cor.epa.gov>
    Re: You should be admired (Henry Penninkilampi)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 22 Sep 1999 11:25:54 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: "Pattern matching"
Message-Id: <MPG.1252bf0868f3d4c8989fbd@nntp.hpl.hp.com>

In article <x3y3dw67vmh.fsf@tigre.matrox.com> on Wed, 22 Sep 1999 
12:34:47 -0400, Ala Qumsieh <aqumsieh@matrox.com> says...
 ...
> 	# check for punctuation marks (don't miss any!)
> 	# are brackets punctuation marks? you decide.
> 	$punc_marks += tr/;':",./?!@#$%^&*(){}~`[]//;
                              ^
                              |
                             Ooof! 

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Wed, 22 Sep 1999 11:34:54 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: (-d $filename) test
Message-Id: <37E9214E.3343B13B@mail.cor.epa.gov>

cacook@my-deja.com wrote:
> 
> Greetings,
> 
> Well I have looked extensively in the Perl FAQ and
> on the web, but I have not found any reason why
> the following code shouldn't work right:
> 
>   if (-d $file_name)
>     {
>     }
>     else
>     {
>     }
> 
> the problem is, that after the first
> sub-directory, it goes into the else clause every
> time, even if the file is a directory!

Because you're not telling -d to test $dir/$file_name ,
as you really want.

> Oh and I am running ActivePerl on NT 4.0; version
> 5.00503 I think (should be).

Well, you should be using 5.005_03, but whether you
should be using NT...  :-)

Seriously, if you're on NT then you should have been
able to find the answer in the ActivePerl FAQ on your
very own hard drive.  Look in the section named
'Programming' at the question:

    "Why doesn't the -d operator work?"

and you'll see an answer which starts:

    It does, in fact, work. However, people tend to 
    use it incorrectly and get bad results. To check
    for all the subdirectories in a directory, try
    code like this: 

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: 22 Sep 1999 11:46:50 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: (-d $filename) test
Message-Id: <m1d7vayeat.fsf@halfdome.holdit.com>

>>>>> "cacook" == cacook  <cacook@my-deja.com> writes:

cacook>   opendir (CURRENTDIR, $dir_name);
 ...
cacook>   @file_list = readdir (CURRENTDIR);
 ...
cacook>   foreach $file_name (@file_list)
 ...
cacook>     { if (-d $file_name)                # if it is

Very common problem.  Please remember what the output of readdir looks
like.  Basenames only.  No leading path.  You are testing
"$current_directory/$file_name", not "$dir_name/$file_name" as you
should be.  Unless there happened to be a directory in the current
directory as a coincidence, you'll get a bunch of negative results.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: Wed, 22 Sep 1999 19:05:39 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: (-d $filename) test
Message-Id: <7M9G3.3600$QJ.211508@typ11.nn.bcandid.com>

In article <m1d7vayeat.fsf@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>Very common problem.  Please remember what the output of readdir looks
>like.  Basenames only.  No leading path.  You are testing
>"$current_directory/$file_name", not "$dir_name/$file_name" as you
>should be.

That's what I thought at first, too.  But he chdir'ed to $dir_name
before he even did the readdir, let alone before he did the -d test.

There's another thing: chdir($dir_name) followed by opendir(CURRENTDIR,
$dir_name) will only work if his paths are absolute.  Right?

I'll bet the first-level path is absolute, but then when he recurses,
opendir fails because it's getting a relative path.

By the way, you should make sure you don't recurse on "." and "..".  :)
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Wed Sep 22 1999
47 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: Wed, 22 Sep 1999 15:18:48 -0300
From: Dave Wallace <dbwallace@iprimus.ca>
Subject: An experienced opinion please
Message-Id: <37E91D88.9050F4D4@iprimus.ca>

I have on one computer a script that takes a $search variable and loads
a page that displays, among other thing, a building photograph and,
below it, a table of floor data, one row per floor. Both the photo and
the table are generated based on the same single variable. OS is NT
running IIS 3.0 and ActivePerl 509. It is a very simple script that
reads a .txt data file and works like a charm (over 800 buildings).

I am setting up another computer: OS is NT running IIS and ActivePerl
509. The web site has been copied under the same root. Perl installed to
same location. Virtual directories all identical and with same rights.
Identical scripts. Registry keys identical.

Problem: When I access a building on the new system, everything displays
as it should: header graphic, photograph, data table header, footer
graphic....but not the data portion of the table.  No error messages,
nothing! It's as if the data file is empty and there is nothing to
display, but I have checked everything that I can think of and
everything seems identical to the original system. I reloaded Perl and
tested it...perfect.  The script must be running because the photo is
getting loaded by the search variable. For some reason the data
retrieval won't happen.

I'm just looking for any clue as to what I should look into or test.
It's baffling.

Thanks

Dave


------------------------------

Date: Wed, 22 Sep 1999 11:19:31 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Array length
Message-Id: <37E91DB3.D8AFCC18@cisco.com>

[ Balasundar Raju wrote:

> Could someone let me know how to find the length of an array - i.e. the
> number
> of elements in an array? Thanks,

$length = scalar ( @a );
$length = $#a +1 ; # adding 1 is very important
$length = @a ;
--




------------------------------

Date: Wed, 22 Sep 1999 19:43:32 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Arrays?!?
Message-Id: <EjaG3.3649$QJ.215539@typ11.nn.bcandid.com>

In article <Pine.LNX.4.10.9909221233090.7611-100000@fnord.io.com>,
Poohba  <poohba@io.com> wrote:
>I have a data file.  The first field has a number in it.  When I run my
>program it creates another record.  I want to subtract the next to last
>record first field from the last record first field.  How do I do that?

Well, in three steps.
1. Get the last field of the next-to-last record and store it in a variable
  $foo.
2. Get the last field of the last record and store it in a variable $bar.
3. Subtract $foo from $bar like so: $bar - $foo.
4. Do something with the result.

Which steps are you having trouble with?

-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Wed Sep 22 1999
47 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: Wed, 22 Sep 1999 11:14:10 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: automatic news poster script
Message-Id: <37E91C72.812621F1@mail.cor.epa.gov>

Job-Base wrote:
> 
> Could someone tell me if it is possible to include some part of perl
> code with which it would be able to directly send a message to a usenet

Yes.

> server.  I would like to have the perl script send the data
> automatically without user intervention.   But how to do that

Why would anyone want to automatically post to a news server?
I'm sure you wouldn't do something so egregiously offensive 
as spamming Usenet.  But then, what purpose would you have in
mind?  The people I know of who submit automatic posts all
have the programming skills to write such beasts themselves.

wondering,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Wed, 22 Sep 1999 19:00:08 GMT
From: "kayec" <delete.the.nospam.kayec@gov.ns.ca>
Subject: Re: Checking for space
Message-Id: <YG9G3.87$Oa2.4109@sapphire.mtt.net>

Ha ha ha !!!



Casey R. Tweten wrote in message ...
>On Wed, 22 Sep 1999, kayec wrote:
>
>:I know there are functions for reading directories, coping files... and
>:other o/s type functions but what would be the best way to check the
>:available drive space??
>
>number_of_platters(PI(r^2))
>
>or, if using tape:
>
>L(W)
>
>--
>   Casey R. Tweten    <joke> This
>    Web Developer      is 100% certified
>HighVision Associates    virus and bug
> crt@highvision.com     free code. </joke>
>




------------------------------

Date: Wed, 22 Sep 1999 11:23:06 -0700
From: Michael Peppler <mpeppler@peppler.org>
Subject: Re: DBD::Sybase, Using Stored Procs with output vars
Message-Id: <37E91E8A.8947F883@peppler.org>

pcastine@prz.tu-berlin.de wrote:
> 
> Perhaps I'm being a bit dim with trying to understand the POD for DBI and
> DBD::Sybase. Be that as it may, can someone (please!) set me straight on
> how to access values returned via output statements?
> 
> My code starts off like this (slightly truncated):
> 
> >>>
>  my $sql = sprintf qq{declare \@myCitID tCitID
>                   execute AddCitation \@myCitID output, %s, %s},
>                                                 $dbh->quote($myRefType),
>                                                 $dbh->quote($myTitle);
> <<<
> 
> tCitID is simply a user type that I use a lot in my DB; it's a numeric
> used as an identity field in the Citation database. I need to grab its
> value when the AddCitation stored proc returns.

What happens is that stored procedures return multiple result sets (one of 
which is the return status of the proc).

So to get the OUTPUT variable you need to do something like

do {
    while($d = $sth->fetch) {
	if($sth->{syb_result_type} == 4042) {  # it's an OUTPUT param
	    $tCidID = $d->[0];
        }
	# ignore other results for now
    }
} while($sth->{syb_more_results});

> If Michael Peppler is reading: more detailed examples in the .pod would
> be wonderful, particularly for us folk who are diving into SQL, Sybase,
> and Perl all at the same time. But thank you for making the module
> available.

I'll see what I can do :-)

Michael
-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@peppler.org    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com


------------------------------

Date: Tue, 21 Sep 1999 14:20:49 GMT
From: jmontany@clarityconnect.com (JeffM)
Subject: Re: image upload using form
Message-Id: <37e78f7c.1145148@news1.clarityconnect.com>

A test  image can be found at http://www.nyhonorbound.org/go.gif
This image was uploaded using the program.
If I try loading it into photoshop, it locks up, crashes photoshop.
Also, when you try to load it using the browser, the default no
image/damaged image symbol is displayed.

If you opened a gif file using a text editor, then saved it without
making any changes, the file will be corrupted. This seems to be
simular to what this program is doing. Its not saving the data in the
proper format.



------------------------------

Date: Wed, 22 Sep 1999 18:56:50 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: image upload using form
Message-Id: <SD9G3.3587$QJ.210478@typ11.nn.bcandid.com>

In article <37e78f7c.1145148@news1.clarityconnect.com>,
JeffM <jmontany@clarityconnect.com> wrote:
>A test  image can be found at http://www.nyhonorbound.org/go.gif

That gif has 2 extra bytes at the beginning: \r and \n. (You can observe this
yourself with od -c go.gif). After removing those two bytes
(tail +3c go.gif > fixed.gif), it becomes a valid file.
-- 
Alan Curry    |Declaration of   | _../\. ./\.._     ____.    ____.
pacman@cqc.com|bigotries (should| [    | |    ]    /    _>  /    _>
--------------+save some time): |  \__/   \__/     \___:    \___:
 Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman


------------------------------

Date: 22 Sep 1999 19:13:06 GMT
From: steve.vanderburg@lhsc.on.ca (Steve van der Burg)
Subject: Re: image upload using form
Message-Id: <8E499ACE0stevevanderburglhsco@newshost.uwo.ca>

jmontany@clarityconnect.com (JeffM) wrote in 
<37e78f7c.1145148@news1.clarityconnect.com>:

>A test  image can be found at http://www.nyhonorbound.org/go.gif
>This image was uploaded using the program.
>If I try loading it into photoshop, it locks up, crashes photoshop.
>Also, when you try to load it using the browser, the default no
>image/damaged image symbol is displayed.
>
>If you opened a gif file using a text editor, then saved it without
>making any changes, the file will be corrupted. This seems to be
>simular to what this program is doing. Its not saving the data in the
>proper format.
>
>

I downloaded the file at the URL you've listed, and it's a valid GIF file 
except for a leading CR-LF and a trailing CR-LF.
Take a look at the raw data stream coming from the browser (your code writes it 
to a file), then take a look at your code.  It looks like you're not dealing 
properly with the blank line between the boundary and the GIF data.

Here's an actual MIME-stream (URL-escaped, of all things, so I could redisplay 
it back to the browser), from a form that includes a few file upload fields:

-----------------------------3085498916756%0D%0A
Content-Disposition%3A%20form-
data%3B%20name%3D%22ufile%22%3B%20filename%3D%22P%3A%5Cg1.gif%22%0D%0A
Content-Type%3A%20image%2Fgif%0D%0A
%0D%0A
GIF89a%0C%00%08%00%B3%00%00%00%00%A5%10%10%A5%29%29%AD99%B5%7B%7B%CE%94%94%D6%B
D%BD%E7%EF%EF%F7%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF
%FF%FF%FF%2C%00%00%00%00%0C%00%08%00%00%04%19%10%C8I%AB%9D%04%E9%AD%87%1C%07b%8
C%A40%09GqaH%B0%BE0%15%01%00%3B%0D%0A
-----------------------------3085498916756%0D%0A
Content-Disposition%3A%20form-
data%3B%20name%3D%22blahfile%22%3B%20filename%3D%22%22%0D%0A
%0D%0A
%0D%0A
-----------------------------3085498916756%0D%0A

Here's the perl program that did that:

use strict;
use CGI;
$|++;
print "Content-type:  text/plain\n\n";
while ( <STDIN> ) { print CGI::escape($_),"\n"; }

So, you can either fix your code to save the data properly (hint: you'll also 
need to *not* save the CR-LF that terminates the data), or just use CGI.pm 
(preferably version 2.56, because earlier versions have at least one file 
upload bug).

 ...Steve

-- 
Steve van der Burg
Technical Analyst, Information Services
London Health Sciences Centre
London, Ontario, Canada
Email: steve.vanderburg@lhsc.on.ca


------------------------------

Date: Wed, 22 Sep 1999 19:22:55 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: image upload using form
Message-Id: <j0aG3.3620$QJ.213430@typ11.nn.bcandid.com>

In article <37e78f7c.1145148@news1.clarityconnect.com>,
JeffM <jmontany@clarityconnect.com> wrote:
>If you opened a gif file using a text editor, then saved it without
>making any changes, the file will be corrupted. This seems to be
>simular to what this program is doing. Its not saving the data in the
>proper format.

BTW, this is not true if you're using a decent text editor on a decent
platform, such as Emacs on Unix.  I have, in the past, edited
executable files with Emacs (generally to change the values of strings
within them; although you can patch in program code this way too, it's
not recommended) and run them successfully afterwards.

It has no trouble with .gif files.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Wed Sep 22 1999
47 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: 21 Sep 1999 15:54:31 GMT
From: tice@hunch.zk3.dec.com (Walter Tice USG)
Subject: latest "stable" perl for alpha
Message-Id: <7s89nn$h7n@zk2nws.zko.dec.com>

Hi, I've been using "5.004_04 built for alpha-dec_osf"
for some time.  I'm wondering what is the latest stable
version (emphasis on stable) which any of you have installed
and used on alpha, which you could reccomend?

TIA
W


------------------------------

Date: Wed, 22 Sep 1999 14:09:31 -0400
From: Elaine -HFB- Ashton <elaine@chaos.wustl.edu>
Subject: Re: memory use of children
Message-Id: <37E91AC8.E932C471@chaos.wustl.edu>

Bill Moseley wrote:
> Oh, but he's forking from a CGI script.  What happens when you kill all
> the 'nobody' processes.  Finally! Some good response time from that
> server.

*snicker* 

sync;sync;reboot  ;)

fork not quietly
into that gentle good night
spawn die all too soon

e.


------------------------------

Date: 22 Sep 1999 18:44:03 GMT
From: lt lindley <ltl@rgsun5.viasystems.com>
Subject: Re: memory use of children
Message-Id: <7sb81j$fdr$2@rguxd.viasystems.com>

Elaine -HFB- Ashton <elaine@chaos.wustl.edu> wrote:
:>Bill Moseley wrote:
:>> Oh, but he's forking from a CGI script.  What happens when you kill all
:>> the 'nobody' processes.  Finally! Some good response time from that
:>> server.

:>*snicker* 

:>sync;sync;reboot  ;)

:>fork not quietly
:>into that gentle good night
:>spawn die all too soon

:>e.

-- 
// Lee.Lindley   /// Programmer shortage?  What programmer shortage?
// @bigfoot.com  ///  Only *cheap* programmers are in short supply.
////////////////////    50 cent beers are in short supply too.


------------------------------

Date: 22 Sep 1999 18:49:08 GMT
From: lt lindley <ltl@rgsun5.viasystems.com>
Subject: Re: memory use of children
Message-Id: <7sb8b4$fdr$3@rguxd.viasystems.com>

Damnit.  I scraped the <enter> key with my pinky again and sent a
100% quoted post.  I've got to do something about that.  

Elaine -HFB- Ashton <elaine@chaos.wustl.edu> wrote:

:>*snicker* 

:>sync;sync;reboot  ;)

You really are ol.. um, well, you learned your sysadmin stuff a long ti..,
um, well, your sysadmin skills were established early in your career,
weren't they.


-- 
// Lee.Lindley   /// Programmer shortage?  What programmer shortage?
// @bigfoot.com  ///  Only *cheap* programmers are in short supply.
////////////////////    50 cent beers are in short supply too.


------------------------------

Date: Wed, 22 Sep 1999 16:01:14 -0400
From: Elaine -HFB- Ashton <elaine@chaos.wustl.edu>
Subject: Re: memory use of children
Message-Id: <37E934EC.89085522@chaos.wustl.edu>

lt lindley wrote:
> :>sync;sync;reboot  ;)
> 
> You really are ol.. um, well, you learned your sysadmin stuff a long ti..,
> um, well, your sysadmin skills were established early in your career,
> weren't they.

Hey little boy, want some candy?  :)

I revel in each and every new grey hair. 

 . o O ( I wonder how old he would think I am if I had used fastboot ...)

e.


------------------------------

Date: Wed, 22 Sep 1999 11:17:41 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Need a simple script
Message-Id: <37E91D45.59403EDD@mail.cor.epa.gov>

blancasd@earthlink.net wrote:
> 
> Looking for some help. Want to get a a hold of a free cgi script that
> will work with Front Page 98 and will send the results of
> a small web form to four or five e-mail recipients "alternately".

I'm sorry to be the one to tell you, but this is not the right
place for your question.  This newsgroup is for helping people
who have written Perl code and want help debugging it or under-
standing the mystical underpinnings of the language.  You
probably want to surf the web for one of several dozen script
repositories, such as:

cgi.resourceindex.com
www.cgi-resources.com
www.freshmeat.net

Do not use one of Matt Wright's scripts and then come back
here because you couldn't get it to work for you, because
people will make fun of you and the script.

HAND,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Wed, 22 Sep 1999 11:22:01 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: newbie question...well kindof
Message-Id: <37E91E49.C8D50133@mail.cor.epa.gov>

Kragen Sitaker wrote:
[snip]
> I usually find that roughly 95%-99% of cases where an inexperienced
> person thinks the compiler or interpreter is broken, it is in fact
> their code that is broken.

That low, huh?  Are the other 4.9% - 0.9% due to win32 flaws?
:-)

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Wed, 22 Sep 1999 19:17:13 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: newbie question...well kindof
Message-Id: <ZW9G3.3612$QJ.212618@typ11.nn.bcandid.com>

In article <37E91E49.C8D50133@mail.cor.epa.gov>,
David Cassell  <cassell@mail.cor.epa.gov> wrote:
>Kragen Sitaker wrote:
>[snip]
>> I usually find that roughly 95%-99% of cases where an inexperienced
>> person thinks the compiler or interpreter is broken, it is in fact
>> their code that is broken.
>
>That low, huh?  Are the other 4.9% - 0.9% due to win32 flaws?

Mostly they're due to broken compilers or interpreters.  You'd be
amazed how bad some of the compilers and interpreters in the PC world
are.  (Actually, maybe you wouldn't.  Maybe you have as much experience
fighting with them as I do.)
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Wed Sep 22 1999
47 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: 22 Sep 1999 18:17:12 GMT
From: asquires@netcom.com (Andy Squires)
Subject: Re: Optimizing processing of text files
Message-Id: <7sb6f8$aas@dfw-ixnews11.ix.netcom.com>


David and others,

I took your advice and looking through perlfaq6 came up with the code
below; however, it still doesn't do quite what I want.  Because I'm OR-ing
the regular expressions, it will only make a substitution for the first
match on a line.  For example, if I'm searching through an html file and
there is a line like:

<a href="HOME.HTML">Home page</a> <a href="THIS.HTML">This Page</a>

only the HOME.HTML get substituted by home.html, but THIS.HTML remains in
upper case.  I guess it's still not clear how to do a substitution for
multiple regular expressions.  

Any more thoughts?  Thanks.

#!/usr/local/bin/perl -w

         sub _bm_build {
             my $condition = shift;
             my @regexp = @_;  # this MUST not be local(); need my()
             my $expr = join $condition => map { "s/\$regexp[$_]/\$regexp[$_]/gio" } (0..$#regexp);
             my $match_func = eval "sub { $expr }";
             die if $@;  # propagate $@; this shouldn't happen!
             return $match_func;
         }

         sub bm_or  { _bm_build('||', @_) }

#   Files to lower case in href tags.
@filepats = qw(home.html this.html that.html);
         $f1 = bm_or  @filepats;

         while ( <> ) {
             print if &$f1;
         }


--
| Andy Squires                  "The trouble with life is
| asquires@netcom.com         there's no background music."
| Web Page is at http://www.capitalrowing.org/andy/



------------------------------

Date: 22 Sep 1999 18:38:25 GMT
From: lt lindley <ltl@rgsun5.viasystems.com>
Subject: Re: Optimizing processing of text files
Message-Id: <7sb7n1$fdr$1@rguxd.viasystems.com>

Andy Squires <asquires@netcom.com> wrote:
:>David and others,

:>I took your advice and looking through perlfaq6 came up with the code
:>below; however, it still doesn't do quite what I want.  Because I'm OR-ing
:>the regular expressions, it will only make a substitution for the first
:>match on a line.  

Then don't do OR-ing.

:><a href="HOME.HTML">Home page</a> <a href="THIS.HTML">This Page</a>

:>only the HOME.HTML get substituted by home.html, but THIS.HTML remains in
:>upper case.  I guess it's still not clear how to do a substitution for
:>multiple regular expressions.  

Just don't quit trying the others after one of them succeeds.

:>Any more thoughts?  Thanks.

:>#!/usr/local/bin/perl -w

:>         sub _bm_build {
:>             my $condition = shift;
:>             my @regexp = @_;  # this MUST not be local(); need my()
:>             my $expr = join $condition => map { "s/\$regexp[$_]/\$regexp[$_]/gio" } (0..$#regexp);
:>             my $match_func = eval "sub { $expr }";
:>             die if $@;  # propagate $@; this shouldn't happen!
:>             return $match_func;
:>         }

:>         sub bm_or  { _bm_build('||', @_) }

	   sub bm_comma { _bm_build(',', @_) }

Or I suppose ';' would work just as well.  Do you need to know
whether any of them matched or a count of how many matched?  If
so, then you have more work to do. Note that I haven't tried this.
I may have missed something important.  If I did, I'm sure someone
will let us know.  :->


:>#   Files to lower case in href tags.
:>@filepats = qw(home.html this.html that.html);
:>         $f1 = bm_or  @filepats;

	   $f1 = bm_comma @filepats;

:>         while ( <> ) {
:>             print if &$f1;
Hmm.  What were you doing before if the line didn't contain any of your
strings?  Looks like you were dropping them.  Just do:
		&$f1;
		print;
:>         }



-- 
// Lee.Lindley   /// Programmer shortage?  What programmer shortage?
// @bigfoot.com  ///  Only *cheap* programmers are in short supply.
////////////////////    50 cent beers are in short supply too.


------------------------------

Date: Wed, 22 Sep 1999 12:13:27 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: printf mask?
Message-Id: <MPG.1252ca30d29252b989fbe@nntp.hpl.hp.com>

In article <ts6G3.3266$QJ.187459@typ11.nn.bcandid.com> on Wed, 22 Sep 
1999 15:19:53 GMT, Kragen Sitaker <kragen@dnaco.net> says...
> In article <7saptd$b6h$1@nnrp1.deja.com>,
> Dunc  <c_duncan_hudson@yahoo.com> wrote:
> >This is probably a simple question, but it has me stumped.  I need to
> >convert a hex string to binary and write the resulting binary string to
> >an output file.  Can I do it with printf, is there an appropriate mask?

In some development versions of perl, there is a 'b' specifier for 
s?printf.  But not in the 'stable' version yet.

> > Is there a better way?  Thanks in advance, sorry if it seems like a
> >trivial question.
> 
> perl -we 'print pack "H*", "464646204646460a"'
> outputs
> FFF FFF

That result isn't a binary string, is it?  I assume Dunc wants a string 
consisting of 0s and 1s, whose value interpreted as binary is that of 
the hex string interpreted as hex.  Equivalently, eight bytes of binary 
for each two bytes of hex.

The best I can come up with is this, which looks slow and ugly.

  print unpack 'B*' => pack 'C*' =>
      map hex, '464646204646460a' =~ /(..)/g;

This uses the same approach, but is somewhat slower:

  print map unpack('B*' => chr hex) => '464646204646460a' =~ /(..)/g;

Output is:

  0100011001000110010001100010000001000110010001100100011000001010

Any better thoughts?

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Wed, 22 Sep 1999 19:27:26 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: printf mask?
Message-Id: <y4aG3.3632$QJ.213239@typ11.nn.bcandid.com>

In article <MPG.1252ca30d29252b989fbe@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>In article <ts6G3.3266$QJ.187459@typ11.nn.bcandid.com> on Wed, 22 Sep 
>1999 15:19:53 GMT, Kragen Sitaker <kragen@dnaco.net> says...
>> perl -we 'print pack "H*", "464646204646460a"'
>> outputs
>> FFF FFF
>
>That result isn't a binary string, is it?  I assume Dunc wants a string 
>consisting of 0s and 1s, whose value interpreted as binary is that of 
>the hex string interpreted as hex.

Well, you may be right about that.  I assumed he wanted a string
consisting of bits, not '0' and '1' characters.

>This uses the same approach, but is somewhat slower:
>
>  print map unpack('B*' => chr hex) => '464646204646460a' =~ /(..)/g;

That's not too bad.

>Output is:
>
>  0100011001000110010001100010000001000110010001100100011000001010
>
>Any better thoughts?

Didn't someone ask a similar question last week, about converting
decimal fractions to binary?  Didn't someone reply by posting a
relatively full-featured module for conversion of arbitrary-length
numbers between arbitrary bases?  (I just posted a one-off thing to do
binary only.)
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Wed Sep 22 1999
47 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: Wed, 22 Sep 1999 11:07:34 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Redirect STDERR
Message-Id: <37E91AE6.383546C0@mail.cor.epa.gov>

Dean A. Henkel wrote:
> 
> Thanks Mike and all who replied.
> 
> Your example seems to work just fine for what I need.  This board is excellent!

Dean, I'm glad you got the answer you needed.  But this is
not a board.  It is not a chat room, either [as some deluded
people seem to think].

It is a newsgroup on Usenet, and as such is different.
With different standards and guidelines.
With a different culture.
And occasional incomplete sentences.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Wed, 22 Sep 1999 14:12:20 -0400
From: xiaowen wu <xwu@micropat.com>
Subject: Re: Regex and my
Message-Id: <37E91C03.7D864013@micropat.com>

whos_john_galt@my-deja.com wrote:

> Thanks in advance.
>
> I am going to research this more intensely, but why does:
>
> my $value="9876543210";
> my ($pubw)=$value=~/(\d{6})/;
> print $pubw;
>
> produce: 987654
>
> BUT...
>
> $value="9876543210";
> $pubw=$value=~/(\d{6})/;
> print $pubw;
>
> produce: 1
>

The $value=~/(\d{6})/ return an array,  and evaluated to the number of
element inin the array in a scalar context.



> I use these statements in a foreach loop, does the my force immediate
> evaluation and the 1 is generated by the loop?...but when I take the
> value of $value away, pubw appears undefined as if the 1 represents
> true..
>
> Any assistance would be greatly appreciated.
>
> Joey
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.





------------------------------

Date: Wed, 22 Sep 1999 19:09:20 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Regex and my
Message-Id: <AP9G3.3605$QJ.211131@typ11.nn.bcandid.com>

In article <37E91C03.7D864013@micropat.com>,
xiaowen wu  <xwu@micropat.com> wrote:
>The $value=~/(\d{6})/ return an array,  and evaluated to the number of
>element inin the array in a scalar context.

No, it returns a list, but only in a list context.  Expressions can't
return arrays, just lists and scalars.  Variables can't hold lists,
just arrays, scalars, and hashes.

In a scalar context, // will return either 1 or '', according to
perldoc perlop.  In a list context, it returns a list of the things
inside ()'s, or if there are no ()'s, () for failure and (1) for
success.

HTH.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Wed Sep 22 1999
47 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


------------------------------

Date: Wed, 22 Sep 1999 15:22:03 -0400
From: planb@newsreaders.com (J. Moreno)
Subject: Re: REQ: tell-a-friend script
Message-Id: <1dyjg4h.14y2iyz11ujt2tN@roxboro0-0046.dyn.interpath.net>

David Cassell <cassell@mail.cor.epa.gov> wrote:

> J. Moreno wrote:
> [snip]
> > Uhm, elsif may be correct perl, but it's still a typo.
> 
> A typo of *what* ?
> 
> I'm siding with Abigail on this.  'elsif' is a slug of
> computer jargon, and is not an English word. It only
> needs to remind people of a couple English words.

But we don't speak just english -- we speak various computer
jargons too; and elseif is the correct and natural spelling.

> So it's not strictly a 'typo'.  No more than the Unix commands 
> 'mv' and 'cp' are typos because they are not the words 
> 'move' and 'copy'.

Yeah, but using tr and dup for mv and cp would be a mistake.

-- 
John Moreno


------------------------------

Date: 22 Sep 1999 13:39:39 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: REQ: tell-a-friend script
Message-Id: <37e9307b@cs.colorado.edu>

In comp.lang.perl.misc, planb@newsreaders.com (J. Moreno) writes:
:But we don't speak just english -- we speak various computer
:jargons too; and elseif is the correct and natural spelling.

You are quite simply, wrong.  We're speaking Perl.  Learn it.  Next you'll
be telling us that "last" is a type for "break".

If someone tells you that "departement" is the correct spelling for the
word in French, you don't tell them that the second "e" is misspelled.

As for your notions of what is natural, this too is misplaced.  "elsif"
is explicitly spelled that way on purpose.  It is by design.  It is not
an accident.  It also has at least two different sound and thoughtful
reasons for that particularly choice.

I repeat: you're wrong.  In fact, you're verging on being full of it.

--tom
-- 
People seem not to see that their opinion of the world is also a
confession of character.                   --Ralph Waldo Emerson


------------------------------

Date: Wed, 22 Sep 1999 13:35:29 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: sort depth
Message-Id: <x3y1zbq7sta.fsf@tigre.matrox.com>


Wise Guy <WiseGuy_73NOcdSPAM@go.com> writes:

> Dana Booth <dana@oz.net> wrote:
> > I should have been more specific... This is Perl 5 on 
> > an OpenBSD box. I have
> > a textfile containing lines which I would like Perl to 
> > sort numerically.
> > Each line is a 23 digit number. And my question would 
> > be, to how many digits
> > is the sort function going to work?
> > -- 
> 
> I tried this out ___ it gives me 13 digits after the 
> decimal point in the format x.xxxxxxxxxxxxxe+n ... where 
> e+n is 10 to the corresponding power. This is if u tell 
> Perl to treat the lines as numbers. If however, u enclose 
> these in quotes, u will get the desired output :-)

You mean lexicographic sorting which would sort 2000 ahead of 300 ?

--Ala



------------------------------

Date: Wed, 22 Sep 1999 20:25:01 +0200
From: Miguel Ortu~o <mortuno@iname.com>
Subject: sorting like numbers an array of strings
Message-Id: <37E91EFD.5B3D5E72@iname.com>

Hello Everybody

I´m rookie programing perl. Seems great, but difficult to learn things
a little complex like this. I could do it like Pascal or C, but I´m
sure there´s a "perl way".

I got an array like this:

@my_array = ( "4 , -20 , file1" ,
              "3 , -15 , file2" ,
              "4 , -2  , file3" ,
              "3 , -14 , file4" )

And I need to sort it to get this:

"3 , -15 , file2" ,
"3 , -14 , file4" ,
"4 , -20 , file1" ,
"4 , -2  , file3" ,

 
They are strings, but must be sorted as numbers;
sorted by the first column, and then by the second one.
(The third doesn´t matter)

Anyone could help me?

Thanks in advance

Miguel


------------------------------

Date: Wed, 22 Sep 1999 18:36:24 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: sorting like numbers an array of strings
Message-Id: <Ik9G3.2195$2k1.74344@news1.rdc2.on.home.com>

In article <37E91EFD.5B3D5E72@iname.com>,
 Miguel Ortu~o <mortuno@iname.com> wrote:
!  
! They are strings, but must be sorted as numbers;
! sorted by the first column, and then by the second one.
! (The third doesn´t matter)
! 
! Anyone could help me?

see section 4 of the perlfaqs for the entry:
    
    perlfaq4.pod: How do I sort an array by (anything)?

The URL given at the end of that entry is worth following
up on as well.

regards
andrew



------------------------------

Date: Wed, 22 Sep 1999 18:37:03 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: sorting like numbers an array of strings
Message-Id: <jl9G3.720$V7.116079@news.itd.umich.edu>

In article <37E91EFD.5B3D5E72@iname.com>,
Miguel Ortu~o  <uov00135@correo.uniovi.es> wrote:
>I´m rookie programing perl. Seems great, but difficult to learn things
>a little complex like this. I could do it like Pascal or C, but I´m
>sure there´s a "perl way".

There usually is.

>I got an array like this:
>@my_array = ( "4 , -20 , file1" ,
>              "3 , -15 , file2" ,
>              "4 , -2  , file3" ,
>              "3 , -14 , file4" )

>And I need to sort it to get this:
>"3 , -15 , file2" ,
>"3 , -14 , file4" ,
>"4 , -20 , file1" ,
>"4 , -2  , file3" ,

Is there a reason that these lines need to remain as strings?  It would be
more convenient to work with them as arrays.

>They are strings, but must be sorted as numbers;
>sorted by the first column, and then by the second one.
>(The third doesn´t matter)

Check out perlfaq4 for a description of the "Schwartzian Transform".

@sorted =
	map  { $_->[0] }
	sort { $a->[1] <=> $b->[1] or $a->[2] <=> $b->[2] }
	map  { [ $_, (split /\s*,\s*/)[0,1] ] } @my_array;

To really understand how it works you'll need to learn about references (if
you haven't already).  They're described in the perlref manpage.

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


------------------------------

Date: Wed, 22 Sep 1999 11:25:56 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: You should be admired
Message-Id: <37E91F34.35E1E47D@mail.cor.epa.gov>

Jeff Zucker wrote:
> 
> James W Corpening wrote:
> >
> > Abigail wrote:
> >
> > > `` I've searched the FAQs, perl.com, and other places, but I haven't found
> > > `` a hint as to how to make a hyperlink work as a submit button.
> > >
> > > What makes you think perl.com would have any information about that?
> >
> > Ya know, some of you illiterates are real idiots.  I write in perl, and I use submit
> > buttons in my html portions, as probably many of you do.  Consequently, I thought to
> > rely on the perl group (the MISC group) to help me.
> 
> Ya know, if I had a friend who had two books -- one on Perl and one on
> HTML -- and he had a question about submit buttons and hyperlinks and
> was looking it up in the Perl book, I would tell him he was looking in
> the wrong book.  I guess that makes me a real idiot.

Jeff, I doubt the poster will get the analogy.  You forgot
to tell him what a 'friend' is.  

He clearly doesn't know the meaning of the word 'illiterate', 
and seems to believe he is writing in something called 'perl'.  
He probably doesn't know that Perl is something other than a
CGI language.  Sad, really...

David, who programs in Perl [among other languages]
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


------------------------------

Date: Thu, 23 Sep 1999 04:19:20 +0930
From: spamfree@metropolis.net.au (Henry Penninkilampi)
Subject: Re: You should be admired
Message-Id: <spamfree-2309990419210001@d6.metropolis.net.au>

People, settle!

The answer to the original question is:

<A HREF="javascript:document.forms['myForm'].submit();">Make it so!</A>

Now, that wasn't too painful, was it?

As everyone can see, it is (obviously) a *JavaScript* question, and (as
such) the original poster would have probably had more luck searching
<http://developer.irt.org/script/script.htm> instead of posting to this
newsgroup.

S/he didn't know that.  Now s/he does.  I trust that s/he will bookmark
the above page, and refer to it in future instances.

In my book, it's OK to make a mistake *once* and we should all exercise a
little bit of patience when newbies pose questions.  Venomous attacks are
possibly best reserved for those that *repeatedly* demonstrate their lack
of research skills, don't you think?

Henry.


------------------------------

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 878
*************************************


home help back first fref pref prev next nref lref last post