[17140] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4552 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 8 11:05:31 2000

Date: Sun, 8 Oct 2000 08:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <971017510-v9-i4552@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 8 Oct 2000     Volume: 9 Number: 4552

Today's topics:
    Re: Best definition of Perl so far in 19100 <wyzelli@yahoo.com>
    Re: Best definition of Perl so far in 19100 <flavell@mail.cern.ch>
        CGI Scripts Required <support@online-cgi.co.uk>
        Checking for existence of file <g.soper@soundhouse.co.uk>
    Re: Checking for existence of file <mak@imakhno.freeserve.co.uk>
    Re: Checking for existence of file <bmb@ginger.libs.uga.edu>
    Re: Comparing Perl and Java <bmb@ginger.libs.uga.edu>
    Re: currency format <bmb@ginger.libs.uga.edu>
        Date formating <mark@marknjude.freeserve.co.uk>
    Re: Date formating (Garry Williams)
    Re: Declaring variable <bernie@fantasyfarm.com>
        extract a segment of strings in a text <dsa@dassda.com>
    Re: Help ! DBI error <palincss@his.com>
    Re: HELP method POST cmf2000@my-deja.com
    Re: how can I get perl CGI to work with win32 perl and  <edmond.nolan@debitel.net>
        How do I show html source as plain text in IE browser? <radevenz@ix.netcom.com>
    Re: How do I show html source as plain text in IE brows <edmond.nolan@debitel.net>
    Re: how to pass info to a script? <edmond.nolan@debitel.net>
    Re: looking for links to Perl+mysql how-to's - tutorial <adamf@box43.gnet.pl>
        Newbie -> ini file to hash table? <edmond.nolan@debitel.net>
    Re: Newbie -> ini file to hash table? <bcaligari@my-deja.com>
    Re: Newbie -> ini file to hash table? <edmond.nolan@debitel.net>
    Re: Newbie -> ini file to hash table? (Gwyn Judd)
    Re: Newbie -> ini file to hash table? (Jon Bell)
        newbie: pws and active perl (Pieter Overbeeke)
        Perl binary for BeOS r5 <mak@imakhno.freeserve.co.uk>
    Re: Perl4-036 compile error in eval.c <palincss@his.com>
    Re: PP, 3rd ed.??? <bmb@ginger.libs.uga.edu>
        Removing of nested C-like comments. <adamf@box43.gnet.pl>
    Re: Reverse by paragraphs - NOT! <bmb@ginger.libs.uga.edu>
    Re: Text file manipulation <ren.maddox@tivoli.com>
    Re: Text file manipulation <hgg@techsoftdesign.com>
    Re: Text file manipulation <hgg@techsoftdesign.com>
        Unable to run an SSI #exec statement outside of my home (Burt Lewis)
        What does $++ mean? harry@drej.com
    Re: What does $++ mean? (Garry Williams)
    Re: What does $++ mean? <bmb@ginger.libs.uga.edu>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 8 Oct 2000 18:12:05 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Best definition of Perl so far in 19100
Message-Id: <jrWD5.4$Dc4.262@vic.nntp.telstra.net>

