[18377] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 545 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 21 21:11:55 2001

Date: Wed, 21 Mar 2001 18:05:12 -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: <985226711-v10-i545@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 21 Mar 2001     Volume: 10 Number: 545

Today's topics:
    Re: `pwd` doesn't work on all servers? <bart.lateur@skynet.be>
    Re: accessing hash from within a for loop doesn't work <jhall@ifxonline.com>
    Re: accessing hash from within a for loop doesn't work (John Joseph Trammell)
    Re: accessing hash from within a for loop doesn't work <jhall@ifxonline.com>
    Re: Can't combine > and $ <krahnj@acm.org>
    Re: diag question <mjcarman@home.com>
    Re: FAQ 7.16:   What's the difference between dynamic a (Chris Fedde)
    Re: How can a SMTP mail be deleted from a Unix mailbox  (Dave LeBlanc)
    Re: How safe is Safe? (Chris Fedde)
    Re: How to insert comma seperated txt file into Excel <carvdawg@patriot.net>
        lwp download status <mail@ericmarques.net>
    Re: Newbie Question re: Webget <krahnj@acm.org>
        passing two arrays two a sub <All@n.due.net>
    Re: passing two arrays two a sub <wyzelli@yahoo.com>
    Re: passing two arrays two a sub <trondmm-usenet@crusaders.no>
    Re: Perl 5.6 - Spinning cursor routine? (Monte)
    Re: question on string identification (Miguel Cruz)
    Re: reading in, writing out checkbox array <uri@sysarch.com>
    Re: Script mysteriously erases file it's supposed to ap <peter.sundstrom-eds@eds.com>
    Re: Script mysteriously erases file it's supposed to ap <hayati@math.uiuc.edu>
    Re: Script mysteriously erases file it's supposed to ap (Martien Verbruggen)
    Re: split array and assign fields in sub? <ren@tivoli.com>
    Re: substitution/pattern matching -- setting the positi (Miguel Cruz)
    Re: Threaded Perl on FreeBSD <tick1@my-deja.com>
    Re: user module install under Solaris 8 (Matthew L. Langford)
        XML::XSLT <ftvdh@xs4all.nl>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 21 Mar 2001 23:25:19 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: `pwd` doesn't work on all servers?
Message-Id: <6odibt8rltit85isbin9hm6en0ir6dakgq@4ax.com>

John A. Grant wrote:

>    My sysadmin guy told me:
>
>    "CGI scripts should not assume that the PATH environment
>     variable includes /usr/bin.  Try the following:
>        chomp($cwd=`/usr/bin/pwd`);
>    "

>    It seems like a shortcoming that Cwd module doesn't try
>    harder to find pwd. 

It doesn't help.

	print `which pwd`;

prints "/bin/pwd" and

	print `/bin/pwd 2>&1`;

prints "pwd: getcwd() failed: Permission denied"

-- 
	Bart.


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

Date: Thu, 22 Mar 2001 00:03:34 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: Re: accessing hash from within a for loop doesn't work
Message-Id: <qjbu6.55975$o7.2422658@news1.rdc1.sdca.home.com>

No responses yet! I won't leave my desk learn something about this!

Sorry about all the exclamation points!!!

I've even tried using a foreach loop now, same problem - $value doesn't show
up if I try to access my hash from within the for or foreach loop.. I don't
get it? Is this the natural order of things? This is cut & paste code - is
it working for you guys and you think i'm nuts with a simple syntax problem?


