[10244] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3837 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 27 15:07:17 1998

Date: Sun, 27 Sep 98 12:00:25 -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           Sun, 27 Sep 1998     Volume: 8 Number: 3837

Today's topics:
    Re: <*> in cgi (I R A Aggie)
        A CGI question about Linux + Apache chifuwang@my-dejanews.com
    Re: A CGI question about Linux + Apache <gellyfish@btinternet.com>
    Re: Best Editor for Perl (under WinNT4) - Syntax Colori (Gene Senyszyn)
        Converting fixed length ascii to pipe delimited <arm@home.com>
        DBI/mysql <dpuryear@usa.net>
    Re: Double-Quotes in Procedure "System" (Mike Stok)
    Re: Double-Quotes in Procedure "System" (Larry Rosler)
    Re: How to read contents of all *.TXT files in director (Gary L. Burnore)
    Re: How to read contents of all *.TXT files in director <gellyfish@btinternet.com>
    Re: How to read contents of all *.TXT files in director (Gary L. Burnore)
    Re: How Too??  File Copy from 1 server to the scripts s <admin@hatsoft.com>
    Re: How Too??  File Copy from 1 server to the scripts s <gellyfish@btinternet.com>
    Re: How Too??  File Copy from 1 server to the scripts s <admin@hatsoft.com>
        just to show you how screwed up the server is... <caustic@causticinteractive.nospam.com>
        perl objects and embedding a hash (JElli23052)
    Re: perl objects and embedding a hash (David A. Black)
    Re: perl objects and embedding a hash <ajs@ajs.com>
    Re: POLL: Perl features springing into your face (Ilya Zakharevich)
        reducing a variable <rob@acc7.ac.cc.md.us>
    Re: reducing a variable (Allan M. Due)
    Re: reducing a variable (Mike Stok)
        Using fork to connect with multiple remote files <jamber@netspun.com>
    Re: Using fork to connect with multiple remote files <ajs@ajs.com>
    Re: using grep to snag patterns from another file <caustic@causticinteractive.nospam.com>
    Re: using grep to snag patterns from another file <gellyfish@btinternet.com>
    Re: using grep to snag patterns from another file <caustic@causticinteractive.nospam.com>
    Re: using grep to snag patterns from another file (Larry Rosler)
    Re: using grep to snag patterns from another file (Larry Rosler)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Sun, 27 Sep 1998 12:54:13 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: <*> in cgi
Message-Id: <fl_aggie-2709981254130001@aggie.coaps.fsu.edu>

In article <360de0cc.0@news.greatbasin.net>, "Henry Wolff"
<admin@hatsoft.com> wrote:

+ Something to the effect of:
+ 
+  $dir = "textfiles";
+  opendir(DH,$dir);
+  @textfiles = readdir(DH);

   @textfiles = grep /\.txt$/, readdir(DH); # if you want to be more explicit

+  closedir(DH);

James


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

Date: Sun, 27 Sep 1998 16:01:32 GMT
From: chifuwang@my-dejanews.com
Subject: A CGI question about Linux + Apache
Message-Id: <6ulngs$ru9$1@nnrp1.dejanews.com>

Hi, friends:
!@!@I just installed REDHAT 5.1, and my objective is to test my perl CGI
scripts by using localhost. Redhat 5.1 installed Apache 1.2.6 to my Linux
system, and put perl to /usr/bin/ directory. Below is some information in my
Apache conf files:
     ServerRoot /etc/httpd
     DocumentRoot /home/httpd/html
     ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/

     In access.conf:
     <Directory /home/httpd/cgi-bin>
     AllowOverride All
     Options ExecCGI
     Order allow,deny
     Allow from all
     </Directory>

    I followed a book to type a simple perl CGI script, the code is:

    #!/usr/bin/perl
    print "Content-type: text\html\n\n";
    print "<H1>Simple CGI Script</H1>\n";
    print "This is my first CGI script!\n";

    I saved this code as "test.cgi" file, and used "chmod755 test.cgi". Then I
put the file into the directory /home/httpd/cgi-bin/.
    However, when I used Netscape to open http://localhost/cgi-bin/test.cgi,
the message showed up:

    "Internal Server Error: The server encountered an internal error or
misconfiguration and was unable to complete your request. ..."

    I do not understand why my script can not run. Please help me to
locate and solve the problem. Thank you very much.

Jeff Wang

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 27 Sep 1998 18:28:42 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: A CGI question about Linux + Apache
Message-Id: <6um04q$bjm$1@gellyfish.btinternet.com>

On Sun, 27 Sep 1998 16:01:32 GMT chifuwang@my-dejanews.com wrote:
> Hi, friends:
> !@!@I just installed REDHAT 5.1, and my objective is to test my perl CGI
> scripts by using localhost. Redhat 5.1 installed Apache 1.2.6 to my Linux
> system, and put perl to /usr/bin/ directory. Below is some information in my
> Apache conf files:

<snip Apache details>

>     #!/usr/bin/perl
>     print "Content-type: text\html\n\n";
>     print "<H1>Simple CGI Script</H1>\n";
>     print "This is my first CGI script!\n";

>     I saved this code as "test.cgi" file, and used "chmod755 test.cgi". 
> Then I put the file into the directory /home/httpd/cgi-bin/.
>     However, when I used Netscape to open http://localhost/cgi-bin/test.cgi,
> the message showed up:

>     "Internal Server Error: The server encountered an internal error or
> misconfiguration and was unable to complete your request. ..."

This message usually means that your script has failed in some manner -
you should look at the servers error log (/var/log/httpd/error_log on my
system) to get more detail.

However except for the typo in the Content-type header (it should be
text/html not text\html) which isnt fatal just confusing to a browser
this script works fine here - I could have told that by looking at it
but tried anyhow.

>     I do not understand why my script can not run. Please help me to
> locate and solve the problem. Thank you very much.

If your script is as you describe then I think that you should be looking
at the configuration of your server - which isnt within the scope of this
group.  You might try comp.infosystems.www.servers.unix or preferably its
FAQ.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>


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

Date: Sun, 27 Sep 1998 18:03:12 GMT
From: scatt@goes.com (Gene Senyszyn)
Subject: Re: Best Editor for Perl (under WinNT4) - Syntax Coloring ?
Message-Id: <360e7d83.84028596@news.goes.com>


I like Perl Builder. It does syntax highlighting, debugging, and has a
CGI wizard which will allow you to test your CGI scripts locally
without a web server. Its not free, though. :(


http://www.solutionsoft.com

On Sat, 26 Sep 1998 17:55:01 GMT, alec@venus.co.uk (Alec Stewart)
wrote:

>
>Hi,
>
>Can anyone recommend a decent Editor for Perl (5) ?
>- Ideally something with Syntax Coloring 
>(like KEDIT seems to do for other languages...)
>
>
>I am running under WinNT 4 (SP3).
>
>
>
>Yrs
>
>
>Alec
>
>
>



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

Date: Sun, 27 Sep 1998 18:57:02 GMT
From: Alan Melton <arm@home.com>
Subject: Converting fixed length ascii to pipe delimited
Message-Id: <360E88FB.9600899F@home.com>

ASCII Datafile (fixed length)

AE   2102   A    KAMAT       REQ CRANDALL    INTRODUCTION TO THE
MECHANICS   0-07-013441-3
AE   2102   A    KAMAT       REQ GERE        MECHANICS OF
MATERIALS          0-534-93429-3
AE   2350   A    MAVRIS      REQ SHEVELL     FUNDAMENTALS OF
FLIGHT          0-13-339060-8
AE   2604   A    RUFFIN      REQ ETTER       ENGINEERING PROB
SOLV           0-13-397688-2
AE   2604   A    RUFFIN      REQ ORVIS       EXCEL FOR
SCIENTISTS            0-7821-1761-9
AE   3003   A    SANKAR      REQ ANDERSON    FUNDAMENTALS OF
AERODYNAMICS    0-07-001679-8
AE   3004   A    STAFF       REQ JOHN        GAS
DYNAMICS                    0-205-08014-6
AE   3106   A    CRAIG       REQ MEGSON      AIRCRAFT
STRUCTURES             0-470-21653-0
AE   3501   A    CALISE      REQ DORF        MODERN CONTROL
SYSTEMS          0-201-30864-9
AE   3501   A    CALISE      REQ BISHOP,R.H. MODERN CONTROLS
DESIGN          0-220-49846-4
AE   4001   A    SMITH       REQ ANDERSON    FUNDAMENTALS OF
AERODYNAMICS    0-07-001679-8

Would like help to convert this to:

AE|2102|A|KAMAT|REQ|CRANDALL|INTRODUCTION TO THE
MECHANICS|0-07-013441-3|
AE|2102|A|KAMAT|REQ|GERE|MECHANICS OF MATERIALS|0-534-93429-3|

and also if possible to be able to change file so that it comes out

NAME=AE|CAT=2102|SEC=A|AUTH=KAMAT|  etc

then write this to a new file.

Thanks for any help
Alan Melton


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

Date: Sun, 27 Sep 1998 11:24:34 -0500
From: Dustin Puryear <dpuryear@usa.net>
Subject: DBI/mysql
Message-Id: <360E66C2.E9DB2655@usa.net>

How do I *create* a table in a database using DBI? I read the DBI
info. and couldn't find it. I tried to create a program, taken from the
documentation, but it doesn't work. ANY help would be appreciated since
I can't find _any_ information on how to create a table rather than
retrieve information from one. Please email a copy of your reply, if
possible, because my access to a news server is only 1 to 2 days a week.

Regards, Dustin

P.S. I have include the create.pl program I was using to setup the
table. Of course, I get an error that the table (the file really)
doesn't exist.

#!/usr/bin/perl -w

# ---
# Author: Dustin Puryear
# Project: learning sql/dbi
# File: create.pl
# ----

use DBI;
use strict;

# ###
# main
# ###

print "I'm learning SQL/DBI, so hang on!\n";
print "Create the name, phone table.\n\n";

# ---
# print out driver/database information
# ---

# $driver           our DBI driver
# @drivers          array of DBI drivers available
# @databases        array of databases available from our server
# $str

my($driver)    = "mysql";
my(@drivers)   = DBI->available_drivers;
my(@databases) = DBI->data_sources($driver);
my($str);

print "Checking out our system...\n";

$str = DBI::neat_list(\@drivers);
print "Database drivers available: $str\n";
$str = DBI::neat_list(\@databases);
print "Databases available: $str\n";
print "\n";

# ---
# connect to the database server
# ---

my($dbh) = DBI->connect('DBI:mysql:test:localhost', '', '', 'mysql', 
			{RaiseError => 1});
die "Database error: $DBI::errstr\n" if (!$dbh);

# ---
# insert the data
# ---

# $sth        statement handle
# IN          our file handle (contains name, phone values)

my($sth);
my($IN);

# prepare our SQL statement
$sth = $dbh->prepare(q{INSERT INTO phonetbl (name, phone) VALUES (?,
?)});

# open our (name, phone) list and load into the table
open IN, "phone.lst" or die "Can't open phone.lst!\n";
while (<IN>) 
{
    chop;
    my ($name, $phone) = split /,/;
    $sth->execute($name, $phone)
}    
close IN;

# ---
# close our session and exit
# ---

$dbh->disconnect;
exit;


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

Date: 27 Sep 1998 16:29:33 GMT
From: mike@mike.stok.co.uk (Mike Stok)
Subject: Re: Double-Quotes in Procedure "System"
Message-Id: <6ulp5d$s1v@news-central.tiac.net>

In article <6ullos$kba$1@tempo.news.iphil.net>,
Benjamin <bench@surfshop.net.ph> wrote:
>How can I pass a quoted string i.e. "This is a subject" in the Perl
>procedure 'system'.  I'm trying to use this in passing a parameter
>in-quotes to 'metasend' program (-s option).
>
>A simple way of testing this is by making a script with the '/bin/echo
>$subject', and assuming that variable $subject="This is a subject".  The
>script should display "This is a subject" (that is, with double-quotes)
>instead of just This is a subject, with no double-quotes.

Do you understand what you're trying to do (That's not meant to be
facetious or rude.)?

