[11230] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4830 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 5 01:07:23 1999

Date: Thu, 4 Feb 99 22:00:20 -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           Thu, 4 Feb 1999     Volume: 8 Number: 4830

Today's topics:
    Re: Browser hangs using CGI.pm chad@vcn.net
    Re: can cgi(perl) do this? <jjarrett@ecpi.com>
        Caputuring output and return code (James Goodall)
        Changing Form Input via Perl Script/Mail Script tnova@riconnect.com
        Help on loading DBI statically <gjohn@crossland.com.au>
    Re: How do I get local IP Address ? (I R A Aggie)
    Re: How do I get local IP Address ? <m_ching@hotmail.com>
    Re: How to replace text in a text file. chad@vcn.net
    Re: How to replace text in a text file. chad@vcn.net
        join func. appending delimiiter before 1st field.. prasad@my-dejanews.com
    Re: local($_) - why not "my"? <sugalskd@netserve.ous.edu>
        log file question <elst.fels@nospam.ping.be>
        matts search -- again (sorry!) <bencas@bigfoot.com>
    Re: Net::FTP (Charles DeRykus)
        Perl IO / newbie problem <dbabowal@powersurfr.com>
    Re: Perl NT login scripts help... <metcher@spider.herston.uq.edu.au>
        Programming with Style chad@vcn.net
    Re: Programming with Style (Steve Linberg)
    Re: Question: Arrays of associative arrays <palincss@his.com>
    Re: Question: Arrays of associative arrays <dgris@moiraine.dimensional.com>
    Re: Question: Arrays of associative arrays (Martien Verbruggen)
    Re: Question: Arrays of associative arrays (Steve Linberg)
        reading a file <nospam-seallama@mailcity.com>
    Re: reading a file <stevenhenderson@prodigy.net>
        regex Help bob.pruett@cox.com
    Re: Sending Perl output to 2 diffent html frames <bob@worldparts.com>
    Re: squashing multiple blank lines into one <m_ching@hotmail.com>
    Re: Using Perl to interrogate Hotmail (Iain O'Cain)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 05 Feb 1999 05:31:39 GMT
From: chad@vcn.net
Subject: Re: Browser hangs using CGI.pm
Message-Id: <79dvnr$1d0$1@nnrp1.dejanews.com>

In article <79dbju$l6s$1@remarQ.com>,
  "Aaron Newcomb" <aaron_newcomb@inter-tel.com> wrote:
> I am trying to learn how to use CGI.pm. One problem I haven't been able to
> solve is when I run a script that uses external information (whether I use a
> form to post the info or even use "open (STDIN,"filename";)") and try to
> manipulate the info my browser hangs. I am running Active Perl for Win32 on
> IIS 4.0. The script runs fine from the command prompt and outputs exactly
> what I would expect. For example, I can't run Lincoln Stein's own
> http://www.wiley.com/compbooks/stein/text/htmlize.txt when I type out the
> script and run it from the browser! Any suggestions would be great. In the
> meantime, I am going to try running it on Apache to see if it is a server
> issue.

Try to see if CGI_Lite.pm will do what you need.  I have used it in many
(100's) of cgi scripts with no pronlems.  I know that doesn't anwser
questions about CGI.pm, I've never used it, maybe I'm missing out.

-chad

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


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

Date: Thu, 04 Feb 1999 23:18:18 -0500
From: "John T. Jarrett" <jjarrett@ecpi.com>
To: Jeff <jeff909@hotmail.com>
Subject: Re: can cgi(perl) do this?
Message-Id: <36BA7109.AEC024@ecpi.com>

You might also look at one of the CGI tutorial sites like
http:www.bignosebird.com which has a free form to e-mail script with this
functionality built in. I know - I use it myself on Hypermart and just make sure
the banner code is in the page referred to.

John T. Jarrett
jjarrett@ecpi.com

Jeff wrote:

> When I want to display a confirmation message to the user after they submit
> thier info on my email auto-responder script is it possible for the CGI
> program to direct thier broswer to a specific html document rather than have
> the html code hard-coded into the script? For instance if I want to have my
> html pages on another server (to avoid the bothersome hypermart pop-ups) and
> the cgi is on the hypermart server(since it is free and allows cgi), after
> hypermart sends my email message for me is it possible for the "Thank You"
> page to be a seperate html document or do I have to type the html code into
> the cgi program? Because even if the page code is hardcoded into a cgi
> program, the pop-up banner appears on any page displayed through hypermart.
> I hope this makes sense.
>
> Jeff



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

Date: Fri, 05 Feb 1999 05:35:54 GMT
From: jgoodall@vt.edu (James Goodall)
Subject: Caputuring output and return code
Message-Id: <36ba8210.24708562@news.vt.edu>

I've used backticks to execute a command from the shell and capture
the output and I've used system() to retrieve the command's return
value, but how can I get both?

e.g.
$errno = system(("grep", $re, $file)); - returns the command's return
value, but not it's output from stdout

$output = `grep $re $file`; - returns the output from stdout of the
command, but not it's return value

I need both without running the command twice.  Anyone know how this
is done?  TIA.

 - James


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

Date: Fri, 05 Feb 1999 05:21:58 GMT
From: tnova@riconnect.com
Subject: Changing Form Input via Perl Script/Mail Script
Message-Id: <79dv5g$vd$1@nnrp1.dejanews.com>

Hello, I've got a form where one would enter their username, say 'USERNAME'
with a password also.  This feeds into a very complex pop3 webmail viewer.  I
would like to find a way, any means, by which the entered 'USERNAME' would be
lookd up in a seperate file or in the script itself to equal another
username... i.e. username entered into the form: webmaster - would translate
to anyname1 which my script would then use.

Endymion MailMan is availible for personal use if anyone wants to look at the
script.

Also, is there a way I can have a perl script post to another cgi script, or
is that just for forms on browsers?  If so I could create two scripts working
independently.

btw: If anyone can get this to work correctly for me, I'll mail ya $15 bucks.
;)

Mike Terranova
tnova@riconnect.com

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


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

Date: Fri, 05 Feb 1999 04:14:01 GMT
From: Gary Robertson <gjohn@crossland.com.au>
Subject: Help on loading DBI statically
Message-Id: <79dr62$tl5$1@nnrp1.dejanews.com>

I am a new perl user. I wish to build perl with the DBI module statically
linked into it, but I can't find the info on this. I assume I should supply
Configure with the full path of the DBI.pm file, however I don't know the
syntax for this.

Also, it would be appreciated if somebody could point me to some info
explaining the differences between statically & dynamically loaded DBI, & the
advantages of each approach.

Apologies if this appears in some FAQ.

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


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

Date: 5 Feb 1999 03:10:39 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: How do I get local IP Address ?
Message-Id: <slrn7bkoe7.83s.fl_aggie@enso.coaps.fsu.edu>

On Thu, 04 Feb 1999 23:42:15 GMT, chad@vcn.net <chad@vcn.net> wrote:

+ What kind of machine is it, I'm assuming it's not UNIX, if it
+ is use 127.0.0.1 which is standard for 'localhost', on Win machine use
+ the one in the Network settings

I think the idea is as follows:

1. dialup networking with dynamic IPs
2. the application needs the functional IP of the machine its running,
   not the loopback network

+ or Just make one up.

That's rather unfriendly behaviour.

James


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

Date: Thu, 04 Feb 1999 05:43:24 -1000
From: Michael Ching <m_ching@hotmail.com>
Subject: Re: How do I get local IP Address ?
Message-Id: <36B9C01C.39E95C23@hotmail.com>

if under winnt, ipconfig

Uri Guttman wrote:
> 
> >>>>> "JL" == James Ludlow <ludlow@us.ibm.com> writes:
> 
>   JL> John Chambers wrote:
>   JL> [snip - IP addresses and interfaces]
> 
>   >> The simplest way to find them is probably to run either or both
>   >> of the commands `ifconfig -a` and `netstat -in`, and parse the
>   >> output.  Unfortunately, these commands are minimally portable,
>   >> and give wildly different formats on different systems, so your
>   >> perl program will need a list of REs to try on each command's
>   >> output.
> 
>   JL> Agreed.  I'm not sure which Unix variant you're using, but under Linux
>   JL> the command would be `netstat -rn`.  Your statement about "wildly
>   JL> different formats" is very much true.
> 
> and it would be hard to do a perl module (xs or pure perl) since the way
> ifconfig and netstat get their info is also wildly system dependent.
> 
> there is another possibility which is to scan the rc.* files and their
> config files. but again this is system dependent and may not reflect
> manual changes. and god knows how to do that on redmondware (i sure
> don't know or care).
> 
> uri
> 
> --
> Uri Guttman                             Hacking Perl for Ironbridge Networks
> uri@sysarch.com                         uri@ironbridgenetworks.com


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

Date: Fri, 05 Feb 1999 04:30:44 GMT
From: chad@vcn.net
Subject: Re: How to replace text in a text file.
Message-Id: <79ds5k$uj2$1@nnrp1.dejanews.com>

In article <36BA273A.9C0A19C7@nnex.net>,
  Ted Bogeman <tbogeman@nnex.net> wrote:
> Please Help
>
> I have a daemon that will call perl scripts when prompted.  What I need
> it to do:  Is take the $username and edit the passwd file.  I would like
> to just send the user info to the script for unlocking and locking user
> accounts.  The script would find the username in /etc/passwd and then
> change the x to ! , thus locking the account.
>
> username:x:1887:100:Real Name:/home/jbsw:/bin/bash   (unlocked account)
>
> username:!:1887:100:Real Name:/home/jbsw:/bin/bash   (locked account)
>
> Could someone please help with completing this script.
>
> #!/usr/bin/perl
> open(INFILE,"@ARGV[0]");
> $file = "@ARGV[0]";
> $inline = <INFILE>;
> ($username,$password,$realname,$shell,$uid,$gid) = split(/\:/,$inline);
> close(INFILE);
>
> Thanks in advance.  You can email me direct.

Do you really want to edit the password file with a
perl script?  Not really a good Idea.  If all you
want to do is lock a account maybe you should just put a
 .login file in their home directory and make it only
write'able by root, of course ... and the script could
be some thing as simple as:

#!/usr/bin/perl

print <<"EOF";
Your Account has been temp. closed, bla, bla
etc ..etc ..
EOF

sleep(5);

print `exit`;

and you might want to catch control-C, etc.

(you can put the .login file in the dir with perl)

Anyways, editing the passwd file with a perl script, espeacially
if your not sure what your doing, is a big no, no.

-chad

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


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

Date: Fri, 05 Feb 1999 05:20:10 GMT
From: chad@vcn.net
Subject: Re: How to replace text in a text file.
Message-Id: <79dv23$uq$1@nnrp1.dejanews.com>

In article <36BA273A.9C0A19C7@nnex.net>,
  Ted Bogeman <tbogeman@nnex.net> wrote:
> Please Help
>
> I have a daemon that will call perl scripts when prompted.  What I need
> it to do:  Is take the $username and edit the passwd file.  I would like
> to just send the user info to the script for unlocking and locking user
> accounts.  The script would find the username in /etc/passwd and then
> change the x to ! , thus locking the account.
>
> username:x:1887:100:Real Name:/home/jbsw:/bin/bash   (unlocked account)
>
> username:!:1887:100:Real Name:/home/jbsw:/bin/bash   (locked account)
>
> Could someone please help with completing this script.
>
> #!/usr/bin/perl
> open(INFILE,"@ARGV[0]");
> $file = "@ARGV[0]";
> $inline = <INFILE>;
> ($username,$password,$realname,$shell,$uid,$gid) = split(/\:/,$inline);
> close(INFILE);
>
> Thanks in advance.  You can email me direct.



Ok, so my .login solution does nothing for FTP accounts.

Here's how I would edit the /etc/passwd file, perl guru's
please speak up.

-- untested code

#!/usr/bin/perl

if(!$ARGV[0] or !$ARGV[1]) {
  die "\nusage: script.pl [-l (lock) -u (unlock)] username\n\n";
}

chomp($now = `date +%s`);

# make a back-up of the passwd file incase I screw up
print `cp /etc/passwd /somewhere/safe/passwd.$now`;

$new_passwd = '';

# read in /etc/passwd
open(PASSWD,"/etc/passwd") or die "You got problems.\n";
while(<PASSWD>) {
  if($ARGV[0] eq "-l" and $_ =~ /^$ARGV[0]\:/) { s/^(.*?):x/$1:!/; }
  if($ARGV[0] eq "-u" and $_ =~ /^$ARGV[0]\:/) { s/^(.*?):!/$1:x/; }
  $new_passwd .= $_;
}
close(PASSWD);

# save changes (yikes);
open(PASSWD,">/etc/passwd") or die "You got problems.\n";
print PASSWD "$new_passwd";
close(PASSWD);

# this can't be good. :(
exit;

PS:  Don't expect a email, come back to the newsgroups that's what they are
for.

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


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

Date: Fri, 05 Feb 1999 05:44:12 GMT
From: prasad@my-dejanews.com
Subject: join func. appending delimiiter before 1st field..
Message-Id: <79e0fb$1rg$1@nnrp1.dejanews.com>

Hello,

I want to scan a line with fields delimited by '--' and print it in a file
as,

field1``field2``field3``field4``x

Instead, it is being written as follows,

``field1``field2``field3``field4``x

current code->
---------------------
  @field_array = split(/--/, $splitlist[$a]);
  chomp @field_array;

  print FILE join("``",(@field_array)),'``x',"\n";
---------------------

Can somebody help me figure out,
What is causing join to print the delimiter before the first field also?
How can I correct this error?

Please mail me the responses if possible as it's difficult to track the
replies through dejanews.

Thanks.

regards,
prasad.
(prasad@chetana.com)


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


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

Date: 5 Feb 1999 02:45:58 GMT
From: Dan Sugalski <sugalskd@netserve.ous.edu>
Subject: Re: local($_) - why not "my"?
Message-Id: <79dm16$t6n$1@news.NERO.NET>

Andrew M. Langmead <aml@world.std.com> wrote:
: Ala Qumsieh <aqumsieh@matrox.com> writes:

:>... what are the potential advantages/disadvantages of yanking the
:>special variables out of the symbol table?

: Since the symbol tables are common accross all threads in threaded
: perl, lexeical variables have the advantage of being thread specific.

Ummmm... no they aren't. Perl's standard scoping rules tend to make them
thread specific, but that's just a happy side-effect. Consider this code:

  use Thread;
  my $foo
  sub bar {
	$foo++;
  }
  my $thr = Thread->new(\&bar);
  $thr->join;
  print $foo, "\n";

You'll find (assuming I didn't make any syntax errors just hacking it in:)
that $foo is well and truly changed by the new thread even though it
was declared in the main thread. You can also pass references to lexicals
from thread to thread if you want. 

The only way to get truly thread-specific variables is to use
Thread::Specific.


					Dan


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

Date: Fri, 5 Feb 1999 06:52:47 +0100
From: "myname@mydomain.com" <elst.fels@nospam.ping.be>
Subject: log file question
Message-Id: <79e0sl$b7c$1@news3.Belgium.EU.net>

Hello everybody,

I just made a perl script that keeps a log of all visitors.
Now I've noticed that the html page it generates becomes very long.
Is there a way to say after x amount of logged entries to start a new page ?

Thank you for your help,

Peter




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

Date: Fri, 5 Feb 1999 02:07:18 -0000
From: "el_pollo_diablo" <bencas@bigfoot.com>
Subject: matts search -- again (sorry!)
Message-Id: <79djsa$4pv$1@news8.svr.pol.co.uk>

I'm attempting to get the form on matts simple search to be able to send
more data to the search script. The form parsing routing is this:

sub parse_form {

# Get the input

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs

@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {

($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$FORM{$name} = $value;

}

}

I've been playing with it allnight and I cant get it too work.

How do I get it to recieve more than the current 3 form objects?

Last time I posted about this I was told that Matts scripts were cack and I
totally agree, however as you can see I'm totally new to this and I'm just
trying to use this as a jumping block!

Thanks for any help!

--
Peace, Empathy, Desire, Mischeif and Gladness.
Ben




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

Date: Fri, 5 Feb 1999 02:15:05 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Net::FTP
Message-Id: <F6nsx5.ux@news.boeing.com>

In article <AFF6077E2C176213.C17CF4F50D7B1463.E394DF45734A1176@library-proxy.airnews.net>,
Robert Saunders <robert@iminet.com> wrote:
>    ...
>   How would I get the list into the $directory variable.. I am not clear
>

    for ($ftp->ls("DIR")) { $directory .= $_ }

hth,
--
Charles DeRykus


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

Date: Thu, 04 Feb 1999 19:14:29 -0700
From: David Babowal <dbabowal@powersurfr.com>
Subject: Perl IO / newbie problem
Message-Id: <36BA5405.14C0893C@powersurfr.com>

Hi,  I installed perl 5.00502 on Redhat Linux 5.2, and tried to run a
script, but it gives me the following horrendous errors (see below).  I
don't have enough perl knowledge (yet) to hack through this and figure
out what's going wrong.  Can anybody help?

Use of uninitialized value at /usr/lib/perl5/5.00502/lib.pm line 28 (#1)


    (W) An undefined value was used as if it were already defined.  It
was
    interpreted as a "" or a 0, but maybe it was a mistake.  To suppress

this
    warning assign an initial value to your variables.

Use of uninitialized value at /usr/lib/perl5/5.00502/lib.pm line 29 (#1)

Use of uninitialized value at /usr/lib/perl5/5.00502/lib.pm line 30 (#1)

Ambiguous call resolved as CORE::kill(), qualify as such or use & at
        /usr/lib/perl5/site_perl/5.005/i686-linux/Tk/IO.pm line 66 (#2)

    (W) A subroutine you have declared has the same name as a Perl
keyword,
    and you have used the name without qualification for calling one or
the
    other.  Perl decided to call the builtin because the subroutine is
    not imported.

    To force interpretation as a subroutine call, either put an
ampersand
    before the subroutine name, or qualify the name with its package.
    Alternatively, you can import the subroutine (or pretend that it's
    imported with the use subs pragma).

    To silently interpret it as the Perl operator, use the CORE:: prefix

    on the operator (e.g. CORE::log($x)) or by declaring the subroutine
    to be an object method (see attrs).

Global symbol "%Config" requires explicit package name at
        /usr/lib/perl5/5.00502/i686-linux/IO/Socket.pm line 211 (#3)

    (F) You've said "use strict vars", which indicates that all
variables
    must either be lexically scoped (using "my"), or explicitly
qualified
to
    say which package the global variable is in (using "::").

Uncaught exception from user code:
        Uncaught exception from user code:
        Uncaught exception from user code:
        Uncaught exception from user code:
        Uncaught exception from user code:
        BEGIN not safe after errors--compilation aborted at
/usr/lib/perl5/5.00502/i686-linux/IO/Socket.pm line 377.
        require IO/Socket.pm called at /usr/local/v2.02/MySpex.pm line
48
        MySpex::BEGIN() called at
/usr/lib/perl5/5.00502/i686-linux/IO/Socket.pm line 377
        eval {...} called at
/usr/lib/perl5/5.00502/i686-linux/IO/Socket.pm line 377
        require MySpex.pm called at /usr/local/v2.02/pamb.pm line 145
        main::BEGIN() called at
/usr/lib/perl5/5.00502/i686-linux/IO/Socket.pm line 377
        eval {...} called at
/usr/lib/perl5/5.00502/i686-linux/IO/Socket.pm line 377
        MySpex::BEGIN() called at
/usr/lib/perl5/5.00502/i686-linux/IO/Socket.pm line 377
        eval {...} called at
/usr/lib/perl5/5.00502/i686-linux/IO/Socket.pm line 377
        require MySpex.pm called at /usr/local/v2.02/pamb.pm line 145
        main::BEGIN() called at
/usr/lib/perl5/5.00502/i686-linux/IO/Socket.pm line 377
        eval {...} called at
/usr/lib/perl5/5.00502/i686-linux/IO/Socket.pm line 377
BEGIN failed--compilation aborted at /usr/local/v2.02/MySpex.pm line 48.

        require MySpex.pm called at /usr/local/v2.02/pamb.pm line 145
        main::BEGIN() called at /usr/local/v2.02/MySpex.pm line 48
        eval {...} called at /usr/local/v2.02/MySpex.pm line 48
        main::BEGIN() called at /usr/local/v2.02/MySpex.pm line 48
        eval {...} called at /usr/local/v2.02/MySpex.pm line 48
BEGIN failed--compilation aborted at /usr/local/v2.02/pamb.pm line 145.






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

Date: Fri, 05 Feb 1999 12:24:38 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: Perl NT login scripts help...
Message-Id: <36BA5666.649EC6A0@spider.herston.uq.edu.au>



Martien Verbruggen wrote:
> 
> In article <c55_9902042146@hccfido.hcc.nl>,
>         UUCP@p1.f3.n500.z2.hccfido.hcc.nl (UUCP) writes:
> Normally you would use unshift here, because most likely you want
> those directories to appear before the other ones.
> 

Yes.

> In that case just use the lib pragma, which was specifically created
> for this:
> 
> use lib qw( p:/bin p:/lib );
> 

Maybe.  If the perl executable isn't sitting on top of its libraries it
won't find lib.pm either.  I wonder if perl.exe is in P:\?  And what
does perl -e "print @INC" say?

-- 
Jaime Metcher


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

Date: Fri, 05 Feb 1999 04:15:37 GMT
From: chad@vcn.net
Subject: Programming with Style
Message-Id: <79dr91$ttv$1@nnrp1.dejanews.com>

I wasn't going to post this question in fear of
being picked on, but here goes.  I have been a perl
programmer for about 6 years, I know my way around
it pretty well and always try to stay current on new
Modules from CPAN, latest news, developments, etc.
I've read *all* the books on perl front to back, so
I'm not a complete idiot.  So where I want some help
or advice (from older programmers or maybe new ones too)
is how to get more efficient on program design.  From
the planning stages of a project to coding, etc.  What
books are there or resources out there, that will help me
become a better programmer?  An example of what I'm looking
for would be like "Efficiency, p.537" and "Programming with
Style, p.546" in the camel book #2.  I'm sure I'll get
better with more and more experience and practice, just
wondering if anyone ran across a good book.  I heard of one
called "The Pearls of Programming", but have never been able
to find it in a store.

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


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

Date: Fri, 05 Feb 1999 05:34:45 GMT
From: slinberg@crocker.com (Steve Linberg)
Subject: Re: Programming with Style
Message-Id: <slinberg-0502990034460001@cc11620-a.lwmrn1.pa.home.com>

In article <79dr91$ttv$1@nnrp1.dejanews.com>, chad@vcn.net wrote:

> I'm sure I'll get
> better with more and more experience and practice, just
> wondering if anyone ran across a good book.  I heard of one
> called "The Pearls of Programming", but have never been able
> to find it in a store.

The Perl Cookbook, by Tom Christiansen and Nathan Torkington, is a great
place to start.  Lots of nice code samples in there.


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

Date: Thu, 04 Feb 1999 20:03:00 -0500
From: Steve Palincsar <palincss@his.com>
Subject: Re: Question: Arrays of associative arrays
Message-Id: <36BA4344.8A1B3570@his.com>

Steve Chen wrote:
> 
> Hello,
> 
> Are "arrays of associative arrays" useful in Perl?  

Here's an example of one I'm using in a survey at work.
The object is, for a given medium and treatment method,
find the appropriate next page in a survey.

Instead of a horribly convoluted if statement, I
can simply say $nextpage = $volumetrics{$medium}{$method}.
If $medium is 'Sediment' and $method is 'Bioventing',
$next page is 29.  For conciseness I've eliminated many
of the mediums and method types.  This piece of code
is actually >400 lines in the production version.

 %volumetrics = (
          'Sediment' => {
                          'Open Burn/Open Detination' => 27,
                          'Containment' => 30,
                          'Soil Vapor Extraction (Ex Situ)' =>
27,
                          'Thermal Treatment' => 27,
                          'Landfarming' => 27,
                          'Incineration' => 27,
                          'Composting' => 27,
                          'Physical/Chemical Treatment, (Ex
Situ)' => 27,
                          'Permeable Treatment Bed' => 29,
                          'Oxidation' => 27,
                          'Pneumatic Fracturing (Enhancement)' =>
29,
                          'Low Temperature Thermal Desorption' =>
27,
                          'Bioventing' => 29,
                          'Neutralization' => 29,
                          'Disposal' => 29,
                          'Recycling' => 27,
                          'Dehalogenation' => 27,
                          'High Temperature Thermal Desorption'
=> 27,
                          'Hot Gas Decontamination' => 27,
                          'Soil Washing' => 27,
                    },

          'Debris' => {
                        'Open Burn/Open Detination' => 27,
                        'Containment' => 30,
                        'Recycling' => 27,
                        'Thermal Treatment' => 27,
                        'Chemical Reduction/Oxidation' => 27,
                        'High Temperature Thermal Desorption' =>
27,
                        'Dehalogenation' => 27,
                        'Incineration' => 27,
                        'Hot Gas Decontamination' => 27,
                        'Composting' => 27,
                        'Physical/Chemical Treatment, (Ex Situ)'
=> 27,
                        'Discharge' => 29,
                },
          'Other' => {
                       'Open Burn/Open Detination' => 27,
                       'Containment' => 30,
                       'Clarification' => 28,
                       'Soil Vapor Extraction (Ex Situ)' => 27,
                       'Bioremediation/Biological Treatment (In
Situ)' => 29,
                       'Encapsulation or Overpacking' => 30,
                       'Passive Treatment Walls' => 29,
                       'Free Product Recovery' => 29,
                       'Hydrofracturing (Enhancement)' => 29,
                       'Physical Separation' => 27,
                       'Aeration' => 27,
                       'Cap' => 30,
                       'Recovery Wells' => 28,
                       'Bioremediation/Biological Treatment (Ex
Situ)' => 28,
                       'Air Sparging' => 29,
                       'Fuming Gasification' => 27,
                       'Chemical Reactive Wall' => 29,
                       'Soil Vapor Extraction (In Situ)' => 29,
                       'Air Stripping' => 28,
                       'Filtration' => 28,
                       'Solidification/ Stabilization' => 27,
                       'Oil Water Separation' => 28
                     },
          'Groundwater' => {
                             'Containment' => 30,
                             'Clarification' => 28,
                             'Oxygen Enhancement' => 28,
                             'Carbon/Liquid Phase Adsorption' =>
28,
                             'Extraction' => 28,
                             'Co-Metabolic Treatment' => 28,
                             'Bioremediation/Biological Treatment
(In Situ)' => 28,
                             'Free Product Recovery' => 28,
                             'Hydrofracturing (Enhancement)' =>
28,
                             'Passive Treatment Walls' => 28,
                             'Aeration' => 27,
                             'Pump And Treat' => 28,
                             'Recovery Wells' => 28,
                             'Bioremediation/Biological Treatment
(Ex Situ)' => 28,
                             'Air Sparging' => 28,
                             'Alternate Drinking Water' => 31,
                             'Chemical Reactive Wall' => 28,
                             'Filtration' => 28,
                             'Air Stripping' => 28,
                             'Oil Water Separation' => 28
                           },
          'Surface Water' => {
                               'Containment' => 30,
                               'Clarification' => 28,
                               'Oxygen Enhancement' => 28,
                               'Carbon/Liquid Phase Adsorption'
=> 28,
                               'Extraction' => 28,
                               'Co-Metabolic Treatment' => 28,
                               'Discharge' => 28,
                               'Physical/Chemical Treatment, (In
Situ.)' => 28,
                               'Oxidation' => 28,
                               'Bioventing' => 28,
                               'Equalization' => 28,
                               'Hot Water or Steam
Flushing/Stripping' => 28,
                               'Filtration' => 28,
                               'Oil Water Separation' => 28,
                             },

          'Solid Waste' => {
                             'Open Burn/Open Detination' => 27,
                             'Containment' => 30,
                             'Soil Vapor Extraction (Ex Situ)' =>
27,
                             'Thermal Treatment' => 29,
                             'Incineration' => 27,
                             'Composting' => 27,
                             'Physical/Chemical Treatment, (Ex
Situ)' => 27,
                             'Oxidation' => 27,
                             'Pneumatic Fracturing (Enhancement)'
=> 29,
                             'Low Temperature Thermal Desorption'
=> 27,
                             'Bioventing' => 29,
                             'Neutralization' => 29,
                             'Disposal' => 29,
                    },
          'Leachate' => {
                          'Containment' => 30,
                          'Clarification' => 28,
                          'Oxygen Enhancement' => 28,
                          'Co-Metabolic Treatment' => 28,
                          'Discharge' => 28,
                          'Physical/Chemical Treatment, (In
Situ.)' => 28,
                          'Oxidation' => 28,
                          'Bioventing' => 28,
                          'Aeration' => 27,
                          'Pump And Treat' => 28,
                          'Bioremediation/Biological Treatment
(Ex Situ)' => 28,
                          'Recovery Wells' => 28,
                          'Air Sparging' => 28,
                          'Chemical Reactive Wall' => 28,
                          'Filtration' => 28,
                          'Air Stripping' => 28,
                          'Oil Water Separation' => 28
                        }
        );

1;

















I seem to be able to
> construct it, but the problem
> is, how do I access the values of the associative arrays?  Let's say I
> have an array:
> 
> @Array = (%comp1, %comp2, ..., %compn);
> 
> where
> 
> %compn = (keys, values)
> 
> To print all the values of the associative arrays, I tried
> 
> (loop over $i)
> foreach $key (sort keys($Array[$i])) {
>     print ....
> }
> 
> But this won't fly with the compiler.  The function "keys" doesn't seem
> to like things that begin
> with a "$".  Any ideas?
> 
> Thanks.
> 
> Steve


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

Date: 04 Feb 1999 18:29:21 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Question: Arrays of associative arrays
Message-Id: <m390ed1vv2.fsf@moiraine.dimensional.com>

mgjv@comdyn.com.au (Martien Verbruggen) writes:

> In article <36B9F39A.F2365854@synopsys.com>,
> 	Steve Chen <stevesc@synopsys.com> writes:
> 
> > Are "arrays of associative arrays" useful in Perl?  
> 
> not really. They're just there so that people can do cool things with
> map and typeglobs. 

Surely you don't mean this seriously.  Arrays of hashes are useful
in exactly the same circumstances that arrays of scalars are.

If you have data that needs to be ordered, you want an array.  It
doesn't matter if it's an array of hashes, an array of scalars, or
even an array of hashes of arrays of hashes of regular expressions.
If it needs to be in a particular order, it needs to be in an array.

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


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

Date: Fri, 05 Feb 1999 02:04:54 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Question: Arrays of associative arrays
Message-Id: <alsu2.102$fP3.8773@nsw.nnrp.telstra.net>

In article <m390ed1vv2.fsf@moiraine.dimensional.com>,
	Daniel Grisinger <dgris@moiraine.dimensional.com> writes:
> mgjv@comdyn.com.au (Martien Verbruggen) writes:
> 
>> In article <36B9F39A.F2365854@synopsys.com>,
>> 	Steve Chen <stevesc@synopsys.com> writes:
>> 
>> > Are "arrays of associative arrays" useful in Perl?  
>> 
>> not really. They're just there so that people can do cool things with
>> map and typeglobs. 
> 
> Surely you don't mean this seriously.  Arrays of hashes are useful
> in exactly the same circumstances that arrays of scalars are.

Maybe I should have added a smiley. Of course I wasn't serious. :)

> - I think that you were probably joking, but I'm not sure

Now you are :)

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


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

