[23904] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6106 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 10 09:05:36 2004

Date: Tue, 10 Feb 2004 06:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 10 Feb 2004     Volume: 10 Number: 6106

Today's topics:
    Re: Anyone using Berkley XML DB w/Perl (of course)...? <paul.marquess@btinternet.com>
        build_dir/perl uses /usr/lib/perl !? <bill_knight2@yahoo.com>
        Expect telnet password is exposed <ajay_kumarsingh@yahoo.com>
    Re: Expect telnet password is exposed <usenet@morrow.me.uk>
    Re: Expect telnet password is exposed <ajay_kumarsingh@yahoo.com>
    Re: Expect telnet password is exposed <usenet@morrow.me.uk>
    Re: Expect telnet password is exposed <xx087@freenet.carleton.ca>
    Re: glob in perl <bart.lateur@pandora.be>
    Re: How to execute a command line in Perlscript (Eric SALGON)
    Re: IO::Socket::INET Problem (Hobbit HK)
    Re: IO::Socket::INET Problem <usenet@morrow.me.uk>
    Re: Pearl "Print Statement" Question <tadmc@augustmail.com>
        Perl usage these days? thumb_42@yahoo.com
    Re: Perl usage these days? <tadmc@augustmail.com>
        Processing variables  <bill@hotmail.com>
    Re: Processing variables <usenet@morrow.me.uk>
    Re: Processing variables <tore@aursand.no>
    Re: script working like daemon <usenet@morrow.me.uk>
    Re: Why is Perl losing ground? <usenet@morrow.me.uk>
    Re: Why is Perl losing ground? <tore@aursand.no>
    Re: Why references?? <thomas.deschepper.ecol@sintjozefscollege.be>
    Re: Why references?? <tore@aursand.no>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Feb 2004 12:38:21 -0000
From: "Paul Marquess" <paul.marquess@btinternet.com>
Subject: Re: Anyone using Berkley XML DB w/Perl (of course)...?
Message-Id: <c0ajc0$14n2ol$1@ID-211855.news.uni-berlin.de>

"Ben Morrow" <usenet@morrow.me.uk> wrote in message
news:c097lg$ajg$2@wisteria.csv.warwick.ac.uk...
>
> Vetle Roeim <vetro@online.no> wrote:
> > * ceo@nospan.on.net
> > > I'm trying to find some Perl API support (read "CPAN module") for
> > > using Sleepcat's Berkley XML DB, but I'm coming up blank.
> >
> >   You're not going to find it on CPAN,  unfortunately. To install it, I
> >   downloaded the source code, compiled it, and then installed the Perl
> >   module from dbxml-1.2.0/src/perl.
>
> Having taken a look at that: bleech.

Thanks for the constructive feedback Ben. :-)

Seriously though, I'd be interested to hear in a bit more detail what you,
and anoyone else in this thread, think about the current interface, both
good and bad.  To date, this is the first negative feedback I've received.

> Is it *quite* necessary to
> trample on that many different (including top-level and pragmatic)
> namespaces?

Yes. There are quite a few objects exposed by the dbxml interface. If you
want those C++ objects to map to Perl objects, you need a namespace for
each.

I didn't think I was reusing any  pragmatic namespaces - which are you
thinking of?

> And is it really necessary to have the interface be so C++ish?

Well it is an interface to a C++ library after all  :-)

When I wrote the interface, it seemed obvious make it mirror the OO
interface that dbxml was already provinding.

> You may be better off writing your own wrapper: it shouldn't be *that*
> hard...

Absolutely, TMTOWTDI.

Paul




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

Date: Tue, 10 Feb 2004 13:15:50 +0000 (UTC)
From: bill <bill_knight2@yahoo.com>
Subject: build_dir/perl uses /usr/lib/perl !?
Message-Id: <c0ali6$nim$1@reader2.panix.com>




I'm doing a re-installation of Perl 5.8.2-2, because the currently
installed version has threads enabled, which I don't want.  When
I do make test, 2 tests fail.  Not surprisingly, these tests also
fail when I run them individually using:

bash-2.05b$ LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd t; ./perl harness <test_file>


The first failing test (run/fresh_perl.t) fails with the error:

/home/knight/build/perl-5.8.2/perl: relocation error: /usr/lib/perl/5.8.2/auto/NDBM_File/NDBM_File.so: undefined symbol: Perl_Gthr_key_pt

which suggests that the perl in the build directory is somehow
using library files from the site installation.  This makes no
sense to me.  How do I fix it?  (To make matters worse, the build
being tested does not include a file NDBM_File.so., so I can't
redirect ./perl to use it.)  (BTW, it looks like this error has
something to do with the fact that the site perl has threads enabled,
whereas the one I'm building doesn't).

The second failing test (../lib/ExtUtils/t/Embed.t) fails with

/usr/bin/ld: cannot find -lperl
collect2: ld returned 1 exit status

Again, another library related failure, but here I'm clueless as
to what may be going on.

I'm sure these tests are not failing for substantial reasons, but
I want to make sure the run properly once these reasons are removed.
What must I do to get these tests to go?

