[11137] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4737 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 24 18:07:11 1999

Date: Sun, 24 Jan 99 15:00:27 -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           Sun, 24 Jan 1999     Volume: 8 Number: 4737

Today's topics:
        Can somebody point out the error of my ways please? (Bob Dubery)
    Re: Can somebody point out the error of my ways please? <jdf@pobox.com>
        chmod and errors <Rytsarsky@iname.com>
    Re: chmod and errors <jdf@pobox.com>
    Re: easy way to query other boxes mkaminer@yahoo.com
    Re: Flatline database help <me@me.com>
    Re: Handling an Empty Line scott.craig@moh.hnet.bc.ca
        Help - file output problem <dales@enhanced-performance.com>
    Re: Help on Perl and Corba (Martien Verbruggen)
    Re: How do I Send a form to a printer ? <bill@fccj.org>
        Installing GD Module <mwatkins@promotion4free.com>
        JPEG manipulation in PERL <Andrew.Wild@env.qld.gov.au>
        Need a script to split an archive (Dan Simoes)
    Re: Need a script to split an archive (brian d foy)
        Need Help Removing (Unlinking) Files in PERL Script wabba@globalnet.co.uk
        Need Help Removing (Unlinking) Files in PERL! wabba@my-dejanews.com
    Re: Need Help Removing (Unlinking) Files in PERL! <allan@due.net>
    Re: Need Help Removing (Unlinking) Files in PERL! <eugene@snailgem.org>
    Re: Need Help Removing (Unlinking) Files in PERL! (Martien Verbruggen)
    Re: Need Help Removing (Unlinking) Files in PERL! (Martien Verbruggen)
    Re: Need script for .htpasswd file (brian d foy)
    Re: ok please don't shoot me for this question (Martien Verbruggen)
    Re: Perl Criticism (Gregory Snow)
        Running External Program <ytsiow@singnet.com.sg>
    Re: Trying to automate FTP <jdf@pobox.com>
    Re: Trying to automate FTP <rick.delaney@home.com>
    Re: Trying to automate FTP <smiths@erols.com>
    Re: Trying to automate FTP <palincss@his.com>
    Re: Trying to automate FTP <jdf@pobox.com>
    Re: Trying to change a line in a file <allan@due.net>
    Re: using search pattern <joe@laffeycomputer.com>
    Re: using search pattern <jdf@pobox.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Sun, 24 Jan 1999 16:53:28 GMT
From: elvis@theking.org (Bob Dubery)
Subject: Can somebody point out the error of my ways please?
Message-Id: <36ab4ff7.1765611@news.icon.co.za>

Consider this code...

@terms = ('please','tell','told');

 foreach $thisword(@terms) {
        $hashname = "/usr/syschanges/$thisword";
        dbmopen(%WORDHASH,$hashname,0666);
        foreach $hashentry(keys %WORDHASH) {
                print "$hashentry ";
                $howmany = $WORDHASH{$hashentry};
                print "$hashentry has $howmany \n";
                $output{$hashentry} += $WORDHASH{$hashentry};
        }
}

It doesn't do what I expected it to do. The line 
	print "$hashentry has $howmany \n";
never produces any output.

In fact, given that the line
	print "$hashentry";
never gets to generate any output I conclude that, for some reason,
the foreach loop is not being execute.

Now I think it's something to do with the variable $hashname. If I
change the line assigning it to
	$hashname = "/usr/syschanges/tell";
then I get to see some output. Granted it's the same output each time
round, but that suggests to me that somehow I'm setting up the
variable holding the path to the file incorrectly. I just wish I knew
how.

The DBM files are there. If I change the inner loop to do
	print -r $hashentry;
instead of opening the hash and trying to loop through it then I get
to see 3 ones (1).

I've tried testing the file in various ways, and there seems to be no
problem with permissions...

I'm stumped. Can somebody help please?
---
the e-mail address in the headers is bogus
unknot megapode@KNOTicon.co.za to mail me


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

Date: 24 Jan 1999 23:57:30 +0100
From: Jonathan Feinberg <jdf@pobox.com>
To: elvis@theking.org (Bob Dubery)
Subject: Re: Can somebody point out the error of my ways please?
Message-Id: <m3vhhwl1np.fsf@joshua.panix.com>

elvis@theking.org (Bob Dubery) writes:

>         dbmopen(%WORDHASH,$hashname,0666);

You fail to check the success of this system call, which is one way
sincerely to beg for trouble in Perl.

  dbmopen(%FOO, '/etc/bar', 0666) || die "No can do: $!\n";

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Sun, 24 Jan 1999 15:00:06 -0600
From: Jay Knight <Rytsarsky@iname.com>
Subject: chmod and errors
Message-Id: <36AB89CE.4223AEA8@iname.com>