"Rosemary I H Powell" <rosie@dozyrosy.plus.com> wrote in message
news:MPG.144942fa6e1d490b9896e1@usenet.plus.net...
> 1) What is CGI?
> CGI (or Perl) is a specail Internet language that allows you
> to run 'programs'.....
>
> 2) What is it useful for?
> Perl is EXTREMELY useful. It's main purpose is to add
> interactivity to a website.....
>
> (found at http://members.freshhosting.co.uk/kb/cgi.html)
>
> Just in case any of you old Perl "gurus" believed differently.
>

Are there any correct items on that page at all?

I will recommend them NOT!

Wyzelli

--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';




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

Date: Sun, 8 Oct 2000 13:42:05 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Best definition of Perl so far in 19100
Message-Id: <Pine.GHP.4.21.0010081336550.8447-100000@hpplus01.cern.ch>

On Sun, 8 Oct 2000, Elaine Ashton wrote:

> When people start taking things so seriously that a joke can't be posted
> without pedantry I start to wonder where the fun has gone to and why.

Thanks for that.  I thought the '19100' was a very clear signal.

I suppose it's arguable that the article ought to have had some kind
of extra health warning inside, for those who don't look at the
subject line; but it's sad that some respected folks have taken
offence at Rosie's posting.

(As opposed to taking offence at the page which she's quoting, I
mean.)




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

Date: Sun, 8 Oct 2000 10:22:38 +0100
From: "Online CGI" <support@online-cgi.co.uk>
Subject: CGI Scripts Required
Message-Id: <39e03d32@news.telinco.net>

Have you designed a script & want to let everyone use it?

Well Online CGI can help you. This soon to be online site is currently
looking for more CGI scripts to add to it's already growing database.
So if you have designed a script that you think
deserves exposure, then e-mail your script to, scripts@online-cgi.co.uk.
Please include contact details and full installation details.
----------------------------------------------------------------------------
Online CGI is a 100% free service dedicated to giving your scripts their
deserved exposure & will allow anyone to download them.

There will be many other features on Online CGI, including the following:

 . Database of CGI scripts
 . CGI Tutorials
 . Monthly e-mail providing details of new scripts
 . CGI Helpdesk (Post a problem to other users)
 . Plus many other features


If you have any questions about the site, or you have a suggestion, please
e-mail support@online-cgi.co.uk.
----------------------------------------------------------------------------
www.online-cgi.co.uk






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

Date: Sun, 08 Oct 2000 13:55:38 +0100
From: Geoff Soper <g.soper@soundhouse.co.uk>
Subject: Checking for existence of file
Message-Id: <4a0a44b0e1g.soper@soundhouse.co.uk>

I would like to save a file but need to check for the existence of a file
with the same name and if it exists change the name of the file I intend
to save. How do I check for the existence of a file of a given file name?

Many thanks

-- 
Geoff Soper
g.soper@soundhouse.co.uk
Take a look at the Soundhouse page http://www.soundhouse.co.uk/


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

Date: Sun, 8 Oct 2000 14:47:51 +0100
From: "Makhno" <mak@imakhno.freeserve.co.uk>
Subject: Re: Checking for existence of file
Message-Id: <8rptu1$llo$1@news6.svr.pol.co.uk>

>I would like to save a file but need to check for the existence of a file
>with the same name and if it exists change the name of the file I intend
>to save. How do I check for the existence of a file of a given file name?

$file="/my/file/whatever";
if (-e $file)
{
    its there
}
else
{
    its not
}




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

Date: Sun, 8 Oct 2000 11:02:20 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Checking for existence of file
Message-Id: <Pine.A41.4.21.0010081049380.16452-100000@ginger.libs.uga.edu>

On Sun, 8 Oct 2000, Makhno wrote:

> >I would like to save a file but need to check for the existence of a file
> >with the same name and if it exists change the name of the file I intend
> >to save. How do I check for the existence of a file of a given file name?
> 
> $file="/my/file/whatever";
> if (-e $file)
> {
>     its there
> }
> else
> {
>     its not
> }

Given the OP's reasons, the example above introduces a race condition.  
The file could get created between the time you '-e' it and the time you
open it for output.  Following is a snippet of code from a backup routine
I use:

    16  use Fcntl;
    17  use POSIX qw(:errno_h);
    ...
    71    ### backup file can't already exist, so skip existing ones
    72    for( my $serial = 0;; ) {
    73      last if sysopen( BAK, $fmt . ++$serial,
                O_WRONLY|O_EXCL|O_CREAT );
    74      die $! unless $! == EEXIST;              ### if other error
    75      die "Infinite loop" if $serial > 10_000; ### last resort
    76    }

I sysopen the file in such a way that the call will fail if the file
exists, without damaging the file.  If the file doesn't exist, I've opened
it in the same atomic process, avoiding the race condition.

I'm not fond of the last resort loop check; any advice welcome.

Brad



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

Date: Sun, 8 Oct 2000 09:25:33 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Comparing Perl and Java
Message-Id: <Pine.A41.4.21.0010080908430.16452-100000@ginger.libs.uga.edu>

On Sun, 8 Oct 2000, shad sluiter wrote:

> I'm sure there are plenty of opinions about this one...
> 
> I started learning Perl about a year ago to write typical scripts for a
> web site (guest books, chat rooms, search engines, discussion boards).
> I used Perl because my web host uses UNIX and perl was available, but
> have been curious about Java. One would have to live in a cave to not
> hear the Java hype in the media.
> 
> Perl has it's nice points such as its text processing abilities that
> can split input strings into nicely managed lists.  I can see how it
> works with the cgi interface of my UNIX web server.  I do wish that the
> Perl syntax was a little more readable.

Having had to write Java code for a recent software upgrade for my site at
work, I say the following from personal painful experience.  Don't do
it.  Don't put yourself through the pain of attempting to do all the
wonderful things you've done in Perl, in Java.  Perl syntax is perfectly
readable if you, the programmer, make it so.  Java syntax is perfectly
horrendous if you, the programmer, make it so.  Actually, I think it's
perfectly horrendous anyway, because of the hoops it makes you navigate.

I like to say that it takes an act of congress to do anything in Java.  I
have that bias because of how easy it is to do almost anything (at least
anything I've needed to do so far), in Perl.


> My experience in Java is very limited, but I'm getting into a project
> to explore the possibilities of XML programming.  Sun seems to think
> that Java and XML are the "Ying and Yang" of cross-platform
> programming.
> 
> Does anyone here use Perl AND Java and can list some strengths of
> each?  I assume Perl can perform XML decoding as good as any text
> processing language.  Any opinions on this issue?

I assume the same.  Explore CPAN for Perl XML modules.  Have you written a
Java CGI yet?  Try writing a guest book and search engine CGI in Perl, and
then in Java.  I suspect that simple exercise may cure you of listening
too closely to the the hype.

Happy coding,

Brad



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

Date: Sun, 8 Oct 2000 09:40:05 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: currency format
Message-Id: <Pine.A41.4.21.0010080930370.16452-100000@ginger.libs.uga.edu>

> Jeff Zucker wrote:
> > 
> > borg wrote:
> > >
> > > Is there a quick a way to get output into a currency format? ie.
> > > $12,000.00
> > >
> > > Right now I am using:  $var=("%4.2f", $var);
> > >
> > > But that does not place the commas in there.
> > 
> > perldoc -q commas
> > 
> > --
> > Jeff
> 
On Sat, 7 Oct 2000, borg wrote:

> Bingo ... that did the trick thank you :-)
> 
> 
> 

Two things:

1) notice how I moved your answer so that it appears AFTER Jeff's.  You
   should do the same.  It's clearer and it's accepted practice in
   newsgroups.

