[18653] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 821 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 2 14:10:52 2001

Date: Wed, 2 May 2001 11:10:21 -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: <988827021-v10-i821@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 2 May 2001     Volume: 10 Number: 821

Today's topics:
    Re: Listing files on client end? <nospam@hotmail.com>
    Re: Perl and maps (Abigail)
        Perl and Upgrading? <bcoon@sequenom.com>
    Re: Perl compete: Java is dead on server side!! PHP is  (Webmaster)
    Re: Please help! <dan@nospam_dtbakerprojects.com>
    Re: Please help! <jpratt@ssr-inc.com>
    Re: Please help! (Cameron)
    Re: Please help! <godzilla@stomp.stomp.tokyo>
        Plz help a newbie add up elements of an array <holman_sh@MailAndNews.com>
    Re: Plz help a newbie add up elements of an array (Eric Bohlman)
    Re: Plz help a newbie add up elements of an array nobull@mail.com
    Re: Plz help a newbie add up elements of an array <joe+usenet@sunstarsys.com>
    Re: possible to dupe STDOUT to a file while still STDOU (Rudolf Polzer)
        Prevent warning: check for open file handle? (Avinash Chopde; <avinash@acm.org>)
        Problem with "require" in server <djberge@uswest.com>
        Problems loading a hive file saved with Win32::TieRegis <perl@programacionweb.com>
        Recursing a directory tree <a.b.horne@NOSPAMexeter.ac.uk>
    Re: Recursing a directory tree <juex@deja.com>
    Re: Recursing a directory tree <rlf@proimages.net>
    Re: RegEx Question <me@spammers.go.away.ericdennis.com>
    Re: requiring something I only need once (Greg Bacon)
    Re: sendmail more reliable with -t flag??? (Michael Fuhr)
    Re: sendmail more reliable with -t flag??? nobull@mail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 2 May 2001 08:34:43 -0500
From: Mr. SunRay <nospam@hotmail.com>
Subject: Re: Listing files on client end?
Message-Id: <U1UH6.38$Fw4.140528@news.uswest.net>

I wrote:

> Scott Shannon (sshannon@acc.com) wrote:
> : Hi. I'd like to know the simplest way, using a perl cgi script, to list
> : the files (placed, say, in a special public accesible directory), on
> : the *clients* end..i.e. the server should do the equivalent of an ls on
> : the clients computer, then create a html page with that listing,
> : which it then displays back to the client. Thanks for any info
> 
> Impossible(*), thank god.  You can set up a frameset and have one of the
> frames point at a local directory using file:, but the files won't be
> known to the server, or in any sense publicly accessible.
> 
> * Modulo the latest Microsoft security misfeatures, of course.
> 

Not impossible, if you want to set up passwordless SSH and use the Net::SSH 
modules directly in the server.  Of course, I'm assuming that the clients are 
ok with having your key in their "authorized keys"  file. :)  If not, tough 
luck.

Ex.

In Temp.html

# Tell it whatever host you want
<A HREF="/cgi-bin/SomeClient?host=bob&command=ls">'ls' on host 'bob'</A><BR>
 ...

In SomeClient

my $port = 9999;
my $host = param( "host" );
my $command = param( "command" );

my $connection = IO::Socket::INET->new(
        Proto           =>      "tcp",
        PeerAddr        =>      $host,
        PeerPort        =>      $port,
        Type            =>      SOCK_STREAM
)or die "Cant connect to port $port on $host: $!\n"; 

print $connection "$host $command\n";
 ...

In Server.pl

use Net::SSH;

# Listening somewhere on port 9999 - syntax not guaranteed to be %100 
accurate, but you'll get the drift.

