[11045] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4645 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 13 19:07:13 1999

Date: Wed, 13 Jan 99 16:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 13 Jan 1999     Volume: 8 Number: 4645

Today's topics:
        @ARGV and $_ Question <roclimb@yahoo.com>
    Re: A really easy string question (Randal L. Schwartz)
    Re: A really easy string question (Randal L. Schwartz)
        bug? reference to array - first element empty? bug? otis@my-dejanews.com
    Re: Changing date display <uri@ibnets.com>
    Re: Changing date display (Tim Crowe)
    Re: coredump & other weirdness with eval(require) (Steve Leibel)
    Re: Data Structure Notation <dgris@moiraine.dimensional.com>
        Downloading a file w/an HTTP address <ptraub@dartmouth.edu>
    Re: Downloading a file w/an HTTP address (brian d foy)
        File searching (Cybernetic Bear)
    Re: How can I compare two arrays? <dgris@moiraine.dimensional.com>
    Re: How can I compare two arrays? (Ilya Zakharevich)
        IE4 problems jhall@idiglobal.com
    Re: Invoking an unattended infinite loop dgbialac@wwitch.unl.edu
        Memory leak when embedding perl <mortis@voicenet.com>
        Need Help with HTTP POST using LWP module <arifk@hotmail.com>
    Re: need help with net::telnet... <dgris@moiraine.dimensional.com>
    Re: Newbie "use strict" question <uri@ibnets.com>
    Re: Perl Criticism <aqumsieh@matrox.com>
    Re: Perl Criticism <staffan@ngb.se>
    Re: Problem with frames <michael_mongeau@stratus.com>
    Re: Problem with frames (Martien Verbruggen)
    Re: question about File::Find <aqumsieh@matrox.com>
    Re: Read file problem <aqumsieh@matrox.com>
        Removing Blank lines <dbohl@sgi.com>
        require, use and "scope" sundar_raman@nopoop.3com.com
    Re: Setting Variables Question <michael_mongeau@stratus.com>
        Simple question:  packages <ringwood@berbee.com>
        split question <b-camp@students.uiuc.edu>
    Re: split question <wcj@iti-oh.com>
    Re: split question <cybertoast@nopoop.mindless.com>
    Re: where can I get perlfunc.pod (I R A Aggie)
    Re: Year 2038 problem (Michal Jaegermann)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Wed, 13 Jan 1999 18:01:09 -0500
From: "Brad" <roclimb@yahoo.com>
Subject: @ARGV and $_ Question
Message-Id: <77j8bf$kgg$1@news.monad.net>

Could someone give me a good definition of these two items and a couple good
examples? Or point me in the direction where I can find good definition and
examples.

I do know that @ARGV is a Global Variable (array) in Perl which stores
command line parameters, but what does that mean?

But that $_ is just a mystery to me.

Thanks for your helps

Brad




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

Date: 13 Jan 1999 14:03:06 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: A really easy string question
Message-Id: <m1ww2q4yqt.fsf@halfdome.holdit.com>

>>>>> "AJ" == AJ  <ajonsson@csi.com> writes:

AJ> @filename = grep(/[.txt]/,@variable);

Grepping for any of . t x (or t again :) in those?

Did you really want a character class?  I suspect not.

print "Just another Perl hacker,"

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 13 Jan 1999 14:05:01 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: A really easy string question
Message-Id: <m1sode4ynm.fsf@halfdome.holdit.com>

>>>>> "kjer" == kjer  <kjer@my-dejanews.com> writes:

kjer> This is a good solution that split a string into path and filename:

kjer> $_=$pathname;
kjer> m/^(.*)([^\/]*)$/;
kjer> print "path is: '$1', filename is '$2'\n";

You're missing the /s on the end to let . match newline.  It's not a general
solution without that.  File::Basename does it more accurately.

use File::Basename;print basename"Just another Perl hacker,"

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Wed, 13 Jan 1999 23:02:13 GMT
From: otis@my-dejanews.com
Subject: bug? reference to array - first element empty? bug?
Message-Id: <77j8lg$jpm$1@nnrp1.dejanews.com>

Hello,

I'm not sure if this is normal perl behaviour or not. I can't find it in docs.

What I noticed is that if I return a reference to an array from a subroutine,
and then go through the array after the call to that subroutine, the very
first element of the array reference that was returned is always empty. Is
this normal?

Example:
my @array = undef;
sub foo
{
  foreach (0 .. 9) { push (@array, $_); } return \@array; }
}

$refArray = &foo;

foreach $bar (@$refArray)
{
  print "BAR: $bar\n";
}

The first $bar will be empty ("").

This is perl, version 5.005_02 built for i686-linux-thread

Thanks,

Otis

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


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