A little change to my last post.  My script, a counter, named count.pl, when
run from the command line (perl count.pl) prints the html for a page showing
the usage.  but count.pl alone returns run-time errors and count.pl =: not
found, or something.  Is there something wrong with the code?  and also,
about permissions, can someone explain what the different parameters do (a+x,
a+xr, 705, etc.)?  or just point to a place that gives a pretty good (and
simple, remember, I'm dumb) explanation.... thank you all very much

cheers,
jk



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

Date: 24 Jan 1999 23:48:29 +0100
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: chmod and errors
Message-Id: <m3zp78l22q.fsf@joshua.panix.com>

Jay Knight <Rytsarsky@iname.com> writes:

> Is there something wrong with the code?

Yes.  Check the eleventh line.

[Translation of my sarcasm: how could anybody possibly know what's
wrong with your code?  You didn't post any.]

> and also, about permissions, can someone explain what the different
> parameters do (a+x, a+xr, 705, etc.)?  or just point to a place that
> gives a pretty good (and simple, remember, I'm dumb) explanation....

This is really a Un*x question, not related to Perl at all.  You'll
want to check the manual pages on your system.  For example

   $ man chmod

But the resulting information won't mean much to you, because you
haven't yet learned enough about the Un*x security model, etc.  Buy
yourself a book that will teach you the basics about Un*x.  O'Reilly
is a respected publisher...

Also, comp.lang.perl does not exist.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Sun, 24 Jan 1999 22:04:18 GMT
From: mkaminer@yahoo.com
Subject: Re: easy way to query other boxes
Message-Id: <78g5cu$c73$1@nnrp1.dejanews.com>

In article <36AA08F5.14FFB76F@patriot.net>,

Thats an idea.	what if the machine doesnt have SNMP capabilities?  no way to
query for the OS?  what about using a banner from a telnet session to
determine the box?

-matt

  keydet89@yahoo.com wrote:
>
>
> > So i have 20 machines on a subnet.  I want to know what each machine (NT,
> > UNIX, ROUTER...) is running.  any ideas?
>
> I have a couple actually...
>
> 1.  SNMP...the Net::SNMP module is great!
> 2.  Write an agent for each system...bind it to a high port.  Load the
>      agent on each system.  If system responds to a ping, but doesn't
>      have an agent...router.  Otherwise, have the agent respond with the
>      platform (I know, this is poor-man's SNMP).
>
>

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


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

Date: Sun, 24 Jan 1999 19:20:59 -0000
From: "Steve" <me@me.com>
Subject: Re: Flatline database help
Message-Id: <78frr9$ivl$1@news7.svr.pol.co.uk>

Hi,

Thanks so much for your help with this. I managed to get it working, using
the following code:

@my_categories = split(/,/,$ITEM{'group'});

foreach $category (@my_categories) {

print "$groups{$category}";

}

In the print_item subroutine.

Cheers.

Steve.


>Take a look at the "split" function above, and check out the perl docs
>on "split" (perldoc -f split). The simplest way to do this would be
>something like this would be somethign like
> @my_categories = split(/,/,$ITEM{'group'}
>
>We're taking the third value that was found by splitting on "|" and
>splitting *that* on the comma character. (I'll save you some time and tell
>you that if you want to allow for the possibility that there might be
>spaces around the comma, you would replace /,/ above with /\s*,\s*/).
>
>: # The print_item subroutine
>
>: local(*ITEM) = shift;
>
>: print "$ITEM{'itemid'}, $ITEM{'price'},\n
>
>: ($groups{$ITEM{'group'}})";
>
>Here's where you need to do a little work. Since you no longer have a
>single value (necessarily), you have to iterate through the values in
>@my_categories and print out each of them. If you're also searching on
>categories, you need to alter the search routine so that *it* first splits
>that category field and then examines each resulting value to see if it
>matches, etc etc. How best to do this is left as an exercise for the
>reader, but it will probably involve a "foreach" loop.






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

Date: Sun, 24 Jan 1999 22:00:18 GMT
From: scott.craig@moh.hnet.bc.ca
Subject: Re: Handling an Empty Line
Message-Id: <78g55f$bup$1@nnrp1.dejanews.com>

In article <78b8v4$uqj$1@nnrp1.dejanews.com>,
  bidyut@yahoo.com wrote:
> Hi there, I have one simple problem. I have a Perl progrma that reads a flat
> file line by line and parse each line. I want the perl program to exit, if
> the next line is empty or might have a carriage return. The program should
> check if the line contains carriage return or basically an empty line.

There is no such thing as an empty line.  By definition, it must have at
least a newline character at the end of it.  If you mean the line should
contain exactly either \r\n or \n, then use  m/^\r?\n$/. (The beginning of
the line, zero or one carriage return, a newline, the end of the line.)

However, if you also will allow spaces and tabs, use m/^\s*$/. (The beginning
of the line, zero or more [space or tab or cr or newline], the end of the
line.)

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


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

Date: Sun, 24 Jan 1999 14:54:44 -0800
From: Dale Sutcliffe <dales@enhanced-performance.com>
Subject: Help - file output problem
Message-Id: <36ABA4B4.937653EF@enhanced-performance.com>

For some reason, the script below is adding extra | to the end of the
file.  Any ideas why?
Thanks
-----------------------------
# open file

unless (open FILE, "+<$secfile") {
    print "Error can not open file: $!\n";
    exit 1;
} else {
    while (<FILE>) {
        push @LoL, [ split(/\|/,$_,16)  ];
    }

     # check where the entry is

     for $i ( 0 .. $#LoL ) {
     if ($LoL[$i][0] eq ($input{'$name'})) {
        if ($LoL[$i][1] eq ($input{'$number'})) {
            $enter = 1;
            $location = $i;
        }
    }
 }

# move to the beginning of the file
seek (FILE, 0, 0);

# write to file

for $i ( 0 .. $#LoL) {
    if ($i eq $location) {

        # print that the person had visited

        print FILE $LoL[$i][0],"|",$LoL[$i][1],"|1|\n";
    } else {

        # print the data

        print FILE $LoL[$i][0],"|",$LoL[$i][1],"|",$LoL[$i][2],"|\n";
    }
 .
close FILE;





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

Date: Sun, 24 Jan 1999 22:50:08 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Help on Perl and Corba
Message-Id: <AsNq2.49$b32.2742@nsw.nnrp.telstra.net>

In article <78d744$8su@bgtnsc03.worldnet.att.net>,
	faf@nafjfa.com (fada) writes:
> 
> A vendor told me that his system is using Perl, Unix Script, and Awk. Perl 
> indirectly support CORBA, therefore the application is CORBA compliance.
> Is this true that using Perl implies that you are CORBA compliance?

There is nothing in perl that stops CORBA. In fact, there are perl
modules for CORBA.

If that is all it needs to be CORBA-compliant, then yes, perl is CORBA
compliant.

perl is also SMTP compliant, WWW compliant, FTP compliant, CGI
complaint (shudder, not a typo), integer compliant and banana
compliant.

buzz, buzz, buzzwords.
marketing speak.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | Make it idiot proof and someone will
Commercial Dynamics Pty. Ltd.       | make a better idiot.
NSW, Australia                      | 


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

Date: Sun, 24 Jan 1999 16:45:05 -0500
From: "Bill Jones" <bill@fccj.org>
Subject: Re: How do I Send a form to a printer ?
Message-Id: <36ab93eb.0@usenet.fccj.cc.fl.us>

On Windows or Unix?

Either way, try opening the prn port under windows, or
if under Unix, create a file and call lp or lpr...

HTH,
-Sneex-
______________________________________________________________________
Bill Jones  | FCCJ Webmaster |  http://www.fccj.org/cgi/mail?webmaster
 http://certserver.pgp.com:11371/pks/lookup?op=get&search=0x37EFC00F


----------
In article <36aa9e81@camcomp2.camcomp.com>, "Jim and Lois"
<kf4dmb@camcomp.com> wrote:


> I am building a Help desk app . I would like users when the fill the form
> out and press
> a button they send it to the help desk printer.
>
> 


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

Date: Sun, 24 Jan 1999 21:32:49 -0000
From: "Mike Watkins" <mwatkins@promotion4free.com>
Subject: Installing GD Module
Message-Id: <#znNAE#R#GA.203@nih2naab.prod2.compuserve.com>

Hi there,

I'm having some trouble installing the GD v1.18 module on my Win98
computer.  First, I had ActiveState's version of perl installed, and
used their PPM.  The module seemed to install fine, but when I ran a
script which used GD, it said it couldn't find Image.al in /auto/GD/.

After a few hours of trying that, I decided to switch to the standard
binary dist. of perl, because it contains the dmake utility.  I switched
over, and tried to install the GD module again with no success.

I have tried to install all 3 versions of GD which are at CPAN, on
both versions of perl with no success.  Can anyone out there help me
out with installing the GD module on either version of perl?

Any help would be greatly appreciated,
Mike Watkins





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

Date: Mon, 25 Jan 1999 08:55:10 +1000
From: Andrew Wild <Andrew.Wild@env.qld.gov.au>
Subject: JPEG manipulation in PERL
Message-Id: <36ABA4CE.B9A3C4A3@env.qld.gov.au>

I am trying to find out if there are any modules/libaries availble to do
JPEG image manipulation. i.e. To resize a JPEG image etc.

Thanks, Andrew.

-- 
Andrew Wild
Coordinator (Web Technology)
Information Systems Branch
Queensland Department of Environment and Heritage
Ph: (07) 3227 7991 Fax: (07) 3227 6534
-------------------------------------------------- 
Visit us online at http://www.env.qld.gov.au
--------------------------------------------------


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

Date: 24 Jan 1999 14:21:50 -0500
From: dans@ans.net (Dan Simoes)
Subject: Need a script to split an archive
Message-Id: <78frse$hot@luso.ny.ans.net>

I'm looking for a script that does the following:
Input is an archive named foo, with mail messages from several dates.
Output should be files in the format:

foo.YYMMDD

where only messages from that date are contained in that file.

Also, I'd like to find something that can take "foo" and split
in completely into individual message files, perhaps in a 
subdir, so that given "foo" as input, you would have:

/YYMMDD/1
/YYMMDD/2
 ...
/YYMMDD/n

Obviously, one answer is "write it yourself" :)  But I know that these
tools are out there, as I've used them in the past.  I just can't
seem to locate them right now.

Thanks for any pointers.  If I do end up writing this, I might use it as
a reason to learn perl...

| Dan |
-- 
Dan Simoes			          dans@ans.net
MCIWorldcom Advanced Networks	http://coimbra.ans.net/dans.html
100 Manhattanville Road, Suite 5	(914) 701-5378 (voice)
Purchase, NY 10577			(914) 701-5310 (fax)


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

Date: Sun, 24 Jan 1999 15:23:14 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Need a script to split an archive
Message-Id: <comdog-ya02408000R2401991523140001@news.panix.com>

In article <78frse$hot@luso.ny.ans.net>, dans@ans.net (Dan Simoes) posted:

> I'm looking for a script that does the following:
> Input is an archive named foo, with mail messages from several dates.
> Output should be files in the format:
> 
> foo.YYMMDD

see the various Mail::* modules (like Mail::Folder) for help.

good luck :)

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


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

Date: Sun, 24 Jan 1999 21:26:06 GMT
From: wabba@globalnet.co.uk
Subject: Need Help Removing (Unlinking) Files in PERL Script
Message-Id: <78g355$aj4$1@nnrp1.dejanews.com>

Hello Everyone.  I am in desperate need of help with regards to PERL
programming. I am currently using Perl Scripting (with CGI), to increase the
portability of a test program running withing my school. This is my 6th Year
Project.  I thought everything was going well, until I ran into the problem
of not being able to delete (unlink) files from within my PERL scripts. I am
using SuSE Linux. I have read all of the PERL man pages in Linux and I have
tried the following pieces of code to unlink files:

1)    @Args=('rm','../htdocs/project/$TestName/$TestName.test');
      system(@Args);

and
2)    unlink("../htdocs/project/$TestName/$TestName.test");


I am aware that the unlink command is meant to be used with a List Parameter,
but I would expect it to work with a single parameter as well. Also, I have
tried putting in the full path-name instead of the shortened name with ".."
but this does not help either.	I have also checked that the permissions are
okay by looking at both the HTTPD  effective ID and the file ID, and these
are okay, and the operation is therefore permittable.

PLEASE HELP! I would be grateful for any suggestions you have, and don't
hesitate to contact me if you have any ideas on how to solve this problem,
thanx.

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


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

Date: Sun, 24 Jan 1999 21:10:20 GMT
From: wabba@my-dejanews.com
Subject: Need Help Removing (Unlinking) Files in PERL!
Message-Id: <78g27m$9rh$1@nnrp1.dejanews.com>

Hi Everyone.  I'm in desperate need of help on PERL programming. I need to
write scripts to handle a testing programming for my Secondary School 6th
Year Project. I thought everything was going fine, until I discovered that I
cannot erase files from a PERL script. This is a crucial part in my program
and is required to be functioning. I have checked all of the Linux Man Pages
on PERL, and have tried the two following commands in PERL. 1) 
@Args=("rm","../htdocs/project/$TestName/$TestName.test");  system(@Args);

2)   unlink ('../htdocs/project/$TestName/$TestName.test');

I am aware that the unlink command is usually used in a context with an
entire LIST as it's parameter but I would expect it to work on single files
also.  I have also tried the full path-name instead of using the two ".." but
this doesn't work either, and I have also checked the permissions on the
HTTPD ID, and the file ID, to make sure that the operation is permitted,
which it is. I would be really grateful for ANY help that you can offer, and
please do not hesitate to respond if you have an ideas which may help, as
time is of the essence.

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


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

Date: Sun, 24 Jan 1999 16:57:21 -0500
From: "Allan M. Due" <allan@due.net>
Subject: Re: Need Help Removing (Unlinking) Files in PERL!
Message-Id: <XHMq2.500$WR1.4255@nntp1.nac.net>

wabba@my-dejanews.com wrote in message <78g27m$9rh$1@nnrp1.dejanews.com>...
:Hi Everyone.  I'm in desperate need of help on PERL programming. I need to
:write scripts to handle a testing programming for my Secondary School 6th
:Year Project. I thought everything was going fine, until I discovered that I
:cannot erase files from a PERL script. This is a crucial part in my program
:and is required to be functioning. I have checked all of the Linux Man Pages
:on PERL, and have tried the two following commands in PERL. 1)
:@Args=("rm","../htdocs/project/$TestName/$TestName.test");  system(@Args);