while(my $clientSock = $serverSock->accept()){
 ...
        while(my($host,$command) = <$clientSock>){
        my $ssh = Net::SSH::Perl->new($host, cipher=>'Blowfish');  # Pick your poison
        $ssh->login('john);
        my($stdout, $stderr, $exit) = $ssh->cmd($command);
        print $clientSock $stdout
 ...
}






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

Date: Wed, 2 May 2001 15:03:08 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Perl and maps
Message-Id: <slrn9f08dc.1u2.abigail@tsathoggua.rlyeh.net>

u376617431@spawnkill.ip-mobilphone.net
(u376617431@spawnkill.ip-mobilphone.net) wrote on MMDCCCI September MCMXCIII in <URL:news:l.988799929.1756072998@gipsy.netsoft.ro>:
&&  Hi there,
&&  I`m trying to develop a site which contains a map of a city. 
&&  I`d like to dynamically generate the image. 
&&  I have an image at a high resolution and when the user 
&&  clicks on the image (which is an imagemap) then the 
&&  CGI script will crop a part of the high resolution 
&&  image and display it. The problem is that I`m using 
&&  PerlMagick and it`s a little bit too slow at cropping 
&&  and zooming. If you have any ideas about the subject 
&&  please give me some directions. 


I'd say keeping the master image in GIF format is something you
do *not* want to do - because then you need to decompress the
image each time you want to crop.

You want to read in your image from disk when your server starts,
decompress it, and keep the decompressed image in memory. To do that, you
best don't use CGI. Use for instance mod_perl, and do the decompression
from a BEGIN block, so all forked childs inherit the uncompressed copy.

Yes, that will use a lot more memory. But it will gain speed as you
eliminate doing the same thing over and over again.



Abigail


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

Date: Wed, 02 May 2001 09:16:44 -0700
From: Bryan Coon <bcoon@sequenom.com>
Subject: Perl and Upgrading?
Message-Id: <3AF032EC.27B0733@sequenom.com>

I have recently had two problems with upgrading perl, first when
I upgraded to the latest version of perl, and second when I upgraded my
redhat box to 7.1.

The problem is simply that all my modules are no longer found in the
path.

In /usr/lib/perl5/ after the upgrade, there are two directories, 5.6.0,
and 5.6.1.  All my modules were of course in 5.6.0.  There were not so
many, so I just used cpan to get them and reinstalled them for 5.6.1.
But now my path is tweaked again after the redhat upgrade.

What is the best way to fix this?

Thanks,
Bryan



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

Date: Wed, 02 May 2001 19:46:01 GMT
From: webmasterDELETETHIS@webmeeters.net (Webmaster)
Subject: Re: Perl compete: Java is dead on server side!! PHP is 4 times faster    than JSP,CF,ASP!!
Message-Id: <3af00fc7.4481300@pubnews.netcom.net.uk>

On Mon, 30 Apr 2001 10:20:30 -0600, havoc <havoc@harrisdev.com> wrote:

>> PHP is the fastest web-scripting language and is 4 times faster than

Ah, so that means that the Java VM was taking up some TIME with it's work!! YOU
DON'T SAY!!!


SMF,
Webmaster.




-- 
http://www.webmeeters.net
 - For forming international Virtual Companies from all talented professionals
   from around the Net.


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

Date: Wed, 02 May 2001 13:52:35 GMT
From: Dan Baker <dan@nospam_dtbakerprojects.com>
Subject: Re: Please help!
Message-Id: <3AF00FC4.31855084@nospam_dtbakerprojects.com>



Jason Pratt wrote:
> 
> Hello all, I am looking for a cgi script/program that I can use on my site
> that will be implemented via SSI that will let the visitors know when a file
> (a zip or exe [archives]) has been last updated.  
-----------------------

if the page is in a "public" place, you dont have to code ANYTHING, just
use the tools at  http://www.netmind.com . They are trying to charge for
it now, but there are still free options.

Otherwise, you'll need a fairly complex set of scripts to manage user
emails, allow subscription/unsubscribe, check for mods, and send emails.

D


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

Date: Wed, 02 May 2001 14:30:24 GMT
From: "Jason Pratt" <jpratt@ssr-inc.com>
Subject: Re: Please help!
Message-Id: <4SUH6.751$aR4.101344@paloalto-snr1.gtei.net>

Dan, I don't want it to do any mailing or anything like that.  I just need
it to show the updated files.  Say I update test1.zip and test2.exe.  Then
on the left table of the site, would show:

"Files last updated"
test1.zip - 05/02/01
test2.exe - 05/02/01

Each file could then be clicked on to be downloaded.  If you want to see
what I'm trying to convey I can point you toward the site I'm currently
building. I have lastcookie.cgi running but it doesn't show the date/time
correct.

Thanks Dan,

Jason Pratt

"Dan Baker" <dan@nospam_dtbakerprojects.com> wrote in message
news:3AF00FC4.31855084@nospam_dtbakerprojects.com...
>
>
> Jason Pratt wrote:
> >
> > Hello all, I am looking for a cgi script/program that I can use on my
site
> > that will be implemented via SSI that will let the visitors know when a
file
> > (a zip or exe [archives]) has been last updated.
> -----------------------
>
> if the page is in a "public" place, you dont have to code ANYTHING, just
> use the tools at  http://www.netmind.com . They are trying to charge for
> it now, but there are still free options.
>
> Otherwise, you'll need a fairly complex set of scripts to manage user
> emails, allow subscription/unsubscribe, check for mods, and send emails.
>
> D




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

Date: Wed, 2 May 2001 15:13:53 +0000 (UTC)
From: cameron@nicnames.co.uk (Cameron)
Subject: Re: Please help!
Message-Id: <8F4C1E471642D411B0BB00508B9A779F6492DB@SOLAR>

write a small cgi to accept in the file name the person is requesting, then
do something like 

$search = `ls -al $search`; #return results of ls -al into variable
$search =~ /regexp to match and return the date./;
print HTML

i doubt anyone will have written something like this and distributed it
already, so it's probably best you try it yourself. instead of the regexp,
you could also split() the string on a space, and return the array indicies
that hold the date and time data.

>Newsgroups: comp.lang.perl.misc 
>From: "Jason Pratt" <jpratt@ssr-inc.com> 
>Subject: Please help! 
>Date: Wed, 02 May 2001 12:17:25 GMT 
>
>---------------------------------------------------------------------------
-----
>
>Hello all, I am looking for a cgi script/program that I can use on my site
>that will be implemented via SSI that will let the visitors know when a
file
>(a zip or exe [archives]) has been last updated.  Does anyone know where I
>can find a script that'll allow me to implement this?  I've tried
>lastcookie.cgi and it doesn't update the date on the page, so that's not
>working.
>
>I've also searched all of the CGI Repositories and can't find anything
>that'll help with this situation.
>
>Please help me find a program that'll help me do this...
>
>Thanks..
>
>Jason Pratt
>pailhead@tampabay.rr.com
>

=====
"In a perfect world, we'd all lie blind and motionless in stacked coffins
filled with pudding. It would be dark and warm and nobody would have to
compete with anybody and also the government would pay for the pudding." -
Erik.


-- 
Posted from iis4.fastnt.co.uk [193.116.54.251] 
via Mailgate.ORG Server - http://www.Mailgate.ORG


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

Date: Wed, 02 May 2001 09:28:27 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Please help!
Message-Id: <3AF035AB.D33073BC@stomp.stomp.tokyo>

Jason Pratt wrote:

(snipped)

> ...I am looking for a cgi script/program that I can use on my site
> that will be implemented via SSI that will let the visitors know when
> a file (a zip or exe [archives]) has been last updated....


There are open source scripts to do this available via our
internet if you truly search. Invest a little time and
effort and you will find what you need.

Following my signature I have enclosed a basic barebones
test script with which you may play, alter and perhaps
adapt to your server side includes need. You will quickly
notice this script is not all encompassing; much work
is left to you, if you are willing to invest some effort.


$directory = ".";

Above line is where you can insert your directory
path you wish to search. My use of a period causes
this script to simply search the same directory
where this script is installed. Remove my period
and type in your full directory path.


@File_Ext = qw (exe zip .pl);

This line above simply sets what type of files
to pull. Remove my  .pl  if you only want to
pull exe and zip files. Other files, such as
jpg and gif can be added by typing in the
last three characters of a file extension.


@Array = reverse sort (@Array);

This one sorts files in descending order, this
is, most recent modified file first. Remove
my reverse to switch to ascending order.

You may also sort by filename by simply switching
positions of $modified and $filename appropriately
in my test script. Research this first before making
changes; it has to be done right.

I wrote my date/timestamp section so you can change
it at will. There are shorter methods but my style
will allow you to change formats, for example adding
names for weekdays and months. There are numerous
scripts to found on our internet which employ this
method which will show you how to use simple arrays
to add names like, Monday, Tuesday.. June, July.

A presumption is made you know enough about Perl to
make simple modifications, add "my" declarations and
the such. If not, have someone help you with my test
script. It can be called directly via server side 
includes to use in an html page.

Read and research. I have never known learning
to cause a person true injury.


Godzilla!
--

TEST SCRIPT:
____________


#!perl

print "Content-type: text/plain\n\n";

$directory = ".";
@File_Ext = qw (exe zip .pl);

opendir (DIRECTORY, $directory);
while (defined ($filename = readdir (DIRECTORY)))
 {
  foreach $extension (@File_Ext)
   {
    if (substr ($filename, -3, 3) eq $extension)
     {
      $modified = (stat ($filename)) [9];
      $filename = "$modified:$filename";
      push (@Array, $filename);
     }
   }
 }

@Array = reverse sort (@Array);

foreach $element (@Array)
 {
  ($modified, $filename) = split (/:/, $element);

  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($modified);

  if ($sec < 10) 
   { $sec = "0$sec"; }
  if ($min < 10)
   { $min = "0$min";}
  if ($hour < 10)
   { $hour = "0$hour"; }
  if ($mon < 10)
   { $mon = "0$mon"; }
  if ($mday < 10)
   { $mday = "0$mday"; }

  $month = ($mon + 1);
  $year = ($year + 1900);

  $date = "$hour\:$min\:$sec $month/$mday/$year";

  print "Filename: $filename\n  ",
        "Last Modified: $date\n\n";
 }

exit;



PRINTED RESULTS:
________________

Filename: dirsort.pl
  Last Modified: 08:48:32 5/02/2001

Filename: test1.pl
  Last Modified: 14:35:52 5/01/2001

Filename: test2.pl
  Last Modified: 19:18:44 3/30/2001

Filename: test4.pl
  Last Modified: 18:00:56 3/11/2001

Filename: test3.pl
  Last Modified: 14:23:54 3/10/2001

Filename: godzil.pl
  Last Modified: 20:25:12 3/01/2001


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

Date: Wed, 2 May 2001 12:22:23 -0400
From: Shawn Holman <holman_sh@MailAndNews.com>
Subject: Plz help a newbie add up elements of an array
Message-Id: <3B2AEECA@MailAndNews.com>

Hi All,
I have a file (survey.out) that looks like this:

shawn|3|shawn test
bruce|5|test for bruce
tom|10|Tom Test
tom|4|
jason|4|jasontest
shawn|1|shawn point test

What I'd like to do is add up the total points (2nd column) for each person. 
I'd like to get the following output (I'll worry about the comment field 
later):

shawn has 4 points.
bruce has 5 points.
tom has 14 points.
jason has 4 points.
Total points = 27

Here's what I've written so far:

#!/usr/bin/perl

open(INF,"survey.out")
@data = <INF>;
close(INF);

# Loop thru the array
foreach $i (@data) {
    chop($i);
    ($name,$points,$comments) = split(/\|/,$i);

# Count number of points in survey.out
    $totalpts = $points + $totalpts;
}

How do I add up the points for each person?

Thanks for any help!

Shawn



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

Date: 2 May 2001 16:42:06 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Plz help a newbie add up elements of an array
Message-Id: <9cpdcu$5r8$1@bob.news.rcn.net>

Shawn Holman <holman_sh@mailandnews.com> wrote:
> Hi All,
> I have a file (survey.out) that looks like this:

> shawn|3|shawn test
> bruce|5|test for bruce
> tom|10|Tom Test
> tom|4|
> jason|4|jasontest
> shawn|1|shawn point test

> What I'd like to do is add up the total points (2nd column) for each person. 
> I'd like to get the following output (I'll worry about the comment field 
> later):