Date: 13 Jan 1999 16:51:42 -0500
From: Uri Guttman <uri@ibnets.com>
Subject: Re: Changing date display
Message-Id: <39btk24z9t.fsf@ibnets.com>

>>>>> "TC" == Tim Crowe <nospam.kane00tc@angis.usyd.edu.au> writes:

  TC> I hope someone may help with this small problem.

  TC> I'm using a script written by someone else which I modified to run a
  TC> message board on my site. It works perfectly except that when a new
  TC> message is displayed it shows the date it was posted on the topic line
  TC> (which I want it to do) EXCEPT that the server I host it on is in the
  TC> USA and I run the site from Australia so there is a time delay of some
  TC> 15-20 hours. Can I modify the following statement in the script so I
  TC> can automatically add on a certain amount of hours to the time
  TC> reported by the server.

  TC> open(TEMPFILE,"|date +\"%a %d %b %Y\" >> $tempfile");

why are you doing this the hard way? call time and add/subtract the number of
delta seconds, call gmtime or localtme to get the time parts and then print it
yourself or use strftime (POSIX) to format it. you never need to run a
sub process.

also why are you opening a pipe into date? it doesn't take an input from
STDIN AFAIK. and don't backwhack " in " strings, use a different quote
char. and why are you appending to the tempfile in the shell command?
none of that code makes sense on any level.

  TC> Please remove "nospam" from my e-mail address to reply

no thanx. you post here, you read here.

hth,

uri

-- 
Uri Guttman                             Hacking Perl for Ironbridge Networks
uri@sysarch.com				uri@ironbridgenetworks.com	


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

Date: Wed, 13 Jan 1999 23:27:14 GMT
From: nospam.kane00tc@angis.usyd.edu.au (Tim Crowe)
Subject: Re: Changing date display
Message-Id: <369d2a43.555230@news.usyd.edu.au>

On 13 Jan 1999 16:51:42 -0500, Uri Guttman <uri@ibnets.com> wrote:

>>>>>> "TC" == Tim Crowe <nospam.kane00tc@angis.usyd.edu.au> writes:
>
>  TC> I hope someone may help with this small problem.
>
>  TC> I'm using a script written by someone else which I modified to run a
>  TC> message board on my site. It works perfectly except that when a new
>  TC> message is displayed it shows the date it was posted on the topic line
>  TC> (which I want it to do) EXCEPT that the server I host it on is in the
>  TC> USA and I run the site from Australia so there is a time delay of some
>  TC> 15-20 hours. Can I modify the following statement in the script so I
>  TC> can automatically add on a certain amount of hours to the time
>  TC> reported by the server.
>
>  TC> open(TEMPFILE,"|date +\"%a %d %b %Y\" >> $tempfile");
>
>why are you doing this the hard way? call time and add/subtract the number of
>delta seconds, call gmtime or localtme to get the time parts and then print it
>yourself or use strftime (POSIX) to format it. you never need to run a
>sub process.
>
>also why are you opening a pipe into date? it doesn't take an input from
>STDIN AFAIK. and don't backwhack " in " strings, use a different quote
>char. and why are you appending to the tempfile in the shell command?
>none of that code makes sense on any level.
>
>  TC> Please remove "nospam" from my e-mail address to reply
>
>no thanx. you post here, you read here.
>
>hth,
>
>uri

Thanks for your reply but I should point out that I didn't write the
script - I only modified it as it was written by a friend as my
programming skills are extremely limited. I guess I was probably after
a simple change to the line to incorporate the date modification. If
it would not be too much trouble to write the command I should insert
to call the local time and then add 15 hours it would be greatly
appreciated.

Thanks.

Tim


Please remove "nospam" from my e-mail address to reply by e-mail.


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

Date: Wed, 13 Jan 1999 14:29:57 -0800
From: stevel@coastside.net (Steve Leibel)
Subject: Re: coredump & other weirdness with eval(require)
Message-Id: <stevel-1301991429570001@dnai-207-181-236-7.dialup.dnai.com>

In article <1dljorf.4kddvvpdbgzkN@bay1-357.quincy.ziplink.net>,
rjk@linguist.dartmouth.edu (Ronald J Kimball) wrote:

> Steve Leibel <stevel@coastside.net> wrote:
> 
> > I am having problems when the file to be required does not return true.
> > For example, if "emptyfile" is an empty file, the following coredumps:
> 
> I don't know why you're getting a coredump when you try to require an
> empty file in an eval (it dumps core for me too), but as a workaround,
> you could check the file size first and skip the eval if it's zero.
> 

Thanks.  Good to know that someone else was able to reproduce this.

I get the same result with any file (empty or not) that does not return
true.  This makes it impossible for me to reliably handle syntax errors in
the require files. 

