[11820] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5420 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 19 15:12:33 1999

Date: Mon, 19 Apr 99 12:00:22 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 19 Apr 1999     Volume: 8 Number: 5420

Today's topics:
    Re: (Me Dummy) Have .pl forum script and want to add an <cassell@mail.cor.epa.gov>
    Re: Adding TCPIP # chris+usenet@netmonger.net
    Re: Adding TCPIP # (Matthew Bafford)
    Re: advanced perl? <cassell@mail.cor.epa.gov>
    Re: Can i use  Apache HTTP Server v1.3.6   to run cgi a (Abigail)
    Re: FAQ 3.16: How can I make my Perl program run faster <cassell@mail.cor.epa.gov>
    Re: FAQ 3.16: How can I make my Perl program run faster <tchrist@mox.perl.com>
    Re: ftp for Windows NT? <jcsbalas@undergrad.math.uwaterloo.ca>
    Re: How to execute script on server startup <arnee@geocities.com>
    Re: invoking by "fire and forget" <cassell@mail.cor.epa.gov>
    Re: invoking by "fire and forget" <e_broyles@yahoo.com>
    Re: invoking by "fire and forget" <tchrist@mox.perl.com>
    Re: matching more than one line ()
    Re: Need example (Mark P.)
    Re: Newbie Question -> Searching a Text File (Tim Herzog)
        Parody script from Camel 1? <aduncan@cs.ucsb.edu>
    Re: Parody script from Camel 1? <tchrist@mox.perl.com>
    Re: Passing variables between scripts? How? <cassell@mail.cor.epa.gov>
    Re: PERL Subroutines in a separate file? <upsetter@ziplink.net>
    Re: Q: Hash tables!!! (Paul M. Hoffman)
    Re: Splitting length instead of delimiting character? <cassell@mail.cor.epa.gov>
        Top 10 newbie errors? <jbc@shell2.la.best.com>
    Re: Top 10 newbie errors? <jeromeo@atrieva.com>
    Re: Top 10 newbie errors? (Clinton Pierce)
    Re: Top 10 newbie errors? (Abigail)
    Re: Top 10 newbie errors? (Larry Rosler)
    Re: umask <cassell@mail.cor.epa.gov>
    Re: Using a Regexp <cassell@mail.cor.epa.gov>
    Re: VB and Perl <cassell@mail.cor.epa.gov>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Mon, 19 Apr 1999 11:41:44 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: (Me Dummy) Have .pl forum script and want to add an extra (blank) line inbetween..
Message-Id: <371B78E8.C82CE4A3@mail.cor.epa.gov>

Mark Austin wrote:
> 
> the various threads / groups of messages to make it more readable.  Any
> ideas as to the neccessary code I need to insert and where?
> 
> I'm using wwwboard.pl a freeware package which I downloaded from;
> http://www.worldwidemart.com if you are aware of it.

Don't expect anyone here to be that familiar with arbitrary programs
written somewhere on this planet in this century.  That's asking a
lot of any Perl expert, even if he/she is using the PSI::ESP
module.  :-)

If you just want to add a line that has only a newline, try:
   print "\n";

If you're doing this for HTML, that's different.  But I can't tell
from here.

David
-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: 19 Apr 1999 17:46:28 GMT
From: chris+usenet@netmonger.net
Subject: Re: Adding TCPIP #
Message-Id: <7ffq5l$foh$1@schenectady.netmonger.net>


In article <m1d810lie9.fsf@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> >>>>> "Matthew" == Matthew Bafford <dragons@dragons.duesouth.net> writes:
> Matthew> ) Wed Mar 31 18:10:17 1999
> Matthew> )  Acct-Session-Id = "0F00007B"
> Matthew> )  User-Name = "user"
[...]
> 
> This is wayyyy too much work.  How about instead:
> 
> $/ = "";
> while (<>) {
>   s/(.*)\n// or die;
>   my $date = $1;
>   my %fields = /^\s*(\S+) = (".*"|\S+)/gm; # parse lines
>   for (@fields{keys %fields}) { s/"(.*)"/$1/; } # pop quotes
>   # ...
> }