Thanks.

bill




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

Date: Tue, 10 Feb 2004 17:15:50 +0530
From: Ajay <ajay_kumarsingh@yahoo.com>
Subject: Expect telnet password is exposed
Message-Id: <4028C46E.EE2E36AA@yahoo.com>

Finally getting hookedup to expect :)
Here is the script i got to start with, it's working fine. I got it frm this NG.
Now i want to modify it to suit my taste.
1) I want to create a new xterm window from this script then telnet into the
remote server and then run the other commands.
2) In the script i have to expose password. How to amke it secure secure it ?
Any help will be appreciated.

Tx
Ajay

#!/opt/exp/bin/expect -f

set name "myname"
set password "XYZ"
set host "server1"
set prompt_regexp "\\$"
set timeout 60

spawn telnet $host

expect {
    login: {
 send "$name\n"
    } timeout {
 send_user "connection to $host timed out.\n"
 exit
    } eof {
 send_user "connection to $host failed: $expect_out(buffer).\n"
 exit
    }
}

expect {   
    Password: {
 send "$password\n"
    } timeout {
 send_user "connection to $host timed out.\n"
 exit
    } eof {
 send_user "connection to $host failed: $expect_out(buffer).\n"
 exit
    }
}


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

Date: Tue, 10 Feb 2004 11:56:33 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Expect telnet password is exposed
Message-Id: <c0agth$3em$2@wisteria.csv.warwick.ac.uk>


Ajay <ajay_kumarsingh@yahoo.com> wrote:
> Finally getting hookedup to expect :)
> Here is the script i got to start with, it's working fine. I got it frm this NG.

> #!/opt/exp/bin/expect -f

I find that unlikely: this is a Perl ng.

> Now i want to modify it to suit my taste.
> 1) I want to create a new xterm window from this script then telnet into the
> remote server and then run the other commands.

You need to create a shell script that runs

  xterm -e /path/to/expect/script

> 2) In the script i have to expose password. How to amke it secure secure it ?

You're using telnet, so you're screwed anyway wrt security. In
general, you can either ask the user for the password each time (and
no, I don't know if/how you can do that in expect) or just make sure
the read permissions on the script are as tight as possible.

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: Tue, 10 Feb 2004 17:53:01 +0530
From: Ajay <ajay_kumarsingh@yahoo.com>
Subject: Re: Expect telnet password is exposed
Message-Id: <4028CD25.B56341ED@yahoo.com>

Ben Morrow wrote:
> 
> Ajay <ajay_kumarsingh@yahoo.com> wrote:
> > Finally getting hookedup to expect :)
> > Here is the script i got to start with, it's working fine. I got it frm this NG.
> 
> > #!/opt/exp/bin/expect -f
> 
> I find that unlikely: this is a Perl ng.

kindly guide me to "expect" grp please || tell me the appropriate grp where i
can post expect related Qs
 
> > Now i want to modify it to suit my taste.
> > 1) I want to create a new xterm window from this script then telnet into the
> > remote server and then run the other commands.
> 
> You need to create a shell script that runs
> 
>   xterm -e /path/to/expect/script
Yeh that's what i do. But i think i can do a fork and run telnet and other
commands inside that process. Still hunting Google...