> shawn has 4 points.
> bruce has 5 points.
> tom has 14 points.
> jason has 4 points.
> Total points = 27

> Here's what I've written so far:

> #!/usr/bin/perl

> open(INF,"survey.out")
> @data = <INF>;
> close(INF);

> # Loop thru the array
> foreach $i (@data) {

Try to avoid the "false idiom" of reading a file into an array and then 
looping over each row.  Instead, read the file one line at a time:

open(INF,"survey.out") or die "Can't open survey.out: $!";
while (<INF>) {


>     chop($i);

chomp;

>     ($name,$points,$comments) = split(/\|/,$i);

Since your input is now in $_, which is the default place that split() 
expects, drop the ",$i".

> # Count number of points in survey.out
>     $totalpts = $points + $totalpts;
> }

> How do I add up the points for each person?

Use a hash keyed by $name where the values are the points.



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

Date: 02 May 2001 17:40:06 +0100
From: nobull@mail.com
Subject: Re: Plz help a newbie add up elements of an array
Message-Id: <u9r8y7vh5l.fsf@wcl-l.bham.ac.uk>

Shawn Holman <holman_sh@MailAndNews.com> writes:

> Subject: Plz help a newbie add up elements of an array

Please think about your subject lines.

"Plz help a newbie" - contains no usefull information, do not waste
space in the subject line.

"add up elements of an array" - describes the bit you've already
worked out how to do, not the bit you haven't.


> shawn|3|shawn test
> bruce|5|test for bruce
> tom|10|Tom Test
> tom|4|
> jason|4|jasontest
> shawn|1|shawn point test
> 
> What I'd like to do is add up the total points (2nd column) for each person. 
> I'd like to get the following output (I'll worry about the comment field 
> later):
> 
> shawn has 4 points.
> bruce has 5 points.
> tom has 14 points.
> jason has 4 points.
> Total points = 27