Usually when you have to put an argument in double quotes on the command
line you're making the shell not use some of the spaces as argunebt
separators, so

  prog -s "hello there"

passes 2 arguments to prog, -s and the 11 character string hello there.

This can be achieved in perl by saying

  system 'prog', '-s', 'hello there';

which doesn't invoke a subshell.  The documentation for system should
explain it in more detail.

If you want the program to get the double quotes too then

  system 'prog', '-s', '"hello there"';

will wrap the 2nd argument to prog in double quotes.

Hope this helps,

Mike


-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Sun, 27 Sep 1998 10:35:00 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Double-Quotes in Procedure "System"
Message-Id: <MPG.1078171ef3e1e2d998988c@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <6ullos$kba$1@tempo.news.iphil.net> on Sun, 27 Sep 1998 
23:22:40 +0800, Benjamin <bench@surfshop.net.ph> says...
> How can I pass a quoted string i.e. "This is a subject" in the Perl
> procedure 'system'.  I'm trying to use this in passing a parameter
> in-quotes to 'metasend' program (-s option).
> 
> A simple way of testing this is by making a script with the '/bin/echo
> $subject', and assuming that variable $subject="This is a subject".  The
> script should display "This is a subject" (that is, with double-quotes)
> instead of just This is a subject, with no double-quotes.

In addition to Mike Stok's suggestion (split up the 'system' 
arguments and enclose the double-quotes in single-quotes), there are 
other approaches if you want the double-quotes to appear in a double-
quoted string (for example, if there are other variables to interpolate 
conveniently:

  system "metasend -s \"This is a subject\" $bar";

or (far better):

  system qq{metasend -s "This is a subject" $bar};

You should read "Quote and Quote-like Operators" in perlop.

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


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

Date: Sun, 27 Sep 1998 16:15:36 GMT
From: gburnore@databasix.com (Gary L. Burnore)
Subject: Re: How to read contents of all *.TXT files in directory into one file?
Message-Id: <360e6444.8068433@nntpd.databasix.com>

On Sun, 27 Sep 1998 11:26:09 EDT, in article
<6ulleh$388$1@earth.superlink.net>, dblack@saturn.superlink.net (David A.
Black) wrote:

>Hello -
>
>gburnore@databasix.com (Gary L. Burnore) writes:
>
>>On Sun, 27 Sep 1998 09:28:05 EDT, in article
>><6uleh5$g39$1@earth.superlink.net>, dblack@saturn.superlink.net (David A.
>>Black) wrote:
>
>>>bart.mediamind@ping.be (Bart Lateur) writes:
>>>
>>>>Michael Yevdokimov wrote:
>>>
>>>>>
>>>>>How to read contents of all *.TXT files in directory into one file using
>>>>>Perl?
>>>
>>>>perl -p *.TXT >output.all
>>>
>>>>Yup, this is a command line. No script necessary.
>>>
>>>Or the ever popular:
>>>
>>>perl -e 'exec "cat *.TXT > output.all"'
>>>
>
>>If you're going to use a shell command, why not just cat?
>
>>cat *.txt > output.all
>
>Well, yeah, that was the point of the joke (you left out the :-) in
>quoting me) 

Yes, I did. Sorry. 

>- the original author had stipulated a solution "using Perl".

Which is actually why I asked. I've seen many times where people ask for and
or use perl for things that seem better suited for an existing command.
-- 
      I DO NOT WISH TO RECEIVE EMAIL IN REGARD TO USENET POSTS