Steve L
stevel@coastide.net


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

Date: 13 Jan 1999 16:02:04 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Data Structure Notation
Message-Id: <m3n23m4w0j.fsf@moiraine.dimensional.com>

Jerome O'Neil <jeromeo@atrieva.com> writes:

> I have been working with some data structures, mostly lists of hashes
> and hashes of hashes.  While commenting my code, I wanted to add some
> notes to explain what the various data structures represent, and I
> wasn't able to come up with a notation that was very satisfying.

If your data structures have gotten complex enough that you have
to think about notation it's time to move past simple 80 column
ascii to show them.  This is one area where images can and do help
clarify your code immensely.  Include comments pointing to the URL
of the images.

Take a look at perlguts illustrated (http://home.sol.no/~aas/perl/guts/) 
for a good example of how visual depictions of data can be used.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: Wed, 13 Jan 1999 15:15:11 +0000
From: peter traub <ptraub@dartmouth.edu>
Subject: Downloading a file w/an HTTP address
Message-Id: <369CB87C.D03E2769@dartmouth.edu>

Hi all,

I have a script that, when given an HTTP address, returns the full
address of all the links to particular soundfiles, if any, on that page.

I'd like to now be able to download those soundfiles to a local dir. Are

there any scripts/modules/functions out there specifically for this?
I've looked on CPAN and downloaded the necessary modules, but I don't
see anything particulary for this (I'm only a beginning Perl programmer
so I'm not quite sure how to go about making one myself). Many thanks in

advance.

Peter Traub
ptraub@dartmouth.edu



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

Date: Wed, 13 Jan 1999 18:58:25 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Downloading a file w/an HTTP address
Message-Id: <comdog-ya02408000R1301991858250001@news.panix.com>

In article <369CB87C.D03E2769@dartmouth.edu>, ptraub@dartmouth.edu posted:

> I have a script that, when given an HTTP address, returns the full
> address of all the links to particular soundfiles, if any, on that page.
> 
> I'd like to now be able to download those soundfiles to a local dir. Are
> 
> there any scripts/modules/functions out there specifically for this?

use LWP qw(getstore);

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>


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

Date: Wed, 13 Jan 1999 23:45:01 GMT
From: cybear_x[nospam]@geocities.com (Cybernetic Bear)
Subject: File searching
Message-Id: <369d2eb9.377737231@news.webhart.net>

I want to write a script that will search for files in subdirectories
on my web server. I have all the code to do what I need except I do
not know a way to determine the directory names.

My directory tree looks something like this:

root
| - dave
        | - graphics
        | - data
| - chris
| - steve
etc...

the directory names vary from time to time as we add and remove users
from our server. Is there a way to read a list of directory names into
a perl script? If not, how can I search multiple, unknown directories
for information?

Thanks in advance

Dave


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

Date: 13 Jan 1999 15:40:21 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: How can I compare two arrays?
Message-Id: <m3vhia4x0q.fsf@moiraine.dimensional.com>

Uri Guttman <uri@ibnets.com> writes:

> so tell me what basic regex stuff and string munging stuff is broken
> pre-5.005? i have seen bug reports on p5p and nothing is close to the
> simple code i am writing. 

Check out the Changes* files from your 5.005 source distribution.  They
have all the details.

<snip>
> it is not a greater tolerance for bugs but an understanding of how they
> can or don't affect me. if there is a bug in some obscure area which i
> don't go near, then does the bug exist for me? 

Bugs aren't usually hidden off in obscure areas.  Usually bugs are
found right smack dab in the middle of your cozy little neighborhood,
just waiting for the right piece of unusual input to tickle them.
Go back and read the p5p archives, most bugs can be reduced to a
simple testcase that looks frighteningly similar to tens of thousands
of lines of code that I have in production here.

>                                                i am for it getting fixed
> but i am not for getting that version if it has other baggage i don't
> need. when 5.005_03 gets out i will install it at home. i may encourage
> them here to do it. i don't know if i will tell them to install
> 5.005_02.

Nonsense, 5.005_02 is certainly better suited for a production
environment than 5.004_04 is.  At the very least 5.005 is still
being somewhat actively hacked on so you have a chance that any
bugs may be fixed.

Yes, there have been problems with _02, but most of those have been
thread-related.  Threads are an experimental feature, are documented
as an experimental feature, and aren't enabled in the default build.
If you use them, expect problems.  If you don't, don't.

> also 5.004_4 is supposed to have a maintenance track to fix those bugs
> you refer to. where is that? 

No, perl has a maintenance track.  It is now focused on version
5.005_02.  There may still be a release or two of 5.004 if someone
is interested enough to put one together, but I wouldn't count on
it.

>                              5.005 requires recompiling o all XS code so
> installing it can be a pain.

This can be automated, so isn't an issue.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: 13 Jan 1999 22:37:32 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: How can I compare two arrays?
Message-Id: <77j77c$doi$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Uri Guttman 
<uri@ibnets.com>],
who wrote in article <39d84i51bo.fsf@ibnets.com>:
>   IZ> What stuns me most is the tolerance of Unix weenees to bugs in
>   IZ> software.  Somehow it feels that this tolerance is *greater* than one
>   IZ> of the DOSISH worlds (this is probably due to my higher expectations
>   IZ> w.r.t. Unix-related people - the expectations which somehow are not met).
> 
> if i hit a bug and the code didn't heave the way i expect it to, i would
> be pissed and force an upgrade. that hasn't happened here. you seem to
> not grasp the small size of subset of perl i am using on these
> programs. just hashes, arrays, basic regexes, string stuff, etc. 
> 
> it is not a greater tolerance for bugs but an understanding of how they
> can or don't affect me. if there is a bug in some obscure area which i
> don't go near, then does the bug exist for me? 

I cannot believe you.  Whatever subset of Perl you use, you cannot get
less than circa one Perl bug per 200 lines of your code (assuming
5.004), maybe even more.  Just look at p5p bug reports/patches.
5.005_02 is 10-20 times better.

Uri >> BUG_TOLERANTS  # ;-)

Ilya


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

Date: Wed, 13 Jan 1999 23:10:39 GMT
From: jhall@idiglobal.com
Subject: IE4 problems
Message-Id: <77j958$k7m$1@nnrp1.dejanews.com>

I write CGI in Perl and have encountered the wierdest bug.  Whenever I have a
somewhat entailing loop in a program, which has a 'print "Location:
xxx\n\n";' at the end.	If a person is running the script from IE4 it will
jump the the next location before finishing the process!  This does not
happen using netscape and the only work around I have found is to print an
HTML page prompting them to click to proceed.  This is extremely annoying as
to require people to have to click after anything is done.  I don't want to
force the program to wait.  Do I have to fork before the loop subroutine is
run then do a wait? or what?

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


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

Date: Wed, 13 Jan 1999 21:46:46 GMT
From: dgbialac@wwitch.unl.edu
Subject: Re: Invoking an unattended infinite loop
Message-Id: <77j482$fti$1@nnrp1.dejanews.com>

In article <m33e5h1zdi.fsf@joshua.panix.com>,
  Jonathan Feinberg <jdf@pobox.com> wrote:
> Jim Rhodes <jim@nospam.deadlock.com> writes:
>
> > If I run it from the command line or my browser it trundles
> > along merrily until my telnet session or browser times out,
> > then it stops.
>
>    $ man nohup
>
>    $ man (whatever shell you use)
>    read about backgrounding a process
>

You can also do this at the beginning of your main code:

if (fork() != 0)
{
   exit;
}

# Rest of program here

Be aware that doing this detaches the process from the shell, so print any
output to a file, stream, etc.

David Bialac
Ameritrade

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


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

Date: Wed, 13 Jan 1999 18:10:37 -0500
From: "Kyle R. Burton" <mortis@voicenet.com>
Subject: Memory leak when embedding perl
Message-Id: <369D27ED.5966005C@voicenet.com>

I'm working on a project where we've got the following:

HP-UX 10.20
perl 5.004 for PA-RISC
and C++ (HP's compiler)

We're embedding the perl interpreter in our C++
application so we can use it's parsing abilities.
We've got a perl subroutine that we're repeatedly 
calling from the C++ code.

The problem is that memory leaks every time we 
call perl_run() or perl_call_argv().  I'm pretty sure
that it's not in the C++ code, as I've written a program
to stub test the code -- almost identical to the example
on the perlembed manpage, and a perl stub (just calls print)
to make sure it wasn't our perl code.

I've read some stuff about watching out for the symbol table
geting polluted (and subsequently growing the size of the
interpreter), but I don't think that we're experiencing
unbounded symtable growth.

Anyone know anything that might help?

Thanks,
Kyle R. Burton
mortis@voicenet.com


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

Date: Wed, 13 Jan 1999 15:05:06 -0800
From: Arif Khan <arifk@hotmail.com>
Subject: Need Help with HTTP POST using LWP module
Message-Id: <369D26A2.AD07FB74@hotmail.com>

Hi,

I am trying to pass on a HTTP post from a perl script to a java servlet.
I am using the LWP::UserAgent module for this. However, I am unable to
pass the environment variables like REMOTE_USER, REMOTE_ADDR etc to the
servlet. Can you please tell me how to achieve this ?

here'e my code:

#!/usr/local/bin/perl5
use strict;

use LWP::UserAgent;

#Printing my environment variables
my $element;
print "Content-type: text/html\n\n";
print "<B>Env Vars for passon.pl</B><BR>";
foreach $element (keys(%ENV)) {
  print $element."=".$ENV{$element}."<BR>";
}

my $ua = new LWP::UserAgent;
$ua->env_proxy();
my $path_info = $ENV{'PATH_INFO'};
my $forward_url = "http://myserver:8500${path_info}";
$forward_url =~ s/\?.*$//g;
my $meth=$ENV{'REQUEST_METHOD'};
my $req;
if ($meth eq 'GET') {
   $req = new HTTP::Request GET => $forward_url.'?'.$ENV{QUERY_STRING};
} else {
    $req = new HTTP::Request POST => $forward_url;
    $req->content_type($ENV{'CONTENT_TYPE'});
    $req->content(<STDIN>)."\n";
}
my $resp= $ua->request($req);
if ($resp->is_success) {
    my $respcnttype = $resp->content_type;
    print "Content-type: $respcnttype\n\n";
    print $resp->content;
} else {
    print "Content-type: text/html\n\n";
    print $resp->error_as_HTML;
}

Thanks!

Arif


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

Date: 13 Jan 1999 15:48:42 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: need help with net::telnet...
Message-Id: <m3r9sy4wmt.fsf@moiraine.dimensional.com>

rlopes@securitydynamics.com writes:

> But I can't get anything to work correctly.  Anybody have any ideas?

Maybe your veeblefrister has a snagglethorpe.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: 13 Jan 1999 15:52:35 -0500
From: Uri Guttman <uri@ibnets.com>
Subject: Re: Newbie "use strict" question
Message-Id: <39g19e520c.fsf@ibnets.com>

>>>>> "n" == nospam  <nospam@here.com> writes:

  n> With Perl for Win32 form www.activestate.com build 508 it recommends
  n> using "use strict".  This then causes perl to complain about any
  n> global variables that you don't refer to as $main::variablename.  My
  n> question is, what is the best way to handle this?  Below is a little
  n> bit of my code.  For some of my global vars I'm using "use vars" to
  n> "declare" them (is that right?), but with the rest of them, I make
  n> them local to my program with the "my" keyword.  Both of these work,
  n> but which is better, or should I be using fully qualified references
  n> to all of my global variables instead?

do you understand the difference between use vars and my? my is
declaring them as lexical, they can only be seen at compile time in this
file. use vars declares them as global fo all code to see. it is only
useful when the vars are being set externally like with getopt. 

a suggestion for getopt is to use a hash for the values. then the hash
can be declared with my in the file or in a argv parsing sub. i then set
better named flag and option vars from the hash values. this obviates
the need for use vars which i try to stay away from since it means
globals.  mostly this is done in a separate sub away from the main logic
of the program. this keeps things neat and uncluttered.

uri


-- 
Uri Guttman                             Hacking Perl for Ironbridge Networks
uri@sysarch.com				uri@ironbridgenetworks.com	


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

Date: Wed, 13 Jan 1999 13:19:20 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Perl Criticism
Message-Id: <x3y3e5fc9y1.fsf@tigre.matrox.com>


topmind@technologist.com writes:

> For example Perl has these stupeeds:
> 
>   thisdate = `date`;
>   dothis || die "error"
> 
> Perl put these things in purely for backward familiarity with
> Unix scripting. The backtics are WAY too easy to confuse with
> string quotes, the the || in this context should be a
> regular "if" statement.

Ok .. from what I see, you criticize Perl because it confuses
you. But that's not Perl's problem. It all depends on the programmer
and his style. If you hate backticks and think they can be easily
confused with single quotes, then don't use them. Perl offers an
alternative, qx//, which can not be confused with anything. You can
even open() a piped command. There's More Than One Way To Do It, and
Perl let's YOU make the choice.

In the same token, if you hate using ||, as you mention above, then
don't! Use a regular if() statement. Perl doesn't force you to be
cryptic. It just allows you to be, which I think is very neat.

I sometimes get confused when I read programs I wrote a while ago, but
that's not Perl's problem. The same thing happens when I read C,
Pascal and Lisp programs I wrote. I am not a professional programmer,
and I change my style quite a bit. But again, that's not Perl's
problem. 

> Why not have a Pipe() or Exec() function instead of backtics?

There are such commands, and you can certainly use them. But,
backticks are easier to type in (yes .. I'm getting lazier every day).

> What the hell was going throught their mind? I suspect they
> thought it was somehow clever or cute to use goofy symbols
> in goofy contexts. That was probably before the days that maintanability
> and readability became part of Computer Science.

Giving the programmer multiple options and tools to do a certain task
is a Good Thing (tm). That's what I hate about most languages and what
I like about Perl.

> Keep the good, chuck the bad!

That's why Perl has prospered so much .. no? ;-)

> My Perl coding tends to resemble non-piping languages such as VB.
> I don't use many of its hidden parameters and goofy stuff.
> If's use if's, loops use loops, etc. It is 10 times more
> readable than that crap that looks like a 3-year-old got
> their finger stuck in the keyboard.

Again, that is not Perl's problem. (It might be Miscrosoft's though).

I had some trouble deciphering "3-year-old got their finger stuck in
the keyboard"-code once I first saw it. But contrary to your reaction,
I was amazed at the ease and simplicity of such code. Once your brain
get used to it, you wouldn't wanna live without it. (you can quote me
on that).

Compare Perl-ish code

	open FILE, $file     || die "Something wrong with $file: $!\n";

with C-ish code

	if (!open(FILE, $file)) {
		print STDERR "Something wrong with $file: $!\n";
		exit;
	}

I agree that the second snippet might be easier to decipher for some
people, but that's because they were taught to think that way. Years
of programming forced people to use if() statements to test return
values of their commands. But why should that way be the Correct Way?
Most people got used to it, and don't want to change. That's why Perl
offers alternatives. But, maybe it's time to change .. don't you
think? 

> Perler's actually have
> contests to see who can write and read the most cryptic code.
> "Nerd Machoism" is what I call it.

Haven't you heard of The Obfuscated C Contest? It's way older than
Perl's. Have I heard you criticizing C?

> -tmind-
> http://www.geocities.com/SiliconValley/Lab/6888/langopts.htm


Ala

PS. I am thinking of writing a little program, say "perl_ish_to_c_ish",
that rewrites a given Perl script into a C-ish style script. Would
that be a useful tool?



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

Date: Thu, 14 Jan 1999 00:28:25 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: Perl Criticism
Message-Id: <369D2C19.932AE597@ngb.se>

OK, a gave a bad piece of advise, and got a personal mail about it.
(From Randall, no less)

>Staffan> [...] In Unix, a smart SysMan aliases 'rm' [...]

>Nope, only the dumb ones do that.  The smart ones alias "del" to 
>"rm -i", and tell the lusers to use "del" instead of "rm".

Agreed. My point was that you shouldn't use a feature if you don't have
a clue how it works, and if you do, you have to take responsibility of
the effects. 

I totally agree that calling it "del" would make more sense, especially
since I know how utterly frustrating it is to move from one system to
another, where the same command yield different results. 

But the main point is that Unix isn't unsafe, and neither is perl. You
can protect yourself if you want to, and if you don't, you have only
yourself to blame when things go wrong.

Fortunately, I am not a Unix System Administrator, nor do I claim to be
one. I do however, program in perl, and I manage to write readable code
performing the tasks I need to get done...

Regards

Staffan


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

Date: Wed, 13 Jan 1999 17:33:42 -0500
From: "Michael Mongeau" <michael_mongeau@stratus.com>
Subject: Re: Problem with frames
Message-Id: <77j6p2$2q3@transfer.stratus.com>


Snotsleeve <swettboy@ncats.net> wrote in message
news:369d0728.0@news.ncats.net...
>Does anyone know if it's possible to have a form in one frame that calls a
>CGI script in another frame?

This is a Perl newsgroup.   Your question will have a better change of being
answered in comp.infosystems.www.authoring.html or
comp.infosystems.www.authoring.cgi

 Michael Mongeau





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

Date: Wed, 13 Jan 1999 22:37:45 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Problem with frames
Message-Id: <Ze9n2.18$%i.3923@nsw.nnrp.telstra.net>

In article <369d0728.0@news.ncats.net>, after wiping his nose,
	"Snotsleeve" <swettboy@ncats.net> writes:
> Does anyone know if it's possible to have a form in one frame that calls a
> CGI script in another frame?

Yes, it is possible. 

No, it has nothing to do with perl.

Ask in one of the comp.infosystems.www.* groups.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | In a world without fences, who needs
Commercial Dynamics Pty. Ltd.       | Gates?
NSW, Australia                      | 


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

Date: Wed, 13 Jan 1999 12:52:07 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: question about File::Find
Message-Id: <x3y4spvcb7d.fsf@tigre.matrox.com>


Alexander Farber <eedalf@eed.ericsson.se> writes:

> could someone explain me the difference between
> find() and finddepth() in File::Find ?

RTFM ... if you type 'perldoc File::Find', you'll get your answer:

     finddepth is just like find, except that it does a depth-
     first search.



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

Date: Wed, 13 Jan 1999 14:24:06 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Read file problem
Message-Id: <x3y1zkzc6y1.fsf@tigre.matrox.com>


John@melon17.freeserve.co.uk (John ) writes:

> 
> When i use:
> 
> open(INF,file$) || die "Can't open file$\n";

what is file$ ??
Maybe you mean $file?

> the script tries to download the file rather than
> read it.

download? from where? what script?

> Any suggestions?

tell us more. Your line above shouldn't even compile!



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

Date: Wed, 13 Jan 1999 17:02:36 -0600
From: Dale Bohl <dbohl@sgi.com>
Subject: Removing Blank lines
Message-Id: <369D260C.8E72089C@sgi.com>

This is a multi-part message in MIME format.
--------------7A9947808C6B654DFBE4861B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

How do I delete blanks lines from an array?


-- 
Thanks,
Dale
--------------7A9947808C6B654DFBE4861B
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for DaleBohl
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             DaleBohl
n:              Bohl;Dale
org:            Silicon Graphics
adr:            1050 Lowater Road;;;Chippewa Falls;WI;54729-1445;USA
email;internet: dbohl@sgi.com
title:          Systems Administrator
tel;work:       (715)-726-8406
tel;fax:        (715)-726-6715
x-mozilla-cpt:  ;0
x-mozilla-html: FALSE
version:        2.1
end:            vcard


--------------7A9947808C6B654DFBE4861B--



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

Date: 13 Jan 1999 13:26:28 -0800
From: sundar_raman@nopoop.3com.com
Subject: require, use and "scope"
Message-Id: <77j324$58b@drn.newsguy.com>

What is the order of searching for function calls (i guess functions names in
the symbol table), and what causes a function's reference (entry in the symbol
table) to be removed (ie, how do function calls go out of scope)?  i understand
that using qualified function invocations works, but when/why/how do unqualified
calls work, and when/why/how do they stop working?