"John Hall" <jhall@ifxonline.com> wrote in message
news:jL9u6.55710$o7.2408784@news1.rdc1.sdca.home.com...
> Sorry for the re-post, but i'm tearing my hair out and nobody has
responded:
>
> Working code first;
>
> For $value, this works fine:
>
> _____________________________________________________
> sub do_adminedsearch {
>
>     open_infile($searchcrit);
>
>     dbmopen(%sitedb,"$datadir/$sitedb", 0644) or die "dbmopen: $!";
>     dbmopen(%permdb,"$datadir/$permdb", 0644) or die "dbmopen: $!";
>     @usrkeys = keys(%permdb);
>
>     $value = $sitedb{user1};
>
>     for ($i=0;$i<@usrkeys;$i++) {
>
>         unless ($usrkeys[$i] eq '_ADMINPW_' || $usrkeys[$i] eq '_ADMIN_'
||
> $usrkeys[$i] eq '_SECTIONS_') {
>
>         $list .= <<HTML;
>
>         stuff, including $value
>
> HTML
>         }
>
>         untie %permdb;
>         untie %sitedb;
>         $content=~s/<--MESSAGE-->/$list/;
>     }
>
> }
>
> _____________________________________________________
> But this DOESN'T!!??!??:
> _____________________________________________________
> sub do_adminedsearch {
>
>     open_infile($searchcrit);
>
>     dbmopen(%sitedb,"$datadir/$sitedb", 0644) or die "dbmopen: $!";
>     dbmopen(%permdb,"$datadir/$permdb", 0644) or die "dbmopen: $!";
>     @usrkeys = keys(%permdb);
>
>     for ($i=0;$i<@usrkeys;$i++) {
>
>         unless ($usrkeys[$i] eq '_ADMINPW_' || $usrkeys[$i] eq '_ADMIN_'
||
> $usrkeys[$i] eq '_SECTIONS_') {
>
>         $value = $sitedb{user1};
>
>         $list .= <<HTML;
>
>         stuff, including $value
>
> HTML
>         }
>
>         untie %permdb;
>         untie %sitedb;
>         $content=~s/<--MESSAGE-->/$list/;
>     }
>
> }
> _____________________________________________________
>
>
> When it's working I want $value to be $sitedb{"$usrkeys[$i]"}; so it needs
> to be inside the for loop...
>
> Thanks for any assistance.
>
>
>
>
>




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

Date: Thu, 22 Mar 2001 00:15:24 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: accessing hash from within a for loop doesn't work
Message-Id: <slrn9bif2i.vb.trammell@bayazid.hypersloth.net>

On Thu, 22 Mar 2001 00:03:34 GMT, John Hall <jhall@ifxonline.com> wrote:
> No responses yet! I won't leave my desk learn something about this!

Learn this:

  use strict;

[snip type=selective]
> sub do_adminedsearch {
>     dbmopen(%sitedb,"$datadir/$sitedb", 0644) or die "dbmopen: $!";
>     for ($i=0;$i<@usrkeys;$i++) {
>         unless ($usrkeys[$i] eq '_ADMINPW_' , etc.) {
>             $value = $sitedb{user1};
>             $list .= stuff;
>         }
>         untie %sitedb;
>     }
> }
[/snip]

I'm guessing you don't want to untie %sitedb until you're done
with it.  Good luck -- you're going to need it.

J



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

Date: Thu, 22 Mar 2001 00:46:30 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: Re: accessing hash from within a for loop doesn't work
Message-Id: <GXbu6.56153$o7.2429408@news1.rdc1.sdca.home.com>

Thanks. so simple!

now i'm trying to make my code strict friendly but it looks like i have
about 500 things to fix.. and it doesn't mention anything about me closing
my db too soon! oh well. in a few years i'll know what i'm doing.


"John Joseph Trammell" <trammell@bayazid.hypersloth.invalid> wrote in
message news:slrn9bif2i.vb.trammell@bayazid.hypersloth.net...
> On Thu, 22 Mar 2001 00:03:34 GMT, John Hall <jhall@ifxonline.com> wrote:
> > No responses yet! I won't leave my desk learn something about this!
>
> Learn this:
>
>   use strict;
>
> [snip type=selective]
> > sub do_adminedsearch {
> >     dbmopen(%sitedb,"$datadir/$sitedb", 0644) or die "dbmopen: $!";
> >     for ($i=0;$i<@usrkeys;$i++) {
> >         unless ($usrkeys[$i] eq '_ADMINPW_' , etc.) {
> >             $value = $sitedb{user1};
> >             $list .= stuff;
> >         }
> >         untie %sitedb;
> >     }
> > }
> [/snip]
>
> I'm guessing you don't want to untie %sitedb until you're done
> with it.  Good luck -- you're going to need it.
>
> J
>




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

Date: Thu, 22 Mar 2001 01:27:04 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Can't combine > and $
Message-Id: <3AB9568A.997C55B5@acm.org>

