[19326] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1521 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 14 14:05:36 2001

Date: Tue, 14 Aug 2001 11:05:13 -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: <997812313-v10-i1521@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 14 Aug 2001     Volume: 10 Number: 1521

Today's topics:
        &my_sub($arg) or die "$!"; (Mario Rizzuti)
    Re: &my_sub($arg) or die "$!"; <Tassilo.Parseval@post.rwth-aachen.de>
    Re: 2 dimensional array suntax help, please (Stan Brown)
    Re: 2 dimensional array suntax help, please (Tad McClellan)
    Re: 2 dimensional array suntax help, please (Tad McClellan)
    Re: 2 dimensional array suntax help, please (Stan Brown)
    Re: 2 dimensional array suntax help, please (Stan Brown)
    Re: 2 dimensional array suntax help, please (Stan Brown)
    Re: 2 dimensional array suntax help, please (Stan Brown)
    Re: 2 dimensional array suntax help, please <ren@tivoli.com>
    Re: 2 dimensional array suntax help, please (Stan Brown)
        Alternative to use URI::Escape; <jtjohnston@courrier.usherb.ca>
    Re: case sensitive <jurgenex@hotmail.com>
    Re: Flock: Just to be sure ! (Brent Dax)
    Re: Flock: Just to be sure ! <godzilla@stomp.stomp.tokyo>
    Re: Format error?? (Tad McClellan)
        Grep Implemented in Perl (Buck Turgidson)
    Re: Grep Implemented in Perl (Tad McClellan)
    Re: Grep Implemented in Perl (Joe Petolino)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 14 Aug 2001 10:16:08 -0700
From: mariorizzuti@yahoo.com (Mario Rizzuti)
Subject: &my_sub($arg) or die "$!";
Message-Id: <42f3ee2.0108140916.468a63c2@posting.google.com>

Is it possible to handle errors in a subroutine in the same way that
built-in functions do (returning undef and an error message at the
same time?)?

What I mean is using a syntax like

my_sub($arg) or die "Can't do it: $!";

sub my_sub {
#
}

Mario Rizzuti


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

Date: Tue, 14 Aug 2001 19:53:36 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: &my_sub($arg) or die "$!";
Message-Id: <3B7965A0.2060305@post.rwth-aachen.de>

Mario Rizzuti wrote:
> Is it possible to handle errors in a subroutine in the same way that
> built-in functions do (returning undef and an error message at the
> same time?)?

Yes, but not an arbitrary error-message. See the code:

#! /usr/bin/perl -w

use strict;

test (1,2) or die "Error: $!";

sub test {
	if (@_ != 3) {
		$! = 1; # = "permission denied"
		return;
	}
}


$! can't just take an arbitrary string...instead it holds a number 
corresponding to the error-message defined in errno (see 'man errno').
When printed inside double quotes, the errno is replaced with the 
textual representation of the error code you assigned to $!.


Tassilo
-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: 14 Aug 2001 11:07:06 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <9lbeqq$e63$1@panix1.panix.com>

In <MPG.15e2fa36d1566a7989682@news.usit.net> Samneric <samneric@DE-SPAMtigerriver.com> writes:

OK, thanks for all the useful critique on this stuff.

>I have no idea where you populate $hash_pointer, or what it contains. But you 
>can access the values that you returned in @rval via:

>$column_value = $rval[$row]->[$col];


But that's really where I'm strugling. I need to pass an array to the
insert function, nit just a single scalar. That's where I'm having a
problem. How do I reference each of the individual arrays?



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

Date: Tue, 14 Aug 2001 10:51:58 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <slrn9nieoe.9os.tadmc@tadmc26.august.net>