a diagram may help to clarify the question (i'm having trouble describing the
problem!):

package first_obj -----calls------> function in library (not package) my_lib.pl
  [ie, $obj1=first_obj->new; $obj1->execute() calls sub funcky in my_lib.pl]
package sec_obj   -----calls------> function in library (not package) my_lib.pl
  [same as above]
separate file test.pl can call either -
    require first_obj; ... $obj1->execute();
OR  require sec_obj; ... $obj1->execute();
however, if both are in the same file, the SECOND call does not work:
require first_obj; require sec_obj;
$obj1 = new first_obj; $obj1->execute;  # works ok
$obj2 = new sec_obj; $obj2->execute;  # bombs

the problem also seems to be related to the ORDER in which the requires are
declared.  ie, if i do "require sec_obj; require first_obj;" instead of the
above, then $obj1->execute() fails!

"programming perl" states:
"if ... you invoke *require* instead of *use*, you must explicitly qualify any
invocation of routines within the required package:
require Cwd;    # make Cwd:: accessible with qualification
$here = Cwd::getcwd();

use Cwd;    # import names from Cwd:: -- no qualification necessary
$here = getcwd();

however, this is NOT the case if the call is made from 2 different objects:
package first_obj;
use my_lib;	# could just as well be "require 'my_lib.pl';"
 ...  # new, exports, etc