---------------------------------------------------------------------------
                  How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore                       |  ][3:]3^3:]33][:]3^3:]3]3^3:]3]][3
                                      |  ][3:]3^3:]33][:]3^3:]3]3^3:]3]][3
DOH!                                  |  ][3:]3^3:]33][:]3^3:]3]3^3:]3]][3
                                      |  ][3 3 4 1 4 2  ]3^3 6 9 0 6 9 ][3
Special Sig for perl groups.          |     Official Proof of Purchase
===========================================================================


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

Date: 27 Sep 1998 17:02:10 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: How to read contents of all *.TXT files in directory into one file?
Message-Id: <6ulr2i$b4f$1@gellyfish.btinternet.com>

On Sun, 27 Sep 1998 13:50:52 GMT Gary L. Burnore <gburnore@databasix.com> wrote:
> On Sun, 27 Sep 1998 09:28:05 EDT, in article
> <6uleh5$g39$1@earth.superlink.net>, dblack@saturn.superlink.net (David A.
> Black) wrote:

>>bart.mediamind@ping.be (Bart Lateur) writes:
>>
>>>Michael Yevdokimov wrote:
>>
>>>>
>>>>How to read contents of all *.TXT files in directory into one file using
>>>>Perl?
>>
>>>perl -p *.TXT >output.all
>>
>>>Yup, this is a command line. No script necessary.
>>
>>Or the ever popular:
>>
>>perl -e 'exec "cat *.TXT > output.all"'
>>

> If you're going to use a shell command, why not just cat?

> cat *.txt > output.all

However on examination of the original posters headers:

> X-Newsreader: Microsoft Outlook Express 4.72.2106.4
> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4

I think that he'll probably want:

C:\> copy *.txt output.all

;-}

However he did say he wanted do it with Perl so that'll be

C:\> perl -e"system('copy *.txt output.all')"

But thats just silly.

I just heard on the Radio:

"Perl goes from playground to playground"

But on examination of the Guide I discover its Pearl.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>


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

Date: Sun, 27 Sep 1998 17:07:12 GMT
From: gburnore@databasix.com (Gary L. Burnore)
Subject: Re: How to read contents of all *.TXT files in directory into one file?
Message-Id: <360f7070.11184686@nntpd.databasix.com>

On 27 Sep 1998 17:02:10 -0000, in article
<6ulr2i$b4f$1@gellyfish.btinternet.com>, Jonathan Stowe
<gellyfish@btinternet.com> wrote:

>On Sun, 27 Sep 1998 13:50:52 GMT Gary L. Burnore <gburnore@databasix.com> wrote:
>> On Sun, 27 Sep 1998 09:28:05 EDT, in article
>> <6uleh5$g39$1@earth.superlink.net>, dblack@saturn.superlink.net (David A.
>> Black) wrote:
>
>>>bart.mediamind@ping.be (Bart Lateur) writes:
>>>
>>>>Michael Yevdokimov wrote:
>>>
>>>>>
>>>>>How to read contents of all *.TXT files in directory into one file using
>>>>>Perl?
>>>
>>>>perl -p *.TXT >output.all
>>>
>>>>Yup, this is a command line. No script necessary.
>>>
>>>Or the ever popular:
>>>
>>>perl -e 'exec "cat *.TXT > output.all"'
>>>
>
>> If you're going to use a shell command, why not just cat?
>
>> cat *.txt > output.all
>
>However on examination of the original posters headers:
>
>> X-Newsreader: Microsoft Outlook Express 4.72.2106.4
>> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
>
>I think that he'll probably want:
>
>C:\> copy *.txt output.all
>
>;-}

Were it not a "joke" it'd be odd to assume that someone's method of posting
reflects the os on which one uses perl.  I post through agent but don't use a
windblows copy of perl.

>
>However he did say he wanted do it with Perl so that'll be
>
>C:\> perl -e"system('copy *.txt output.all')"
>
>But thats just silly.

Yup. :)

>
>I just heard on the Radio:
>
>"Perl goes from playground to playground"
>
>But on examination of the Guide I discover its Pearl.

How does a pearl go from playground to playground? :)
-- 
      I DO NOT WISH TO RECEIVE EMAIL IN REGARD TO USENET POSTS