2) don't overlook the hidden message in Jeff's answer.  READ THE FAQ'S.
   Your question is so frequently asked (or was in years past) that it
   not only appears in the FAQ's, but in many (if not most) books about
   Perl.

Of course, number 2) is more important than number 1) because the FAQ's
will make you a Perl expert in short order, reducing the number of posts
you'll send.

Cheers,

Brad



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

Date: Sun, 8 Oct 2000 14:36:01 +0100
From: "Mark Roberts" <mark@marknjude.freeserve.co.uk>
Subject: Date formating
Message-Id: <8rpt8s$n82$1@news7.svr.pol.co.uk>

I'm trying to write a function that will do the following

Given a string in the form yymmdd e.g. 001008 it should produce output of
the form 8th October 2000

I'm sure its fairly easy, I just don't know how to extract the relevant
pieces of the string.

Thanks.

Mark Roberts




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

Date: Sun, 08 Oct 2000 13:53:39 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Date formating
Message-Id: <D%_D5.250$lw3.31366@eagle.america.net>

On Sun, 8 Oct 2000 14:36:01 +0100, Mark Roberts
<mark@marknjude.freeserve.co.uk> wrote:
>
>Given a string in the form yymmdd e.g. 001008 it should produce output of
>the form 8th October 2000
>
>I'm sure its fairly easy, I just don't know how to extract the relevant
>pieces of the string.

perldoc -f substr

-- 
Garry Williams


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

Date: Sun, 08 Oct 2000 06:26:01 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: Declaring variable
Message-Id: <gsi0us8f312he7g6gb2d9f0hpi1ul5g6m4@news.supernews.net>

Jim Mauldin <mauldin@netstorm.net> wrote:

} Geoff Soper wrote:
} > 
} > I want to be able to use %VAR throughout a program. The hash is set up in
} > subroutine 'X' and needs to be accessed by subroutine 'Y' called from
} > subroutine 'X'.
} > 
} > I thought I should be declaring it as:
} > local (%VAR) = ();
} > in subroutine 'X' but this gives the compilation error below when run
} > under strict.
} > 
} > Global symbol "%VAR" requires explicit package name at line 136.
} > 
} > I'd be grateful if somebody point me in the right direction.
} > 
} 
} As a general rule, the 'strict' pragma requires that variables either:
} 
} 1.  be declared using the my (or our) function, or
} 2.  be referred to using their fully qualified package name, e.g.
} $main::variable.

Or
  3. declared via a "use vars qw(v1 v2 v3 ...)"

  /Bernie\
-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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

Date: Sun, 8 Oct 2000 21:27:46 +0800
From: DT <dsa@dassda.com>
Subject: extract a segment of strings in a text
Message-Id: <MPG.144af72d6322ebf6989689@news.cyberway.com.sg>

Hi,
Can someone tell me how to extact, segment of a string that enclosed by 
tags. Like:

whatever, whatever, whatever, <tag>I want this<tag> whatever, whatever, 
whatever,whatever, whatever, whatever,whatever, whatever, whatever,<tag>I 
want this 111<tag> ,whatever, whatever <tag>I want this 222<tag> 
whatever, whatever

the end result I want is: I want this, I want this 111, I want this 222


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

Date: Sun, 08 Oct 2000 11:00:11 -0400
From: Steve Palincsar <palincss@his.com>
Subject: Re: Help ! DBI error
Message-Id: <39E08BFB.767A7ECD@his.com>