Or even:

use Logfile::Radius;
$l = new Logfile::Radius(File => "radius.log");


Or.. some guy wrote some modules to do the RADIUS server itself in Perl,
and it could log directly to.. oh, I don't know.. a MySQL database or
something.
-- 
	    Christopher Masto <chris+usenet@netmonger.net>
         Senior Network Monkey, NetMonger Communications, Inc.

		     "Behold the Power of Cheese"


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

Date: Mon, 19 Apr 1999 18:05:51 GMT
From: dragons@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Adding TCPIP #
Message-Id: <slrn7hmqef.t2k.dragons@dragons.duesouth.net>

[CC'd]

On 19 Apr 1999 08:49:50 -0700, Randal L. Schwartz <merlyn@stonehenge.com>
lucked upon a computer, and thus typed in the following:
) Matthew> $/="";
) Matthew> while (<>) {
) Matthew>     chomp;
) Matthew>     my ($date, $rest) = split /\n/, $_, 2;
) Matthew>     my(%fields) =
) Matthew>         map { s{^"}{};   s{"$}{};   $_ }
) Matthew>         map { s{^\s+}{}; s{\s+$}{}; $_ }
) Matthew>         map { split /=/                }
) Matthew>         split /\n/, $rest;              
) 
) Matthew>     # ...
) Matthew> }
) 
) This is wayyyy too much work.  How about instead:
) 
) $/ = "";
) while (<>) {
)   s/(.*)\n// or die;
)   my $date = $1;
)   my %fields = /^\s*(\S+) = (".*"|\S+)/gm; # parse lines
)   for (@fields{keys %fields}) { s/"(.*)"/$1/; } # pop quotes
)   # ...
) }

Darn.  A whole lot faster, but it just doesn't look as nice. :(
 
) print "Just another Perl hacker (and columnist),"

Thanks Randal,

--Matthew


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

Date: Mon, 19 Apr 1999 11:07:53 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: advanced perl?
Message-Id: <371B70F9.BDD85587@mail.cor.epa.gov>

Dunn One wrote:
> 
> Does anybody have any suggestions for learning advanced perl? If so, please
> helpth

Perhaps you could clarify what you mean as 'advanced' first.  Do you
consider regexes advanced?  Objects and methods?  Embedding?  GUIs?

There are a host of good Perl books at the O'Reilly website.  You might
want to go there and look through the descriptions, and decide which
book best meets your needs.

HTH,
David
-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: 19 Apr 1999 18:07:27 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Can i use  Apache HTTP Server v1.3.6   to run cgi and ASP in Win 95 ??
Message-Id: <7ffrcv$9uq$1@client2.news.psi.net>

Kevin !;!;!;!;!;!;!;!;!;!;!;!;!;!;!;!;!;!;!;!;!;
(austin95002887@yahoo.com) wrote on MMLVII September MCMXCIII in <URL:news:1103_924534968@austin>:
!! 
!! 
!! Can i use  Apache HTTP Server v1.3.6   to run cgi and ASP in 
!! Win 95 ??


Maybe, maybe not. But this isn't the appropriate group to ask.
Try bionet.biology.symbiosis, that's a slightly more appropriate group.



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: Mon, 19 Apr 1999 10:39:46 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: FAQ 3.16: How can I make my Perl program run faster?
Message-Id: <371B6A62.63EA385D@mail.cor.epa.gov>

Tom Christiansen wrote:
> 
>  [well-written text snipped to save bandwidth]

Would you consider an addition like this:

If you are attempting to speed up your Perl programs on a web server,
you may want to look into mod_perl for the Apache webserver, or
PerlEx for Microsoft IIS.

Since so many web-wannabe's ask this sort of question...

David
-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: 19 Apr 1999 11:49:27 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: FAQ 3.16: How can I make my Perl program run faster?
Message-Id: <371b6ca7@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    David Cassell <cassell@mail.cor.epa.gov> writes:
:Would you consider an addition like this:
:
:If you are attempting to speed up your Perl programs on a web server,
:you may want to look into mod_perl for the Apache webserver, or
:PerlEx for Microsoft IIS.