> > 2) In the script i have to expose password. How to amke it secure secure it ?
> 
> You're using telnet, so you're screwed anyway wrt security. In
> general, you can either ask the user for the password each time (and
> no, I don't know if/how you can do that in expect) or just make sure
> the read permissions on the script are as tight as possible.
i saw somewhere ppl talking about ssh.
how to do it into ssh ?
> Ben
Tx for reply
> 
> --
> Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
>    From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
> (Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
>  /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: Tue, 10 Feb 2004 12:35:55 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Expect telnet password is exposed
Message-Id: <c0aj7b$4ue$2@wisteria.csv.warwick.ac.uk>


Ajay <ajay_kumarsingh@yahoo.com> wrote:
> Ben Morrow wrote:
> > Ajay <ajay_kumarsingh@yahoo.com> wrote:
> >
> > > #!/opt/exp/bin/expect -f
> > 
> > I find that unlikely: this is a Perl ng.
> 
> kindly guide me to "expect" grp please || tell me the appropriate grp where i
> can post expect related Qs

You will find that politeness and full English sentences will get you
a long way in life. Try comp.lang.tcl (IIRC expect is written in or
for tcl), but don't blame me if it's wrong.

Ben

-- 
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
  ben@morrow.me.uk   <=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>   (Kate Rusby)


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

Date: 10 Feb 2004 13:08:54 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Expect telnet password is exposed
Message-Id: <slrnc2hlv6.kid.xx087@smeagol.ncf.ca>

Ajay <ajay_kumarsingh@yahoo.com> wrote:
>  Ben Morrow wrote:
> > Ajay <ajay_kumarsingh@yahoo.com> wrote:
> > > #!/opt/exp/bin/expect -f
> > I find that unlikely: this is a Perl ng.
>  kindly guide me to "expect" grp please || tell me the appropriate grp where i
>  can post expect related Qs

comp.lang.tcl


-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


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

Date: Tue, 10 Feb 2004 11:12:12 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: glob in perl
Message-Id: <e2fh20h1dnhrc7g9qnk7bkjoehg85l71t3@4ax.com>

Andreas Boehm wrote:

>And does there exist a solution that correctly globs folders containing 
>spaces in their names?

On Windows, this works:

	#!perl -l
	print for glob('"c:/My Documents/*.txt"');

Note the extra double quotes around the path, inside the string.

-- 
	Bart.


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

Date: Tue, 10 Feb 2004 13:40:18 +0000 (UTC)
From: eric.salgon@mane.com (Eric SALGON)
Subject: Re: How to execute a command line in Perlscript
Message-Id: <c0an02$4m5$1@s1.read.news.oleane.net>

Chris,

It was not a problem of backward ticks, no chance.
The result is unfortunatly the same ...

another idea ?

Thx

Eric
 
In article <A4bVb.19477$2x6.1543@newssvr16.news.prodigy.com>, 
ceo@nospan.on.net says...
>
>Chris wrote:
>> Eric SALGON wrote:
>> 
>>> In article <elvUb.19067$Fp6.2360@newssvr16.news.prodigy.com>, 
>>> ceo@nospan.on.net says...
>>>
>>>> Eric SALGON wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> Is there someone who knows how to execute a command line (such a simple 
>>>
>>>
>>> echo
>>>
>>>>> cmd) in PerlScript.
>>>>>
>>>>> I hve tryed '' or system() but the result is the same: no result but no 
>>>
>>>
>>> error
>>>
>>>>> !
>>>>>
>>>>> This syntax works fine in a perl program but not in PerlScript
>>>>>
>>>>> An idea ?
>>>>>
>>>>
>>>> I just realized I didn't answer your question in my last response.
>>>>
>>>> First of all, as a general rule, and one that is outlined in the FAQ 
>>>> (and asked about a lot here is) system() does NOT provide output.  
>>>> But most especially in the Windows world where Microsoft writes their 
>>>> own rules, this is also not the case in either ASP or WSH (still 
>>>> assuming you are talking about "PerlScript" and not "Perl script.")
>>>>
>>>> Using output wrappers in the ASP and WSH worlds for outputing a 
>>>> string, the following code will work in both worlds for outputing a 
>>>> "system" command:
>>>>
>>>> sub shell {
>>>>
>>>>   my @output;
>>>>   for (@_) { push( @output, `$_` ) }
>>>>   chomp( @output );
>>>>   return wantarray ? @output : \@output;
>>>>
>>>> }
>>>>
>>>> puts( shell( 'dir /l/on/' ) );
>>>>
>>>> or you can:
>>>>
>>>> puts( shell(
>>>>   'dir',
>>>>   'type c:\\autoexec.bat',
>>>>   'dir c:\\winnt\\system32',
>>>>   'command4',
>>>>   'command5',
>>>> ));
>>>>
>>>> If:
>>>>
>>>> ASP: sub puts { for (@_) { $Response->Write( "$_\n" ) } }
>>>> WSH: sub puts { for (@_) { $WScript->Echo( "$_\n" ) } }
>>>>
>>>> Incidentially using PerlScript in Windows allows you this 
>>>> convenience. The "official" Microsoft "interface" (read "complicated 
>>>> and convolluted") for executing a command in a scripting environment 
>>>> (both ASP and WSH) is WshShell.Exec() (which takes two calls to set 
>>>> up.)  You can do this in PerlScript if you want, but the regular Perl 
>>>> way of executing a system command works much smoother.
>>>>
>>  > [Top Posting Fixed]
>>  >
>> 
>>> Unfortunatly, I have implemented "shell" and "puts" functions in my 
>>> ASP code but `$_` return no result in @output array with a simple 
>>> 'dir' command.
>>>
>>> I'm afraid it's a problem of right on my IIS server.
>>>
>> 
>> If your tick marks above are an accurate portrayal of what you used in 
>> your shell() code, then, no you will not get output.  (You would only 
>> get an echo back of the command(s) you wanted to run that way.)  The 
>> single tick marks in my shell() routine above are backward ticks.  Use 
>> qx() if this is confusing:
>> 
>> sub shell {
>> 
>>    my @output;
>>    for (@_) { push( @output, qx($_) } }
>>    chomp( @output );
>>    return wantarray ? @output : \@output;
>> 
>> }
>> 
>
>The extra "}" at the end of the line "for (@_) { push..." in the shell() 
>routine should be removed.  Should have been:
>
>for (@_) { push( @output, qx($_) ) }
>
>Chris
>-----
>Chris Olive
>chris -at- --spammers-are-vermin-- technologEase -dot- com
>http://www.technologEase.com
>(pronounced "technologies")
>
>"Uh?  Yes... well...  You don't know *everything*..."
>--Puddleglum, _The Silver Chair_



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

Date: 10 Feb 2004 04:37:42 -0800
From: hobbit_hk@hotmail.com (Hobbit HK)
Subject: Re: IO::Socket::INET Problem
Message-Id: <22ee5d47.0402100437.4d0d1a50@posting.google.com>

Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c085k2$h2n$5@wisteria.csv.warwick.ac.uk>...
> hobbit_hk@hotmail.com (Hobbit HK) wrote:
> > I'm using WinXP (although I also have RH Linux and there's no
> > difference) and I want to write a script which uses sockets... Now, my
> > main problem is when there's  nothing else to read from the socket...
> > That's where my script stucks... My guess is that because it keeps on
> > waiting for something (it can still get data)... Is there some way to
> > bypass this?
> 
> What do you want it to do in that case? Stop? It is usual for socket
> programs to either wait until the other end closes the socket (which
> will come out as reading EOF) or to close it yourself on some
> condition, ie. during the processing immediately after having read something.
> 

Yes, I want it to stop reading and move on... After a while when no
data has arrived to just stop reeading... It's kinda annoying with
IO::Select because it still waits the number of seconds I told it,
even if there's data...

> > Will Blocking=>0 in IO::Socket::INET's new() help?
> > I'm using $line=<$sock> to read from the socket.
> 
> Might do. It won't if you use buffered reads, though, so you either
> want to switch to sysread or (if you have 5.8) push a :unix (NB. I
> have never tried this and, though it ought to work, I don't really
> know... :). 

What do you mean by buffer reads? read($sock, $buffer, 1000)?
And "push a :unix"?

>You may also, as someone else said, want to use
> IO::Select.

> Ben


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

Date: Tue, 10 Feb 2004 13:24:14 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: IO::Socket::INET Problem
Message-Id: <c0am1u$727$1@wisteria.csv.warwick.ac.uk>


hobbit_hk@hotmail.com (Hobbit HK) wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote in message
>  news:<c085k2$h2n$5@wisteria.csv.warwick.ac.uk>...
> > What do you want it to do in that case? Stop? It is usual for socket
> > programs to either wait until the other end closes the socket (which
> > will come out as reading EOF) or to close it yourself on some
> > condition, ie. during the processing immediately after having read something.
> > 
> 
> Yes, I want it to stop reading and move on... After a while when no
> data has arrived to just stop reeading... It's kinda annoying with
> IO::Select because it still waits the number of seconds I told it,
> even if there's data...

No it doesn't. It should return when there's data, or when the timeout
has expired, whichever is the sooner.

> > > Will Blocking=>0 in IO::Socket::INET's new() help?
> > > I'm using $line=<$sock> to read from the socket.
> > 
> > Might do. It won't if you use buffered reads, though, so you either
> > want to switch to sysread or (if you have 5.8) push a :unix (NB. I
> > have never tried this and, though it ought to work, I don't really
> > know... :). 
> 
> What do you mean by buffer reads? read($sock, $buffer, 1000)?

Yup. Use sysread instead.

> And "push a :unix"?

If you are using 5.8 and built your perl with PerlIO, 

binmode $FH, ':unix';

*ought* to make all reads on that FH unbuffered, even those done with
<>... as I said, though, I've not tried it, and I wouldn't be
surprised if it didn't work. See perldoc PerlIO.

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Tue, 10 Feb 2004 06:47:33 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Pearl "Print Statement" Question
Message-Id: <slrnc2hkn5.55c.tadmc@magna.augustmail.com>

Information <vpnavy@yahoo.com> wrote:

>> AAAARGH!
>> it was a CGI question after all !

> Gosh, I should have said it was a CGI question.


Gosh, you should have posted it to a newsgroup that is
somehow related to CGI then.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 10 Feb 2004 12:50:12 GMT
From: thumb_42@yahoo.com
Subject: Perl usage these days?
Message-Id: <8s4Wb.270436$xy6.1380339@attbi_s02>

Just a curious question:

What is perl being used for these days?

Seems almost everything web related I see is PHP or Java. (mostly PHP)

My own experience is that Perl is wonderful for batch processing, command
line stuff, cron and specialized servers but compared to what is available
today, really doesn't seem suitable for serious web applications anymore.

So... what are people doing with it? is it still alive? Do people actually
get paid to work in perl, or is it strictly a labor of love?

(Yes, I know these are FAQ's, but times change, I'm curious about what
people think these days)

Jamie


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

Date: Tue, 10 Feb 2004 07:26:47 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl usage these days?
Message-Id: <slrnc2hn0n.5a4.tadmc@magna.augustmail.com>

thumb_42@yahoo.com <thumb_42@yahoo.com> wrote:

> What is perl being used for these days?
> 
> Seems almost everything web related I see is PHP or Java. (mostly PHP)


   "There are more things in heaven and earth, Horatio, than are 
    dreamt of in your philosophy." 

There is lots and lots of computing that is not "web related".


> So... what are people doing with it?


The same things they were doing with Perl for all those years before
the web was invented, plus some more.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 10 Feb 2004 11:49:35 GMT
From: "blnukem" <bill@hotmail.com>
Subject: Processing variables 
Message-Id: <jz3Wb.4177$rv1.1388282@news4.srv.hcvlny.cv.net>



Hi All

I use this script to update my website it is called via a second script that
uses strict. The problem is in the in the last routine "#Print the new web
page" section on the bottom the "foreach (@HtmlTemplate)" routine will only
process a "few" of the pages in the @MainLinks Array and then is stops. But
if I null out the entire "foreach (@HtmlTemplate)" routine and put print
"$HTMLPageData"; it will work fine but without the template data. I cant
seem to figure it out.

Thnaks in advance
blnukem

PERL CODE:

#!/usr/bin/perl -w

sub RebuildWebSite {

my ($DataBase,$PageType,$PageName,$LinkStatus);

######################################
# Get the master template
######################################
open (MASTERTEMPLATE,
"<$FolderPath/cgi-bin/data/webbuilder/templates/mastertemplate.dat") ||
print "ERROR: Could not open MASTERTEMPLATE
$FolderPath/cgi-bin/data/webbuilder/templates/mastertemplate.dat to read the
data: $!";
my @HtmlTemplate = <MASTERTEMPLATE>;
close(MASTERTEMPLATE);

######################################
# Read all of the sites pages into one array and reverse them
######################################
opendir (DIR,
"/usr/local/etc/httpd/htdocs/localhost/cgi-bin/data/webbuilder/sitelinks")
|| print "ERROR: Cannot open directory: $!";
@ARGV = map
"/usr/local/etc/httpd/htdocs/localhost/cgi-bin/data/webbuilder/sitelinks/$_"
, grep ! -d, readdir DIR;
closedir DIR;

@MainLinks = <>;
@MainLinks =  reverse(@MainLinks);

print "@MainLinks";  #<-- For testing to make sure the array is complete.

foreach my $LinkName (@MainLinks) {
($DataBase,$PageType,$PageName,$LinkStatus) = split (/\|/, $LinkName);

$LinkStatus=~ s/\r//ig;
$LinkStatus =~ s/\n//ig;

######################################
# If the page is a blindlink skip it (for java menu).
######################################
if ($PageType eq "blindlink"){
next;
}

$LowercaseName =  "$PageName";
$LowercaseName =~ s/\W//ig;  # Remove all junk
$LowercaseName = lc($LowercaseName);

$HtmlPageToPrint =  "$LowercaseName";

######################################
# We look for the index page
######################################
if ($PageType eq "index"){
$HtmlPageToPrint = "index";
}

######################################
# Get the text for the particular page in question
######################################
open (HTMLTEXT,
"<$FolderPath/cgi-bin/data/webbuilder/sitepages/$LowercaseName.dat") ||
print "ERROR: Could not open HTMLTEXT
$FolderPath/cgi-bin/data/webbuilder/sitepages/$LowercaseName.dat to read the
data: $!";
my @HtmlText = <HTMLTEXT>;
close(HTMLTEXT);

my $HTMLPageData = "@HtmlText";   #<-- $HTMLPageData is the varaible were
the text should go on the main template.

######################################
# Print the new web page     #<-- Here is the trouble spot
######################################
open (HTLMLPAGE, ">$FolderPath/$HtmlPageToPrint.htm") || print "ERROR: Could
not open HTLMLPAGE $FolderPath/$HtmlPageToPrint.htm to print the data: $!";

foreach (@HtmlTemplate) {
my $xdata = $_;
$xdata =~ s/(\$\w+)/$1/eeg; # Process the variables
print HTLMLPAGE "$xdata";
}

close(HTLMLPAGE);

    }# End of foreach
} # end of sub

1;

############# This also works fully but doesn't use template.
#
#                           #foreach (@HtmlTemplate) {
#                           #my $xdata = $_;
#                           #$xdata =~ s/(\$\w+)/$1/eeg; # Process the
variables
#                           #print HTLMLPAGE "$xdata";
#                           print HTLMLPAGE "$HTMLPageData";
#                           #}
#                           close(HTLMLPAGE);





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

Date: Tue, 10 Feb 2004 12:23:30 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Processing variables
Message-Id: <c0aig2$4ue$1@wisteria.csv.warwick.ac.uk>


"blnukem" <bill@hotmail.com> wrote:
> I use this script to update my website it is called via a second script that
> uses strict. The problem is in the in the last routine "#Print the new web
> page" section on the bottom the "foreach (@HtmlTemplate)" routine will only
> process a "few" of the pages in the @MainLinks Array and then is stops. But
> if I null out the entire "foreach (@HtmlTemplate)" routine and put print
> "$HTMLPageData"; it will work fine but without the template data. I cant
> seem to figure it out.
>
> PERL CODE:
> 
> #!/usr/bin/perl -w

use warnings is better than -w.
use strict will not have propagated from the other script: put it here
as well.

> sub RebuildWebSite {
> 
> my ($DataBase,$PageType,$PageName,$LinkStatus);

Fix your indenting. Declare your variables in the smallest scope
possible: i.e. just before you use them.

> ######################################
> # Get the master template
> ######################################

Girt big boxes like this are not helpful.

> open (MASTERTEMPLATE,
> "<$FolderPath/cgi-bin/data/webbuilder/templates/mastertemplate.dat")
> || print "ERROR: Could not open MASTERTEMPLATE
> $FolderPath/cgi-bin/data/webbuilder/templates/mastertemplate.dat to read the
> data: $!";
> my @HtmlTemplate = <MASTERTEMPLATE>;
> close(MASTERTEMPLATE);

Use or rather than ||; put the newlines in meaningful places; use
lexical FHs; use die for fatal errors as the message goes to stderr
and the program halts; don't *ever* type such a long string twice, use
a variable:

    my $webbuilder      = "$FolderPath/cgi-bin/data/webbuilder";
    my $master_template = "$webbuilder/templates/mastertemplate.dat";

    my @HtmlTemplate = do {
        open my $MASTERTEMPLATE, '<', $master_template
            or die "can't open $master_template: $!";

        <$MASTERTEMPLATE>;
    };

The file will be closed at the end of the do block.

> 
> ######################################
> # Read all of the sites pages into one array and reverse them
> ######################################

Comments should not explain what the code does: that should be clear
from the code. They should explain why.

> opendir (DIR,
> "/usr/local/etc/httpd/htdocs/localhost/cgi-bin/data/webbuilder/sitelinks")

Is this /usr/local/.../localhost the same as $FolderPath above, or
not? In either case, it should be in a variable.

> || print "ERROR: Cannot open directory: $!";
> @ARGV = map
> "/usr/local/etc/httpd/htdocs/localhost/cgi-bin/data/webbuilder/sitelinks/$_"
> , grep ! -d, readdir DIR;
> closedir DIR;
> 
> @MainLinks = <>;
> @MainLinks =  reverse(@MainLinks);

my @MainLinks = reverse <>;

> print "@MainLinks";  #<-- For testing to make sure the array is
> complete.

Useless use of double-quotes: unless you specifically wanted $" rather
than $,?

> foreach my $LinkName (@MainLinks) {
> ($DataBase,$PageType,$PageName,$LinkStatus) = split (/\|/, $LinkName);
> 
> $LinkStatus=~ s/\r//ig;
> $LinkStatus =~ s/\n//ig;

Neither of those is alphabetic: the /i is useless.

> ######################################
> # If the page is a blindlink skip it (for java menu).
> ######################################
> if ($PageType eq "blindlink"){
> next;
> }

    next if $PageType eq 'blindlink';

or

    $PageType eq 'blindlink' and next;

according to taste.

> $LowercaseName =  "$PageName";

  ^^ my

> $LowercaseName =~ s/\W//ig;  # Remove all junk
> $LowercaseName = lc($LowercaseName);
> 
> $HtmlPageToPrint =  "$LowercaseName";

What exactly is the point of this?

> ######################################
> # We look for the index page
> ######################################
> if ($PageType eq "index"){
> $HtmlPageToPrint = "index";
> }

Oh, I see.

$HtmlPageToPrint = ($PageType eq 'index') ? 
                   'index'                :
                   $LowercaseName;

Or something... I'm never entirely sure how to indent those.

> ######################################
> # Get the text for the particular page in question
> ######################################
> open (HTMLTEXT,
> "<$FolderPath/cgi-bin/data/webbuilder/sitepages/$LowercaseName.dat") ||
> print "ERROR: Could not open HTMLTEXT
> $FolderPath/cgi-bin/data/webbuilder/sitepages/$LowercaseName.dat to read the
> data: $!";
> my @HtmlText = <HTMLTEXT>;
> close(HTMLTEXT);
> 
> my $HTMLPageData = "@HtmlText";   #<-- $HTMLPageData is the varaible were
> the text should go on the main template.

What's wrong with doing

    my $HTMLPageData = do { local $/; <HTMLTEXT> };

in the first place? (OK, that should be 'local $/ = $";', but I bet
it's undef.)

> ######################################
> # Print the new web page     #<-- Here is the trouble spot
> ######################################
> open (HTLMLPAGE, ">$FolderPath/$HtmlPageToPrint.htm") || print "ERROR: Could
> not open HTLMLPAGE $FolderPath/$HtmlPageToPrint.htm to print the data: $!";
> 
> foreach (@HtmlTemplate) {
> my $xdata = $_;
> $xdata =~ s/(\$\w+)/$1/eeg; # Process the variables

CAREFUL. You would be much better off using something like the
Template Toolkit for doing this; or at least use a real hash instead
of the symbol table:

    my %templates;
    # and then, instead of creating $HTMLPageData above,
    $templates{HTMLPageData} = ...;

    ...

    $xdata =~ s/\$(\w+)/$templates{$1} || ????/eg;

Note that this doesn't require /ee, which is dangerous as the template
can contain arditrary code; and also that it shows up templates you
haven't given a value to.

I have no idea where your original problem lies: I can't see anything
here that would cause it.

> print HTLMLPAGE "$xdata";

Useless use of double quotes.

> }
> 
> close(HTLMLPAGE);
> 
>     }# End of foreach
> } # end of sub

If you'd done your indenting properly, you wouldn't need these
comments.

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Tue, 10 Feb 2004 13:48:16 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Processing variables
Message-Id: <pan.2004.02.10.12.16.15.579044@aursand.no>

On Tue, 10 Feb 2004 11:49:35 +0000, blnukem wrote:
> #!/usr/bin/perl -w

Change this to:

  #!/usr/bin/perl
  #
  use strict;
  use warnings;

> open (MASTERTEMPLATE,
> "<$FolderPath/cgi-bin/data/webbuilder/templates/mastertemplate.dat") ||
> print "ERROR: Could not open MASTERTEMPLATE
> $FolderPath/cgi-bin/data/webbuilder/templates/mastertemplate.dat to read the
> data: $!";

Why do you want to continue if you're not able to open this file?  You
might also want to assign the _whole_ filename to a variable.

> opendir (DIR,
> "/usr/local/etc/httpd/htdocs/localhost/cgi-bin/data/webbuilder/sitelinks")
> || print "ERROR: Cannot open directory: $!";

Again;  Opening this directory seems _very_ essential for _if_ your script
will work or not.  Why do you continue if this operation fails?

> @ARGV = map
> "/usr/local/etc/httpd/htdocs/localhost/cgi-bin/data/webbuilder/sitelinks/$_"
> , grep ! -d, readdir DIR;

Are you sure you want to assign to the @ARGV array?

> @MainLinks = <>;
> @MainLinks =  reverse(@MainLinks);

Hmm.  To me it seems like you only need the last line...?

> ($DataBase,$PageType,$PageName,$LinkStatus) = split (/\|/, $LinkName);

It's always nice to tell split how many you want returned;

  split( /\|/, $LinkName, 4 );

> $LinkStatus=~ s/\r//ig;
> $LinkStatus =~ s/\n//ig;

No need to make this substitution case-insensitive;

  $LinkStatus =~ s,\r,,g;
  $LinkStatus =~ s,\n,,g;

> if ($PageType eq "blindlink"){
> next;
> }

To me, this is easier to read:

  next if ( $PageType eq 'blindlink' );

> $LowercaseName =  "$PageName";
> $LowercaseName =~ s/\W//ig;  # Remove all junk
> $LowercaseName = lc($LowercaseName);

Could be written as:

  $LowercaseName =~ s,\W,,g;
  $LowercaseName =  lc( $LowercaseName );

> $HtmlPageToPrint =  "$LowercaseName";

Don't use double quotes - or quotes at all - if you don't need to;

  $HtmlPageToPrint = $LowercaseName;

And why do you use two different variables for the same data?

> foreach (@HtmlTemplate) {
> my $xdata = $_;
> $xdata =~ s/(\$\w+)/$1/eeg; # Process the variables
> print HTLMLPAGE "$xdata";
> }

Could be written as:

  foreach ( @HtmlTemplate ) {
      s,(\$\w+),$1,eg; # Are you sure this works?
      print HTLMLPAGE $_;
  }


-- 
Tore Aursand <tore@aursand.no>
"I am become Death, shatterer of worlds." -- J. Robert Oppenheimer,
 upon witnessing the explosion of the first atomic bomb.


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

Date: Tue, 10 Feb 2004 11:50:29 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: script working like daemon
Message-Id: <c0agi5$3em$1@wisteria.csv.warwick.ac.uk>

[please wrap your posts at 72 characters or so]

vangelob@in.tum.de (murph) wrote:
> James Willmore <jwillmore@remove.adelphia.net> wrote in message
> news:<pan.2004.02.09.16.56.35.23637@remove.adelphia.net>...
> >
> > Another option is to put together a script to read from a FIFO, alter
> > your syslog.conf file to include sending messages to the FIFO, and then do
> > something when a specified line is encountered.
>
> I understand how to configure the syslogd.conf to put the logs direct
> to a named pipe . Now i want to write my perl script , but i have
> really problems using named pipes .
> I created named pipe manually (mkfifo pipe ) , change it permissions
> so that the script can read and write from it ( 0777 )

Whoa there, that's a little extreme. You certainly don't need execute
permissions on a fifo, and you probably don't need anything higher
than 600 if you can arrange for the reader to run as the same user as
syslog (and make that user own the fifo, of course; though it will if
syslogd creates it for you).

> #!/usr/bin/perl
> $fifo_name = "./fifo" ;
> while(1){
>         open(FIFO ,"> $fifo_name");

You are opening FIFO for writing...

>         $error = <FIFO> ;

 ...and then trying to read from it. The open will block until there is
a reader, so this will appear to hang.

Also, you should be using lexical FHs, and checking the return of
open; and your loop should be structured differently:

    open my $FIFO, '<', $fifo_name or die "can't open $fifo_name: $!";
#   this ^^^^^^^^
#   is a lexical FH. It will close when it goes out of scope.

    while (<$FIFO>) { # implicitly while (defined( $_ = <$FIFO> )) {
        chomp;        # this will loop until EOF
        print "Error: $_\n";
    }

If you want to try opening it again after the other end closes it, put
another loop around all of that.

>         if($error){
>                 chomp($error);
>                 print "Error: $error\n";
>         }
> }
> 
> But i didn't receice a log messages
> Than i try to make two scripts reader.pl and writer.pl just for
> testing
> But they didn't work two .

What happened? Show us the scripts.

Ben

-- 
"If a book is worth reading when you are six,                * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis


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

Date: Tue, 10 Feb 2004 11:38:25 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Why is Perl losing ground?
Message-Id: <c0afrh$2e3$1@wisteria.csv.warwick.ac.uk>


Peter Hickman <peter@semantico.com> wrote:
> Tore Aursand wrote:
> > On Mon, 09 Feb 2004 16:32:59 -0600, David Dyer-Bennet wrote:
> >>PHP out-performs Perl by a tremendous margin in a shared hosting
> >>environment, which is where most sites are implemented.  mod_perl
> >>doesn't isolate the various users enough to be very safe in a shared
> >>hosting environment, and you need mod_perl to get performance.
> > 
> > Well.  What you _actually_ is trying to say, is that:
> > 
> >   a) mod_php is faster than CGI
> 
> No he did not. Read it again and look for the string CGI. It's not there 
> is it - you made that bit up.
> 
> >   b) You don't trust mod_perl
> 
> Again read what he has said, the 'in a shared hosting environment' is a 
> caveat on the use of mod_perl. Not a declaration that he does not trust 
> mod_perl.
> 
> > Now.  Do _you_ see how smart your statement was? :)
> 
> How about yours?