Richard Kennaway wrote:
> 
> In article <E0Ps6.73$ez4.3092@eagle.america.net> Garry Williams,
> garry@zvolve.com writes:
> > open(OUT, ">$_/scripts/make_mask.txt")
> >     || die "can't open $_/scripts/make_mask.txt: $!\n";
> 
> The three-argument version of open would be better:
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Really? Did you compile your own version of Perl with this feature
added?


>     open(OUT, ">", "$_/scripts/make_mask.txt")

Too many arguments for open at -e line 1, near
""$_/scripts/make_mask.txt")"
Execution of -e aborted due to compilation errors.



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 21 Mar 2001 16:44:32 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: diag question
Message-Id: <3AB92ED0.124ACCC9@home.com>

Dale Bohl wrote:
> 
> Can anyone tell me which is better to use during
> debugging and production?
> 
> #!/usr/bin/perl -w
> 
> or
> 
> use diagnostics;

This isn't an either-or choice. -w enables warnings. Using diagnostics
(which implicitly enables -w) makes those warnings more verbose.

You should *always* use -w during production of any non-trivial script.
(And you really should leave it there afterwards, too.) You should 'use
diagnostics' if you find the standard warning messages to be too
cryptic.

I think of diagnostics.pm like a set of training wheels. It's helpful
when your just getting started, but annoying after you've learned how to
ride.

-mjc


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

Date: Thu, 22 Mar 2001 01:02:02 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: FAQ 7.16:   What's the difference between dynamic and lexical (static) scoping?  Between local() and my()?
Message-Id: <eacu6.143$T3.135468032@news.frii.net>

In article <slrn9b3ivq.i5o.rgarciasuarez@rafael.kazibao.net>,
Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
>PerlFAQ Server wrote in comp.lang.perl.misc:
>> 
>>   What's the difference between dynamic and lexical (static) scoping? 
>Between local() and my()?
>
>It would be probably useful to add a word about our() in this FAQ.

Care to post modifications of the text to that effect?

thanks
chris
-- 
    This space intentionally left blank


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

Date: 22 Mar 2001 00:13:39 GMT
From: whisper@oz.net (Dave LeBlanc)
Subject: Re: How can a SMTP mail be deleted from a Unix mailbox by a script?
Message-Id: <99bg3j$ou2$0@216.39.170.247>

I'd take a look at the pop3 utilities in TclLib. Just looked at it and
found:
# ::pop3::delete --
#
#	Delete messages on the POP3 server.
#
# Arguments:
#	chan      The channel, returned by ::pop3::open
#       start     The first message to delete in the range.
#                 May be "next" (the next message after the last
#                 one seen, see ::pop3::last), "start" (aka 1),
#                 "end" (the last message in the spool, for 
#                 deleting only the last message).
#       end       (optional, defaults to -1) The last message
#                 to delete in the range. May be "last"
#                 (the last message viewed), "end" (the last
#                 message in the spool), or "-1" (the default,
#                 any negative number means delete only
#                 one message).
#
# Results:
#	None.
#       May throw errors from the server.

The rest of the package seems equally well documented and simple to
use.

SMTP is for sending mail btw.

Regards,

Dave  LeBlanc

On Tue, 20 Mar 2001 10:16:51 +0100, "Markus Elfring" <elf@messer.de>
wrote:

>I've written a script that processes a SMTP mail to import it into another
>system after it was piped by the forward command (see "man forward"). The
>script should delete the original message from the inbox or mailbox after a
>successful import.
>
>- How can the mail deleted with the use of the Unix commands "mail" or
>"mailx" in the preferred programming languages "bash", "Perl", "PHP" or
>"TCL"?
>- What actions must be performed to remove the specific mail from the mbox
>file?
>
>



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

Date: Thu, 22 Mar 2001 00:40:07 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: How safe is Safe?
Message-Id: <HRbu6.140$T3.170585088@news.frii.net>

In article <1eq5x2z.tpekt179z036N%kpreid@attglobal.net>,
Kevin Reid <kpreid@attglobal.net> wrote:
>Is the Safe module secure enough to allow execution of arbitrary code
>with no danger except resource usage (memory/processor)?
>
>This question applies to Perl versions 5.004 and up.
>