Well, yes, but doesn't the other question answer that?

--tom
-- 
    "Sometimes I wish I could put an expiration date on my quotes." --Larry Wall


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

Date: Mon, 19 Apr 1999 13:53:07 -0400
From: Joe Bala <jcsbalas@undergrad.math.uwaterloo.ca>
Subject: Re: ftp for Windows NT?
Message-Id: <371B6D83.DD2858F4@undergrad.math.uwaterloo.ca>

try:

http://www.terminalp.com/scripts/

It works for me on Win NT.

Joe

ToddNKay wrote:

> Hello all,
> Has anyone written a perl script for Windows NT that transfers a file from a
> user's machine to the web server executing the script?
>
> Any suggestions or samples that could point me in the right direction?  I've
> written a similar script for UNIX, but even something as simple as opening
> the user's file for reading doesn't work on our NT server.
>
> Thanks in advance,
> -Todd



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

Date: Mon, 19 Apr 1999 10:16:58 -0700
From: arnee <arnee@geocities.com>
Subject: Re: How to execute script on server startup
Message-Id: <371B6509.544EC3F3@geocities.com>



kellykross@my-dejanews.com wrote:

> I have a site that runs on a Apache/1.3.1 Cobalt (Unix) server. I would like
> to know if it is possible to have a CGI script execute on startup and remain
> present. I share space on this server. The site Admin isnt the helpful type
> if possible I would like to enable this myself. Ive tried to execute the
> program from browser and telnet command line but it appears to terminate when
> exiting or logging off. P.S The script is designed to continuously monitor
> files in a directory.
>
> Thanks in advance for any help.
> Kelly Kross
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own

the answer that you are looking for is cron or background processes. so, you
might wanna do a search on those and learn it. plus, you have to ask your sys
admin if you are allowed to use cron. and she is right, what was the perl
question again? oh, might have to do with the CGI, hmmm.

hint: background processes has to do with your shell.



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

Date: Mon, 19 Apr 1999 10:19:24 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: invoking by "fire and forget"
Message-Id: <371B659C.6368516E@mail.cor.epa.gov>

e_broyles wrote:
> 
> Yes, I see that I phrased that incorrectly.  I want to split off another
> process that will continue even if the parent process fails.  I am pretty sure
> that fork() is not available in the NT version.

Well, not in the ActiveState version.  If you want to install Cygwin32
on
your NT box, you'll get a suite of Unix-ish tools, and the ability to
fork().  But you'll have to build Perl yourself.  There's a well-written
article covering this in the latest issue of The Perl Journal
(www.tpj.com).

And don't worry about the unix fanatics like TomC.  NT?  Nothing that
five years and 50 million dollars of work couldn't fix.  :-)

David, who is at this moment sitting in an office with a Slowlaris box 
and two different M$ OSes...
-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: Mon, 19 Apr 1999 17:49:46 GMT
From: e_broyles <e_broyles@yahoo.com>
Subject: Re: invoking by "fire and forget"
Message-Id: <7ffqbm$md1$1@nnrp1.dejanews.com>

Does this mean that there is no way to get a child process that continues to
run even if the parent process dies or stops intentionally?


In article <371b2586@cs.colorado.edu>,
  tchrist@mox.perl.com (Tom Christiansen) wrote:
>  [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc,
>     e_broyles <e_broyles@yahoo.com> writes:
> :I am pretty sure
> :that fork() is not available in the NT version.
>
> So what?  Neither is most anything of interest.  You get a toy "operating
> system", then you must content yourself to writing toy programs.
> In other words, it's your mess, now you live in it.
>
> I will never forgive the idiots for omitting fork.
>
> --tom
> --
> As Mike O'Dell once said, only half jokingly, "the most brilliant
> decision in all of UNIX was the choice of a *single* character for
> the newline sequence"...
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 19 Apr 1999 12:15:03 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: invoking by "fire and forget"
Message-Id: <371b72a7@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, e_broyles <e_broyles@yahoo.com> writes:
:Does this mean that there is no way to get a child process that continues to
:run even if the parent process dies or stops intentionally?

Of course not.  In fact, it's not even relevant under most setups.
See the collected works on one Mr W. Richard Stevens for details. :-)