'PHP out-performs Perl ... in a shared hosting environment'

We are only talking about shared hosting.

'you need mod_perl to get performance'

Hence, since he hasn't 'got performance', he is using CGI perl.

Try applying a small amount of logic when reading: it tends to help.

Ben

-- 
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
  ben@morrow.me.uk   <=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>   (Kate Rusby)


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

Date: Tue, 10 Feb 2004 12:54:35 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Why is Perl losing ground?
Message-Id: <pan.2004.02.10.10.54.53.711264@aursand.no>

On Tue, 10 Feb 2004 09:33:44 +0000, Peter Hickman wrote:
>>>PHP out-performs Perl by a tremendous margin in a shared hosting
>>>environment, which is where most sites are implemented.  mod_perl
>>>doesn't isolate the various users enough to be very safe in a shared
>>>hosting environment, and you need mod_perl to get performance.

>> Well.  What you _actually_ is trying to say, is that:
>>
>>   a) mod_php is faster than CGI

> No he did not. Read it again and look for the string CGI. It's not there
> is it - you made that bit up.

Look at what he wrote, ok?  He compares PHP/mod_php with Perl.  He leaves
out mod_perl, which assumes that we're left with Perl in an ordinary CGI
environment.

>>   b) You don't trust mod_perl
> 
> Again read what he has said, the 'in a shared hosting environment' is a
> caveat on the use of mod_perl. Not a declaration that he does not trust
> mod_perl.