---------------------------------------------------------------------------
                  How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore                       |  ][3:]3^3:]33][:]3^3:]3]3^3:]3]][3
                                      |  ][3:]3^3:]33][:]3^3:]3]3^3:]3]][3
DOH!                                  |  ][3:]3^3:]33][:]3^3:]3]3^3:]3]][3
                                      |  ][3 3 4 1 4 2  ]3^3 6 9 0 6 9 ][3
Special Sig for perl groups.          |     Official Proof of Purchase
===========================================================================


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

Date: Sun, 27 Sep 1998 09:48:35 -0700
From: "Henry Wolff" <admin@hatsoft.com>
Subject: Re: How Too??  File Copy from 1 server to the scripts server
Message-Id: <360e6c0c.0@news.greatbasin.net>

I think I finally found it. There is a File::Copy module.

Now I just got to get the sys admin to install it.

Henry Wolff
Send Some Virtual Postcards - FREE
http://www.hatsoft.com/webcard/index.html






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

Date: 27 Sep 1998 19:06:50 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: How Too??  File Copy from 1 server to the scripts server
Message-Id: <6um2cb$bo9$1@gellyfish.btinternet.com>

On Sun, 27 Sep 1998 09:48:35 -0700 Henry Wolff <admin@hatsoft.com> wrote:
> I think I finally found it. There is a File::Copy module.

Hang on there - if things are as you describe in your original post then
this just ain't gonna work.  File::Copy does just what it says - It can
copy files from one place to another on your local filesystems or from or
to a mounted network filesystem (NFS,SMB,NetWare etc) however it doesnt
work with HTTP which is not designed for that purpose. You will need to
use one of the LWP::* modules as I outlined in an earlier followup or some 
similar contrivance to retrieve the file via HTTP and save it locally.

> Now I just got to get the sys admin to install it.

If you are having problems on this score you should read perlfaq8:

  "How do I keep my own module/library directory"

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>


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

Date: Sun, 27 Sep 1998 11:37:57 -0700
From: "Henry Wolff" <admin@hatsoft.com>
Subject: Re: How Too??  File Copy from 1 server to the scripts server
Message-Id: <360e85ac.0@news.greatbasin.net>

Yep,  File::Copy is localhost only...
But Image::Grab worked just fine.

Henry Wolff
Send Some Virtual Postcards - FREE
http://www.hatsoft.com/webcard/index.html





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

Date: Sun, 27 Sep 1998 13:21:42 -0400
From: "caustic" <caustic@causticinteractive.nospam.com>
Subject: just to show you how screwed up the server is...
Message-Id: <356c5b2d.0@newsprime.tidalwave.net>

i tried out a sample script before using the headlines code:

#!/usr/bin/perl
   print ("hello world!\n");

and i received an 'internal server error'.

then i tried execing the script from the location bar in my browser, then i
even tried using a SSI <!--#exec cgi="/cgi-bin/headlines"-->

and nothing happens!  :)

i know that perl scripts work because i've got a customized version of
wwwboard and mailform.

very bizarre.

keith.





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

Date: 27 Sep 1998 17:31:37 GMT
From: jelli23052@aol.com (JElli23052)
Subject: perl objects and embedding a hash
Message-Id: <19980927133137.13013.00000174@ng09.aol.com>


I have been working with perl objects for a few weeks.  I would like to add a
hash as a member variable(not global).  for example:

sub new {

      my $this ={};                               # initialize object "hash"
     $this->{NewMemberHash}={};        #initialize member variable hash

      bless($this);
      return $this;

} # end sub new

I would like to know how to access this hash using two public methods, GetHash
and SetHash.

Please advise.

Thanks,

John Elliott


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

Date: Sun, 27 Sep 1998 14:38:12 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: perl objects and embedding a hash
Message-Id: <6um0mk$shj$1@earth.superlink.net>

Hello -

jelli23052@aol.com (JElli23052) writes:


>I have been working with perl objects for a few weeks.  I would like to add a
>hash as a member variable(not global).  for example:

>sub new {

>      my $this ={};                               # initialize object "hash"
>     $this->{NewMemberHash}={};        #initialize member variable hash

>      bless($this);
>      return $this;

>} # end sub new

>I would like to know how to access this hash using two public methods, GetHash
>and SetHash.


The hash reference is instance data, so you can return it or, since it's
a hash reference, do things with it.  Here's a small working example:

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

package HashPack;
sub new { bless { newmemberhash => {} }, shift }

sub gethash {
   my ($self, $key) = @_;
   return $self{newmemberhash}{$key};
}

sub sethash {
   my ($self, %h) = @_;
   while (($k,$v) = each %h) {
      $self{newmemberhash}{$k} = $v
   }
}


my $w = new HashPack;

$w->sethash( qw(one i two ii three iii) );

print $w->gethash('one');

__END__



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

Date: Sun, 27 Sep 1998 14:52:19 -0400
From: Aaron Sherman <ajs@ajs.com>
To: JElli23052 <jelli23052@aol.com>
Subject: Re: perl objects and embedding a hash
Message-Id: <360E8963.F3963A4@ajs.com>

JElli23052 wrote:
[snip!]
> I would like to know how to access this hash using two public methods, GetHash
> and SetHash.