--tom
-- 
San Francisco, n.:
        Marcel Proust editing an issue of Penthouse.


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

Date: 19 Apr 1999 17:28:38 GMT
From: hdiwan@diwanh.stu.rpi.edu ()
Subject: Re: matching more than one line
Message-Id: <slrn7hmpv9.i3a.hdiwan@diwanh.stu.rpi.edu>

This is by no means an exhaustive analysis.
>#!/usr/local/bin/perl -w
use strict;
use diagnostics; 
> ($file) = @ARGV;
You may want to write this as:
my $file = $ARGV[0]; # Avoid confusion
> open(HANDLE, $file)
or die "$!"; # tells you if open was successful
> while (<HANDLE>) {
> print  if /((99)\n|(Event)|dependency)/msix; #99 for date stamp,  Event
>is 					    #first line of text and 					    #dependency is for 3rd line
> }


-- 
Hasan Diwan


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

Date: Mon, 19 Apr 1999 17:46:50 GMT
From: mag@imchat.com (Mark P.)
Subject: Re: Need example
Message-Id: <371b6b33.368803651@news.ionet.net>

	Well that wasn't a good way to enter the news group. <G> The
answer to your question can be found at
http://stein.cshl.org/WWW/software/CGI/cgi_docs.html , which is the
home of CGI.pm.
	BTW, your question really could apply to any number of
programming languages, but to most of us novices perl is always what
comes to mind.

On Sun, 18 Apr 1999 20:20:11 GMT, Jim <jim@newglobal.net> wrote:

>Hi,
>
>I've been searching for an example of how to pass  the contents of one
>form to another.
>What I want to achieve is a form that when a user chooses option(1) then
>the user will be served another script, and another form. Same for
>option(2), etc....
>
>If there's a howto someone could direct me  to I'd be very grateful,
>
>thanks in advance,
>
>Jim
>



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

Date: Mon, 19 Apr 1999 12:25:29 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: Newbie Question -> Searching a Text File
Message-Id: <therzog-1904991225290001@therzog-host105.dsl.visi.com>

In article <j5HS2.44$QO.1214@nswpull.telstra.net>, "Paul Gregor"
<peej_79@yahoo.com> wrote:

>Hello all,
>
>To start off with I am sorry if this post is too the wrong NG.

It is (the wrong NG).

>I have a win95 LAN at home with TinyWeb HTTP server running on the main PC.
>I have ActivePerl 5.14 installed on the main PC. I have a Perl Script that I
>got from http://www.technotrade.com/cgi/search.html
>
>The perl script and the text file that it searches resides in the cgi-bin
>dir.
>
>When I perform a search on the other PC I receive a "Document Contains No
>Data" error.
>
>Is there a problem with the pearl script?
>Or is it my setup thats the problem?

Your setup.  That browser message comes up if the browser receives this
reply from the server:

Content-type:  text/html

In other words, an empty HTML document.  For some reason, probably a
config problem, your script isn't returning any content, thus the message.

-- 
Tim Herzog


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

Date: Mon, 19 Apr 1999 10:57:58 -0700
From: aduncan <aduncan@cs.ucsb.edu>
Subject: Parody script from Camel 1?
Message-Id: <371B6EA6.7A356EBF@cs.ucsb.edu>

Alas! I've recycled (reasonable) my 1st edition Camel book, and lost
(unforgiveable) the script it contained to make parodies of text by
measuring word combination frequencies. Searched the Web and DejaNews
with no success. Can somebody post it? Thanks.

Andrew Duncan
aduncan@cs.ucsb.edu
http://www.cs.ucsb.edu/~aduncan


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

Date: 19 Apr 1999 12:19:51 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Parody script from Camel 1?
Message-Id: <371b73c7@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    aduncan@cs.ucsb.edu writes:
:Alas! I've recycled (reasonable) my 1st edition Camel book, and lost
:(unforgiveable) the script it contained to make parodies of text by
:measuring word combination frequencies. Searched the Web and DejaNews
:with no success. Can somebody post it? Thanks.