NDQ wrote:
> 
> Hi,
> I'm newbie with DBI. My test is :
> -------------------------------------------
> #!/usr/bin/perl
> 
> use DBI;
> $driver = "mysql";
> $database = 'toto';
>
> while(my @row = $sth->fetchow_array()){

> Can't locate object method "fetchow_array" via package "DBI::st" at
> ./test-DBI.pl line 22

You do realize the name of the method is "fetchrow_array" (that is,
"chrow" rather than "chow") as you have it?

Of course you can't locate an object method that does not exist.


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

Date: Sun, 08 Oct 2000 10:11:19 GMT
From: cmf2000@my-deja.com
Subject: Re: HELP method POST
Message-Id: <8rph86$p0d$1@nnrp1.deja.com>

Thank for your answer. i hope it is good


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 08 Oct 2000 09:52:46 +0200
From: Edmond Nolan <edmond.nolan@debitel.net>
Subject: Re: how can I get perl CGI to work with win32 perl and win32 apache?
Message-Id: <39E027CE.D97033D0@debitel.net>

better still, make sure the directory with the perl.exe is in your
path (check with the command 'set') then you avoid the space
in the "Program Files" part of the path, spaces shouldn't be there
period, MS know this and do this to make live more complicated
for everyone ; )

david wrote:

> Hullo there!  Add this line to the start of your perl script:
>
> #!C:\Program Files\Perl\bin\perl.exe
>
> Of course, change the drive letter and directories to suit (if necessary).
>
> Hopefully this helped!



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

Date: Sun, 8 Oct 2000 04:02:22 -0400
From: "Richard DeVenezia" <radevenz@ix.netcom.com>
Subject: How do I show html source as plain text in IE browser?
Message-Id: <8rp9nf$m2s$1@nntp9.atl.mindspring.net>

I am trying to write a simple 'push' perl program to deliver example parts
of my web as plain text.

The problem is when I try to deliver an html file, it gets interpreted as
html and is rendered by the IE browser.
Netscape 4.7 simply shows the text, IE is too smart for it's britches.  Is
there some way to make IE honor the content-type ?

snippet

# invoked as <server>/cgi-bin/push?file=<some file name>&type=txt
# & type=txt is to hopefully fool some browsers to really deal with the
content as text

use CGI;
my $q = new CGI;
my $file = $q->param('file');

if ( <... file exists and file is allowed to be pushed ...>) {
    print $q->header('text/plain');
    print "###### $file #######\n";

    system ("cat $file");
}


--
Richard DeVenezia




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

Date: Sun, 08 Oct 2000 10:41:37 +0200
From: Edmond Nolan <edmond.nolan@debitel.net>
Subject: Re: How do I show html source as plain text in IE browser?
Message-Id: <39E03341.3F6021EE@debitel.net>

Hi Richard,

I don't have an answer, just thought I grumble along with you! I've seen
this kinda behaviour before with MSIE 5, even opening a text file (.txt)
locally which contains HTML code is read as a HTML file :(

Richard DeVenezia wrote:

> I am trying to write a simple 'push' perl program to deliver example parts
> of my web as plain text.
>
> The problem is when I try to deliver an html file, it gets interpreted as
> html and is rendered by the IE browser.
> Netscape 4.7 simply shows the text, IE is too smart for it's britches.  Is
> there some way to make IE honor the content-type ?
>
> snippet
>
> # invoked as <server>/cgi-bin/push?file=<some file name>&type=txt
> # & type=txt is to hopefully fool some browsers to really deal with the
> content as text
>
> use CGI;
> my $q = new CGI;
> my $file = $q->param('file');
>
> if ( <... file exists and file is allowed to be pushed ...>) {
>     print $q->header('text/plain');
>     print "###### $file #######\n";
>
>     system ("cat $file");
> }
>
> --
> Richard DeVenezia



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

Date: Sun, 08 Oct 2000 10:38:13 +0200
From: Edmond Nolan <edmond.nolan@debitel.net>
Subject: Re: how to pass info to a script?
Message-Id: <39E03275.4C3A2D8@debitel.net>

think you gotta say something like src="topframe.pl?x=y"

x and y in this case would be read by topframe.pl through its environment
variables
y though would either be a HTML form field value (text field value etc) and I
don't
think that $who would be resolved ("interpolated" I think it's called in PERL
speak)
anyway

Eddie


Duoc B T wrote:

> hi all
>
> i call topframe.pl with a command like this:
>
> src="topframe.pl/$who"
>
> i want to pass the value of $who to topframe.pl, which output the page for
> the top frame. it doesn't work. please help. thank you.
>
> duoc



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

Date: Sun, 08 Oct 2000 16:31:56 +0200
From: Adam <adamf@box43.gnet.pl>
Subject: Re: looking for links to Perl+mysql how-to's - tutorials etc
Message-Id: <39E0855C.C1E@box43.gnet.pl>

Robert Chalmers wrote:
> 
> Looking for links to sites with howto's - tutorials - examples - code
> examples and so on.
> 
> Does anyone know of a couple of good ones they can recommend. I know - I
> could spend hours searching but maybe someone can offer a short cut.
> 
> Thanks a lot for any help
> 
> BC

i.e:
http://savage.net.au/Perl-tutorials.html
http://www.mysqlwebring.com/sites.php?category_id=4

Adam.


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

Date: Sun, 08 Oct 2000 09:39:23 +0200
From: Edmond Nolan <edmond.nolan@debitel.net>
Subject: Newbie -> ini file to hash table?
Message-Id: <39E024AB.62974AAC@debitel.net>

Hi,

how do I add entries from an INI file to a hash table?

My INI file would look like this ...

debug = true
debug_level = ff
comm = http

I'd like to read each line and split it at the "=" sign into
a key and value, for insertion into a hash table.

I've seen numerous example of how to do this "hardcoded", i.e.

my %ini_hash = ( "debug", "true",  "debug_level", "ff" );
so that $ini_hash{ "debug" } would equate to "true" and
           $ini_hash{ "comm" } would equate to "http"

I need something like Java's ResourceBundle.
Any help appreciated!

Eddie



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

Date: Sun, 08 Oct 2000 08:10:34 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: Newbie -> ini file to hash table?
Message-Id: <8rpa5o$kku$1@nnrp1.deja.com>

In article <39E024AB.62974AAC@debitel.net>,
  Edmond Nolan <edmond.nolan@debitel.net> wrote:
> Hi,
>
> how do I add entries from an INI file to a hash table?
>
> My INI file would look like this ...
>
> debug = true
> debug_level = ff
> comm = http
>
> I'd like to read each line and split it at the "=" sign into
> a key and value, for insertion into a hash table.
>
> I've seen numerous example of how to do this "hardcoded", i.e.
>
> my %ini_hash = ( "debug", "true",  "debug_level", "ff" );
> so that $ini_hash{ "debug" } would equate to "true" and
>            $ini_hash{ "comm" } would equate to "http"
>
> I need something like Java's ResourceBundle.
> Any help appreciated!
>
> Eddie

Go to the oreilly web site and buy all the perl books :)