I would have thought that would have gotten you pretty darn close.  But I am a
POB so little help with rm.  It is not how I would have done it but:

my $filename = 'C:\temp\tick\this.dat';
@args = ('del',"$filename");

deletes this.dat in Windoze.

:2)   unlink ('../htdocs/project/$TestName/$TestName.test');


Here is a hint: what do you think those single quotes do to your  variable
names?

Here is another, what error message do you get when you check the return value
from your unlink.  You do check it don't you?

unlink $filename or die "Problem unlinking due to: $!";
(or warn instead if you prefer)

HTH

AmD




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

Date: Sun, 24 Jan 1999 17:04:26 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
To: wabba@my-dejanews.com
Subject: Re: Need Help Removing (Unlinking) Files in PERL!
Message-Id: <36AB98EA.C15099F2@snailgem.org>

wabba@my-dejanews.com wrote:
> 
> Hi Everyone.  I'm in desperate need of help on PERL programming. I need to
> write scripts to handle a testing programming for my Secondary School 6th
> Year Project. I thought everything was going fine, until I discovered that I
> cannot erase files from a PERL script. This is a crucial part in my program
> and is required to be functioning. I have checked all of the Linux Man Pages
> on PERL, and have tried the two following commands in PERL. 1)
> @Args=("rm","../htdocs/project/$TestName/$TestName.test");  system(@Args);
> 
> 2)   unlink ('../htdocs/project/$TestName/$TestName.test');
> 
> I am aware that the unlink command is usually used in a context with an
> entire LIST as it's parameter but I would expect it to work on single files
> also.  I have also tried the full path-name instead of using the two ".." but
> this doesn't work either, and I have also checked the permissions on the
> HTTPD ID, and the file ID, to make sure that the operation is permitted,