sub execute {  callsubinmylib(); }
1;
[package sec_obj is identical]

# test file
require 'first_obj.pl'; require 'sec_obj.pl';
$obj1 = new first_obj;
$obj2 = new sec_obj;
$obj1->execute();	# works as anticipated
$obj2->execute();	# looks for (and does not find) sec_obj::callsubinmylib()

this is causing me lack of sleep, and i would REALLY appreciate any help!
  

please remove "nopoop" from my email address to contact me directly.


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

Date: Wed, 13 Jan 1999 17:28:57 -0500
From: "Michael Mongeau" <michael_mongeau@stratus.com>
Subject: Re: Setting Variables Question
Message-Id: <77j6g6$2ki@transfer.stratus.com>


mikej <mikej@1185design.com> wrote in message
news:369CE50D.9BA5FDB9@1185design.com...
>Hello,
>
>
>#how should I be setting these variables?
>
>       $username = "$data_username";
>       $password = "$data_password";
>

You're just assigning one variable to another - no quotes are necessary:

       $username = $data_username;
       $password = $data_password;

You say it works unreliably - are you sure the data file has values for all
three fields ?  The split will assign null values to one or more of the
variables if there aren't at least three values on each line of your data
file.

 Michael Mongeau






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

Date: Wed, 13 Jan 1999 17:32:55 -0600
From: Tim <ringwood@berbee.com>
Subject: Simple question:  packages
Message-Id: <369D2D27.7324@berbee.com>