Well.  For me, mod_perl has never been a problem in a "shared hosting
environment".  mod_perl has never been a problem no matter what.


-- 
Tore Aursand <tore@aursand.no>
"Omit needless words. Vigorous writing is concise. A sentence should
 contain no unnecessary words, a paragraph no unnecessary sentences,
 for the same reason that a drawing should have no unnecessary lines
 and a machine no unnecessary parts." -- William Strunk Jr.


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

Date: Tue, 10 Feb 2004 12:40:22 +0100
From: Thomas Deschepper <thomas.deschepper.ecol@sintjozefscollege.be>
Subject: Re: Why references??
Message-Id: <c0afv7$mhe$1@news.worldonline.be>

[Monday 09 February 2004 17:41]Thomas Deschepper
(thomas.deschepper.ecol@sintjozefscollege.be) wrote:

> I've been reading Beginning Per & Programming Perl from O'Reilly for some time
> now and I'm getting used to references and how to grow them..
> 
> But why would someone use a reference if they can use a normal variable? Yeah,
> I know, with references you can grow complex data structures, but in simple
> programs, why would you use them (=references)?
> 
> Thanks for your (smart) answers :)
> 
> Greets from Belgium,
> 
> Thomas

Thanks for the constructive comment on this question guys :) Good newsgroup,
good programming language ;)


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

Date: Tue, 10 Feb 2004 13:48:15 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Why references??
Message-Id: <pan.2004.02.10.12.06.53.594714@aursand.no>

On Mon, 09 Feb 2004 17:41:02 +0100, Thomas Deschepper wrote:
> But why would someone use a reference if they can use a normal variable?

I've read a lot of the other answers in this group, but none of them seem
to relate to why I prefer references: performance.

Copying the reference to a huge array is always faster than copying the
array itself.  It also uses less memory.  And - I think references are
easier to "read" (syntax wise) than "ordinary variables".


-- 
Tore Aursand <tore@aursand.no>
"What we see depends mainly on what we look for." -- Sir John Lubbock


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V10 Issue 6106
***************************************


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