Date: Fri, 05 Feb 1999 05:50:39 GMT
From: slinberg@crocker.com (Steve Linberg)
Subject: Re: Question: Arrays of associative arrays
Message-Id: <slinberg-0502990050400001@cc11620-a.lwmrn1.pa.home.com>

In article <MPG.11239bbd6aa7a4a9989a05@nntp.hpl.hp.com>, lr@hpl.hp.com
(Larry Rosler) wrote:

> You can't have an array of hashes.  The elements of an array are 
> scalars, so they must be references to the hashes:
> 
>   @Array = (\%comp1, \%comp2, ..., \%compn);

I know you know your stuff, Larry, so I'm sure you're correct, but I'm a
little confused by this.  The Camel, 2nd edition, p. 268-270 talks about
arrays of hashes, and I use an array-of-hash structure right now in some
code I'm working on.  perldsc has samples.  They don't seem to be using
references, unless it's in some implicit way I don't understand.  Can you
shed any light?

--------------------------------------------------------------
 @LoH = (
        {
           Lead      => "fred",
           Friend    => "barney",
        },
        {
            Lead     => "george",
            Wife     => "jane",
            Son      => "elroy",
        },
        {
            Lead     => "homer",
            Wife     => "marge",
            Son      => "bart",
        }
  );