I've been usuig Perl for 4 years or so and I've always wondered
how to solve the following problem (I'm sure the answer is
really obvious!)

I have an application which has lots of packages (30 or so) cause
I'm anal and like to keep thing organized.

There are some functions in "main" which every package can use
and to call them of course you do: &main'function_name 
when in another package.

Now sometimes I need do to a numeric sort on a keys in a hash.

To do that I define the (stolen) one line sub in  my  main package:

 sub num { $a <=> $b;};

Saying:
  foreach (sort num keys %hash)

works fine when in main, but when in another package:

 foreach sort main'num keys %hash

fails. It calls "num" but since $a and $b are not in the main
package the compares just don't work.

My "workaround" is to define the 'num' sub in every package that
I need to sort in. That's just darn ugly, and was hoping for a
better answer.

Again I'm sure this is something I've just missing in my pooh brain;
any help finding it would be appreciated.

tim


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

Date: Wed, 13 Jan 1999 16:14:17 -0600
From: Bryan Camp <b-camp@students.uiuc.edu>
Subject: split question
Message-Id: <Pine.SOL.3.96.990113160519.28504A-100000@ux5.cso.uiuc.edu>

I'm having a problem using the split command.
I have a file with the following format:

SRC1=A510I52616300 AMP|52453

I want the output of this line to look like this:

SRC1=A510I52616300_52453|AMP

So what I tried to do was split on " ",
which gives me SRC1=A510I52616300 as the
first value in my array and AMP|52453 as the
second value in my array.  Next, I tried to 
split the second value in the array on "|",
but this isn't working for me.  I'm not
sure what's going wrong here.  Any help
would be greatly appreciated.  The script is
below, and the output follows.


#!perl -w
while(<>) {
 
@array1 = split(" ", $_);
$source1 = $array1[0]; 
$source2 = $array1[1]; 
 
@array2 = split("|", $source2);
$source3 = $array2[0];
$source4 = $array2[2]; 
 
printf "%s_%s|%s\n", $source1, $source4, $source3;
}

OUTPUT: SRC1=A510I52616300_P|A

Thanks,

Bryan






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

Date: Wed, 13 Jan 1999 17:33:05 -0500
From: Bill Jackson <wcj@iti-oh.com>
To: Bryan Camp <b-camp@students.uiuc.edu>
Subject: Re: split question
Message-Id: <369D1F21.9D244AA@iti-oh.com>

Try this:

@array2 = split('\|', $source2);

Put the vertical bar ('pipe') character in single quotes and preceed it
with
a backslash (\).

It worked for me.

Also, note that your $source4 should be $array2[1] instead of
$array2[2].