Stan Brown <stanb@panix.com> wrote:
>Just as I thought I was getting a handle on this, I have managed to confuse
>myself again :-(
>
>I have a subroutine I call that creates and array of refeences to arrays.
>The relevant bits look like this:
>
>my @rval = undef ;


@rval now contains one element.

Doesn't matter much as you will overwrite the value below, but
I think you wanted an _empty_ array to start with?

   my @rval;        # guaranteed to be empty
or
   my @rval = ();   # if you insist on initializing it explicitly


>$rc = $sths->execute or die $DBI::errstr;
>my $row = 0;
>my $col = 0;
>while ( @extracted_data = $sths->fetchrow_array ) {
>	for ($col = 0; $col < $col_qty; $col++) {
>	$rval[$col][$row] = $extracted_data[$col];


   push @{$rval[$col]}, $extracted_data[$col];


Let perl do the indexing for you, now you do not need to maintain $row.


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


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

Date: Tue, 14 Aug 2001 11:07:26 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <slrn9nifle.9vd.tadmc@tadmc26.august.net>

Stan Brown <stanb@panix.com> wrote:
>In <MPG.15e2fa36d1566a7989682@news.usit.net> Samneric <samneric@DE-SPAMtigerriver.com> writes:
>
>OK, thanks for all the useful critique on this stuff.
>
>>I have no idea where you populate $hash_pointer, or what it contains. But you 
>>can access the values that you returned in @rval via:
>
>>$column_value = $rval[$row]->[$col];
>
>
>But that's really where I'm strugling. I need to pass an array to the
>insert function, 


You cannot pass arrays as subroutine arguments in Perl.

Functions arguments are always a "list". (but you can get the
list from inside of an array)

Perl FAQ, part 4:

   "What is the difference between a list and an array?"


So I guess you need to pass a list to the insert() function?


>nit just a single scalar. That's where I'm having a
>problem. How do I reference each of the individual arrays?


Follow the simple rule (Use Rule 1) given in perlreftut.pod.

First pretend it is a normal array (from which the arg "list"
will be extracted):

   insert( @array );

Then replace the name with a (empty for now) block:

   insert( @{ } );

Then put something in the block that will return a reference
to an array:

   insert( @{ $rval[$row] } );


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


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

Date: 14 Aug 2001 12:25:44 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <9lbje8$9rm$1@panix3.panix.com>

In <slrn9nieoe.9os.tadmc@tadmc26.august.net> tadmc@augustmail.com (Tad McClellan) writes:

>Stan Brown <stanb@panix.com> wrote:
>>Just as I thought I was getting a handle on this, I have managed to confuse
>>myself again :-(
>>
>>I have a subroutine I call that creates and array of refeences to arrays.
>>The relevant bits look like this:
>>
>>my @rval = undef ;

Old C habits die hard :-)


>>while ( @extracted_data = $sths->fetchrow_array ) {
>>	for ($col = 0; $col < $col_qty; $col++) {
>>	$rval[$col][$row] = $extracted_data[$col];


>   push @{$rval[$col]}, $extracted_data[$col];


>Let perl do the indexing for you, now you do not need to maintain $row.


So that's what the push thingie is for.


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

Date: 14 Aug 2001 12:39:50 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <9lbk8m$efo$1@panix3.panix.com>

In <slrn9nifle.9vd.tadmc@tadmc26.august.net> tadmc@augustmail.com (Tad McClellan) writes:

>Stan Brown <stanb@panix.com> wrote:
>>In <MPG.15e2fa36d1566a7989682@news.usit.net> Samneric <samneric@DE-SPAMtigerriver.com> writes:
>>
>>OK, thanks for all the useful critique on this stuff.
>>
>>>I have no idea where you populate $hash_pointer, or what it contains. But you 
>>>can access the values that you returned in @rval via:
>>
>>>$column_value = $rval[$row]->[$col];
>>
>>
>>But that's really where I'm strugling. I need to pass an array to the
>>insert function, 


>You cannot pass arrays as subroutine arguments in Perl.

>Functions arguments are always a "list". (but you can get the
>list from inside of an array)

>Perl FAQ, part 4:

>   "What is the difference between a list and an array?"


>So I guess you need to pass a list to the insert() function?


>>nit just a single scalar. That's where I'm having a
>>problem. How do I reference each of the individual arrays?


>Follow the simple rule (Use Rule 1) given in perlreftut.pod.

>First pretend it is a normal array (from which the arg "list"
>will be extracted):

>   insert( @array );

>Then replace the name with a (empty for now) block:

>   insert( @{ } );

>Then put something in the block that will return a reference
>to an array:

>   insert( @{ $rval[$row] } );


Hmm, I'm still doing something wrong here:

Global symbol "@vals" requires explicit package name at ./foo.pl line 920.

Let me sketch out the problem again. I;m loading an array of refeences to
arrays in a subroutine, like this:

my $row = 0;
my $col = 0;
while ( @extracted_data = $sths->fetchrow_array ) {
	for ($col = 0; $col < $col_qty; $col++) {
	$rval[$col][$row] = $extracted_data[$col];
	print_debug(5,"Added $extracted_data[$col] to [$row][$col]\n",0);
	}
$row++;
}

BTW, I'm fairly certain that this does what I want, which is creates a two
dimensional array. The first dimension is filled with references to arrays.
Each of these arrays contain all the values that the SELECT returned for a
given collumn, That is all data brough back in extrated_data[0] will go in
one array, all data from extrated_data[1] will go in the next array ....

Am I crossed up here?

The I return this to the caller as:

return @rval; 

Now in the caller, I need to pass each of these arrays (as a list) to
Tk::entry->insert. The second argumnet to this call is a list. 

Here is what I am trying:

my $vals = get_foreign_key_values(
		$$hash_pointer{$col}{'SRC_TABLE'},
		$$hash_pointer{$col}{'SRC_COLS'});
$entry->insert(0,@{ $vals[0] });

The logic is that $vals in the caller should be a refernce to an array of
references to arrays. 

Where am I going wrong?




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

Date: 14 Aug 2001 12:58:31 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <9lblbn$pet$1@panix2.panix.com>

In <9lbk8m$efo$1@panix3.panix.com> stanb@panix.com (Stan Brown) writes:

>In <slrn9nifle.9vd.tadmc@tadmc26.august.net> tadmc@augustmail.com (Tad McClellan) writes:

>>Stan Brown <stanb@panix.com> wrote:
>>>In <MPG.15e2fa36d1566a7989682@news.usit.net> Samneric <samneric@DE-SPAMtigerriver.com> writes:
>>>
>>>OK, thanks for all the useful critique on this stuff.
>>>
>>>>I have no idea where you populate $hash_pointer, or what it contains. But you 
>>>>can access the values that you returned in @rval via:
>>>
>>>>$column_value = $rval[$row]->[$col];
>>>
>>>
>>>But that's really where I'm strugling. I need to pass an array to the
>>>insert function, 


>>You cannot pass arrays as subroutine arguments in Perl.

>>Functions arguments are always a "list". (but you can get the
>>list from inside of an array)

>>Perl FAQ, part 4:

>>   "What is the difference between a list and an array?"


>>So I guess you need to pass a list to the insert() function?


>>>nit just a single scalar. That's where I'm having a
>>>problem. How do I reference each of the individual arrays?


>>Follow the simple rule (Use Rule 1) given in perlreftut.pod.

>>First pretend it is a normal array (from which the arg "list"
>>will be extracted):

>>   insert( @array );

>>Then replace the name with a (empty for now) block:

>>   insert( @{ } );

>>Then put something in the block that will return a reference
>>to an array:

>>   insert( @{ $rval[$row] } );


>Hmm, I'm still doing something wrong here:

>Global symbol "@vals" requires explicit package name at ./foo.pl line 920.

>Let me sketch out the problem again. I;m loading an array of refeences to
>arrays in a subroutine, like this:

>my $row = 0;
>my $col = 0;
>while ( @extracted_data = $sths->fetchrow_array ) {
>	for ($col = 0; $col < $col_qty; $col++) {
>	$rval[$col][$row] = $extracted_data[$col];
>	print_debug(5,"Added $extracted_data[$col] to [$row][$col]\n",0);
>	}
>$row++;
>}

>BTW, I'm fairly certain that this does what I want, which is creates a two
>dimensional array. The first dimension is filled with references to arrays.
>Each of these arrays contain all the values that the SELECT returned for a
>given collumn, That is all data brough back in extrated_data[0] will go in
>one array, all data from extrated_data[1] will go in the next array ....

>Am I crossed up here?

>The I return this to the caller as:

>return @rval; 

>Now in the caller, I need to pass each of these arrays (as a list) to
>Tk::entry->insert. The second argumnet to this call is a list. 

>Here is what I am trying:

>my $vals = get_foreign_key_values(
>		$$hash_pointer{$col}{'SRC_TABLE'},
>		$$hash_pointer{$col}{'SRC_COLS'});
>$entry->insert(0,@{ $vals[0] });

>The logic is that $vals in the caller should be a refernce to an array of
>references to arrays. 

>Where am I going wrong?

The closest I have gotten is when I do this:

$entry->insert(0,$$vals[0 ]);

Whic tells me it can't use '2' as a reference

This is with vals declared as a scalr.

I've also tried this:

$entry->insert(0,$vals[0]);

with vals declared as an array

This results in the array ref being displayed as the only choice in the
Browsentry feild.

The first dereferences one to many times, the second one to few :-(






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

Date: 14 Aug 2001 13:12:34 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <9lbm62$s06$1@panix2.panix.com>

In <9lblbn$pet$1@panix2.panix.com> stanb@panix.com (Stan Brown) writes:

>In <9lbk8m$efo$1@panix3.panix.com> stanb@panix.com (Stan Brown) writes:

>>In <slrn9nifle.9vd.tadmc@tadmc26.august.net> tadmc@augustmail.com (Tad McClellan) writes:

>>>Stan Brown <stanb@panix.com> wrote:
>>>>In <MPG.15e2fa36d1566a7989682@news.usit.net> Samneric <samneric@DE-SPAMtigerriver.com> writes:
>>>>
>>>>OK, thanks for all the useful critique on this stuff.
>>>>
>>>>>I have no idea where you populate $hash_pointer, or what it contains. But you 
>>>>>can access the values that you returned in @rval via:
>>>>
>>>>>$column_value = $rval[$row]->[$col];
>>>>
>>>>
>>>>But that's really where I'm strugling. I need to pass an array to the
>>>>insert function, 


>>>You cannot pass arrays as subroutine arguments in Perl.

>>>Functions arguments are always a "list". (but you can get the
>>>list from inside of an array)

>>>Perl FAQ, part 4:

>>>   "What is the difference between a list and an array?"


>>>So I guess you need to pass a list to the insert() function?


>>>>nit just a single scalar. That's where I'm having a
>>>>problem. How do I reference each of the individual arrays?


>>>Follow the simple rule (Use Rule 1) given in perlreftut.pod.

>>>First pretend it is a normal array (from which the arg "list"
>>>will be extracted):

>>>   insert( @array );

>>>Then replace the name with a (empty for now) block:

>>>   insert( @{ } );

>>>Then put something in the block that will return a reference
>>>to an array:

>>>   insert( @{ $rval[$row] } );


>>Hmm, I'm still doing something wrong here:

>>Global symbol "@vals" requires explicit package name at ./foo.pl line 920.

>>Let me sketch out the problem again. I;m loading an array of refeences to
>>arrays in a subroutine, like this:

>>my $row = 0;
>>my $col = 0;
>>while ( @extracted_data = $sths->fetchrow_array ) {
>>	for ($col = 0; $col < $col_qty; $col++) {
>>	$rval[$col][$row] = $extracted_data[$col];
>>	print_debug(5,"Added $extracted_data[$col] to [$row][$col]\n",0);
>>	}
>>$row++;
>>}

>>BTW, I'm fairly certain that this does what I want, which is creates a two
>>dimensional array. The first dimension is filled with references to arrays.
>>Each of these arrays contain all the values that the SELECT returned for a
>>given collumn, That is all data brough back in extrated_data[0] will go in
>>one array, all data from extrated_data[1] will go in the next array ....

Yhis does indeed seem to be doing what I need as evidenced by this
Dumpvar() ouptut:


$VAR1 = [
          '100',
          '11X',
          '11Y',
          '12Y',
          '13P',
          '140',
          '14X',
          '15P',
          '16X',
          '16Y',
          '18P',
          '22P',
          '26X',
          '300',
          '310',
          '31A',
          '31B',
          '31C',
          '320',
          '330',
          '340',
          '350',
          '360',
          '370',
          '380',
          '390',
          '400',
          '410',
          '41A',
          '41B',
          '41C',
          '420',
          '430',
          '440',
          '450',
          '460',
          '470',
          '480',
          '490',
          '500',
          '510',
          '520',
          '530',
          '540',
          '550',
          '560',
          '570',
          '580',
          '590',
          '600',
          '610',
          '620',
          '630',
          '640',
          '650',
          '660',
          '670',
          '680',
          '690',
          '720',
          '730',
          '750'
        ];
$VAR2 = [
          '1',
          '0',
          '0',
          '0',
          '0',
          '1',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '1',
          '1',
          '1',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '1',
          '1',
          '1',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0',
          '0'
        ];

THat's my breaker names in VAR1 and the breaker levels in VAR2 which are
the 2 lists than Browsentry needs to allow selection from.



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

Date: 14 Aug 2001 10:47:56 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <m366bq7idv.fsf@dhcp9-161.support.tivoli.com>

On 14 Aug 2001, stanb@panix.com wrote:

> In <MPG.15e2fa36d1566a7989682@news.usit.net> Samneric
> <samneric@DE-SPAMtigerriver.com> writes:
> 
>>$column_value = $rval[$row]->[$col];
> 
> 
> But that's really where I'm strugling. I need to pass an array to
> the insert function, nit just a single scalar. That's where I'm
> having a problem. How do I reference each of the individual arrays?

@{$rval[$row]}

-- 
Ren Maddox
ren@tivoli.com


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

Date: 14 Aug 2001 13:43:25 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <9lbnvt$4f4$1@panix2.panix.com>

In <m366bq7idv.fsf@dhcp9-161.support.tivoli.com> Ren Maddox <ren@tivoli.com> writes:

>On 14 Aug 2001, stanb@panix.com wrote:

>> In <MPG.15e2fa36d1566a7989682@news.usit.net> Samneric
>> <samneric@DE-SPAMtigerriver.com> writes:
>> 
>>>$column_value = $rval[$row]->[$col];
>> 
>> 
>> But that's really where I'm strugling. I need to pass an array to
>> the insert function, nit just a single scalar. That's where I'm
>> having a problem. How do I reference each of the individual arrays?

>@{$rval[$row]}

Sorry, thats in the sybroutine that fills the array. It's the caller that I
need to reference it in, and I need the whole array (as a list),



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

Date: Tue, 14 Aug 2001 17:23:36 GMT
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: Alternative to use URI::Escape;
Message-Id: <3B795F0A.3B21B047@courrier.usherb.ca>

>Here is my very special Easter-Egg hunt for you:
>What happens if you try it? ;-)
>>use URI::Escape;
>>$in{'P1OC2Q1'} = uri_escape($in{'P1OC2Q1'}, "^A-Za-z");

A luck would have it, when I tried my script on the University server,
URI.pm was not installed in the last installation of libnet. Rather than
wait 6 months, can anyone come up with an alternative to URI.pm. I have
found this line of code, but does it escape everything?

$in{'blah'} =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;



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

Date: Tue, 14 Aug 2001 09:47:02 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: case sensitive
Message-Id: <3b795606$1@news.microsoft.com>

"jtjohnston" <jtjohnston@courrier.usherb.ca> wrote in message
news:3B788B5F.9CCB9FD0@courrier.usherb.ca...
> I have an array (delicious supper :)
>
> @MyArray = (split/\n/,"Spicy Sichuan-style Shrimp
> Cashew Chicken
> Northern-style Cold Noodles
> Peking-style Caramel Walnuts
> Stir-fried Mixed Vegetables");
>
> I want to find out if the user inputted, from html, the correct answer,
> but using case insensitive. Here is what I have so far. How can I change
> this to make it case insenstitive? Here is the code I have so far:

Convert both text pieces (your pattern and the users answer) into a normal
form, in this case convert both into either all upper or all lower case and
then compare.

jue




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

Date: 14 Aug 2001 08:40:48 -0700
From: brentdax1@earthlink.net (Brent Dax)
Subject: Re: Flock: Just to be sure !
Message-Id: <45d61f04.0108140740.4ddb1761@posting.google.com>

Mariman@mariman.net (Mariman Center) wrote in message news:<6412737777.20010813234629@mariman.net>...
> We  have  some  problems  in  a  script on a domain with high traffic,
> 
> Please correct me if I make mistakes here:
> 
> 
> When I want the users to only READ in a file:
> 
> open (FILE, "$file");
> flock (FILE,1);
> #operations
> close (FILE)

    use Fcntl qw(LOCK_EX LOCK_SH);
    flock(FILE, LOCK_SH);

Always use the constants from Fcntl.

> So, multiple users can access the file in reading, right ?

Yup. 

> When I want one user to WRITE in a file
> open (FILE, ">>$file"); # or open (FILE, ">$file");
> flock (FILE,2);
> #operations
> close (FILE)

flock(FILE, LOCK_EX);

> So, NO other user may write in this file til it isn't closed, right ?

Or read it, for that matter.

> Now,  what  happens if a file is flock (FILE,1) and that somebody else
> tries to write into it, doing a flock (FILE,2) ? In other words, the 2
> operations above, together by different users ?

Only one LOCK_EX may be on at a time, and no LOCK_SHes are allowed to
be on at the same time as a LOCK_EX.

C<flock(FILE, LOCK_EX)> will block the program until there are no more
shared locks on it.  Any attempts to C<flock(FILE, LOCK_SH)> will be
blocked until there are no more LOCK_EXes on it.

> Last, is it requested to write a flock (FILE,8), before closing it ?

There's no need to do that--close()ing the filehandle will unlock the
file.

--Brent Dax
brentdax1@earthlink.net
  From a remote location


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

Date: Tue, 14 Aug 2001 09:32:43 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Flock: Just to be sure !
Message-Id: <3B7952AB.75AE230C@stomp.stomp.tokyo>

Brent Dax wrote:
 
> Mariman Center wrote:

(snipped)

> > When I want the users to only READ in a file:

> > open (FILE, "$file");
> > flock (FILE,1);
> > #operations
> > close (FILE)

 
>     use Fcntl qw(LOCK_EX LOCK_SH);
>     flock(FILE, LOCK_SH);
 
> Always use the constants from Fcntl.
 

Yours is mindless Perl 5 Cargo Cult Dogma.

Making use of the fcntl module will bloat memory usage
and slow down a script. This module should be used when
standard unix style flock is not supported.

At best, locking files is risky business today due to
this high variety of operating systems and web servers.
An extraordinary number of servers do not support file
locking at all, regardless of methodology.

Today, file locking is truly a custom feature which needs
to be designed on a server-by-server basis. Promulgating
Perl 5 Cargo Cult Dogma serves no beneficial purpose.

To exemplify how mindless is this Perl 5 Cargo Cult Dogma,
another often promulgated precept is to never use a classic
nym lock file for file locking. For systems which do not
support flock file locking, there is no choice but to make
use of nym lock files. Nonetheless, Perl 5 Cargo Cult Dogma
dictates, with fervent vigor, to never do this.

Promulgating Perl 5 Cargo Cult Dogma only serves to increase
poor programming practices which lead to inefficient, slow
scripts or, quite often, scripts which won't compile.

Perl 5 Cargo Cultism is the Dark Age of Perl programming.


Godzilla!   Queen Of Perl Heretics.


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

Date: Tue, 14 Aug 2001 10:45:40 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Format error??
Message-Id: <slrn9nieck.9os.tadmc@tadmc26.august.net>

Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
>
>I am encountering an error that has me stumped and would appreciate 
>anyone's input on it.  Perhaps someone can see something in the code 
>below off the bat.  


>format STDOUT =
>@<<<<<<<<<<<<<<<<<<<, @<<<<<<<<<<<<<<<<, @<<<<<<<<<<<<<<<, @<<<<<<<<<<<
>@<<<<<<<<<<<<<<<<<<<, @<<<<<<<<<<<<<<<<, @<<<<<<<<<<<<<<<
>$email_address,       $first_name,       $tos_agreement_version,
>$country,             $city,             $new_subscriber 
>.


Argument lines must immediately follow their corresponding
picture lines:

format STDOUT =
@<<<<<<<<<<<<<<<<<<<, @<<<<<<<<<<<<<<<<, @<<<<<<<<<<<<<<<, @<<<<<<<<<<<
$email_address,       $first_name,       $tos_agreement_version,
@<<<<<<<<<<<<<<<<<<<, @<<<<<<<<<<<<<<<<, @<<<<<<<<<<<<<<<
$country,             $city,             $new_subscriber


I haven't used "format" for years. printf() and a word-wrapping
module do it for me.

formats will be removed from the core in perl6.

The payback you get for learning them is not worth the trouble, IMO.


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


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

Date: 14 Aug 2001 08:59:34 -0700
From: jc_va@hotmail.com (Buck Turgidson)
Subject: Grep Implemented in Perl
Message-Id: <f98999c8.0108140759.4a1fe83@posting.google.com>

I vaguely remember running across a version of grep implemented in
Perl. I believe it was in a book I read.  I did a web search, and
didn't come up with anything close
 
Can someone point me to a good version of grep written in Perl
somewhere?


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

Date: Tue, 14 Aug 2001 11:28:41 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Grep Implemented in Perl
Message-Id: <slrn9nigt9.a1l.tadmc@tadmc26.august.net>

Buck Turgidson <jc_va@hotmail.com> wrote:

>Can someone point me to a good version of grep written in Perl
>somewhere?


Here's "grep -h":

   perl -ne 'print if /PATTERN/' filenames...


Here's "grep -H":

   perl -ne 'print qq($ARGV: $_) if /PATTERN/' filenames...


Then there's always the Perl Power Tools project:

   http://language.perl.com/ppt/src/grep/index.html


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


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

Date: Tue, 14 Aug 2001 09:17:24 -0700
From: petolino@localhost.localdomain (Joe Petolino)
Subject: Re: Grep Implemented in Perl
Message-Id: <kuibl9.mu.ln@localhost.localdomain>

In article <f98999c8.0108140759.4a1fe83@posting.google.com>,
Buck Turgidson <jc_va@hotmail.com> wrote:
>I vaguely remember running across a version of grep implemented in
>Perl. I believe it was in a book I read.  I did a web search, and
>didn't come up with anything close
> 
>Can someone point me to a good version of grep written in Perl
>somewhere?

Look at the Perl Power Tools project:

    http://language.perl.com/ppt/src/grep/index.html
    http://language.perl.com/ppt/src/egrep/index.html

-Joe

-- 
Joe Petolino                                            petolino@alum.mit.edu


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

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


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