Generation of a LIST OF HASHES

 # reading from file
 # format: LEAD=fred FRIEND=barney
 while ( <> ) {
     $rec = {};
     for $field ( split ) {
         ($key, $value) = split /=/, $field;
         $rec->{$key} = $value;
     }
     push @LoH, $rec;


 # reading from file
 # format: LEAD=fred FRIEND=barney
 # no temp
 while ( <> ) {
     push @LoH, { split /[\s+=]/ };

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

 ...etc.  What am I missing?  Cheers.


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

Date: Thu, 04 Feb 1999 20:59:51 -0800
From: dan <nospam-seallama@mailcity.com>
Subject: reading a file
Message-Id: <36BA7AC7.9B140EA4@mailcity.com>

lets say i did this:

#!/usr/bin/perl
print "Content-type:text/html\n\n";
open(TEST, "template.txt");
@test = <TEST>;
close(TEST);
print "@test";

how can i have the script read the file until it reaches a certain
string and then stop? for the sake of argument, lets say $search =
"12345"
also, how can i get it to read the file from $search on? thanks for your
help




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

Date: Thu, 4 Feb 1999 21:28:54 -0600
From: "Steven T. Henderson" <stevenhenderson@prodigy.net>
Subject: Re: reading a file
Message-Id: <ckvu2.45930$641.22569@news.san.rr.com>

how about:


if(! OpenDefaultData("read"))
{
    print "ERROR: could not open data file<br>";
    exit;
}


# Store each entry in string array
while(<DEFAULT>)
{
        # assume data looks like:
        # 02.01.1999=this reservation spans two
months|stevenhenderson@hotmail.com|

        ($tmp_date, $tmp_remaining)  = split(/=/, $_);

        # Or perform you check here...
        print "your date: $tmp_date ->  $res{$tmp_date}<br>";

}

&CloseDefaultData;


and there are lots of other tricks you can play, but this is the easyest.



dan wrote in message <36BA7AC7.9B140EA4@mailcity.com>...
>lets say i did this:
>
>#!/usr/bin/perl
>print "Content-type:text/html\n\n";
>open(TEST, "template.txt");
>@test = <TEST>;
>close(TEST);
>print "@test";
>
>how can i have the script read the file until it reaches a certain
>string and then stop? for the sake of argument, lets say $search =
>"12345"
>also, how can i get it to read the file from $search on? thanks for your
>help
>
>




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

Date: Fri, 05 Feb 1999 05:09:00 GMT
From: bob.pruett@cox.com
Subject: regex Help
Message-Id: <79dud7$ct$1@nnrp1.dejanews.com>

Ok all you PH's out there give me a hand.

I have a simple search and replace engine that uses regex to find tags in a
string, process them, and put them back in the string. While I am sure there
is a module that does something like this we really need to keep our module
in place because of the processing.

Our problem is the processor seems sluggish and very processor intensive.

The form of the tags are $BEGIN foo.bar $END or $BEGIN foo $END both of these
forms can also have parameters passed.

My environment is Perl 5.004 running on Sun Solaris 2.51

Here are the questions:

1. I have read that I can use qr// to precompile the expression. I have tried
this and have had no luck. How do I precompile this expression? Will it speed
the processing?

2. I have made the script use small strings instead of the whole file at once.
This seemed to have sped it up greatly. What other regex tricks should I be
using?

3. Should I abandon regex altogether and start walking through the string
manually?

4. This script does alot of concatenating of strings and I am concerned about
garbage collection. Should I be? What can I do about it?


Here is some sample code:

open(FILE, $fname)

while(<FILE>)
{
   $_ =~ s/\$BEGIN\s*([\w\.\s]*)\s*\$END/proc_tag($1)/ge;
   $template .= $_;
}
close(FILE);

return $template;


sub proc_tag {
    my $this = shift;
    my $tagstring = shift;

    # Parse template and replace template tags.
    $replacement = "Do something to process the tags in here";

    return($replacement);
}

Thanks in advance;

Bob Pruett
http://pyropepper.com - Fiery foods for everyone.

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


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

Date: 5 Feb 1999 04:57:33 GMT
From: "Bob Van Der Ploeg" <bob@worldparts.com>
Subject: Re: Sending Perl output to 2 diffent html frames
Message-Id: <79dtnt$2fc$1@comet3.magicnet.net>


>chad@vcn.net writes:
>
>> Of course you can do that.
>

Thanks for all you replies to this issue.  Chad's "Perl with a little JAVA"
did the trick.

I have a script that creates an HTML document with JAVA in the header
eg:

print <<"EOF";
 ...<head><script language="javascript">
function displayAd(){
adWindow = window.open("","$framename","$features");

str='<html><head><title>Banner ad</title><head>' +
    '<body><center><a href="$URL" target="new"><img src="$banner"
border="0"></a> +
   '</center></body></html>';

self.adWindow.document.write(str);
}
</script>
 ...


then I  add "onCLick=displayAd()" to the submit button like this:
<input type ="submit" value="Continue" onClick=displayAd()>

Java changes the contents of $framename and the perl output changes the
orignal frame.







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

Date: Thu, 04 Feb 1999 05:45:41 -1000
From: Michael Ching <m_ching@hotmail.com>
Subject: Re: squashing multiple blank lines into one
Message-Id: <36B9C0A5.C32524FE@hotmail.com>

I don't know what you are doing

s/\n+/\n/g should do it

eric wrote:
> 
> Hi,
> 
> This is really a sed question, but I didn't know where else
> to post it.  Sorry!
> 
> I'm using the following to squash multiple blank lines into
> one.
> 
>   /^[  ]*$/ {
>    N
>    N
>    N
>    N
>    N
>    N
>    N
>    N
>    N
>    N
>    N
>    N
>    N
>    N
>    N
>    N
>    N
>    s/\
> */\
> /
> 
> But it's limited because it needs to know the most possible
> blank lines it might encounter.  How else can I do this?
> 
> Eric


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

Date: 4 Feb 1999 21:41:25 -0700
From: iocain@grouper.edm.gds.ca (Iain O'Cain)
Subject: Re: Using Perl to interrogate Hotmail
Message-Id: <79dspl$3eh$1@grouper.edm.gds.ca>

In article <fl_aggie-2901991651230001@aggie.coaps.fsu.edu>,
I R A Aggie <fl_aggie@thepentagon.com> wrote:

>In article <78t356$38n$1@nnrp1.dejanews.com>, Barb - perlgirl
><perlquestions@yahoo.com> wrote:
>
>+ I have been noodling with a couple Perl libraries, but haven't figured out
>+ where to look for code that will help me through the login, etc.
>
>perldoc LWP
>perldoc lwpcook

Actually, I think those sites do both support POP3 (and sadly not
IMAP4 ;-), so Mail::POP3Client and Net::POP3 and their ilk may be of
more interest.

>This is something I'd like to try, but haven't had time. Let me know how
>far you get, and if you run into problems.

Likewise!

- Iain


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

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

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