You want /usr/src/perl5.005_56/eg/travesty for that.  But see also the
new K&P markov chainer:

# markov.pl: markov chain algorithm for 2-word prefixes
# [Excerpted for purposes of review from p79-80 of _The Practice of
# Programming_, 1999, by Brian Kernighan and Rob Pike.]
# 

srand(1);

$MAXGEN = 10000;
$NONWORD = "\n";
$w1 = $w2 = $NONWORD;		# initial state
while (<>) {			# read each line of input
    foreach (split) {
	push(@{$statetab{$w1}{$w2}}, $_);
	($w1, $w2) = ($w1, $_);	# multiple assignment
    } 
}
push(@{$statetab{$w1}{$w2}}, $NONWORD);	    # add tail

$w1 = $w2 = $NONWORD;
for ($i = 0; $i < $MAXGEN; $i++) {
    $suf = $statetab{$w1}{$w2};	# array reference
    $r = int(rand @$suf);	# @$suf is number of elems
    exit if (($t = $suf->[$r]) eq $NONWORD);
    print "$t\n";
    ($w1, $w2) = ($w1, $t);	# advance chain
} 

-- 
It's all magic.  :-)    --Larry Wall in <7282@jpl-devvax.JPL.NASA.GOV>


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

Date: Mon, 19 Apr 1999 10:54:52 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Passing variables between scripts? How?
Message-Id: <371B6DEC.A947D40B@mail.cor.epa.gov>

cgi@higherlove.com wrote:
> 
> I have some scripts set-up allowing people to search a database and
> then contact others if they need to whom they find through the
> database. What I was wondering...is there anyway that I can keep a
> user's login name variable constant with them in the system, so they
> don't have to keep entering their basic "name, email, etc."
> information everytime they contact another database user? How can I
> send a session/user idenitifier with them through all their system
> usage?

Lisa, this is really a CGI problem not a Perl problem.  You would have
better luck asking this in a newsgroup such as 
comp.infosystems.www.authoring.cgi .

That said, look into the CGI.pm module, which can help you with this.

HTH,
David
-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: Mon, 19 Apr 1999 17:44:06 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: PERL Subroutines in a separate file?
Message-Id: <GXJS2.239$U15.33265@news.shore.net>

Tom Christiansen <tchrist@mox.perl.com> wrote:
: :I am relatively new to perl, but am trying to write a suite of
: :scripts for some web work we are doing.   I have several
: :subroutines that are common to each of the scripts.  

:     require 'library.pl';

[snip]

: First, learn the differences between do, require, and use.
: Then learn the difference between programs, libraries, and modules.
: Now, get a simple library working.  
: Finally, write a module.