Is this a CGI? 
> which it is. I would be really grateful for ANY help that you can offer, and
> please do not hesitate to respond if you have an ideas which may help, as
> time is of the essence.

Oy, yet another of these permission problems . . .

OK, first you have to tell us what error messages you get.
Then you have to tell us if you're running from the command line or if
this is a CGI.
It would also be useful to tell us what the permissions of the file
you're trying to remove are.



-- 

Eugene

 "I have an Apache Web Server that uses CGI forms written in COBOL."
 							Post in clpm


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

Date: Sun, 24 Jan 1999 22:51:52 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Need Help Removing (Unlinking) Files in PERL!
Message-Id: <cuNq2.52$b32.2742@nsw.nnrp.telstra.net>

In article <36AB98EA.C15099F2@snailgem.org>,
	Eugene Sotirescu <eugene@snailgem.org> writes:

> Oy, yet another of these permission problems . . .

Not really. Just a misunderstanding of which quotes to use. Check the
original code again.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | I took an IQ test and the results were
Commercial Dynamics Pty. Ltd.       | negative.
NSW, Australia                      | 


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

Date: Sun, 24 Jan 1999 22:57:07 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Need Help Removing (Unlinking) Files in PERL!
Message-Id: <7zNq2.57$b32.2742@nsw.nnrp.telstra.net>