The docs that come along with perl are also a valuable source of info.

I presume you can read your 'ini hash' by opening the file, iterating
over each line, using split() or a regex match to translate the line
into a key/value pair.

Brendon
++++




Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 08 Oct 2000 10:30:28 +0200
From: Edmond Nolan <edmond.nolan@debitel.net>
Subject: Re: Newbie -> ini file to hash table?
Message-Id: <39E030A4.E1EC54E3@debitel.net>

Thanks for the reply but ... (see below)

Brendon Caligari wrote:

> In article <39E024AB.62974AAC@debitel.net>,
>   Edmond Nolan <edmond.nolan@debitel.net> wrote:
> > Hi,
> >
> > how do I add entries from an INI file to a hash table?
> >
> > My INI file would look like this ...
> >
> > debug = true
> > debug_level = ff
> > comm = http
> >
> > I'd like to read each line and split it at the "=" sign into
> > a key and value, for insertion into a hash table.
> >
> > I've seen numerous example of how to do this "hardcoded", i.e.
> >
> > my %ini_hash = ( "debug", "true",  "debug_level", "ff" );
> > so that $ini_hash{ "debug" } would equate to "true" and
> >            $ini_hash{ "comm" } would equate to "http"
> >
> > I need something like Java's ResourceBundle.
> > Any help appreciated!
> >
> > Eddie
>
> Go to the oreilly web site and buy all the perl books :)

    Hmmm, thank god there was a smiley there! But I do actually have
    2 Perl books in front of me, couldn't find what I wanted though :(

>
>
> The docs that come along with perl are also a valuable source of info.
>
> I presume you can read your 'ini hash' by opening the file, iterating
> over each line, using split() or a regex match to translate the line
> into a key/value pair.

    Yup, that's the plan, but I'm kinda sorta a PERL newbie and don't know
how
    to add hash (or associative array) entries (key / value entries that
is) on the fly.

>
>
> Brendon
> ++++
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.



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

Date: Sun, 08 Oct 2000 12:32:19 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Newbie -> ini file to hash table?
Message-Id: <slrn8u0qag.5h2.tjla@thislove.dyndns.org>

I was shocked! How could Edmond Nolan <edmond.nolan@debitel.net>
say such a terrible thing:
>Hi,
>
>how do I add entries from an INI file to a hash table?
>
>My INI file would look like this ...
>
>debug = true
>debug_level = ff
>comm = http
>
>I'd like to read each line and split it at the "=" sign into
>a key and value, for insertion into a hash table.

Sounds like a good overall plan to me. I would do something like:

#!/usr/bin/perl -w
use strict;

open INI, "inifile.ini" or die $!;

my %hash;

while (<INI>)
{
    chomp;
    my ($key, $value) = split /\s+=\s+/;
    $hash{$key} = $value;
}

# print the hash out
use Data::Dumper;

print Dumper \%hash;

__END__

Note that this doesn't do anything in the situation where one key is
mentioned more than once (correction: it overwrites the original value).
This may or may not be correct :)

