[18278] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 446 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 8 18:05:56 2001

Date: Thu, 8 Mar 2001 15:05:17 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <984092717-v10-i446@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 8 Mar 2001     Volume: 10 Number: 446

Today's topics:
    Re: alarm() syntax <ritter@bolt.sonic.net>
    Re: ASP/PerlScript - Database Connection Problem <junk@spam.com>
    Re: Backreferencing in ()*-like patterns <bart.lateur@skynet.be>
    Re: Bug in "perldoc -f our" (was: use strict (vars, etc <Jonathan.L.Ericson@jpl.nasa.gov>
        building data structure with hash references (Daniel's account)
    Re: building data structure with hash references <maheshasolkar@yahoo.com>
    Re: building data structure with hash references (Greg Bacon)
    Re: building data structure with hash references (Clinton A. Pierce)
    Re: Converting dates to numbers??? <mail@ericmarques.net>
    Re: Count matches? <godzilla@stomp.stomp.tokyo>
    Re: FAQ 6.0:   Why do I get weird spaces when I print a <mjcarman@home.com>
        file share <sat_ring@hotmail.com>
    Re: file share <mail@ericmarques.net>
    Re: file share <wizard@psychodad.com>
        Free Linux account <schetelig@web.de>
    Re: HELP!!! my perl writen text file deletes itself som (Richard J. Rauenzahn)
    Re: HELP!!! my perl writen text file deletes itself som <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: HELP!!!! perl script that writes to a text database (Gwyn Judd)
    Re: HELP!!!! perl script that writes to a text database <alan@afdsolutions.com>
        How do I fetch clipboard content? <turnerj@lapdog.lmtas.lmco.com>
        How to gret rid of Warning message? "Value of <HANDLE>" <thanh.q.lam@alcatel.com>
    Re: How to gret rid of Warning message? "Value of <HAND (Malcolm Dew-Jones)
    Re: if($array1[1]  eq $string1) DOESN'T WORK?? <peter.sundstrom-eds@eds.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 08 Mar 2001 19:29:56 GMT
From: Walter Greenwood <ritter@bolt.sonic.net>
Subject: Re: alarm() syntax
Message-Id: <U4Rp6.167$fk.8449@typhoon.sonic.net>

Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
: Walter Greenwood wrote in comp.lang.perl.misc:
:> 
:> I am new to perl and am having difficulty adding an alarm to this webmonitor
:> script. I would like to have it restart apache and coldfusion if it detects 
:> a hung server. When I test the script with perl -d, it hangs at "head(URL)". 
:> I tried to modify the alarm example to timeout after 60secs and then run the 
:> resurrect subroutine. 
: [...]
:> # script: webmonitor
:> 
:> use LWP::Simple;

: ... or, instead of using alarm, you could replace LWP::Simple by
: LWP::UserAgent : you can specify a timeout value for LWP::UserAgent.

: -- 
: Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/

Thanks for the sugggestion. That got me a little farther along. The timeout
works properly, but now it hangs when closing STDOUT. I'm sorry if I'm
overlooking the obvious, but programming is new to me, and I'm trying to make
sense of it all. 

This is where the script hangs.
nmain::(test2.pl:53):           system APACHECTL,'graceful';
  DB<2> 
main::(test2.pl:55):            print <<END;
  DB<2> main::(test2.pl:58):    close STDERR;
  DB<2> n
main::(test2.pl:59):            close STDOUT;
  DB<2> n

Here is the code.
#!/usr/local/bin/perl -w
# Create a user agent object

use LWP::UserAgent;
use constant APACHECTL => '/usr/local/apache/bin/apachectl';
use constant CSTOP     => '/usr/local/coldfusion/bin/stop';
use constant CSTART    => '/usr/local/coldfusion/bin/start';
$MAIL                  =  '/usr/lib/sendmail';
$MAIL_FLAGS            =  '-t -oi';
$WEBMASTER             =  'wg';
$SERVER                 = 'appsdev';

$ua = new LWP::UserAgent;
$ua->agent("AgentName/0.1 " . $ua->agent);
$ua->timeout(10);

# Create a request
my $req = new HTTP::Request GET => 'http://192.168.1.85/BigLoop.cfm';
$req->content_type('application/x-www-form-urlencoded');
$req->content('match=www&errors=0');

# Pass request to the user agent and get a response back
my $res = $ua->request($req);

# Check the outcome of the response
if ($res->is_success) {
      print "success \n";
} 
else {
#      print "No response from web server.\n";
     open (STDOUT,"| $MAIL $MAIL_FLAGS") || die "mail: $!";
     select STDOUT; $| = 1;
     open (STDERR,">&STDOUT");
 
     my $date = localtime();
     print <<END;
To: $WEBMASTER
From: The Web Server Monitor <nobody>
Subject: The web server is down
 
The Web server $SERVER at $date doesn't appear to be responding.
Attempting to restart apache and coldfusion.
 
END
        ;
 
        system CSTOP;
        system CSTART;
        system APACHECTL,'graceful';

print <<END;
 
END
        close STDERR;
        close STDOUT;
}


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

Date: Thu, 8 Mar 2001 21:49:13 -0000
From: "John Brown" <junk@spam.com>
Subject: Re: ASP/PerlScript - Database Connection Problem
Message-Id: <988upv$ftj$1@neptunium.btinternet.com>

Oops!  It seems that the Open($connString) is working, and if I omit the 'or
die', then the script carries on and runs quite happily.

"John Brown" <junk@spam.com> wrote in message
news:988464$5j6$1@neptunium.btinternet.com...
> Hi,
>
> I've got an ASP page, and am trying to use PerlScript to access a database
> with a DSN-less connection.
>
> The code is...
>
> <script language=perlscript runat=server>
> $objConn = $Server->CreateObject("ADODB.Connection")
>          or die "CreateObject: $!";
> $connString = "Provider=Microsoft.Jet.OLEDB.4.0;";
> $connString .= "Data Source=D:\\Test\\Test.mdb;";
> $connString .= "User Id=;Password=;";
> $objConn->Open($connString) or die "OpeningConnection: $!";
> </script>
>
> This produces an error...
>
> > Error Type: PerlScript Error (0x80004005)
> > (in cleanup) OpeningConnection:
> > /scripts/search.asp, line 7
>
> I also have the same error if I try it with a system DSN, rather than the
> above connection string.
>
> Any idea what I'm doing wrong?  I'm fairly new to Perl & ASP, and this
> really has me stumped.
>
> Regards
> JB
>
>
>




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

Date: Thu, 08 Mar 2001 19:36:06 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Backreferencing in ()*-like patterns
Message-Id: <hlnfatslgi1ch9t20o1ej08lrvk1ral6mi@4ax.com>

Antoine Beaupre (LMC) wrote:

>I was wondering wether it was possible to do a regexp pattern like:
>
>/^([0-9]+)(-[0-9]+)*/
>
>and access matches like: $1, $2, $3, $4, until there's no match... 

Nope. It doesn't work that way. All you can do, is a two step approach:

	if(/^([0-9]+)((?:-[0-9]+)*)/) {
	    my @part = $1;
	    my $rest = $2;
	    while($rest =~ /\G-([0-9]+)/g) {
	        push @part, $1;
	    }
	    print "@part\n";
	}
	         
Something like that. Untested, though, there could be some typos.

-- 
	Bart.


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

Date: 08 Mar 2001 21:12:43 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Bug in "perldoc -f our" (was: use strict (vars, etc.))
Message-Id: <86itlk6k38.fsf@jon_ericson.jpl.nasa.gov>

David Bakhash <cadet@alum.mit.edu> writes:

> I don't know for sure, but the *point* of my question was that our()
> doesn't get involved with bindings; it only declares variables to be
> dynamic extent.

Could you elaborate on what you mean by "bindings"?  My understanding
is that "our $x;" binds the lexically scoped symbol $x to the global
variable $::x.  perldelta says:

  "our" declarations

  An "our" declaration introduces a value that can be best
  understood as a lexically scoped symbolic alias to a
  global variable in the package that was current where the
  variable was declared.  This is mostly useful as an
  alternative to the "vars" pragma, but also provides the
  opportunity to introduce typing and other attributes for
  such variables.  See the our entry in the perlfunc
  manpage.

> The best way to state what I wanted is in Common Lisp:
> 
> (defun f (x)
>   (let ((y (* x x)))
>     (declare (special y))
>     (g)))
> 
> (defun g ()
>   (declare (special y))
>   (format t "The value of y is ~d~&" y))

Looking at this (and not really knowing Common Lisp), I wonder why you
didn't use "our" in both places.  You want both f and g to have
access to have access to the value of y, but you don't want some other
function (say h) to have access unless it jumps through some loops
(like declaring y in h).  

> I thought initially that local() was what I wanted, and so it would
> look like this:
> 
> use strict 'vars';
> 
> sub f {
>  my $x = shift();
>  local $y = $x * $x;
>  g();
> }
> 
> sub g {
>  our $y;
>  print "the value of y is ", $y, "\n";
> }
> 
> but that didn't work.  But it has to do with what I consider poor
> semantics on local() -- even when using
> 
> use strict 'vars';

I think everyone agrees that local is poorly (or at least
unfortunately) named.  The semantics of local are very useful in select
cases.  If I understand everything correctly (and I probably don't),
"our $x;" in perl is the equivalent of "(declare (special x))" in
Common Lisp.

<sidenote>

Hmm... this is odd:

  $ perl -Mstrict -wce 'use 'vars' q{$x}'
  -e syntax OK

  $ perl -Mstrict -wce 'our $x'
  Name "main::x" used only once: possible typo at -e line 1.
  -e syntax OK

I'd say there should be no warning in either case.  

</sidenote>

Jon


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

Date: Thu, 08 Mar 2001 20:48:11 GMT
From: dfkoehne@C1323610-A.iowact1.ia.home.com (Daniel's account)
Subject: building data structure with hash references
Message-Id: <slrn9afs6t.o0i.dfkoehne@C1323610-A.iowact1.ia.home.com>

I have some data that is clearly hierarchical, for example like a 
directory listing is.
   eg: /home/foo/test

I want to put this data into a hash data structure. Using the above
example, I want to create the following hash:

   home
    |-> foo
         |-> test

This problem is complicated by the fact that my data is not of a fixed
depth. For example, 
   one entry is:   /home/foo/test
   another is:     /home/foo/test/applepie
   and another is: /home/foo

So I cannot use the following perl code:
   $ref->{1}->{2}->{3};
where the numbers represent home, foo, test in my above example.

Could someone give me some pointers on how to best populate my data
structure (hash).

Here is what I currently have, but it doesn't seem to be working (keeping
with my directory listing example):

my %structure;
my $ref = \%structure;
my $counter;
my $walk;
 ...
# process each line read in from a file
my @path = split(/\//, $line_to_process);
my $num_split = $#path + 1;

for ($counter = 0; $counter < $num_split; $counter++){
   print "    counter: $counter - $path[$counter]\n";
   if ($counter == 0){
      print "       initial\n";
      $walk = $ref->{$path[$counter]};
   } elsif ($counter == ($num_split -1) ){
      # at last entry in @path array
      print "       final\n";
      $walk = $walk->{$path[$counter]} = 1;
   } else {
      print "       somewhere in between\n";
      $walk = $walk->{$path[$counter]};
   }
}
my $d = Data::Dumper->new([$walk]);
print $d->Dump;
 ...

When I run this on some test data I get:
 47: 3 home/foo/dns
    - home
    - foo
    - dns
    counter: 0 - home
       initial
    counter: 1 - foo
       somewhere in between
    counter: 2 - dns
       final
$VAR1 = 1;

Thanks for your help
   Daniel



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

Date: Thu, 8 Mar 2001 13:23:23 -0800
From: "Mahesh A" <maheshasolkar@yahoo.com>
Subject: Re: building data structure with hash references
Message-Id: <tafu2fj6r0mf2@corp.supernews.com>

"Daniel's account" <dfkoehne@C1323610-A.iowact1.ia.home.com> wrote in
message news:slrn9afs6t.o0i.dfkoehne@C1323610-A.iowact1.ia.home.com...
> I have some data that is clearly hierarchical, for example like a
> directory listing is.
>    eg: /home/foo/test
>
> I want to put this data into a hash data structure. Using the above
> example, I want to create the following hash:
>
>    home
>     |-> foo
>          |-> test
>
> This problem is complicated by the fact that my data is not of a fixed
> depth. For example,
[snip]

I think your case needs a recursive routine which traverses a directory tree
(or any tree for that matter), to any depth. The nature of the routine would
be (not syntactically correct)...

sub recurse ($file) {
    create new node (key) in the hash
    if ($file is directory) {
        &recurse ($file);
    }else {
        add the file to the hash
    }
}

See my post on 6th March under the artical:
Re: opening and reading several directories on win32...perl beginner.

I've posted a script that may be helpful.

-M




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

Date: Thu, 08 Mar 2001 21:41:10 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: building data structure with hash references
Message-Id: <tafv3meq7a6tf8@corp.supernews.com>

In article <slrn9afs6t.o0i.dfkoehne@C1323610-A.iowact1.ia.home.com>,
    Daniel's account <dfkoehne@C1323610-A.iowact1.ia.home.com> wrote:

: I have some data that is clearly hierarchical, for example like a 
: directory listing is.
:    eg: /home/foo/test
: 
: I want to put this data into a hash data structure. Using the above
: example, I want to create the following hash:
: 
:    home
:     |-> foo
:          |-> test
: 
: This problem is complicated by the fact that my data is not of a fixed
: depth. For example, 
:    one entry is:   /home/foo/test
:    another is:     /home/foo/test/applepie
:    and another is: /home/foo
: 
: So I cannot use the following perl code:
:    $ref->{1}->{2}->{3};

Enjoy,
Greg

----

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

use strict;

my @entries = (
   '/home/foo/test',
   '/home/foo/test/applepie',
   '/home/foo',
);

sub insert {
    my $root = shift;
    my $path = shift || '';

    return unless ref $root;

    $path =~ s|^/||;
    my @path = split /\//, $path;

    while (@path) {
        $root = $root->{shift @path} ||= {};
    }

    $root->{'.path'} = "/" . $path;
}

sub find {
    my $root = shift;
    my $path = shift || '';

    return unless ref $root;

    $path =~ s|^/||;
    return $root unless $path;

    my @path = split /\//, $path;
    my $step;
    while (@path) {
        $step = shift @path;

        if (exists $root->{$step} && ref $root->{$step}) {
            $root = $root->{$step};
        }
        else {
            return;
        }
    }

    $root;
}

sub print_tree {
    my $root = shift;
    my $name = shift || '';
    my $pre  = shift || '';

    if ($name) {
        my $path = exists $root->{'.path'} ? " - $root->{'.path'}" : "";
        print $pre, $name, $path, "\n";

        if ($pre =~ /\S/) {
            $pre =~ s/^/  /;
        }
        else {
            $pre = "  |-> ";
        }
    }

    foreach my $kid (grep { ref $root->{$_} } keys %$root) {
        print_tree($root->{$kid}, $kid, $pre);
    }
}

## main
my $dir = {};

foreach my $ent (@entries) {
    insert $dir => $ent;
}

print_tree $dir;

for (qw< /home/foo/test /home/not/present >) {
    my $node = find $dir => $_;
    if ($node) {
        print "$_: FOUND: $node->{'.path'}\n";
    }
    else {
        print "$_: NOT FOUND\n";
    }
}
__END__
-- 
Nothing defines humans better than their willingness to do irrational things
in the pursuit of phenominally unlikely payoffs. 
    -- Scott Adams


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

Date: Thu, 08 Mar 2001 21:54:13 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: building data structure with hash references
Message-Id: <9cTp6.37900$W05.7847165@news1.rdc1.mi.home.com>

[Posted and mailed]

In article <slrn9afs6t.o0i.dfkoehne@c1323610-a.iowact1.ia.home.com>,
	dfkoehne@C1323610-A.iowact1.ia.home.com (Daniel's account) writes:
> I have some data that is clearly hierarchical, for example like a 
> directory listing is.
>    eg: /home/foo/test
> 
> I want to put this data into a hash data structure. Using the above
> example, I want to create the following hash:
> 
>    home
>    |-> foo
>         |-> test
> 
> This problem is complicated by the fact that my data is not of a fixed
> depth. For example, 
>    one entry is:   /home/foo/test
>    another is:     /home/foo/test/applepie
>    and another is: /home/foo
> 
> So I cannot use the following perl code:
>    $ref->{1}->{2}->{3};
> where the numbers represent home, foo, test in my above example.
> 
> Could someone give me some pointers on how to best populate my data
> structure (hash).
> 
> Here is what I currently have, but it doesn't seem to be working (keeping
> with my directory listing example):

For directories?  This assumes no duplicate "leafs" of course:

	use warnings;
	use strict;
	use File::Find;

	# Get a directory tree to give us some data...
	my @dir;
	find( sub { push(@dir, $File::Find::name) } , "/tmp");

	# Now make a structure out of it..
	my($f,$str)=({},"");
	foreach(sort { length $b <=> length $a } @dir ) {
		my $t= join('->', map { "{'$_'}" } 
				split(/\//, substr($_,1)));
		$str.= "\$f->$t=1 unless exists \$f->$t;";
	}
	eval $str;
	# Your structure is in $f, ready to use now...

Essentially this translates:

	/foo/bar/baz

into 

	$f->{'foo'}->{'bar'}->{'baz'}=1;

And relies on autovivification to create the intermediate nodes.
Note: the sort function isn't just for show!

-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org         Perl Developer's Dictionary -- May 2001
"If you rush a Miracle Man,     for details, see http://geeksalad.org     
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Thu, 08 Mar 2001 21:02:46 GMT
From: "Eric" <mail@ericmarques.net>
Subject: Re: Converting dates to numbers???
Message-Id: <WrSp6.12082$PF4.17632@news.iol.ie>

yep thanks
i searched for Time::Local on cpan and found the code i need

but it confused me for a while
it seems that this module thinks the month January is month 0
i took away 1 from my month value to correct this


--
Eric Marques
mail@ericmarques.net

"Charles K. Clarkson" <c_clarkson@hotmail.com> wrote in message
news:F81E3004E7FBFA19.2BF3692CD9D5F4CA.FD17F891FE988CF6@lp.airnews.net...
> Eric <mail@ericmarques.net> wrote
> : oops i entered that date wrong
> : i mean 31/03/2001 not 31/3/2001
> : DD/MM/YYYY
> :
> :
> : "Eric" <mail@ericmarques.net> wrote in message
> : news:b1Qp6.12038$PF4.17433@news.iol.ie...
> : > I need to know how to covert dates to numbers like the ones time()
> outputs
> : > eg...
> : > to covert somethink like 31/3/2001 12:00:00AM should covert to the
> : relevant
> : > number like 943534342
> : > (the time will always be 12AM)
> : > dates converted will always be a future date
> : >
> : > plz help
>
>     According tho the docs on localtime:
>
>         Also see the Time::Local module (to convert the second, minutes,
>     hours, ... back to seconds since the stroke of midnight the 1st of
>     January 1970, the value returned by time()), and the strftime(3) and
>     mktime(3) functions available via the POSIX module.
>
> HTH,
> Charles K. Clarkson
>
>
>
>




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

Date: Thu, 08 Mar 2001 11:49:12 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Count matches?
Message-Id: <3AA7E238.A784953@stomp.stomp.tokyo>

emelin@my-deja.com wrote:
 
> foreach ...whatever... {
>      if ...whatever... {
>           print $match;
>      }
> }
 
> Can I somehow count the number of matches???

No, you cannot. You have not provided parameters.
Any answer given for your question, is invalid.

Are you comparing elements to a data string or
looking for duplicate elements within an array
or whatever?

Ask a whatever questions and...

Whatever!


Godzilla!
-- 
@ø=(a .. z);@Ø=qw(6 14 3 25 8 11 11 0 17 14 2 10 18);
$§="\n";$ß="\b";undef$©;print$§x($Ø[4]/2);
for($¡=0;$¡<=$Ø[2];$¡++){foreach$¶(@Ø){
$ø[$¶]=~tr/A-Z/a-z/;if(($¡==1)||($¡==$Ø[2]))
{$ø[$¶]=~tr/a-z/A-Z/;}print$ø[$¶];if($¶==0)
{print" ";}if($¶==$Ø[12]){print" !";}&D;}
print$ßx($Ø[4]*2);}print$§x($Ø[10]*2);
sub D{select$©,$©,$©,.25;}exit;


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

Date: Thu, 08 Mar 2001 15:51:32 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: FAQ 6.0:   Why do I get weird spaces when I print an array of lines?
Message-Id: <3AA7FEE4.1E7CC0F5@home.com>

Gwyn Judd wrote:
> 
> PerlFAQ Server <faq@denver.pm.org>:
>>
>>  Why do I get weird spaces when I print an array of lines?
>>
>>  Saying
>>
>>     print "@lines\n";
>>
>>  joins together the elements of `@lines' with a space between them.
> 
> This is a ridiculous answer. 

[Snip of better answer]

The regular FAQ postings have resulted in a lot of messages like this.
While its great to see the folks here improving the quality of the
answers, I've yet to see anyone say that they've submitted their
enhancements for inclusion into future revisions. Have people been doing
this silently? (I hope so.)

-mjc


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

Date: Thu, 8 Mar 2001 20:27:46 -0000
From: "Chris45" <sat_ring@hotmail.com>
Subject: file share
Message-Id: <988pbp$ncp3$1@ID-54577.news.dfncis.de>

Hi ,
I'm looking for a cgi script that will work like yahoo's file share. One
that you can upload a file by your browser and it will write a link to the
file and maybe comments. Cost hopefully free .I think
Post Board 0.1b by Stephen is what I may need but all link to it at
http://www.itm.com/ are dead .

Thanks for your help
Chris





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

Date: Thu, 08 Mar 2001 21:03:52 GMT
From: "Eric" <mail@ericmarques.net>
Subject: Re: file share
Message-Id: <YsSp6.12083$PF4.17741@news.iol.ie>

www.ericscgi.com
FTC 1.0 Beta 2


--
Eric Marques
mail@ericmarques.net

"Chris45" <sat_ring@hotmail.com> wrote in message
news:988pbp$ncp3$1@ID-54577.news.dfncis.de...
> Hi ,
> I'm looking for a cgi script that will work like yahoo's file share. One
> that you can upload a file by your browser and it will write a link to the
> file and maybe comments. Cost hopefully free .I think
> Post Board 0.1b by Stephen is what I may need but all link to it at
> http://www.itm.com/ are dead .
>
> Thanks for your help
> Chris
>
>
>




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

Date: Thu, 08 Mar 2001 16:51:40 -0600
From: "Michael D. Kirkpatrick" <wizard@psychodad.com>
Subject: Re: file share
Message-Id: <3AA80CFC.4E01089E@psychodad.com>

E-Mail me directly and I will send you the upload engine.  You can just build
your script around it.  It is easy to use and allows for multiple uploads at
the same time...

Chris45 wrote:

> Hi ,
> I'm looking for a cgi script that will work like yahoo's file share. One
> that you can upload a file by your browser and it will write a link to the
> file and maybe comments. Cost hopefully free .I think
> Post Board 0.1b by Stephen is what I may need but all link to it at
> http://www.itm.com/ are dead .
>
> Thanks for your help
> Chris



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

Date: Thu, 8 Mar 2001 21:19:57 +0100
From: "Alfred Schetelig" <schetelig@web.de>
Subject: Free Linux account
Message-Id: <3aa7e9ff_2@news.arcor-ip.de>

Does anybody know of a free linux account offer on the WEB? Alfred




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

Date: 8 Mar 2001 21:50:23 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: HELP!!! my perl writen text file deletes itself somehow at random.
Message-Id: <984088214.395847@hpvablab.cup.hp.com>



"alan scanlon" <alan@afdsolutions.com> writes:
>################### STARTS HERE
>
>sub change_preferences {
>     $data="preferences.txt";
>     $tempfile="$data.tmp";
>
>     open(FILE, $data) or die "Error opening file: $data $!\n";
>     open (TEMP, ">$tempfile") or die "Error opening file: $!\n";
                   ^^^^^^^^^^^
  
You've just zero'd out $tempfile before you've locked it.  Reread the
perlfunc manpage entry for 'open' -- and read carefully the perlfaq5
entry on locking.

$ perldoc -f open
$ perldoc -q lock

If its truely a tmpfile, then you might want to look at

$ perldoc -q temp

You shouldn't need to lock it if its unique to this instance -- and has
a unique filename.

>
>     flock TEMP, $EXCLUSIVE;
>     $temp = "";
>     while(<FILE>)
>     {
>              ($key,$value) = split /\|/, $_;
>              $val = $q->param($key);
>
>    if ($val)
>           {
>
>     $val =~ s/<br>/\n/g;
>     $val =~ s/\n/<br>/g;
>
>                $preferences{$key} = $val;
>                chomp $preferences{$key};
>                $temp .= "$key\|$val\n";
>           }
>          else
>          {
>
>         chomp $value;
>               $preferences{$key} = $value;
>               $temp .= $_;
>
>          }
>     }
>
>     chomp $temp;
>     print TEMP $temp;
>     flock FILE, $EXCLUSIVE;
>     unlink($data);

You've just created a race condition here (and made your lock on
preferences useless).  What if another instance creates a new
preferences.txt between this unlink and the following rename?  

Either truncate and seek $data to 0 and write out the new contents, or
use a different synchronization mechanism -- perhaps a
preferences.txt.lock file.  I'd be inclined to do the latter.

>     rename($tempfile,$data);
>     flock FILE, $UNLOCK;
>     flock TEMP, $UNLOCK;
>     close(TEMP);
>     close(FILE);

Don't flock $UNLOCK -- just close them.  Close will unlock them and
flush the IO buffers.  This is all covered in the FAQ.

>
>}
>
>

In this function below, you need a shared lock.  Again, read the perl
FAQ on locking files.

>sub set_preferences {
>     $data="preferences.txt";
>     open(FILE, $data) or die "Error opening file: $data $!\n";
>     while(<FILE>)
>
>     {
>          ($key,$value) = split /\|/, $_;
>          chomp $value;
>          $preferences{$key} = $value;
>     }
>
>
>     close(FILE);
>}
>
>################### ENDS HERE


-- 
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant     | I speak for me,     |   19055 Pruneridge Ave. 
Development Alliances Lab|            *not* HP |                MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014


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

Date: 08 Mar 2001 22:52:40 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: HELP!!! my perl writen text file deletes itself somehow at random.
Message-Id: <864rx3j2kn.fsf@jon_ericson.jpl.nasa.gov>

"alan scanlon" <alan@afdsolutions.com> writes:

> My perl script below writes to a text file called preferences.txt that holds
> a user's preferences on each new line of a text file. The problem is that
> somehow at random my perl code will now just delete the entire
> preferences.txt file at random losing any new data and all the data that had
> been posted into that file. And so then i have to reupload a backed up older
> preferences.txt file losing any new data and preferences that the user has
> posted. I think there is a bug in my perl code below.

Your going to have to debug this problem yourself, I think.  Here are
some hints to get you started.

1) You should use strict and warnings.  These are perl's best
debugging tools.

2) Simplify the run environment.  Do you have the problem when you run
from the command line?

3) Simplify the script.  It looks like you've started doing that by
isolating two functions.  What is the minimal _operational_ script
that causes the problem?

4) Simplify the input.  What is the minimal dataset needed to cause
the problem?  Since your program doesn't seem to be data driven, this
may not be useful.

5) Check the state of your script.  Throw in print statements at
strategic moments.  Do your variables have values you were expecting?

Looking back over your functions, I notice you have flocks for the
output, but none for input.  What happens if you read preferences.txt
just after another script unlinks it?

Jon



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

Date: Thu, 08 Mar 2001 19:15:42 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: HELP!!!! perl script that writes to a text database question.
Message-Id: <slrn9afmte.334.tjla@thislove.dyndns.org>

I was shocked! How could alan scanlon <alan@afdsolutions.com>
say such a terrible thing:
>My perl script below writes to a text file called preferences.txt that holds
>a user's preferences on each new line of a text file. The problem is that
>somehow at random my perl code will now just delete the entire
>preferences.txt file at random losing any new data and all the data that had

>     open(FILE, $data) or die "Error opening file: $data $!\n";
>     open (TEMP, ">$tempfile") or die "Error opening file: $!\n";
>
>     flock TEMP, $EXCLUSIVE;
>     
>     while (<FILE>)
>     {
>     }
>
>     print TEMP $temp;
>     flock FILE, $EXCLUSIVE;
>     unlink($data);
>     rename($tempfile,$data);

I think this makes it more obvious what is happening. You are reading
from FILE without obtaining a lock, therefore one process can delete
FILE just before another one opens it for reading. You should be able to
get away with merely a shared lock on FILE if all you are doing is
reading from it though.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Do, or do not. There is no try.

		-- George Lucas, "The Empire Strikes Back" (Yoda)


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

Date: Thu, 08 Mar 2001 21:44:43 GMT
From: "alan scanlon" <alan@afdsolutions.com>
Subject: Re: HELP!!!! perl script that writes to a text database question.
Message-Id: <f3Tp6.37895$W05.7842121@news1.rdc1.mi.home.com>

hmm... how do i fix it then?

"Gwyn Judd" <tjla@guvfybir.qlaqaf.bet> wrote in message
news:slrn9afmte.334.tjla@thislove.dyndns.org...
> I was shocked! How could alan scanlon <alan@afdsolutions.com>
> say such a terrible thing:
> >My perl script below writes to a text file called preferences.txt that
holds
> >a user's preferences on each new line of a text file. The problem is that
> >somehow at random my perl code will now just delete the entire
> >preferences.txt file at random losing any new data and all the data that
had
>
> >     open(FILE, $data) or die "Error opening file: $data $!\n";
> >     open (TEMP, ">$tempfile") or die "Error opening file: $!\n";
> >
> >     flock TEMP, $EXCLUSIVE;
> >
> >     while (<FILE>)
> >     {
> >     }
> >
> >     print TEMP $temp;
> >     flock FILE, $EXCLUSIVE;
> >     unlink($data);
> >     rename($tempfile,$data);
>
> I think this makes it more obvious what is happening. You are reading
> from FILE without obtaining a lock, therefore one process can delete
> FILE just before another one opens it for reading. You should be able to
> get away with merely a shared lock on FILE if all you are doing is
> reading from it though.
>
> --
> Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
> Do, or do not. There is no try.
>
> -- George Lucas, "The Empire Strikes Back" (Yoda)




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

Date: 8 Mar 2001 22:34:02 GMT
From: Jim Turner <turnerj@lapdog.lmtas.lmco.com>
Subject: How do I fetch clipboard content?
Message-Id: <9891cq$6722@news1.lmtas.lmco.com>

	Greetings.  I am running Perl 5 in Linux and X.  Is there a way to 
fetch the current contents of the clipboard?  What I want to write is a Perl 
script which I can highlight text in an xterm, click on a button to invoke 
my Perl script and have it do something with the text I highlighted.

Thanks in advance for any help.  If possible, I would also like to be able 
to grab clipboard information even if NOT running X.


Jim Turner
turnerjw2@netscape.net



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

Date: Thu, 08 Mar 2001 14:10:05 -0500
From: Thanh Q Lam <thanh.q.lam@alcatel.com>
Subject: How to gret rid of Warning message? "Value of <HANDLE>"
Message-Id: <3AA7D90D.8ECDA89E@alcatel.com>

I keep getting this warning message when I run listChg.pl script

Value of <HANDLE> construct can be "0"; test with defined() at
 ./listChg.pl line 65535.


I don't even have that many lines in my code.  the listChg.pl is very
simple, it just read a file and check for condition.  Everything works
fine with my script, except that warning message.

Do you know how to get rid of that warning message?


Your reply will be very appreciated.

-Thanh


See my code in below:

# This script returns date of files that have changed during a give
period
sub main
{
    my $startdate = $ARGV[0];
    my $rmstodo;
    my $date = UnixDate("$startdate","%y%m%d");

    # Get all date information from a given start date to today
    # ie. if enter 20010305, it will grep changes from 20010305,
    # 20010306, 20010307 and 20010308
    GetChgDate ($startdate);

    open(RMSTODO, "< $PROJECTDIR/SCCS/rmstodo")
	or die (" Cannot open rmstodo list!\n");

    while ($rmstodo = <RMSTODO>)
    {   
	# Get stream entries from today to last built date
	foreach my $datechg (@DATEINFO)
	{
	   if (($rmstodo =~ $datechg))
	   {
		print "$rmstodo";
	    }
	 }
     }
    close(RMSTODO)
}


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

Date: 8 Mar 2001 12:03:02 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: How to gret rid of Warning message? "Value of <HANDLE>"
Message-Id: <3aa7e576@news.victoria.tc.ca>

Thanh Q Lam (thanh.q.lam@alcatel.com) wrote:
: I keep getting this warning message when I run listChg.pl script

: Value of <HANDLE> construct can be "0"; test with defined() at
: ./listChg.pl line 65535.

see below, the line should be 

     while (defined($rmstodo = <RMSTODO>))
            ^^^^^^^^                    ^

: I don't even have that many lines in my code.  the listChg.pl is very

On some occasions the line number is all wrong.


: simple, it just read a file and check for condition.  Everything works
: fine with my script, except that warning message.

: Do you know how to get rid of that warning message?


: Your reply will be very appreciated.

: -Thanh


: See my code in below:

: # This script returns date of files that have changed during a give
: period
: sub main
: {
:     my $startdate = $ARGV[0];
:     my $rmstodo;
:     my $date = UnixDate("$startdate","%y%m%d");

:     # Get all date information from a given start date to today
:     # ie. if enter 20010305, it will grep changes from 20010305,
:     # 20010306, 20010307 and 20010308
:     GetChgDate ($startdate);

:     open(RMSTODO, "< $PROJECTDIR/SCCS/rmstodo")
: 	or die (" Cannot open rmstodo list!\n");

*** Next line is the one to change, as shown above

:     while ($rmstodo = <RMSTODO>)
:     {   
: 	# Get stream entries from today to last built date
: 	foreach my $datechg (@DATEINFO)
: 	{
: 	   if (($rmstodo =~ $datechg))
: 	   {
: 		print "$rmstodo";
: 	    }
: 	 }
:      }
:     close(RMSTODO)
: }

--


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

Date: Fri, 9 Mar 2001 09:42:12 +1300
From: "Peter Sundstrom" <peter.sundstrom-eds@eds.com>
Subject: Re: if($array1[1]  eq $string1) DOESN'T WORK??
Message-Id: <988qrh$ndi$1@hermes.nz.eds.com>


"Gwyn Judd" <tjla@guvfybir.qlaqaf.bet> wrote in message
news:slrn9ae0as.2un.tjla@thislove.dyndns.org...
> I was shocked! How could Peter Sundstrom <peter.sundstrom-eds@eds.com>
> say such a terrible thing:
>
> >Your problem is more than likely related to your data.  As you don't
provide
> >any input, it is not possible to say where the exact problem is.
>
> I'd say his problem is more likely related to his syntax. But that's
> just me.

Just goes to show that it is difficult to guess what the orginal problem
without all the information.  I'll have to submit a bug fix to the PSI::ESP
module.




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

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


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