In article <78g27m$9rh$1@nnrp1.dejanews.com>,
	wabba@my-dejanews.com writes:

> 2)   unlink ('../htdocs/project/$TestName/$TestName.test');

Where is 1) ?

Have you read the documentation to see what the difference between
using single (') and double (") quotes is?

# perldoc perldata

You should also always check the return values of any system calls. In
this case, you should check whether the number of files unlinked is
equal to the number of files you wanted unlinked.

# perldoc -f unlink

> I am aware that the unlink command is usually used in a context with
> an entire LIST as it's parameter but I would expect it to work on
> single files also.

A single argument is just a list with one element. No problem there at
all.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | The number of the beast is not 666. Its
Commercial Dynamics Pty. Ltd.       | number is 95, and it's awake.
NSW, Australia                      | 


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

Date: Sun, 24 Jan 1999 15:20:45 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Need script for .htpasswd file
Message-Id: <comdog-ya02408000R2401991520450001@news.panix.com>

In article <36AB6D1E.44C3190C@hotmail.com>, JS <js148@hotmail.com> posted:

> Thanks for you advice and I don't want to appear too dumb but ... don't
> these assume I have some sort of access to the server? My web site is
> hosted remotely and the only access I have is via FTP. Don't even have a
> Unix shell but would readily move my site if that would solve my
> problem. (Would it?).

shell access is good, and it's a competitive market.  don't settle 
for less.  make sure you tell your old ISP why you're leaving ;)

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


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

Date: Sun, 24 Jan 1999 22:45:32 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: ok please don't shoot me for this question
Message-Id: <goNq2.46$b32.2742@nsw.nnrp.telstra.net>

In article <78cme9$rva$1@news3.belgium.eu.net>,
	"Familie Elst" <elst.fels@nospam.ping.be> writes:
> Ok, is there anybody who can write me a guestbook script without banners in
> perl
> or tell me where I can find it ?

To find someone who can write it: post in one of the job groups, hire
one of the people responding.

To find it: use the web. Start at www.cgi-resources.com or something
like that. Use Altavista. Use Yahoo.

> I was trying to write one but my brain has burned out and I really have a
> deathline.

Hmm.

# cat program.pl
#!/usr/local/bin/perl -w
use strict;

die "This is it!";
# perl program.pl
Death found at program.pl line 4.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd.       | again. Then quit; there's no use being
NSW, Australia                      | a damn fool about it.


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

Date: 24 Jan 1999 22:34:54 GMT
From: snow@biostat.washington.edu (Gregory Snow)
Subject: Re: Perl Criticism
Message-Id: <78g76e$16sq$1@nntp6.u.washington.edu>

In article <783lia$b21$1@nnrp1.dejanews.com>,
 <topmind@technologist.com> wrote:
>In article <x767a3g6h3.fsf@home.sysarch.com>,
>  Uri Guttman <uri@home.sysarch.com> wrote:

>
>I asked for examples from yous of indespensable Perl cryptology
>and nobody showed any. Unless you produce some Uri, you are
>a hypocrite.

But Uri has posted code (specificaly as a follow-up extension to one
of my posts) and is not a hypocrite. 

Let's look at your challenge, I think I can answer it with 1 line of
Perl code, but first I want to make sure that we understand the true
challange (I don't work for the NSA and know little about true
cryptology).

There seem to be 2 main points to your posts and challange:

1.  Maintainability, especcialy by someone else, is the most
important, i.e. given 2 pieces of code that instruct the computer to
do the same thing, the better code is the one that someone other than
the author has an easier time understanding.

Am I correct there?  Is that a fair comparison for determining the
best code?  Can something be considered indespensible if removing
makes the code harder for a second person to easily read/understand
it?


2.  Your main complaint against Perl seems to be that there is more
than one way to do something, and you especcialy dislike using
shortcut boolean operators in place of conditionals.

Am I correct?


Here is my answer to your challange:

  open(IN, "myfile.dat") || die "unable to open myfile.dat: $!\n";

(this should have you cringing if my #2 above was correct)

Your alternative would be something like:

  if( !open(IN, "myfile.dat") ){
    die "unable to open myfile.dat: $!\n";
  }

Correct?  (ignoring how you might phrase the error differently).

Let's compare the 2 based on the readability criterion above (note
that since we are talking about a 2nd person reading the code, saving
keystrokes is irrelivant).

First a simmulated thought process for reading the "if" version:

1. I see an "if", this is a conditional is the argument true or false?
2. I see an "!" so the true/false is reversed
3. Ah, the "open" function, what does it return, when does it return
false (which reversed is when the block will be executed).
4. The block will be executed when the open fails.
5. The block consists of a die statement.
6. I know so far that the program will exit if the open fails, but
since this is my first scan of the program I care about what happens
when it succeeds.
7. Back-up to that open function and look at it's arguments.
8. Ah, the filehandle IN is now associated with the file: myfile.dat.
9. Where is that closing brace?

Now let's look at the simmulated thought process for the || (or "or"):

1. I see an "open" function, what are it's arguments?
2. Ah, the filehandle IN is now associated with the file: myfile.dat.
3. I see "||" (or "or"), there is code to handle the case of a failed
open, ignore it for now.
4. The next line is ...

(The first time through the code we should be focusing on the rule,
not the exceptions, so I don't pay any real attention to what comes
after the boolean until the 5th or 6th time through the code (if ever).


Which is simpler to read, understand, and maintain for someone other
than the original programmer?  

Here the important thing is what filehandle is associated with which
file, not what is returned by the open function or what to do when the
open fails, so the above idiom very good at focusing the mind on the
important point and letting the reader easily skip what is of minor
importance.  Now as has been pointed out in other posts, sometimes the
conditional is the most important, so we can't get rid of it and
always use short-cicut conditionals.  And sometimes what is done
because of the conditional is the most important and the programmer
can easily emphasize this to the reader by using Perl's "expression if
conditional" syntax.

The very things that you say make Perl hard to read, are what makes it
easier to read and understand (when used properly, of course).


Your challange has been answered with posted code and explanation
(whether it succeeded or not is yet to be seen :).






-- 
-------------------------------------------------------------------------------
     Gregory L. Snow         | MATZ'S RULE REGARDING MEDICATIONS:
     (Greg)                  |   A drug is that substance which, when injected
snow@biostat.washington.edu  |   into a rat, will produce a scientific report.


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

Date: Mon, 25 Jan 1999 01:45:44 +0800
From: "Yong Teck" <ytsiow@singnet.com.sg>
Subject: Running External Program
Message-Id: <78fm9i$ptb$1@mawar.singnet.com.sg>

Hi there,

I am using Sambar web server to host my web-site and uses a program call
HTPASSWD.EXE that come with Sambar to password protect my site.  I wanted to
write a perl script that will allow users to change their password through
the web browser.  The problem is the way HTPASSWD.EXE works.  I have to run
it in the DOS prompt by typing :
HTPASSWD users runner

where users is the file that keeps all the user name and password, runner is
one of the user in the file.
After typing that, I hit ENTER key and it will immediately ask for a new
password and I have to key in and hit ENTER key again.  It will then ask me
to re-enter the new password and I have to do it again and hit ENTER key
again.

I have an HTML form that get the user name and password but how can I write
a Perl script that will pass the user name and password for HTPASSWD.EXE to
process?  I heard that the pipe function can do it but not sure how to do it
because I am really new to Perl.

Any help will be very much appreciated, thank you.


Alex




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

Date: 24 Jan 1999 20:28:52 +0100
From: Jonathan Feinberg <jdf@pobox.com>
To: "The Smiths" <smiths@erols.com>
Subject: Re: Trying to automate FTP
Message-Id: <m34spgmpvv.fsf@joshua.panix.com>

"The Smiths" <smiths@erols.com> writes:

> This would be handy for the automation of other
> commands as well.

I bet someone's already thought of ways to control an interactive
process.  I... *Expect* they have done so.

> open (FTP, "|ftp");
> print FTP "open ftp.site.com\n";
> print FTP "userid\n";

You're assuming that everything works.  You wanna get spanked?

> The concept that I am looking for is the ability to stack commands
> so that everytime FTP reads from the command line, it pulls the next
> entry off the stack.

It's not going to listen unless you do, too.

   $ perldoc perlipc

Search for "Bidirectional Communication with Another Process".

Also, as I rather obscurely suggested, check out Expect.pm.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Sun, 24 Jan 1999 19:50:01 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Trying to automate FTP
Message-Id: <36AB7B27.752A27FD@home.com>

[posted & mailed]

The Smiths wrote:
> 
> I know that I can use NET::FTP, LWP, and other socket related packages to
> drive an FTP connection, but I wanted to simply drive the FTP shell command
> from a Perl script.

Can you explain why?  Net::FTP is far superior to the method you are
trying below.
   
> This would be handy for the automation of other commands as well.

That's what Net::FTP is for.

> 
> However, I have not succeeded and was wondering if anyone may have an
> example.  I can get the first FTP command piped to the program, but
> subsequent FTP commands go unrecognized.
> 
> I tried system, back ticks, and most recently this:
> 
> open (FTP, "|ftp");
> print FTP "open ftp.site.com\n";
> print FTP "userid\n";


This will work for executing ftp commands but I don't think you can use
this for entering userids or passwords since this is an interactive
thing.  You could set up entries in your .netrc file to connect you and
then print your ftp commands to the above filehandle but you have no way
to trap errors or output using the above method.

> .
> .
> .
> 
> The concept that I am looking for is the ability to stack commands so that
> everytime FTP reads from the command line, it pulls the next entry off the
> stack.

You could always stacke Net::FTP commands (which are mostly the same as
ftp commands anyway) and eval them.

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

use strict;
use Net::FTP;

my $ftp;
my @files;

while(<DATA>) {
    eval $_;
}

$" = "\n";
print "@files\n";

__END__
$ftp = Net::FTP->new('host', Debug => 1) or die "Can't connect:  $!\n";
$ftp->login('login', 'passwd') or die "Can't login:  $!\n";
@files = $ftp->ls('.')
$ftp->quit;

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Sun, 24 Jan 1999 16:50:28 -0500
From: "The Smiths" <smiths@erols.com>
Subject: Re: Trying to automate FTP
Message-Id: <78g43s$kg9$1@winter.news.rcn.net>


Jonathan Feinberg wrote in message ...
>You're assuming that everything works.

I agree that this is not the best approach.  In fact, I already wrote and
tested my script with Net::FTP from my server (Win32, ActiveState).
However, when I run it in my hosted shell account, it croaks with:

Can't locate NET/FTP.pm in @INC (@INC contains:
/usr/local/lib/perl5/i386-freebs
d/5.00404 /usr/local/lib/perl5 /usr/local/lib/perl5/site_perl/i386-freebsd
/usr/local/lib/perl5/site_perl .) at stats.pl line 3.

If I have everything set up correctly (I'm learning as I go) and this is
really what is going on, then I rather doubt that they will install a
package just for me.

Thus, the desire for an alternative... Tim.






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

Date: Sun, 24 Jan 1999 17:01:53 -0500
From: Steve Palincsar <palincss@his.com>
Subject: Re: Trying to automate FTP
Message-Id: <36AB9851.21E10202@his.com>

The Smiths wrote:
> 
> Jonathan Feinberg wrote in message ...
> >You're assuming that everything works.
> 
> I agree that this is not the best approach.  In fact, I already wrote and
> tested my script with Net::FTP from my server (Win32, ActiveState).
> However, when I run it in my hosted shell account, it croaks with:
> 
> Can't locate NET/FTP.pm in @INC (@INC contains:
> /usr/local/lib/perl5/i386-freebs
> d/5.00404 /usr/local/lib/perl5 /usr/local/lib/perl5/site_perl/i386-freebsd
> /usr/local/lib/perl5/site_perl .) at stats.pl line 3.
> 
> If I have everything set up correctly (I'm learning as I go) and this is
> really what is going on, then I rather doubt that they will install a
> package just for me.

So install it yourself in yourown space, and use "use libs" to
add
your space to the @INC search path.  Check out Randal's columns -
the one in which he presents the program to create a what's-new
file
for his web site illustrates this technique.

You might just also try asking your ISP to add this module. 
What's
the worst they could do?  Say no?


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

Date: 24 Jan 1999 23:51:18 +0100
From: Jonathan Feinberg <jdf@pobox.com>
To: "The Smiths" <smiths@erols.com>
Subject: Re: Trying to automate FTP
Message-Id: <m3yamsl1y1.fsf@joshua.panix.com>

"The Smiths" <smiths@erols.com> writes:

> Jonathan Feinberg wrote in message ...
> >You're assuming that everything works.
> 
> I agree that this is not the best approach. 

My response doesn't touch on whether or not your approach is good
overall.  I simply meant literally that, by not checking the return
value of system calls, you're assuming that nothing ever fails.
That's suicidal.

   open(SOME_PROCESS, "| /bin/foo") || die $!;

Do read perlipc.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Sun, 24 Jan 1999 15:18:32 -0500
From: "Allan M. Due" <allan@due.net>
Subject: Re: Trying to change a line in a file
Message-Id: <afLq2.394$WR1.3750@nntp1.nac.net>

THE Groovy wrote in message <19990123223134.09864.00001849@ng-cd1.aol.com>...
:I am making a script that has several users, all with ID's (starting with 1
and
:going up) and each ID has a line in a file that logs hits to an area with
their
:ID. The hit file is in the format ID|TotalHits\n. When there is another hit
for
:someone with an ID, I want it to add 1 to the Total Hits for that user. I was
:trying to do it with the splice function,

Splice?  Here?  Are you trying to make this as complicated as possible? <g>

:but couldn't find enought information
:on it. Here is the code I have, which doesn't work :-).
:open (HITS,"hits.log");

Always, always check the return value from your open and close statements.

open (HITS,"hits.log") or die "An ugly death trying to open hits.log because:
$!\n";

:@hits=<HITS>;
:close(HITS);

Ditto here.

:foreach $reseller (@hits) {
: $reseller =~ s/\n//g;


chomp is better.

: @reseller_info = split(/\|/, $reseller);


Good, you avoided the common mistake of not escaping the | symbol here.

: if ($reseller_info[0] == "$idnumber") {
: $hits = $reseller_info[1];
: $new_hits = $hits++;
: $new_info =~ s/$idnumber|$hits/$idnumber|$new_hits\n/;


That is not a pretty line.  First, you forgot to escape the pipe.  So your
code says substitute $idnumber *or* $hits with $idnumber|$new_hits using the
string $new_info.  But where did $new_info get any data to be substituted?

: open (HITS,"hits.log");

I don't really like the idea of opening the file inside the if but may just be
me.  You forget to check the open again.  And then, are you thinking about
writing to the file this time?  If so you forgot something.
open (HITS,">hits.log") or die "young trying to open hits.log for output
because $!\n";

: s/$reseller/$new_info/g;

Now what is that supposed to do?  There really isn't any $_ to be working on.

: close(HITS);

So we opened and closed the file without doing anything to it.  No data read
in, no data written out. Not good.
:
:Any ideas on why it won't add 1 to the total hit count?


Some ideas.  Open your file and read your data into a hash, key => id and
value => hits.  Close the file.  Next, increment the hash value for $idnumber.
Open the file for output and write out your new data.  Then close.  As another
alternative, read the FAQ on editing a file in place.  Read up on hashes, file
locking, next and last.

One quick little example of an approach you might try to get you started.  One
advantage is that it works fine for new ids as well.
#!/usr/local/bin/perl -w
use strict;

my @array = <DATA>;
my ($foo,$bar,%hash);

foreach (@array){
    chomp;
    ($foo,$bar) = split /\|/;
    $hash{$foo} = $bar;
}
my $idnum = '123';
$hash{$idnum}++;

$new_idnum = '222';
$hash{$new_idnum}++;

foreach my $key (keys %hash) {
    print "$key|$hash{$key}\n";
}

__DATA__
123|1
345|4
567|3

prints
567|3
345|4
222|1
123|2

Of course, TIMTOWTDI.  Different conditions warrent different approaches.

HTH

AmD




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

Date: Sun, 24 Jan 1999 13:58:37 -0600
From: Joe Laffey <joe@laffeycomputer.com>
Subject: Re: using search pattern
Message-Id: <Pine.LNX.4.05.9901241355020.13472-100000@tripe.laffeycomputer.com>

On Sun, 24 Jan 1999, brettr wrote:

> How would I extract the last.html file from the string below?
> 
> /dir/dir/last.html


$my_String = /dir1/dir2/last.html;

$my_rev_string = reverse $my_string;

$my_rev_string =~ m/^([\w_\.]+)\//;

$my_filename = reverse $1;


Something like that would probably work. Note that only allows word chars,
underscores, and periods... Of course \w may cover underscore too, without
the need for the underscore.


Joe Laffey
LAFFEY Computer Imaging
St. Louis, MO
http://www.laffeycomputer.com/
 ------------------------------



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

Date: 24 Jan 1999 21:38:31 +0100
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: using search pattern
Message-Id: <m31zkkmmns.fsf@joshua.panix.com>

Joe Laffey <joe@laffeycomputer.com> writes:

> On Sun, 24 Jan 1999, brettr wrote:
> 
> > How would I extract the last.html file from the string below?
> > 
> > /dir/dir/last.html
> 
> 
> $my_String = /dir1/dir2/last.html;
> $my_rev_string = reverse $my_string;
> $my_rev_string =~ m/^([\w_\.]+)\//;
> $my_filename = reverse $1;

Is it April already?

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

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

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