Here is a pointer to some documentation so you can figure out some of
this stuff. I've included a fair amount here since I'm guessing from one
of your other responses that you are fairly new to this:

perldoc -f open
perldoc perldata # see the stuff on hashes
perldoc perlop   # see the stuff on I/O operators
perldoc -f split
perldoc -f chomp # leave the 'chomp' line out and run the program again
                 # to see what it actually does
perldoc -f my
perldoc strict

I'm not sure if the 'perldoc' command is available on windows, however
whatever distribution of perl you have should have this documentation in
there in some form or other.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Don't tell any big lies today. Small ones can be just as effective.

		-- Unknown


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

Date: Sun, 8 Oct 2000 14:10:05 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: Newbie -> ini file to hash table?
Message-Id: <G247Ct.IFu@presby.edu>

In article <39E030A4.E1EC54E3@debitel.net>,
Edmond Nolan  <edmond.nolan@debitel.net> wrote:
>Thanks for the reply but ... (see below)
>
>Brendon Caligari wrote:
>
>> In article <39E024AB.62974AAC@debitel.net>,
>>   Edmond Nolan <edmond.nolan@debitel.net> wrote:
>> >
>> > how do I add entries from an INI file to a hash table?
>> >
>> > My INI file would look like this ...
>> >
>> > debug = true
>> > debug_level = ff
>> > comm = http
>>
>> I presume you can read your 'ini hash' by opening the file, iterating
>> over each line, using split() or a regex match to translate the line
>> into a key/value pair.
>
>    Yup, that's the plan, but I'm kinda sorta a PERL newbie and don't know
>    how to add hash (or associative array) entries (key / value entries
>    that is) on the fly.

OK, assuming you've got $Key equal to, say, "debug_level", and
$Value equal to "ff", and your hash is named %IniSettings, then to add
that entry to the hash you would do this:

    $IniSettings{$Key} = $Value;