Or, if you just want to get some work done and go have some fun outside
(assuming it's spring where you are), just use a library.

Put your subroutines in a library file (traditionally with a ".pl" 
suffix). Somewhere in your calling script (before you need to use a
subroutine, usually at the beginning of the script), you put the line
"require 'library.pl'" (as shown above). The only trick is that your
library file has to return a "true" value for the "require" statement to
succeed, so people usually put a "1" on the last line of their library
files. 

Then, later, when you're more of a perl jockey, you can work on the
differences between modules and libraries, and between do, require and
use, but it's hardly necessary just to create a library of common
subroutines.

--Art
-- 
--------------------------------------------------------------------------
                    National Ska & Reggae Calendar
                  http://www.agitators.com/calendar/
--------------------------------------------------------------------------


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

Date: Mon, 19 Apr 1999 14:22:16 -0400
From: nkuitse@umich.edu (Paul M. Hoffman)
Subject: Re: Q: Hash tables!!!
Message-Id: <nkuitse-1904991422160001@host-78.subnet-36.med.umich.edu>

Jim Kangosjdrvi <Jim.Kangosjarvi@Abc.se> wrote:

>When i create a hash table and then add 1000's of variables to
>it then it grows few MB (ex. 5 MB).  And when i Delete all the
>Variables, the size of the hash table is still several 5 MB.

Right.  This follows from the principle that, when in doubt, Perl
sacrifices memory for speed.  Perl doesn't know whether or not you'll add
elements to the hash, and shrinking the hash's memory footprint might slow
things down later.  So you have to tell Perl explicitly.  If you have an
empty hash %h, this may free up much of its memory:

  require 5.004;  # This trick requires Perl 5.004 or higher
  keys(%h) = 0;

In fact, you can specify any number N to obtain a hash with N buckets,
which may save time if you know the hash will be very large.  Non-powers
of 2 will be raised to the nearest power of 2; e.g., keys(%h) = 100 has
the same effect as keys(%h) = 128.

(A bucket holds zero or more entries.  When preallocating large hashes,
you might want to use a size smaller than the number of entries would seem
to indicate.  For example, for an empty hash %h that will end up with
about 5000 elements, try keys(%h) = 4096 rather than 8192.  This might
help, or then again it might not.)

Adapted loosely from the Perl Cookbook, p.149-150.

Followups to comp.lang.perl.misc.

Paul.

-- 
Paul Hoffman :: Taubman Medical Library :: Univ. of Michigan
nkuitse@umich.edu :: http://www-personal.umich.edu/~nkuitse/


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

Date: Mon, 19 Apr 1999 11:03:15 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Splitting length instead of delimiting character?
Message-Id: <371B6FE3.2DBF6BF9@mail.cor.epa.gov>

Ronny wrote:
> 
> [big snip]
>
> There is no builtin function that does what you want (at least none that I
> know), but it is easy to write one yourself.

As previous posters to this thread said, unpack().  It's ideal for this
sort of task.
 
> Three easy approaches come to my mind:
> 
> (1) You could do a
>         split /\s+/
> and then use sprintf to format the items, or

Doesn't work, for reasons pointed out by the poster.. and doesn't work 
when a field is filled with digits, so there's no whitespace on either 
side of that field.
 
> (2) you could define an array of the field lengths desired, and then use
> repeated substr calls to extract the fields, or

unpack() will do all this in one op, and save you the trouble of
doing all the calcs to get the field lengths right.
 
> (3) you could use a regexp such as
>         /(.{7})(.{4})(.{4}).../
> and extract the fields as $1, $2, $3 etc.

You might want to anchor that regex to the beginning of the line.
A regex solution is usually a lot slower.  But not to worry.
Larry R will Benchmark it and show you a better way.  :-)

David
-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: 19 Apr 1999 16:59:23 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Top 10 newbie errors?
Message-Id: <371b60eb$0$219@nntp1.ba.best.com>

I'm putting together a list of the top 10 ways that people new to both
Perl and programming screw things up. (Screw things up in their
scripts, I mean. Thus, "Posting CGI questions to c.l.p.m." or "Asking
for advice without posting the suspect code" would not qualify.)

Here, in rough order of decreasing frequency (by which I really mean,
in the rough order in which they occurred to me), is what I think I've
done most often myself. I'm curious whether other folks' lists are
similar.

1. Block-delimiting curly brackets (braces) not matching up properly.
2. Failing to supply the closing quotation character on a quoted
string.
3. Parentheses in a compound conditional test (e.g., if '(((this) and
(that)) or (that))' ) not matching up properly.
4. Variable-name "creep" (i.e., using $walnuts in one place and $walnut
in another, while intending for them to refer to the same variable).
5. Using '$' instead of '%' in front of the hash variable's name in an
argument to the 'keys' function.
6. Confusing assignment with numeric equality in a logical test ('='
vs. '==').
7. Confusing string and numeric equality in a logical test ('==' vs.
'eq').
8. Transferring a script from Windows to Unix in binary-mode FTP,
resulting in a corrupt shebang line (among others).
9. Omitting a statement-ending semicolon.
10. Improperly terminating a here-document quotation (e.g., by having a
bogus space after the terminating string).