Bill





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

Date: 13 Jan 1999 14:38:39 -0800
From: Sundar <cybertoast@nopoop.mindless.com>
Subject: Re: split question
Message-Id: <77j79f$dri@drn.newsguy.com>

>second value in my array.  Next, I tried to 
>split the second value in the array on "|",
>but this isn't working for me.  I'm not

you need to use /\|/:

>@array2 = split("|", $source2);

change to: @array2 = split(/\|/, $source2);

your could do the whole thing as:
($source1, $source2, $source3) = ($_=~ /(.*)\s(.*)\|(.*)/);

remove nopoop from mail to get to me


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

Date: Wed, 13 Jan 1999 17:17:38 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: where can I get perlfunc.pod
Message-Id: <fl_aggie-1301991717380001@aggie.coaps.fsu.edu>

In article <369D13C6.1804506@hrb.com>, "Michael J. Wrobel" <mjw@hrb.com> wrote:

+ what is perlfun.pod?

It is the POD file describing perl's builtin functions.

+ I want to use it to answer my questions, but am unable to find it.

It should be included with every distribution of perl. Do you mean to say
that 'perldoc perlfunc' doesn't work for you?

James


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

Date: 13 Jan 1999 22:44:52 GMT
From: michal@gortel.phys.ualberta.ca (Michal Jaegermann)
Subject: Re: Year 2038 problem
Message-Id: <77j7l4$ks6$1@pulp.ucs.ualberta.ca>

Bart Lateur (bart.lateur@skynet.be) wrote:

: The largest problems are probably in the Unix kernels.

I do not think so.  Unix kernels, at least these I know about, know
really nothing about the current date.  This is purely a library
(i.e. user space) issue.

For those who tried my example code on 32-bit machines - time_t is
a signed value so it can represent a range of dates in the past.
If you overflow it then Perl sets it to 0 and you you will this:

perl -e 'print (scalar gmtime 0, "\n")'
Thu Jan  1 00:00:00 1970

which happens to be "epoch begining" - at least on Unix.  You will
get the same effect if you will overflow a range which Perl can
represent on 64-bit machine.

Once again - applications are not limited to storing time in
seconds in time_t format and quite often they do not.  OTOH
Unix file systems maintain file time stamps in such way.

  Michal



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

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

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