Then to test the setting and act accordingly,

    if ($IniSetting{"debug_level"} eq "ff") {
    {
        # do something
    }

Note the $ instead of % at the beginning of the hash name here.  Use $
when you want to refer to a single element of the hash; use % when you
want to refer to the entire hash.  This is analogous to $ versus @ with
arrays.

-- 
Jon Bell <jtbell@presby.edu>                        Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA
[ Questions about newsgroups?  Visit http://www.geocities.com/nnqweb/  ]
[                or ask in news:news.newusers.questions                ]


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

Date: Sun, 08 Oct 2000 09:34:17 GMT
From: overbeek@chello.nl (Pieter Overbeeke)
Subject: newbie: pws and active perl
Message-Id: <39e04087.67372614@news.arnhem.chello.nl>

Hi all, 

I'm trying to get cgi (perl) scripts working on pws but i'm bot being
very succesfull yet. So i hope someone can help me.

I am running pws on win98. I have installed activeperl, set the
mimetypes right, in the registry, in
HKEY_LOCAL_MACHINE/System/CurrentControlSet/Services/w3svc/parameters/Script
Map i have added .pl .cgi and .plx which refer to c:/perl/bin/perl.exe
%s %s (also tried c:/perl/bin/perl5.6.0.exe %s %s).
I have made a virtual directory : cgi-bin in PWS and set the rights to
read/execute/scripts.

When i try to execute a cgi script in my browser
(http://ns/cgi-bin/xxx.cgi)  then the browser just keeps on waiting
for something to return from the server, but nothing happens.

Did i forgot something or am i doing something wrong?
 
I would be very gratefull if someone could explain this.

Greetings, Pieter


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

Date: Sun, 8 Oct 2000 14:46:32 +0100
From: "Makhno" <mak@imakhno.freeserve.co.uk>
Subject: Perl binary for BeOS r5
Message-Id: <8rptrh$ljr$1@news6.svr.pol.co.uk>

Does anybody know where I can get hold of a binary Perl distribution that
was compiled under BeOS r5? I've contacted Tom Spindler, the maintainer of
the r4-compiled perl binary, but I hear from other newsgroups that he's no
longer responding.





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

Date: Sun, 08 Oct 2000 11:04:21 -0400
From: Steve Palincsar <palincss@his.com>
Subject: Re: Perl4-036 compile error in eval.c
Message-Id: <39E08CF5.8B5CCDF5@his.com>

"Long T. Nguyen" wrote:
> 
> In attempt to compile perl4.036 for an old in-house perl application here

Why, for heaven's sake?  With very few and well-documented exceptions,
that old code will run OK on a modern Perl.  Have you tried that
approach?


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

Date: Sun, 8 Oct 2000 10:15:59 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: PP, 3rd ed.???
Message-Id: <Pine.A41.4.21.0010081014580.16452-100000@ginger.libs.uga.edu>

On Fri, 6 Oct 2000, Godzilla! wrote:
> Josiah wrote:
> > Geesh Kiralynne... can't you answer with a bit of Kindness? There is
> 
> Clearly you have mistaken me for someone who cares.
> 

Truer words ...

Brad



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

Date: Sun, 08 Oct 2000 15:52:26 +0200
From: Adam <adamf@box43.gnet.pl>
Subject: Removing of nested C-like comments.
Message-Id: <39E07C1A.6DFE@box43.gnet.pl>

Hi everybody.
I actually solved the problem from the subject of
this meaasge, and the solution I came up with (example 
code below) works fine with files of size less than 20kB.
A weak point of this solution I realize of, is
reading the whole file into $src. 
Thus I wonder if there is an elegant and efficient solution
applying reading the file line by line, or
even a parser module appropriate for such a problem.

Any advice is welcome.
Adam.

P.S. 
for the curious: 
 I use it to "clean up" 4GL Progress source.
to the example code beneth: 
 I want to retain the original structure and justification. 
 Spaces are replaced with # for better readability.

# CODE START
undef $/ ;
$src = <DATA> ;

$s = "\201" ;                 # Characters I do not expect 
$e = "\202" ;                 # to be in the source file
$src =~ s!/\*!$s$s!g ;        # Make the comment delimiters
$src =~ s!\*/!$e$e!g ;        # easier to recognize
$pat = "$s$s\[^$s$e\]\*$e$e"; # Silgne, not nested comment

while ( $src =~ /$pat/go ) {
  $rem = $& ;
  $rem =~ tr/\n/#/c ;
  $src =~ s/$pat/$rem/ ;
}

print $src ;
__DATA__
1  /* 1 */    1
2 /* /* */ */ 2
3    /*3      3
4    3*/      4
5             5
66/*6*/6/*66*/6
7 /*12/*34*/  7
8  /*8*/      8
9       */    9
a/*aa/*bb/*cc a
b dd*/ee*/ff*/b
# CODE END

the output:
1  #######    1
2 ########### 2
3    ##########
########      4
5             5
66#####6######6
7 #############
###############
##########    9
a##############
##############b


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

Date: Sun, 8 Oct 2000 10:22:32 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <Pine.A41.4.21.0010081017510.16452-100000@ginger.libs.uga.edu>

On Sat, 7 Oct 2000 ollie_spencer@my-deja.com wrote:
> Thank you for your answer. I will happily comform to whatever norm
> is in vogue. I just want technical dialog with personalities
> left out.

You're not alone.  OTOH, some personalites are fun.


> FWIW:Less than 2 years ago I was severely criticised for posting
> non-jeopardy fashion(i.e., my new message "at bottom") in company
> e-mails! The execs like their meat upfront, I guess.

True in my case as well.  I've long since stopped trying to change that.


> That was my template. If you've had the stomach to follow this thread,
> you know my other stupidities.

I think you're adjusting your scores pretty well.  :-)

Brad



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

Date: 08 Oct 2000 00:09:07 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Text file manipulation
Message-Id: <m3bswvyl58.fsf@dhcp11-177.support.tivoli.com>

<@tampabay.rr.com> writes:

> Given is a textfile with content like this:
> 
> NAME='var1;var2;var3;var4'
>     NAME1='var5;var6;var7'
> NAME='var1;var2;var3;var4'
>     NAME1='var5;var6;var7'
> NAME='var1;var2;var3;var4'
>     NAME1='var5;var6;var7'
> 
> I need to convert it into:
> 
> var1;var2;var3;var4;var5;var6;var7
> var1;var2;var3;var4;var5;var6;var7
> var1;var2;var3;var4;var5;var6;var7

You've left the definition of the input data pretty wide open, so some
assumptions are necessary.  The one I have chosen is that the "NAME"
and "NAME1" labels are completely irrelevant and all that matters is
that the data within the single quotes on two consecutive lines is
joined with a semicolon.

while(<DATA>) {
  $_ .= <DATA>;
  s/[^']*'([^']*)'[^']*'([^']*)'/$1;$2/;
  print;
}
__DATA__
NAME='var1;var2;var3;var4'
    NAME1='var5;var6;var7'
NAME='var1;var2;var3;var4'
    NAME1='var5;var6;var7'
NAME='var1;var2;var3;var4'
    NAME1='var5;var6;var7'
__END__

Converting this to read from a file and to be called from another
script is left as an exercise... unless, of course, that was the real
question....

Also, there are lots of other ways to express that regex, but I
believe that one tends to be faster. On the other hand... split is
likely to be even faster than that:

$_ = join(';', (split /'/)[1,3]) . "\n";

Aw... what the heck:

#!/usr/bin/perl -w
use strict;
use Benchmark;

our $str = "NAME='var1;var2;var3;var4'\nNAME1='var5;var6;var7'";
timethese -10, { RE =>
                   sub {
                     $_ = $str;
                     s/[^']*'([^']*)'[^']*'([^']*)'/$1;$2/;
                   },
                 SPLIT =>
                   sub {
                     $_ = $str;
                     $_ = join(';', (split /'/)[1,3]) . "\n";
                   }
               };
__END__


Benchmark: running RE, SPLIT, each for at least 10 CPU seconds...
     RE: 11 wallclock secs (10.80 usr +  0.01 sys = 10.81 CPU)
         @ 22315.17/s (n=241227)
  SPLIT: 10 wallclock secs (10.53 usr + -0.10 sys = 10.43 CPU)
         @ 39721.67/s (n=414297)

So the split is about 78% faster on this particular data.

HTH,
-- 
Ren Maddox
ren@tivoli.com


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

Date: Sun, 08 Oct 2000 14:46:12 GMT
From: "Henning" <hgg@techsoftdesign.com>
Subject: Re: Text file manipulation
Message-Id: <UM%D5.59952$O95.4285395@typhoon.tampabay.rr.com>

Hello,

Actually, I will be using this script in a cron job on a Unix box that will
run twice a week to process between 10 and 20 files. I have been doing it
manually but I am getting tired of it.  :-)

Henning

"Dale Emmons" <dale@emmons.dontspamme.com> wrote in message
news:stvip2654qd740@corp.supernews.com...
> Since you used outlook to send the message, I assume you can use windows
to
> process the file. If you only have a few files to do, it may be easier to
> just grab edit plus (www.editplus.com), open the text file and use edit
> plus's text replacement dialog box. (ctrl + H)
> Replace >NAME='< with >< (nothing)
> Replace >'\n\tNAME1='< with >;<
> Replace >'< with ><. Done.





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

Date: Sun, 08 Oct 2000 14:54:44 GMT
From: "Henning" <hgg@techsoftdesign.com>
Subject: Re: Text file manipulation
Message-Id: <UU%D5.59953$O95.4287622@typhoon.tampabay.rr.com>

> PS. This will work on your input. If the REAL input is more complex,
> then please, next time, post some REAL input. I'm really going to be
> pissed off if you come back with something like 'But, the real input can
> contain single quothes in other places'.

Thanks for the help, I appreciate it greatly. You were pretty much right on,
in your other mails in this thread. Sorry for not stating the task more
clearly. But I was 100% accurate with presenting the data.  :-)

Thanks
Henning




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

Date: Sun, 08 Oct 2000 10:33:34 GMT
From: burt@ici.net (Burt Lewis)
Subject: Unable to run an SSI #exec statement outside of my home directory
Message-Id: <24YD5.41103$tn.758536@typhoon.ne.mediaone.net>

Hello,

I can run this <!--#exec cmd="cgi-bin/eastonmass/banner/banner2.cgi"-->

with no problem from my root or home directory with no problem.
/files/WWW/htdocs/myhomepagearea

It does not work from any other sub-directory and I have tried to change the 
path every way I can imagine. Is this something my ISP has to change or do I 
just have the wrong path?

Appreciate any help?



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

Date: Sun, 08 Oct 2000 12:21:15 GMT
From: harry@drej.com
Subject: What does $++ mean?
Message-Id: <8rporq$tgv$1@nnrp1.deja.com>

I'm looking at some sample code which begins:

#!/usr/bin/perl -T
use strict;
$++;

I have looked far and wide for the meaning of $++. I would not be
posting this if I could find it myself, have looked through "Programming
Perl", other books, newsgroups, etc.

Doesn't help that search engines like deja.com apparently interpret this
combination, making it impossible to search for.

I would appreciate any help.

TIA,

Harry M. Pierson


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 08 Oct 2000 14:13:10 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: What does $++ mean?
Message-Id: <Wh%D5.251$lw3.31366@eagle.america.net>

On Sun, 08 Oct 2000 12:21:15 GMT, harry@drej.com <harry@drej.com> wrote:
>I'm looking at some sample code which begins:
>
>#!/usr/bin/perl -T
>use strict;
>$++;
>
>I have looked far and wide for the meaning of $++. 

    $ perl -Mstrict -Twe '$++;'
    syntax error at -e line 1, near "+;"
    Execution of -e aborted due to compilation errors.
    $ 

Does this help?  

-- 
Garry Williams


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

Date: Sun, 8 Oct 2000 10:38:21 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: What does $++ mean?
Message-Id: <Pine.A41.4.21.0010081037450.16452-100000@ginger.libs.uga.edu>

On Sun, 8 Oct 2000 harry@drej.com wrote:

> I'm looking at some sample code which begins:
> 
> #!/usr/bin/perl -T
> use strict;
> $++;
> 
> I have looked far and wide for the meaning of $++. I would not be
> posting this if I could find it myself, have looked through "Programming
> Perl", other books, newsgroups, etc.
> 

Looks like a misprint to me.

Brad



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

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


Administrivia:

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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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.

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 V9 Issue 4552
**************************************


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