You want to run (don't walk) out to buy the Perl Cookbook, and look at
section 13.3, specifically page 452.

You have thrown in the wrench that you want to manipulate a hash as an
instance variable, but that's not big magic. Here's an example of hash
manipulation, which you should be able to extend to your object.

$hash = {};
$hash->{subhash} = {};
$subhash = $hash->{subhash};
$hash->{subhash} = $subhash;
$subhash->{foo} = 1;
print keys %{$hash->{subhash}};

If none (or very little) of that makes sense to you, I also recommend
section 11.3, pp. 373.


-- 
Aaron Sherman			Safety Net Solutions
ajs@ajs.com			Senior Perl Snob (and bottle-washer)
www.ajs.com/~ajs		finger ajskey@lorien.ajs.com


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

Date: 27 Sep 1998 14:31:25 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: POLL: Perl features springing into your face
Message-Id: <6uli7t$q8d$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Thomas A. Horsley
<Tom.Horsley@worldnet.att.net>],
who wrote in article <uu31u24jo.fsf@worldnet.att.net>:
> >   c) difference in scope of my and local, of if and when
> 
> I think I'd restate this one a bit as:
> 
>     use of "my" outside of a subroutine (inside a routine, it makes
>     just about infinitely more sense to use my than local, outside of
>     a routine, I don't know what good either of them are :-).

Do not follow you.  Do you want to prohibit lexicals at toplevel
scope, or what?  If yes, why?  And how is this a restate of
life-time-of-emporaries issues?

> Another one I'd add to the list is:
> 
>     Use of nested subs. They don't have proper "lexical" nesting
>     (perl doesn't pass static links around), so what they are is really
>     some sort of useless nonsense that can only cause trouble (not
>     to mention making it next to impossible to define "proper" nested
>     routines someday due to backwards compatibility issues).

Hmm, yea.  Do not know: nested subs, are they good for anything?  I
did not see any meaningful usage, but maybe there is?

> While we're talking about pet peeves, I'd also add:
> 
>     barewords - if you want a quoted string, for gosh sakes put $#@!
>     quotes around it!

Definitely I like barewords where they are unambiguous: in ->{foo},
foo => and `use foo'.  A list of places where they should be allowed
should be created.

And yesterday, tracing an obscure bug in my tool written many years
ago (tex2mail): 

  x) If it looks like a block, it should behave like a block.
     In particular, prohibit label-less last/next/redo if they are
     immediately inside something which looks like a block, but is
     not: 

	  if (FOO) {NONBLOCK}
	  do {NONBLOCK}

     etc. come to mind.

Ilya


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

Date: Sun, 27 Sep 1998 12:08:06 -0400
From: Rob <rob@acc7.ac.cc.md.us>
Subject: reducing a variable
Message-Id: <360E62E6.4030@acc7.ac.cc.md.us>

Hi, I'm very new to perl as I'm sure you see by the following code
segment. I've been trying to shorten the variable $lname to 8 characters
and move that result to $sname and then print it to a file. I've tried
the following code several different ways but it either doesn't reduce
$lname at all or reduces it to nothing. Also, when I write to the file
it will write the first part but not the variable.  Any help would be
greatly appreciated because I told the boss that I would have it
finished by Monday %^)

$_ = $lname;
$cnt = length($_);
while ($cnt > 8)
{
   tr/a-z//d;
   $cnt = length($cnt);
}
$sname = $_;
print OUT "set INETSNAME=$sname\n";

Thanks in advance
Rob


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

Date: 27 Sep 1998 16:36:20 GMT
From: Allan@Due.net (Allan M. Due)
Subject: Re: reducing a variable
Message-Id: <6ulpi4$hkl$0@206.165.146.62>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <360E62E6.4030@acc7.ac.cc.md.us>, Rob (rob@acc7.ac.cc.md.us) 
posted...
|Hi, I'm very new to perl as I'm sure you see by the following code
|segment. I've been trying to shorten the variable $lname to 8 characters
|and move that result to $sname and then print it to a file. I've tried
|the following code several different ways but it either doesn't reduce
|$lname at all or reduces it to nothing. Also, when I write to the file
|it will write the first part but not the variable.  Any help would be
|greatly appreciated because I told the boss that I would have it
|finished by Monday %^)
|
|$_ = $lname;
|$cnt = length($_);
|while ($cnt > 8)
|{
|   tr/a-z//d;
|   $cnt = length($cnt);
|}
|$sname = $_;
|print OUT "set INETSNAME=$sname\n";
|
|Thanks in advance
|Rob
|

Hmm, lets do this the easy way. You want a substr here:

$lname = '123456789abcd';
$sname= substr($lname,0,8);
print OUT "set INETSNAME=$sname\n";
-- 

__
Allan M. Due
Allan@Due.net

The beginning of wisdom is the definitions of terms.
- Socrates


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

Date: 27 Sep 1998 16:37:20 GMT
From: mike@mike.stok.co.uk (Mike Stok)
Subject: Re: reducing a variable
Message-Id: <6ulpk0$sd5@news-central.tiac.net>

In article <360E62E6.4030@acc7.ac.cc.md.us>, Rob  <rob@acc7.ac.cc.md.us> wrote:

>$_ = $lname;
>$cnt = length($_);
>while ($cnt > 8)
>{
>   tr/a-z//d;
>   $cnt = length($cnt);
>}
>$sname = $_;
>print OUT "set INETSNAME=$sname\n";

  $sname = $lname;
  $sname = substr ($sname, 0, 8) if length ($sname) > 8;

is one way of doing it, assuming $[ hasn't been touched.  Another way of
doing it might be to use printf

  printf OUT "set INETSNAME=%.8s\n", $lname;

Note that there's more than one way to do it in perl and there are many
other ways to achieve this result.

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Sun, 27 Sep 1998 17:16:24 GMT
From: Amber <jamber@netspun.com>
Subject: Using fork to connect with multiple remote files
Message-Id: <360E71F1.9CC690CF@netspun.com>

Hello,

I have had success with the following code to open a remote connection
and GET the contents of a file.

    #!/usr/bin/perl -w
    use IO::Socket;
    $host = "www.yahoo.com";
    $document = "/index.htm"
    $remote = IO::Socket::INET->new( Proto     => "tcp",
                                         PeerAddr  => $host,
                                         PeerPort  => 80,
                                        );
        unless ($remote) { die "cannot connect to http daemon on $host"
}
     $remote->autoflush(1);
     print $remote "GET $document HTTP/1.0\n\n";
     while ( <$remote> ) { print }
     close $remote;
    }




But I would like to keep the connection up and continue to GET other
files.  I have tried to use the following fork code but I'm not exactly
sure how to incorporate it.

#!/usr/bin/perl -w
    use strict;
    use IO::Socket;
    my ($host, $port, $kidpid, $handle, $line);

    unless (@ARGV == 2) { die "usage: $0 host port" }
    ($host, $port) = @ARGV;

    # create a tcp connection to the specified host and port
    $handle = IO::Socket::INET->new(Proto     => "tcp",
                                    PeerAddr  => $host,
                                    PeerPort  => $port)
           or die "can't connect to port $port on $host: $!";

    $handle->autoflush(1);              # so output gets there right
away
    print STDERR "[Connected to $host:$port]\n";

    # split the program into two processes, identical twins
    die "can't fork: $!" unless defined($kidpid = fork());

    # the if{} block runs only in the parent process
    if ($kidpid) {
        # copy the socket to standard output
        while (defined ($line = <$handle>)) {
            print STDOUT $line;
        }
        kill("TERM", $kidpid);                  # send SIGTERM to child
    }
    # the else{} block runs only in the child process
    else {
        # copy standard input to the socket
        while (defined ($line = <STDIN>)) {
            print $handle $line;
        }
    }


Help.  Any suggestions would be much appreciated.

Amber



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

Date: Sun, 27 Sep 1998 14:59:57 -0400
From: Aaron Sherman <ajs@ajs.com>
To: Amber <jamber@netspun.com>
Subject: Re: Using fork to connect with multiple remote files
Message-Id: <360E8B2D.98A31227@ajs.com>

Amber wrote:

> I have had success with the following code to open a remote connection
> and GET the contents of a file.
[...]
> But I would like to keep the connection up and continue to GET other
> files.  I have tried to use the following fork code but I'm not exactly
> sure how to incorporate it.

First off, you should check out libwwwperl, which is available from the
CPAN site near you (http://www.perl.com/CPAN/modules/by-module/WWW/).
This module will allow you to do something like this:

	use LWP::UserAgent;
	use HTTP::Request;
	my $ua = LWP::UserAgent->new();
	my $request = HTTP::Request->new("GET","http://www.yahoo.com/");
	my $result = $ua->request($request,10); # Timeout in 10 seconds
	print $result->as_string;
	$request = HTTP::Request->new("GET","http://www.redhat.com/");
	$result = $ua->request($request);
	print $result->as_string;

Second, HTTP does not "stay open" for multiple requests. You can request
"keep alive" which allows you to receive multiple responses on the same
connection (e.g. an HTML page and all of it's graphics), but that's not
the same thing.

			-AJS

-- 
Aaron Sherman			Safety Net Solutions
ajs@ajs.com			Senior Perl Snob (and bottle-washer)
www.ajs.com/~ajs		finger ajskey@lorien.ajs.com


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

Date: Sun, 27 Sep 1998 12:11:37 -0400
From: "caustic" <caustic@causticinteractive.nospam.com>
Subject: Re: using grep to snag patterns from another file
Message-Id: <356c4ac0.0@newsprime.tidalwave.net>

>I'm not sure what you mean by that last sentence.  I don't know of very
>many program files that search themselves.


what i meant by that was that a string is pushed into the script and that is
searched.  instead of opening a file and then searching the contents of that
file.

i'm getting screwed up following the Llama book because it only discusses
searching a STDIN string.

>Anyway, can you post some (non-working) code so that we can see exactly
>what/where the problem is?


okay, i've got an open statement:

if (open(NEWS, "newsmain.html")) {
    $line = (NEWS);
}

and then i throw in my expression:

if ($line =~ \<headline>(.*)<\/headline>/i) {
    $headline = $1;
}


and then when i get to this point, i don't even know what to tell the
program to print.

my main problem is that i learn by example, i need to see something to
understand how it works, and since the books i'm looking through don't have
similar examples, i can't figure out how to piece my needs together.  damn
the right side of my brain...

oh, here's what newsmain.html looks like:

<html>
<head>
<title>
newsmain.html
</title>
</head>

<body>

<p>
<headline><b>Headline 1</b></headline><br>
dafkjlafj dlfjsdlf dkfjdlsfj dl kjlfjds fj ldfjldsfj dsfljsdlf
jasdflj ldf jdlsfjld ldfjlds jldjdfasdj ldjfdasj ldsfjal
</p>

<p>
<headline><b>Headline 2</b></headline><br>
dafkjlafj dlfjsdlf dkfjdlsfj dl kjlfjds fj ldfjldsfj dsfljsdlf
jasdflj ldf jdlsfjld ldfjlds jldjdfasdj ldjfdasj ldsfjal
</p>
<p>
<headline><b>Headline 3</b></headline><br>
dafkjlafj dlfjsdlf dkfjdlsfj dl kjlfjds fj ldfjldsfj dsfljsdlf
jasdflj ldf jdlsfjld ldfjlds jldjdfasdj ldjfdasj ldsfjal
</p>
<p>
<headline><b>Headline 4</b></headline><br>
dafkjlafj dlfjsdlf dkfjdlsfj dl kjlfjds fj ldfjldsfj dsfljsdlf
jasdflj ldf jdlsfjld ldfjlds jldjdfasdj ldjfdasj ldsfjal
</p>

</body>
</html>

thanks,

keith.





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

Date: 27 Sep 1998 17:54:35 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: using grep to snag patterns from another file
Message-Id: <6ulu4r$bc2$1@gellyfish.btinternet.com>

On Sun, 27 Sep 1998 10:53:33 -0400 caustic <caustic@causticinteractive.nospam.com> wrote:
> hi,

> i'm still having problems trying to get a script to pull lines out of a flat
> file.  and let me tell you, this has been exasperating.  i know that the
> script must be simple, but i've been working on this for 2 days now!

Eeh come on show us some code - we can only do just so much without it ;)

> the need:
> to create a script that searches "news.html" for every line that looks
> similar to the following:
> <headline><b>Headline 1</b></headline><br>

Despite the typo in my response to your previous post that seemed like
what you were looking for.

> and only prints the first 3 it finds (which would be the latest news).

> i can grep the file from the command line (grep headline news.html) but
> can't seem to get a regular expression to work in my perl script.
> everything i run across is directed to searching for a pattern within the
> same document, not an external one.

OK how about:


#!/usr/bin/perl

open(HEADLINES,"news.html") || die "etc ..\n";

@heads = grep { /headline/i && $count++ < 3 } <HEADLINES> ;

print @heads;

__END__

> any ideas?

use HTML::Parser - one day some twat is going to open you file
in Frontpage or worse (if such there is) and your page winds up like:


<HEADLINE>
<B><FONT SIZE="3">Headline 1</FONT></b>
</headline><br>
<headline><b>
Headline 2</b></headline><br>
<headline><B>Headline 3</b></headline
><br>
<hEADline> <b>Headline 4
</b>
</headline><BR>
<headline><b>Headline 5</b></headline><br>
<headline><b>Headline 6</b></headline><br>
<headline><b>Headline 7</b></headline><br>
<headline><b>Headline 8</b></headline><br>
<headline><b>Headline 9</b></headline><br>

and then the simple approach is broken.

What follows is a two minute hack that demonstrates what you
might do:

#!/usr/bin/perl

package NewsParse;

@ISA = qw(HTML::Parser);
require HTML::Parser;

$parser = new NewsParse;

$parser->parse_file("news.html");

sub start()
{
   my($self,$tag,$attr,$attrseq,$orig) = @_;
   
   if($tag eq "headline")
    {
     $in_headline++;
     $headlines_seen++;
    }
}

sub text()
{
   my ($self,$text) = @_;
   
   if ($in_headline && $headlines_seen < 4)
     {
       print $text;
     }
}


sub end()
{
   my ($self,$tag) = @_;
   
   $in_headline-- if ( $tag eq "headline" );
}

1;
__END__

There that wasnt so bad now was it ?

Now go and grab HTML::Parser from CPAN and read the docs -
you know it makes sense.

> thanks a ton,

Nay problem

> keith
> don't you just hate it when designers pretend to be programmers?

Yes, but on the other it might be worse when programmers start to
come over all omniscient and think they can do design ;-}

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>


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

Date: Sun, 27 Sep 1998 13:03:36 -0400
From: "caustic" <caustic@causticinteractive.nospam.com>
Subject: Re: using grep to snag patterns from another file
Message-Id: <356c56f1.0@newsprime.tidalwave.net>


>#!/usr/bin/perl
>
>open(HEADLINES,"news.html") || die "etc ..\n";
>
>@heads = grep { /headline/i && $count++ < 3 } <HEADLINES> ;
>
>print @heads;


EGADS!  that's great!  thank you SOOOO much.  :)

i was reluctant to start playing around with HTML::Parser because my hosting
service's CGI capabilities are sketchy and i didn't want to try dealing with
a module.

but i'll definitely look into it because it could solve some of my *other*
problems.  :)

thanks again,

keith.





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

Date: Sun, 27 Sep 1998 10:16:04 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: using grep to snag patterns from another file
Message-Id: <MPG.107812b088ce21be98988a@nntp.hpl.hp.com>

In article <356c4ac0.0@newsprime.tidalwave.net> on Sun, 27 Sep 1998 
12:11:37 -0400, caustic <caustic@causticinteractive.nospam.com> says...
 ... 
> if (open(NEWS, "newsmain.html")) {
>     $line = (NEWS);
> }

      $line = <NEWS>;

But that gets only one line.  You need to put it in a loop.

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


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

Date: Sun, 27 Sep 1998 10:25:16 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: using grep to snag patterns from another file
Message-Id: <MPG.107814d92d34b04d98988b@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <6ulu4r$bc2$1@gellyfish.btinternet.com> on 27 Sep 1998 
17:54:35 -0000, Jonathan Stowe <gellyfish@btinternet.com> says...
 ...
> @heads = grep { /headline/i && $count++ < 3 } <HEADLINES> ;

OK, so it is simple for the newbie.  But I hate reading the whole file 
after I've already got my desired three lines.

Extracted from perlfaq4:  "How can I tell whether an array contains a 
certain element?":
 ...
Please do not use 
    $is_there = grep $_ eq $whatever, @array;
 ...
 ... slow (checks every element even if the first matches), inefficient 
(same reason), ...
 
-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 12 Jul 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 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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