It's interesting to me how my favorite goofs has evolved in the 4 years
or so I've been learning Perl. For example, I rarely screw up the
string-vs.-numeric equality thing these days, but I still can count on
one or two curly-bracket goofs in any decent-sized script (yes, I know
I should be using a real editor that checks that for me).

-- 
John Callender
jbc@west.net
http://www.west.net/~jbc/


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

Date: Mon, 19 Apr 1999 10:40:22 -0700
From: Jerome O'Neil <jeromeo@atrieva.com>
To: John Callender <jbc@shell2.la.best.com>
Subject: Re: Top 10 newbie errors?
Message-Id: <371B6A86.38D87A75@atrieva.com>

John Callender wrote:
> 
> I'm putting together a list of the top 10 ways that people new to both
> Perl and programming screw things up. (Screw things up in their
> scripts, I mean. Thus, "Posting CGI questions to c.l.p.m." or "Asking
> for advice without posting the suspect code" would not qualify.)

1. Not using warnings and strict( #/bin/perl -w and use strict;).

[Snip many common goofs that would be caught with warnings and strict]

Good Luck!

-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


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

Date: Mon, 19 Apr 1999 17:21:22 GMT
From: cpierce1@ford.com (Clinton Pierce)
Subject: Re: Top 10 newbie errors?
Message-Id: <371b6573.1652792560@news.ford.com>

On 19 Apr 1999 16:59:23 GMT, John Callender <jbc@shell2.la.best.com>
wrote:

>I'm putting together a list of the top 10 ways that people new to both
>Perl and programming screw things up. (Screw things up in their

0. Not using "-w" as an option when running perl.
1. Not glancing at the FAQ's once-in-a-while, even when they don't have a
problem, to see what's there.  (So when they do have a problem, they're
not panic-stricken.)


-- 
Clinton A. Pierce       "If you rush a Miracle Man, you get rotten
clintp@geeksalad.org        Miracles."  -- Miracle Max, The Princess Bride
http://www.geeksalad.org


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

Date: 19 Apr 1999 18:49:56 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Top 10 newbie errors?
Message-Id: <7fftsk$af4$1@client2.news.psi.net>

John Callender (jbc@shell2.la.best.com) wrote on MMLVII September
MCMXCIII in <URL:news:371b60eb$0$219@nntp1.ba.best.com>:
&& I'm putting together a list of the top 10 ways that people new to both
&& Perl and programming screw things up. (Screw things up in their
&& scripts, I mean. Thus, "Posting CGI questions to c.l.p.m." or "Asking
&& for advice without posting the suspect code" would not qualify.)


1)  Failing to use 'use strict;'.
2)  Failing to use '-w'.
3)  Failing to check the return value of system calls.




Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Mon, 19 Apr 1999 11:58:25 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Top 10 newbie errors?
Message-Id: <MPG.11851cae5af3e35f9898dd@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <371b60eb$0$219@nntp1.ba.best.com> on 19 Apr 1999 16:59:23 
GMT, John Callender <jbc@shell2.la.best.com> says...
> I'm putting together a list of the top 10 ways that people new to both
> Perl and programming screw things up. (Screw things up in their
> scripts, I mean. Thus, "Posting CGI questions to c.l.p.m." or "Asking
> for advice without posting the suspect code" would not qualify.)

> Here, in rough order of decreasing frequency (by which I really mean,
> in the rough order in which they occurred to me), is what I think I've
> done most often myself. I'm curious whether other folks' lists are
> similar.

I think your list is muddled between 'inexcusable' errors (failure to 
compile, and misused variables, and others which can be caught 
trivially) and 'understandable' errors (wrong semantics, for example) 
which may be difficult to identify immediately without testing and 
debugging.

So before going into detail, lets start with this:

  1.  Failure to use the '-w' flag.
  2.  Failure to use the 'use strict;' pragma.

Now let's see how your top ten fare against that.

> 1. Block-delimiting curly brackets (braces) not matching up properly.

Trivial syntax error.  By requiring curlies, Perl obviates the more 
subtle semantic C bugs involving mismatched if/else's.  One BIG cheer 
for The Larry.

> 2. Failing to supply the closing quotation character on a quoted
> string.

Trivial syntax error.

> 3. Parentheses in a compound conditional test (e.g., if '(((this) and
> (that)) or (that))' ) not matching up properly.