Read the manual pages for Safe.  I think that will be eye opening.
Particulary the section titled "Some Safety Issues" In particular
Safe is not safe wrt most system resources such as memory, CPU
usage, signals, and some other important issues.  Until Safe supports
limits on system resources it will not be Safe enough for me.

chris
-- 
    This space intentionally left blank


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

Date: Wed, 21 Mar 2001 18:21:31 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: How to insert comma seperated txt file into Excel
Message-Id: <3AB9377B.9740F29A@patriot.net>

Look into using SpreadSheet::WriteExcel.  This module produces files
that are binary-compatible with Excel, and several other spreadsheet
formats.

Damian James wrote:

> Murali Gudala chose Wed, 21 Mar 2001 11:54:46 -0800 to say this:
> >Hi ,
> > Does anyone know how to insert a comma seperated txt file into an Excel
> >Spreadsheet. I am running the app on Solaris box..
> >
> >Any help is greatly appreciated.
> >
>
> Well, you could always just rename the file with a .xls extension. Excel
> should open it and import the data appropriately. Likewise, if it's going
> out via cgi, you could specify a content type of application/msexcel (or
> whatever).
>
> Otherwise I suggest you search CPAN for modules relating to:
>
>         - parsing CSV files
>         - parsing/generating Excel files
>
> both of which exist in abundance.
>
> HTH,
>
> Cheers,
> Damian
> --
> @;=0..23;@;{@;}=split//,<DATA>;while(@;){for($;=@;;--$;;){next if($:=rand($;
> +1))==0+$;;@;[$;,$:]=@;[$:,$;]}print map{$;{$_}}(@| ,@;);push@|,shift@;if$;[
> 0]==@|;$|=1;select$&,$&,$&,1/80;print"\b"x(@;+@|)}print"\n"__END__
> Just another Perl Hacker



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

Date: Thu, 22 Mar 2001 01:56:06 GMT
From: "Eric" <mail@ericmarques.net>
Subject: lwp download status
Message-Id: <WYcu6.20020$PF4.26981@news.iol.ie>

is there any way to show the status of a file transfer using lwp in
activeperl?


--
Eric Marques
mail@ericmarques.net




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

Date: Thu, 22 Mar 2001 00:59:17 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Newbie Question re: Webget
Message-Id: <3AB94FEA.CF97AC50@acm.org>

Roger Howse wrote:
> 
> Hi Folks,
> 
> I am no Perl genius and am having trouble formulating a call to webget.pl.
> Can someone clue me in as to the proper syntax to nab a web page to a file
> called exchange.htm? Sure would appreciate it.

#!/usr/bin/perl -w
use strict;
use LWP::Simple;

getstore( 'http://www.somewebpage.ca', 'exchange.htm' );



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 21 Mar 2001 23:27:03 GMT
From: "Allan M. Due" <All@n.due.net>
Subject: passing two arrays two a sub
Message-Id: <bNau6.52228$Ok4.4510693@news1.rdc1.ct.home.com>

Hi Folks,

    Well, I haven't been around here much these days.  Kind of miss it.
Anyway, a question came up at work the other day and I thought I might
pressure test my solution by exposing it here on clpm.  One of my employees
(who is new to Perl) came to me the classic "how to pass two arrays to a sub"
question.  I pointed him to using pass by reference and a bit later he came
back and said this was mucking up his code.  He didn't want the sub work to
modify the original arrays.  I didn't have time to look at the code and after
thinking about it for a sec I came up with:

 @{shift @_};

Just curious if there are any gotchas.

TIA

AmD

__dumb example__
#! /usr/bin/perl -w
use strict;
my @first = qw(foo bar bat);
my @second = qw(cat dog mouse);

do_it(\@first,\@second);

sub do_it {
    my @inside1 = @{shift @_};
    my @inside2 = @{shift @_};
    print "@inside1\n";
    print "Then\n";
    print "@inside2\n";
    pop @inside1;
}

--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--Random Quote--
Williams and Holland's Law:  If enough data is collected,
 anything may be proven by statistical methods.





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