Sounds a bit like homework to me.
 
> Here's what I've written so far:
> 
> #!/usr/bin/perl

Get into the habit of using "strict" and "warnings" sooner rather than
latter.

> open(INF,"survey.out")

Always check return value of open.

> @data = <INF>;
> close(INF);
> 
> # Loop thru the array

Why?  Why not simply loop though the file?

> foreach $i (@data) {

Missing "my" - use strict would have caught this.

>     chop($i);
>     ($name,$points,$comments) = split(/\|/,$i);

Missing "my" - use strict would have caught this.
> 
> # Count number of points in survey.out
>     $totalpts = $points + $totalpts;

There is a += operator in Perl.

> }
> 
> How do I add up the points for each person?

Use an associative array ("hash") keyed on $name.

$personpts{$name} += $points;

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 02 May 2001 14:01:13 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Plz help a newbie add up elements of an array
Message-Id: <m3hez3zl3q.fsf@mumonkan.sunstarsys.com>


[tip: don't use Plz and newbie in your subject]

Shawn Holman <holman_sh@MailAndNews.com> nicely describes his question:

> shawn|3|shawn test
> bruce|5|test for bruce
> tom|10|Tom Test
> tom|4|
> jason|4|jasontest
> shawn|1|shawn point test
> 

[...]

> Here's what I've written so far:
> 
> #!/usr/bin/perl
                  ^^^
                  -w
  use strict;
> 

=pod

=for trashcan
> open(INF,"survey.out")
> @data = <INF>;
> close(INF);
> 
> # Loop thru the array
> foreach $i (@data) {
>     chop($i);
>     ($name,$points,$comments) = split(/\|/,$i);

Don't read the file into an array if you only need to parse it
one line at a time:

=cut

  open INF, "survey.out" or die "Can't open survey.out: $!";
  my %score;    # see below

  while (<INF>) {                               # work with line in $_
    chomp;                                      # smart version of chop
    my ($name, $points, $comments) = split /[|]/;

> How do I add up the points for each person?

Use a hash in your loop:
  
    $score{$name}{points}   += $points;
    $score{$name}{comments} .= $comments . "\n";
  }
  close INF;

then %score will wind up looking like this:

  %score = %{ shawn => { points => 4, 
                         comments => "shawn test\nshawn point test\n",
                       }
             ...
            };



ISTR a recent golf game in clp.misc that had a similar objective.

% perl -wpF'\|' -ale'$F{$F[0]}+=$F[1]}for(map"$_=$F{$_}",sort keys%F){' file


-- 
Joe Schaefer    "The important thing is not to stop questioning. Curiosity has
                                its own reason for existing."
                                               --Albert Einstein


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

Date: Wed, 2 May 2001 19:41:05 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: possible to dupe STDOUT to a file while still STDOUT-ing? :)
Message-Id: <slrn9f0hlg.251.eins@www42.t-offline.de>

Scott R. Godin <webmaster@webdragon.unmunge.net> wrote:
> In article <oh7tetglrot6amgfp9t9stfa61jd0f8p92@4ax.com>,
>  Bart Lateur <bart.lateur@skynet.be> wrote:
> 
>  | Scott R. Godin wrote:
>  | 
>  | >I'd like to know if it's possible to do such a thing.. continue printing 
>  | >to STDOUT but also have same echoed to a file without multiple print 
>  | >statements or suffling back and forth with select($fh)
>  | 
>  | What you're asking for, is known as tee-ing. There's even an entry n the
>  | fAQ about it.
>  | 
> [snip]
> 
>  | Bummer. Possible solutions still include a tied filehandle, get tee()
>  | from the GNU-for-Win32 toolbox (Cygwin), or use a perl script tee clone,
>  | like (as per the FAQ)
>  | <http://www.perl.com/CPAN/authors/id/TOMC/scripts/tct.gz>
>  | 
>  | 
>  | >I have an instance where, a program I've written to output an html-based 
>  | >template from form input is sent to the browser for preview, but I'd 
>  | >also like it dumped to a local file at the same time, so that the user 
>  | >can download it. 
>  | 
>  | Isn't that silly? Can't the user just rightclick (or something similar)
>  | and choose "Save As..."?
> 
> well, yeah, but some *cough* browsers don't preserve the name of the 
> original file in the save dialog, which in this case is important to me.

Perhaps this helps. Good webservers (like Apache) support a feature named
PATH_INFO. That is, you can call the CGI script

$ENV{DOCUMENT_ROOT}/cgi-bin/test.cgi

using an URL like

http://localhost/cgi-bin/test.cgi/download.zip

and get the additional information transmitted ('/download.zip') in the
environment variable $ENV{PATH_INFO}. So your script behaves like a directory
and the browser does not even know it called a CGI script. It will try to get
the filename portion of the path, and since it does not know 'test.cgi'
is a script and not a directory named 'test.cgi', it asks if you want to
save the file as 'download.zip'. You can still use GET and POST forms to
transmit additional data to the script, since a URL like

http://localhost/cgi-bin/test.cgi/download.zip?sess=deadbeef439864319ff1a

is correctly parsed (PATH_INFO only contains '/download.zip', the rest
is saved in QUERY_STRING). In particular, this does not interfere with
CGI.pm.


-- 
#!/usr/bin/perl -- Random sig generator. Editor command in slrn => ~/siggs
$F=shift;open H,"+<$F";$_=join"",<H>;$s=index$_,"\n\n-- \n";$s<0||truncate
H,$s;close H;system"$ENV{EDITOR} $F</dev/tty>/dev/tty";$s=$n=0;for#sichtig
(<~/siggs/*>){++$n;int rand$n or$s=$_};`(echo "\n\n-- ")|cat - $s>>$F`+nan


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

Date: Wed, 02 May 2001 17:35:20 GMT
From: achopde@BLACKHOLE.nyx.net (Avinash Chopde; <avinash@acm.org>)
Subject: Prevent warning: check for open file handle?
Message-Id: <988824646.149539@irys.nyx.net>

There are probably many ways to get this done, but
I've not yet found any myself :-)

In my sighandler, I need to send some log messages
to a file. Sometimes this subroutine gets called after the
main script has nearly ended  - and the file has been closed,
or called before the file has been opened.

Is there a way to check if a filehandle is valid in perl?
print FH "xxx" if (FH is valid);

It all still works, I'm only trying to stop the warning
about print to invalid filehandle showing up in STDERR
(am running with -w)

-- 
Avinash Chopde  
e-mail: avinash@acm.org
home page: http://www.aczone.com/ 



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

Date: Wed, 02 May 2001 12:22:41 -0500
From: "Mr. Sunray" <djberge@uswest.com>
Subject: Problem with "require" in server
Message-Id: <3AF04261.FF5D9088@uswest.com>

Hi all,

Perl 5.6 on Bughat 6.2

I've got a server set up in conjuction with a CGI script that allows the
user to perform various monitoring tasks through a web interface (like
disk space, for example).   In the same directory as the server are a
series of modules that correspond to the 'command' parameter in the HTML
anchor (with a .pm added).  The server then tries to 'require' the
module.

i.e.

Test.html
________
<A href="/cgi-bin/MyClient?host=myHost&command=disk_space">Check Disk
Space</A>

So when the user clicks "Check Disk Space", the command "disk_space" is
sent to the server via the CGI script.  The server then does a "require
disk_space", looking for the "disk_space.pm" module, which is located in
the same directory as the server, which then does whatever its supposed
to do via the 'interact' method common to all the OO modules.

Here's the dilemma.  If I do a "use lib '/home/MyServer' at the top of
the server, everything works fine.  Unfortunately, this server is going
to be set up on several differenct machines, so I can't guarantee the
home directory, but I do know that the modules and the server will all
be in the same directory.

Here's a snippet from the server:

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

# use lib '/home/MyServer';       # I DON'T WANT TO HARD CODE THIS

use lib './';     # Look in the current directory for remaining modules.

use BrainLib; # Successful with either 'use lib' pragma

 ...

# The main loop
while(my $clientSock = $serverSock->accept()){
   ...

   # Get the module name, import it and execute the 'interact()' method.

   while(my $mod = <$clientSock>){
      chomp($mod);
      unless($mod =~ /^(\w+)$/){
         warn "Invalid module name passed to server.\n";
         last;
      }
      $mod = $1;                                             # Taint
check
      eval "require $mod";                          # Import module -
FAILS HERE if lib is set to './'
      if($@){
         warn "Unable to load module $mod: $!\n";
         last;
      }
 ...
}

It doesn't appear able to see the 'disk_space.pm' module, unless I
specify the path explicitly at the top with "use lib
'/home/MyServer';".  So, my question is why does "use lib './' fail for
require'd modules but succeed for use'd modules?

Thanks in advance for any help.

Mr Sunray





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

Date: Wed, 2 May 2001 19:15:06 +0200
From: "Perl Programación Web" <perl@programacionweb.com>
Subject: Problems loading a hive file saved with Win32::TieRegistry
Message-Id: <9cpf8n$1me$1@talia.mad.ttd.net>

Hello:

I've saved part of my Win32 registry in a hive file at
d:\programas\win32registry\registro with this code:

 my $separador_anterior= $Registry->Delimiter("/");
 $diskKey= $Registry->{"LMachine/Software/Fermin/"} or  die "Can't read
LMachine/Software/Fermin key: $^E\n";
 $diskKey->AllowSave( 1 );
 $diskKey->RegSaveKey( "registro", [] ); #No poner aquí letras, porque no
funcionaría.

Now, I want to retrieve this information whith Load, but I don't know how.

I've tried and tried, without a Result.
I've read the Win32::TieRegistry documentation, but the example shown, seems
no work.

$newKey= $Registry->Load( "d:/programas/win32registry/registro" );

Could you help me?
Do you have an example which works?

Thanks a lot

Fermín







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

Date: Wed, 2 May 2001 18:39:47 +0100
From: "Arun Horne" <a.b.horne@NOSPAMexeter.ac.uk>
Subject: Recursing a directory tree
Message-Id: <9cpggi$1se1a$1@athena.ex.ac.uk>

Does anyone have some simple code to recurse a directory tree please?? Best
regards Arun Horne.

Replace NOSPAM with @ in address to reply




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

Date: Wed, 2 May 2001 10:53:24 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Recursing a directory tree
Message-Id: <3af04994$1@news.microsoft.com>

"Arun Horne" <a.b.horne@NOSPAMexeter.ac.uk> wrote in message
news:9cpggi$1se1a$1@athena.ex.ac.uk...
> Does anyone have some simple code to recurse a directory tree please??
Best
> regards Arun Horne.

File::Find should do the job

jue




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

Date: Wed, 02 May 2001 10:53:24 -0700
From: Robert Fonda <rlf@proimages.net>
Subject: Re: Recursing a directory tree
Message-Id: <3AF04993.DD7F597@proimages.net>

Arun Horne wrote:
> 
> Does anyone have some simple code to recurse a directory tree please?? Best
> regards Arun Horne.
> 
> Replace NOSPAM with @ in address to reply

Go pick up a copy of the Perl Cookbook from O'reilly & Associates. ISBN:
1-56592-243-3. It has a nice example of exactly what you want to do! Not
to mention a bazillion other good examples.

r.f


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

Date: Wed, 02 May 2001 15:06:02 GMT
From: "Eric Dennis" <me@spammers.go.away.ericdennis.com>
Subject: Re: RegEx Question
Message-Id: <unVH6.6596$9X6.486606@news1.bnapk1.occa.home.com>

my ($text) = $data =~ /(.*)\$\$/s;

Eric Dennis
http://www.ericdennis.com

In article <hWnH6.4781$SZ5.388106@www.newsranger.com>, "Dan"
<nospam@newsranger.com> wrote:

> Thank you...  But, how can I get all the data before the $$?
> 
> ---
> WIDELY SCATTERED STRONG THUNDERSTORMS WILL CONTINUE ACROSS THE BISTATE
> REGION THROUGH 800 PM CDT. 
> 
> $$
> RP 
> ---
> 
> Thanks, Dan
> 
> In article <slrn9es0ik.59s.abigail@tsathoggua.rlyeh.net>, Abigail
> says...
>>
>>Dan (nospam@newsranger.com) wrote on MMDCCC September MCMXCIII in
>><URL:news:65nH6.4725$SZ5.384799@www.newsranger.com>:
>>``  Here is a portion of the data I am using:
>>``  
>>``  SEVERE WEATHER STATEMENT
>>``  NATIONAL WEATHER SERVICE ST LOUIS MO
>>``  617 PM CDT MON APR 30 2001
>>``  
>>``  How can I use a regular expression to get all the text after
>>SERVICE?
>>
>>my ($text) = $data =~ /SERVICE(.*)/s;
>>
>>
>>Abigail
>>


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

Date: Wed, 02 May 2001 14:50:16 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: requiring something I only need once
Message-Id: <tf07l8fe18fs9b@corp.supernews.com>

In article <%IIH6.42647$B22.10434142@news1.rdc2.pa.home.com>,
    Dodger <dodger@necrosoft.net> wrote:

: "Bart Lateur" <bart.lateur@skynet.be> wrote in message
: news:2oiuet0ghgn18emknr7h7bnisaqtcm8svi@4ax.com...
:
: > What's so bad about a global once in a while, anyway.
: 
: Nothing, provided you know what you are doing with them. It's also generally
: a good idea to declare them, to avoid problems with strict and to help other
: people see what you are doing before they get lost in your code.

You'll note the code I posted plus s/foreach/foreach my/ is strict-clean.

Greg
-- 
If you can't beat your computer at chess, try kickboxing.


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

Date: 2 May 2001 09:40:54 -0600
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: sendmail more reliable with -t flag???
Message-Id: <9cp9q6$gsq@flatland.dimensional.com>

u251892089@spawnkill.ip-mobilphone.net writes:

> I've recently noticed that my Perl Scripts driving sendmail after
> years of working w/o a problem, had stopped working. Without ever
> finding out what had gone wrong I found that the problem could be solved
> by using the -t flag. Has sendmail been upgraded over the last 6 months or so.
> Any suggestions welcome

By "stopped working" what do you mean?  What exactly happens or
doesn't happen?  If you get an error message, please post the
exact text of the message.

New versions of sendmail have been released in the past few months,
but we have no way of knowing if *your* sendmail installation has
been upgraded.

Sendmail's -t option tells sendmail to read the message for
recipients instead of reading them from the command line.  This
is safer than specifying recipients on the command line if the
recipient address comes from outside your program (e.g., entered
by a remote user on a web page form).  A malicious user could
give an email address that would result in shell code being
executed if your script doesn't have taint checking turned on.

Have you recently added taint checking (Perl's -T option) to
your script?  If so, and if the recipient email address came
from outside your program and hadn't been laundered (see the
perlsec manual page), then this could explain why your program
stopped working.

If the script used to work and now it doesn't, then something
must have changed.  We have no way of knowing what changed on
your system -- you'll have to tell us.

Hope this helps.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


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

Date: 02 May 2001 17:45:23 +0100
From: nobull@mail.com
Subject: Re: sendmail more reliable with -t flag???
Message-Id: <u9oftbvgws.fsf@wcl-l.bham.ac.uk>

u251892089@spawnkill.ip-mobilphone.net writes:

> Newsgroups: comp.lang.perl.misc

This is a newsgroup where we discuss matters relating to Perl.

> I've recently noticed that my Perl Scripts driving sendmail after
> years of working w/o a problem, had stopped working.

Did it change when you upgraded Perl?  If not then this does not sound
like it's gonna have anything to do with Perl.

> Without ever finding out what had gone wrong I found that the
> problem could be solved by using the -t flag.

Yeah, I seem to recall reading somewhere that some versions of
sendmail would infer the -t switch if it was missing but that this was
deprecated.  Nothing to do with Perl here.

> Has sendmail been upgraded over the last 6 months or so. Any suggestions welcome

Sounds likely.  I suggest you speak to your system andministrator
since only (s)he could answer this.  Nothing to do with Perl here.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

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.  

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


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