Because your snippet parses correctly, this is indeed a semantic error.

> 4. Variable-name "creep" (i.e., using $walnuts in one place and $walnut
> in another, while intending for them to refer to the same variable).

'-w' and 'use strict;' obviate these kinds of errors.

> 5. Using '$' instead of '%' in front of the hash variable's name in an
> argument to the 'keys' function.

Trivial syntax error.

> 6. Confusing assignment with numeric equality in a logical test ('='
> vs. '==').

'-w' catches this if either operand is a constant.

> 7. Confusing string and numeric equality in a logical test ('==' vs.
> 'eq').

'-w' catches this for '==' if either operand isn't numeric.

> 8. Transferring a script from Windows to Unix in binary-mode FTP,
> resulting in a corrupt shebang line (among others).

This is not a Perl error at all.

> 9. Omitting a statement-ending semicolon.

Trivial syntax error.  (BTW, ITYM statement-separating semicolon.)

> 10. Improperly terminating a here-document quotation (e.g., by having a
> bogus space after the terminating string).

Trivial syntax error.

> It's interesting to me how my favorite goofs has evolved in the 4 years
> or so I've been learning Perl. For example, I rarely screw up the
> string-vs.-numeric equality thing these days, but I still can count on
> one or two curly-bracket goofs in any decent-sized script (yes, I know
> I should be using a real editor that checks that for me).

Such a tool would certainly help, if you are prone to doing this.  
Another approach is to write the braces first, then go back and put in 
the content between them.

A while ago, I began to compile a list of 'most frequent errors posted 
on c.l.p.misc'.  I'll try to find it again.

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


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

Date: Mon, 19 Apr 1999 10:51:48 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: umask
Message-Id: <371B6D34.5A354B9A@mail.cor.epa.gov>

Ronny wrote:
> 
> (This message mailed and posted)
> 
> In article <7fb3up$sie$1@newnews.global.net.uk>,
>   "Martin" <martin@guest-books.com> wrote:
> 
> > Will umask(00) at the top of my script cause new files made to have
> > default properties of 0777?
> 
> No, it would set them to 0666. There is no way to automatically set the x-bit
> under Unix.
> 
> You said you are running the program under NT. I do not know to what extend NT
> honours umask at all.

Perhaps the ActivePerl FAQ [section 'Quirks'] would be of help.  It
explains what NT does [and does not do] with chmod().  

Martin may want to look into the Win32::FileSecurity module.  It comes 
with current version of ActiveState Perl.

HTH,
David
-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: Mon, 19 Apr 1999 11:11:56 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Using a Regexp
Message-Id: <371B71EC.B8629306@mail.cor.epa.gov>

Wyzelli wrote:
> [big snip of entire post]

Umm, pardon me, but isn't this the identical post you submitted 
yesterday?

And didn't you get some excellent answers to that thread?

I don't understand why you're re-submitting this.  Is there a problem
with your news server?

David
-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: Mon, 19 Apr 1999 10:31:57 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: VB and Perl
Message-Id: <371B688D.EC96CB83@mail.cor.epa.gov>

Brad Hilton wrote:
> 
> How can I integrate Perl into VB?  Is it possible to program entirely in
> Perl but use VB for screens?  Where can I go for information on this?

Sextuplets!  Congratulations!  (No thanks on that cigar, I don't smoke.)
Umm, are you using Nyetscape as your newsreader?  Because you may not
be aware that you submitted this post K times, where K >> 1.  [That's
math notation, not the Perl >> operator.]

Now that ActiveState Perl comes with Win32::OLE, you should consider
whether you need any VB at all.  VBA may have more examples for use 
inside MS Office programs, but Perl will do all that stuff too.
COM?  Perl does it too.  OLE Automation?  Yup.

Drastically changing the language with every revision?  No, Perl
will protect you from that.  :-)

David
-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 5420
**************************************

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