Date: Thu, 22 Mar 2001 09:59:36 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: passing two arrays two a sub
Message-Id: <gvbu6.8$971.4012@vic.nntp.telstra.net>

"Allan M. Due" <All@n.due.net> wrote in message
news:bNau6.52228$Ok4.4510693@news1.rdc1.ct.home.com...
> Hi Folks,
>
> #! /usr/bin/perl -w
> use strict;
> my @first = qw(foo bar bat);
> my @second = qw(cat dog mouse);
>
> do_it(\@first,\@second);
>
> sub do_it {
>     my @inside1 = @{shift @_};
>     my @inside2 = @{shift @_};
>     print "@inside1\n";
>     print "Then\n";
>     print "@inside2\n";
>     pop @inside1;
> }
>

I don't know of any 'gotchas' with that.  Perhaps clarity, but having
looked at several different ways of achieving the same thing, I don't
see a lot of clarity difference between them, so I would say... user
choose.

# Address references in @_ explicity, @_ remains unchanged
sub do_it {
    my @inside1 = @{@_[0]};
    my @inside2 = @{@_[1]};

    print "@inside1\n";
    print "Then\n";
    print "@inside2\n";
}


# Using intermediate scalars to hold references, $refs remain for
possible later use, @_ unchanged
sub do_it {
    my ($ref1, $ref2) = @_;
    my @inside1 = @$ref1;
    my @inside2 = @$ref2;
    print "@inside1\n";
    print "Then\n";
    print "@inside2\n";
}

This last possibly only provides the advantage (ephemeral at that) that
the references remain in $ref1 and $ref2 for later use if required, and
@_ is unchanged, though I don't really see any advantage with that.

I don't think I have really added a lot to what you have done, but I had
a bit of fun playing with the refs anyway.!

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";






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

Date: Thu, 22 Mar 2001 00:43:32 GMT
From: "Trond Michelsen" <trondmm-usenet@crusaders.no>
Subject: Re: passing two arrays two a sub
Message-Id: <UUbu6.8815$8c.967874@news01.chello.no>


>> #! /usr/bin/perl -w
>> use strict;
>> my @first = qw(foo bar bat);
>> my @second = qw(cat dog mouse);
>>
>> do_it(\@first,\@second);
>>
>> sub do_it {
>>     my @inside1 = @{shift @_};
>>     my @inside2 = @{shift @_};
>>     print "@inside1\n";
>>     print "Then\n";
>>     print "@inside2\n";
>>     pop @inside1;
>> }

> # Address references in @_ explicity, @_ remains unchanged
> sub do_it {
>     my @inside1 = @{@_[0]};
>     my @inside2 = @{@_[1]};

<picky>
No need to use a slice. Use $_[0] and $_[1] instead.
</picky>

Anyway.

If he doesn't want a subroutine to be able to modify the original arrays,
then he should not pass references to the original arrays to the sub.

do_it([ @first ], [ @second ]);

sub do_it {
  my ($ref1, $ref2) = @_;
  # Feel free to do anything you want to @$ref1 and @$ref2
}

--
Trond Michelsen





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

Date: Thu, 22 Mar 2001 00:18:03 GMT
From: montep@about.com (Monte)
Subject: Re: Perl 5.6 - Spinning cursor routine?
Message-Id: <3ab94419.12025291@news.hal-pc.org>

On 21 Mar 2001 20:23:37 GMT, rich@bofh.concordia.ca (Rich Lafferty)
wrote:

>In comp.lang.perl.misc,
>dennis <dennis.moreno@pop.safetran.com> wrote:
>> Does anyone know wher to get a routine that would display
>> a stationary spinning cursor while a program is processing?
>
>Remember, everything that can be written has already been
>written -- it's just that some of it is easier to find.
>
>   http://www.phreeow.net/bjm/Status-Indicator-1.1.tar.gz
> 
>  -Rich


It's called a "twiddle"
Here's the one I wrote years ago.

$count=0;  # place this at beginning of program
           # you can make the following a subroutine

if ($count==0) {
        print "\|\b" ;
        }
    if ($count==1) {
        print ("\/\b");
        }
        print "-\b";
    if ($count==2) {
        print "\\\b";
        }

$count = $count + 1;
    if ($count==3) {
        $count=0;
    }
f your gonna spam.....

admin@loopback, $LOGIN@localhost, $LOGNAME@localhost,
$USER@localhost, $USER@$HOST, -h1024@localhost, root@mailloop.com
root@localhost, postmaster@localhost, admin@localhost, abuse@localhost
Chairman Reed Hundt: rhundt@fcc.gov
Commissioner James Quello: jquello@fcc.gov
Commissioner Susan Ness: sness@fcc.gov
Commissioner Rachelle Chong: rchong@fcc.gov
US Postal Service: customer@email.usps.gov
Fraud Watch: fraudinfo@psinet.com
Pyramid Schemes: pyramid@ftc.gov
Federal Trade Commission: consumerline@ftc.gov
net-abuse@nocs.insp.irs.gov


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

Date: Wed, 21 Mar 2001 23:25:13 GMT
From: mnc@admin.u.nu (Miguel Cruz)
Subject: Re: question on string identification
Message-Id: <tLau6.90$d33.50196@typhoon2.ba-dsg.net>

R.J. Brown <u7rjb@csc.liv.ac.uk> wrote:
> I need to check the format of an input from a web page into a perl script
> but don't know how. It needs to be checked to ensure that there are no
> numbers or symbols in the string, letters allowed only. The solution I
> expect is really simple but I can't find the answer.

You need to construct a regular expression.

   if ($input_line =~ /[^a-z]/i) { print "Bad input!\n"; }

The regular expression here (between the slashes) matches anything
containing a character that is not (^) between 'a' and 'z'. The 'i' after
the second slash makes it case-insensitive.

miguel


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

Date: Thu, 22 Mar 2001 00:43:50 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: reading in, writing out checkbox array
Message-Id: <x7pufa3a60.fsf@home.sysarch.com>

>>>>> "u" == uNcONvEntiOnaL  <tomcat@visi.com> writes:

  u> whotocheckboxes only has one value in it, it doesn't remember
  u> all the checked boxes.  Does someone know what else I need
  u> to add?

use CGI ;

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Thu, 22 Mar 2001 10:28:03 +1200
From: "Peter Sundstrom" <peter.sundstrom-eds@eds.com>
Subject: Re: Script mysteriously erases file it's supposed to append to
Message-Id: <99b9tv$mdf$1@hermes.nz.eds.com>


"Katia Hayati" <hayati@math.uiuc.edu> wrote in message
news:Pine.GSO.4.32.0103202220080.19833-100000@u05.math.uiuc.edu...
> Hello,
>
> Consider the following short script:
>
> ==========
>
> #!/usr/local/bin/perl -w
> use strict;
> use Fcntl ':flock';
>
> print "Content-type:text/plain\n\n";
> my $logfile = "uiuc.log";
> my $fool = $ENV{'QUERY_STRING'} ? $ENV{'QUERY_STRING'} : '';
> if (($fool eq 'index') or ($fool eq 'pers')) {
>         my $when = localtime();
>         my $where = $ENV{'HTTP_REFERER'};
>         my $what = $fool;
>         my $who = $ENV{'REMOTE_ADDR'};
>
>         open(LOG, ">>$logfile") or die "Could not open log file $logfile:
$!\n";
>         flock(LOG, LOCK_EX);
>         print LOG "$who | $when | $what | $where\n";
>         close LOG or die "Could not close log file $logfile: $!\n";
> }
> print "\n";

Your locking is the equivalent to breaking the door down and then putting
the key in the lock.





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

Date: Wed, 21 Mar 2001 19:07:53 -0600
From: Katia Hayati <hayati@math.uiuc.edu>
Subject: Re: Script mysteriously erases file it's supposed to append to
Message-Id: <Pine.GSO.4.32.0103211904300.19690-100000@u13.math.uiuc.edu>

On Thu, 22 Mar 2001, Peter Sundstrom wrote:

>
> "Katia Hayati" <hayati@math.uiuc.edu> wrote in message
> >
> > #!/usr/local/bin/perl -w
> > use strict;
> > use Fcntl ':flock';
> >
> > print "Content-type:text/plain\n\n";

> >	[...]

> >         open(LOG, ">>$logfile") or die "Could not open log file $logfile:
> $!\n";
> >         flock(LOG, LOCK_EX);
> >         print LOG "$who | $when | $what | $where\n";
> >         close LOG or die "Could not close log file $logfile: $!\n";
> > }
> > print "\n";
>
> Your locking is the equivalent to breaking the door down and then putting
> the key in the lock.

Ah. But why? The example in the man page for flock() is almost exactly the
same as what I just wrote. The difference is that they use a seek(), which
I don't think I need here, and unlock the file before closing. Regulars at
clpm seem to disapprove of this last point, so this is why I close the
file to release the lock. Can you please explain your comment?

Another weird behavior: I created a hard link to the log file. The
log file got deleted, but the hard link didn't, and there was no new info
in it.


Thanks again,
KH



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

Date: Thu, 22 Mar 2001 01:59:49 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Script mysteriously erases file it's supposed to append to
Message-Id: <slrn9bin2u.7q6.mgjv@verbruggen.comdyn.com.au>

On Tue, 20 Mar 2001 22:28:47 -0600,
	Katia Hayati <hayati@math.uiuc.edu> wrote:
> Hello,
> 
> Consider the following short script:
> 

> 
>         open(LOG, ">>$logfile") or 
>	            die "Could not open log file $logfile: $!\n";
>         flock(LOG, LOCK_EX);

There was a thread on this group not that long ago about all the
hardships of locking, etc. You might want to try to find it, and have
a read.

When you open a file for appending like this, and don't write before
you get the lock, the file may actually grow while you're waiting for
your lock. You should seek to the end of the file before writing. I'm
not entirely sure whether that will _guarantee_ correct behaviour on
all systems. If you're really paranoid, use sysopen with
O_CREAT|O_WRONLY, followed by a seek to the end after you have the
lock.

>         print LOG "$who | $when | $what | $where\n";
>         close LOG or die "Could not close log file $logfile: $!\n";
> }
> print "\n";
> 
>====================
> 
> Now most of the time, and all the times I've tested it, this works fine,
> and appends to the logfile. I've also tested it with two browsers
> simultaneously requesting the script, and that works fine too. But
> sometimes, I check the log file and it doesn't exist. Any clues as to
> why? I'm baffled.

I can only think of one thing that would cause this: Something removes
the file, and your program does not have the permissions to recreate
it. It probably has permissions to write to it once it exists, but
that isn't enough when the file doesn't exist yet. Check the
permissions on the directory where this file needs to be created, and
make sure the user of these scripts can create files there.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Think of the average person. Half of
Commercial Dynamics Pty. Ltd.   | the people out there are dumber.
NSW, Australia                  | 


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

Date: 21 Mar 2001 15:32:22 -0600
From: Ren Maddox <ren@tivoli.com>
Subject: Re: split array and assign fields in sub?
Message-Id: <m3g0g6lsex.fsf@dhcp9-175.support.tivoli.com>

On Tue, 20 Mar 2001, dp@dsoft.com wrote:

> @database_rows = &split_db($database_rows[$i]);

[snip]

> sub split_db {
>     ($sku, $name, $partnum, $descrip, $cpu, $stock, $list, $price) =
> split(/\|/,$_);
>     return ($_);
> 
> }

Ignoring the general bad design (well, in my opinion, at least) you
have of using global variables everywhere, you still have a problem
with what split_db returns.  Here you have it returning $_, and then
you assign to an array.  I doubt that's what you want, but I'm not
sure what you do want.  Assigning to @database_rows is going to wreak
havoc on your loop through that array.

Furthermore, you are passing a parameter to split_db, but then you
operate on $_ directly, which is not the parameter.  Perhaps you mean
$_[0] there.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 21 Mar 2001 23:08:13 GMT
From: mnc@admin.u.nu (Miguel Cruz)
Subject: Re: substitution/pattern matching -- setting the position...
Message-Id: <xvau6.80$d33.40153@typhoon2.ba-dsg.net>

Miguel Cruz <mnc@admin.u.nu> wrote:
> J.B. Moreno <planb@newsreaders.com> wrote:
>> while ($chat =~ s/\n([hv][^ ]+ )(.+)\n\n\1/\n\1\2 /ig) {
>> };
>
> Couldn't you just do something far simpler:
>
>  $chat =~ s/\s*\n+\s*/ /g;

Sorry, somehow I missed where you said you wanted to preserve the speakers.

miguel


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

Date: Wed, 21 Mar 2001 16:31:03 -0800
From: "Mike Stevens" <tick1@my-deja.com>
Subject: Re: Threaded Perl on FreeBSD
Message-Id: <cJbu6.2515$E2.832689@newsrump.sjc.telocity.net>

In article <lU9u6.52036$Ok4.4496506@news1.rdc1.ct.home.com>, "Dan
Sugalski" <dan@tuatha.sidhe.org> wrote:

> Mike Stevens <tick1@my-deja.com> wrote:
>> Greetings,
> 
>> I am trying to build a threaded Perl 5.6.0 on FreeBSD 4.2-RELEASE.  I
>> ran configure as:  sh Configure -des -Duserthreads -Duseithreads
>> -Dcc=gcc. make seemed to complete without errors.  However, make test
>> fails on the lib/posix test.  The README.threads file seems to apply to
>> 5.005 threading style, so it does not seem to apply to my problem. 
>> Does anyone have any ideas what I need to do to get past this problem? 
>> TIA,
> 
> It doesn't surprise me that some tests fail. Running the test by hand
> and capturing the result might help diagnose things.
> 
> Out of curiosity, what do you have in mind for this build of perl? You
> won't be able to spawn multiple threads from inside perl code with it.
> 
> 					Dan

Thanks for the reply Dan.  make test fails with: lib/posix ...... Failed
at test 10.  If I cd to the t directory, and run ./TEST, it fails with
the same error.  Running ./perl lib/posix.t gives me:

bash-2.04$ ./perl lib/posix.t
1..27
ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
ok 10
ok 9
ok 11
ok 12
ok 13
ok 14
ok 15
ok 16
ok 17
ok 18 # 16:27, on 03/21/01
ok 19
ok 20
ok 21
ok 22
ok 23
ok 24
ok 25
ok 26
ok 27
bash-2.04$ 

So is the 'test' successful or not?

I'm building the threaded perl to use with PerlMx, a sendmail milter
program,  Thanks again,

-- 
Mike Stevens


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

Date: Wed, 21 Mar 2001 23:38:36 +0000 (UTC)
From: langfml@goodall.eng.auburn.edu (Matthew L. Langford)
Subject: Re: user module install under Solaris 8
Message-Id: <99be1s$3re$1@aunews.duc.auburn.edu>

Elaine Ashton (elaine@chaos.wustl.edu) wrote:
: "Matthew L. Langford" <langfml@goodall.eng.auburn.edu> wrote in message
: news:998jlu$4vt$1@aunews.duc.auburn.edu...
: > Is there a POD which spells all this stuff out?  perlmodinstall doesn't
: even begin
: > to cover this special case.

: You might want to explore sudo and making a perlinstall user.

Let me clarify what I'm looking for.  I don't want to delegate the
responsibility for the main perl installation. I want _everybody_ to be
able to install and keep up-to-date their own set of modules.  Isn't that
what PERL5LIB is for?  It looked kinda like there was some thought given
to this situation (LIB=~/ for user installs, for example).  I just can't
seem to make it work.

If I am on a machine without the /usr/bin/perl, or if I replace
/usr/bin/perl with my own compiled version, this works...uh, well, it
_can_ work:  CPAN installs into ~/perl/lib.  But _with_ Sun's precompiled
perl, I can't figure out how to get CPAN to override its settings and
install modules into a local directory.


--
MattLangford 


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

Date: Thu, 22 Mar 2001 01:38:36 +0100
From: Thomas van der Hulst <ftvdh@xs4all.nl>
Subject: XML::XSLT
Message-Id: <3AB9498C.537D0AD3@xs4all.nl>

I' m trying to transform an xml file with XML::XSLT,
using version 0.32

I'm looking for an example, because I don't know wether it's my script
or the module thats giving me trouble

regards,
Thomas



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

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


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