[21835] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4039 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 28 21:12:19 2002

Date: Mon, 28 Oct 2002 18:06:36 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 28 Oct 2002     Volume: 10 Number: 4039

Today's topics:
    Re: Activestate Perl problem with multiple file opening <usenet@dwall.fastmail.fm>
    Re: amateur socketeer: long wait <mike_constant@yahoo.com>
        archiving & thumbnailing webcam images <chris.harris@cwfi.co.fk>
    Re: AUTOLOAD and multiple inheritance <goldbb2@earthlink.net>
    Re: Best way to traverse multilevel hash? <goldbb2@earthlink.net>
    Re: Can package names be supplied on-the-fly? <goldbb2@earthlink.net>
    Re: Can package names be supplied on-the-fly? <jkeen@concentric.net>
        Can't locate Storable.pm in @INC  diskmaskin@hotmail.com
    Re: Can't locate Storable.pm in @INC  <mgjv@tradingpost.com.au>
    Re: Can't locate Storable.pm in @INC <goldbb2@earthlink.net>
        Cut characters from string (SlimClity)
    Re: Cut characters from string (Tad McClellan)
    Re: Cut characters from string <jds@trumpetweb.co.uk>
    Re: Cut characters from string <jurgenex@hotmail.com>
        diff that ignores newlines? (Paul M Lieberman)
        Dynamic fields in HTML with Database <corin@cadaway.co.uk>
        filehandles in reference array within reference hash (X Onon)
    Re: filehandles in reference array within reference has <pinyaj@rpi.edu>
        flock question addendum <ihave@noemail.com>
    Re: flock question addendum <nobull@mail.com>
    Re: flock question addendum <ihave@noemail.com>
        flock question <ihave@noemail.com>
    Re: Grep v Foreach <jurgenex@hotmail.com>
        Looking for a handy vanilla base class <gina02122000@yahoo.com>
    Re: Missing assignment operator <goldbb2@earthlink.net>
    Re: newbie: Multiply picture lines in format doesn't wo <goldbb2@earthlink.net>
        OT Re: significance of 42 for perl, any?!? (Walter Roberson)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 28 Oct 2002 22:36:42 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Activestate Perl problem with multiple file opening
Message-Id: <Xns92B5B327A3AC1dkwwashere@216.168.3.30>

Jan Fure <jan_may2002_fure@attbi.com> wrote on 28 Oct 2002:

> #!/usr/local/bin/perl
> use strict;
> use warnings;
> my $file_number=0;
> while ($file_number<3){
>      my @data_array;
>      my $line_number=0;
>      my $R=0;
>      $file_number++;
>      while ($line_number<100000){
>           $line_number++;
>           $R=rand;
>           push @data_array, "$line_number \t Second_column \t
>           Third_column \t 
> $R \n";

Why are you accumulating everything into an array?  It would be much easier 
to write each line as you go. (see below)

>      }
>      open WORKFILE, ">$file_number.txt";
>      print WORKFILE @data_array;
>      close WORKFILE;
> }

For example:

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

for my $file_number (1..3) {
  open WORKFILE, ">$file_number.txt" 
      or die "Cannot open $file_number.txt: $!";
  for my $line_number (1..100000) {
    print WORKFILE 
      "$line_number \t Second_column \t Third_column \t", 
      rand(), " \n";
  }
  close WORKFILE;
}

This way you only have to hold one line at a time in memory instead of 
having a huge array.  Or is there some reason you need all the data in 
memory at one time?

[rest of code snipped, as it does similar things]

-- 
David K. Wall - usenet@dwall.fastmail.fm
"Oook."


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

Date: Mon, 28 Oct 2002 12:23:46 -0800
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: amateur socketeer: long wait
Message-Id: <apk6br$2f2oo$1@ID-161864.news.dfncis.de>


"Leaffoot" <leaffoot@hotmail.com> wrote in message
news:d7bd06a3.0210280848.120fa135@posting.google.com...
> I am doing some socket-to-socket communication using io::socket, and
> this is my first time doing so, so bear with me.  Sometimes the
> handshake and data transmittal occurs in less than a couple seconds,
> and sometimes it takes 10 minutes, for the same amount of data.
This totally depends on your network connection (bandwidth, flaky hubs
etc.).

>  Does anyone know how I can get around this problem, or what is going
> on?
Yep (see below). By the way, you should drop Perl 4 syntax, it's way too
noisy to read.

sub sendstr {
    my $sock = shift;
    my $str    = shift;
    print $sock "$str" || confess "I can't send the str $str!\n";   # <=
hope that you don't mix it with sysread/syswrite before entering this sub
    return 1;
}

sub recstr {
     my $sock = shift;
     my $len = shift;
     my $stuff = "";
     my $comeback_l = 0;
     my $length_l = 0;
     my $out = 0;
     my $flag = 0;

     my $time_start = new Benchmark;

     while($length_l = sysread $sock, $comeback_l, $len) {
 # You don't need this because $length_1 can never be undef
 #        if(!defined $length_l) {
 #             confess "System read error: $!\n";
 #       }
          write(STDOUT, $comeback, $length_1) or die "write error: $!\n";
           $stuff .= $comeback;
          last if ($comeback_l =~ m/END OF REPORT/);
          last if ($comeback_l =~ m/^\d+CERRUR\d+.*/);
          my $time_end = new Benchmark;
          my $this_time = timediff($time_end, $time_start);
          my $timestr = timestr($this_time);
          print "Time taken to send & retrieve: ", timestr($this_time),
"\n";
          if($timestr =~ m/\b(\d+) wallclock secs/) {
             if($1 > 50) {
               close($sock);
               $flag = 1;
               last;
            }
        }
     }
   return $stuff,$flag;
 }

 Then after connecting, I call:
sendstr($socket, $dialstr) || die "Can't send for $ur";

 my ($report,$flag) = recstr($socket, $linesize);
if($flag) {$socket = connect_to_socket($logfile);}

 And it hangs on after the last data is transferred, as if still trying
to read.  Can anyone help?  Thanks!!
Indeed. You should close the socket at the sender end. It will signal an EOF
and thus, the sysread call in the receiver will bail out.

> Becka Louden




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

Date: Mon, 28 Oct 2002 16:22:51 -0300
From: "Chris Harris" <chris.harris@cwfi.co.fk>
Subject: archiving & thumbnailing webcam images
Message-Id: <apk2s2$2acps$1@ID-134007.news.dfncis.de>

Hi,

I need to operate a couple of webcams to cover two memorial events and want
to be able to archive the images. Each event will run for appoximately an
hour and I plan to archive images once a minute. After the images are
archived  I want to run some sort of script to generate thumbnails and a
html page that will use the thumbnails as in index to allow viewers to
access the full size images.

I think I can do this using Perl scripts and tools such as
ImageMagick/PerlMagick. I am just starting to play with perl scripts and
could do with a few pointers on the methodology to use for this project.

Anybody here have any experince of a similar operation, what tools are
reccomended for this sort of thing?

Cheers
Chris Harris
Stanley,
Falkland Islands.






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

Date: Mon, 28 Oct 2002 15:43:15 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: AUTOLOAD and multiple inheritance
Message-Id: <3DBDA163.9D433D2A@earthlink.net>

Da Witch wrote:
[snip]
> NEXT is a useful module.  Thanks for pointing it out.
> 
> There's something in the docs for NEXT that I don't follow:
> 
>   ...a call to $self-NEXT::m()> resumes the depth-first, left-to-right
>   search of $self's class hierarchy that resulted in the original call
>   to m.
> 
>   Note that this is not the same thing as $self-SUPER::m()>, which
>   begins a new dispatch that is restricted to searching the ancestors
>   of the current class.  $self-NEXT::m()> can backtrack
>   past the current class -- to look for a suitable method in other
>   ancestors of $self -- whereas $self-SUPER::m()> cannot.
> 
> I've read this last paragraph several times, but I still can't
> visualize this difference between NEXT and SUPER.  Any clarification
> or example would be much appreciated.

Try this:

   use NEXT;
   package Left;
   sub foo { shift()->NEXT::foo(); }
   sub bar { shift()->SUPER::foo(); }
   package Right;
   sub foo { print "foo\n" }
   sub bar { print "bar\n" }
   package Dual;
   @ISA = qw(Left Right);
   package main;
   Dual->foo();
   Dual->bar();
   __END__

[untested]

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Mon, 28 Oct 2002 16:00:27 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Best way to traverse multilevel hash?
Message-Id: <3DBDA56B.799AAC0F@earthlink.net>

bill wrote:
> 
> Is there a better (or at least more elegant) way to traverse a
> multilevel hash than something like
[snip]

I don't know about more elegant, but you can do it with fewer levels of
indentation, and using less memory, with something like:

my @stack = \%h;
while( @stack ) {
   my ($key, $value) = each %{ $stack[-1] }
      or (pop @levels), next;
   ref($value) eq "HASH"
      and (push @stack, $value), next;
   # process $key, $value.
}

[untested]

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Mon, 28 Oct 2002 18:04:17 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Can package names be supplied on-the-fly?
Message-Id: <3DBDC270.A46337DA@earthlink.net>

James E Keenan wrote:
[snip]
>     no strict 'refs';
>     foreach (sort keys %$pkg::) {
>         local *sym = $$pkg::{$_};
> 
> Suggestions?

       no strict 'refs';
       foreach (sort keys %{ $pkg . "::" } ) {
          # local *sym = ${ $pkg . "::" }{ $_ };
          local *sym = *{ $pkg . "::" . $_ };

[untested]

Both the commented and uncommented lines should work; I prefer the
uncommented one, since it's a bit more obvious to me what it's doing.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: 29 Oct 2002 02:02:55 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Can package names be supplied on-the-fly?
Message-Id: <apkq8f$m5b@dispatch.concentric.net>


"Tina Mueller" <usenet@tinita.de> wrote in message
news:apiull$1t1ek$1@fu-berlin.de...
> James E Keenan <jkeen@concentric.net> wrote:
> [snip my original message]
>
> no strict 'refs';
> my $pkg = __PACKAGE__ . "::";
> foreach sort keys %{$pkg} {
>  local *sym = ${$pkg.$_};
>  ...
> }

Tina:  Once I put parens around (sort keys %{$pkg}) your code compiled, but
it didn't pick up the subroutines beginning with 'reprocess_' in the
package.

"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3DBDC270.A46337DA@earthlink.net...
> James E Keenan wrote:
> [snip]
> >     no strict 'refs';
> >     foreach (sort keys %$pkg::) {
> >         local *sym = $$pkg::{$_};
> >
> > Suggestions?
>
>        no strict 'refs';
>        foreach (sort keys %{ $pkg . "::" } ) {
>           # local *sym = ${ $pkg . "::" }{ $_ };
>           local *sym = *{ $pkg . "::" . $_ };
>
> [untested]
>
> Both the commented and uncommented lines should work; I prefer the
> uncommented one, since it's a bit more obvious to me what it's doing.
>
Yes, both lines worked.  Yes, the second is a bit less opaque (no way around
opacity here).  Here's the way I coded it:

    my $pkg = __PACKAGE__;
    {
        no strict 'refs';
        foreach (sort keys %{ $pkg . "::" } ) {
            local *sym = *{ $pkg . "::" . $_ };
            $reprocess_subs{$_}++ if (defined &sym and $_ =~ /^reprocess_/);
        }
    }

Thanks to all who responded.

jimk




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

Date: Mon, 28 Oct 2002 23:30:19 +0100
From: diskmaskin@hotmail.com
Subject: Can't locate Storable.pm in @INC 
Message-Id: <gcerruo3ecn3iq36du2iki0jei435mnh9p@4ax.com>

Im totally new to this with perl and cgi. Im trying to run a webmail
script on my apache server running on slackware. Ive installed a bunch
of mouldes that it need, but when im trying to run it i get the above
error message. If i got this right the Storable.pm is a part of the
standard perl installation, so how do i install it again (as it is
missing). Im running perl 5.6.1.

/Johan


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

Date: Mon, 28 Oct 2002 23:16:57 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Can't locate Storable.pm in @INC 
Message-Id: <slrnarrhea.kud.mgjv@verbruggen.comdyn.com.au>

On Mon, 28 Oct 2002 23:30:19 +0100,
	diskmaskin@hotmail.com <diskmaskin@hotmail.com> wrote:
> Im totally new to this with perl and cgi. Im trying to run a webmail
> script on my apache server running on slackware. Ive installed a bunch
> of mouldes that it need, but when im trying to run it i get the above

moulds? :)

> error message. If i got this right the Storable.pm is a part of the
> standard perl installation, so how do i install it again (as it is
> missing). Im running perl 5.6.1.

It comes as part of the 5.8.0 distribution, but it is not part of
5.6.1. You'll have to use the process that you normally use to install
modules. If your OS has packages for this, use those. If not, use
perl's way to install modules. The FAQ, section 8, contains a question
"How do I install a module from CPAN?", which tells you how. I'd
advise you to use the CPAN module.

Martien
-- 
                        | 
Martien Verbruggen      | Begin at the beginning and go on till you
Trading Post Australia  | come to the end; then stop.
                        | 


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

Date: Mon, 28 Oct 2002 18:10:53 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Can't locate Storable.pm in @INC
Message-Id: <3DBDC3FD.954C8791@earthlink.net>

diskmaskin@hotmail.com wrote:
> 
> Im totally new to this with perl and cgi. Im trying to run a webmail
> script on my apache server running on slackware. Ive installed a bunch
> of mouldes that it need, but when im trying to run it i get the above
> error message. If i got this right the Storable.pm is a part of the
> standard perl installation, so how do i install it again (as it is
> missing). Im running perl 5.6.1.

Although Storable is part of the standard 5.8.0 distribution, it is not
part of the standard 5.6.1 distribution -- if you want it with 5.6.1,
you have to download it from CPAN.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: 28 Oct 2002 11:15:20 -0800
From: slimclity@hotmail.com (SlimClity)
Subject: Cut characters from string
Message-Id: <3c209c5f.0210281115.36743620@posting.google.com>

Hi,

I'am just new to perl...

I have a string that contains a filename like: squid-1.1.2.tar.gz and
I want to cut off the .tar.gz. (squid-1.1.2.tar.gz --> squid-1.1.2) In
Visual Basic I can do this with the left command but I unable to find
the perl command.

Hopefully somebody can help me in the right direction and post an
example...


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

Date: Mon, 28 Oct 2002 13:24:46 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Cut characters from string
Message-Id: <slrnarr3nu.28m.tadmc@magna.augustmail.com>

SlimClity <slimclity@hotmail.com> wrote:

> I have a string that contains a filename like: squid-1.1.2.tar.gz and
> I want to cut off the .tar.gz.


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

my $fname = 'squid-1.1.2.tar.gz';
$fname =~ s/\.tar\.gz$//;          # remove ".tar.gz" from end of string
print "$fname\n";

$fname = 'squid-1.1.2.tar.gz';
substr($fname, -7) = '';           # remove last 7 characters from string
print "$fname\n";
-----------------------------


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


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

Date: Mon, 28 Oct 2002 20:41:19 -0000
From: "Julia deSilva" <jds@trumpetweb.co.uk>
Subject: Re: Cut characters from string
Message-Id: <xghv9.702$8c5.622@news-binary.blueyonder.co.uk>

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnarr3nu.28m.tadmc@magna.augustmail.com...
> SlimClity <slimclity@hotmail.com> wrote:
>
> > I have a string that contains a filename like: squid-1.1.2.tar.gz and
> > I want to cut off the .tar.gz.
>
>
> -----------------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my $fname = 'squid-1.1.2.tar.gz';
> $fname =~ s/\.tar\.gz$//;          # remove ".tar.gz" from end of string
> print "$fname\n";
>
> $fname = 'squid-1.1.2.tar.gz';
> substr($fname, -7) = '';           # remove last 7 characters from string
> print "$fname\n";
> -----------------------------
>
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas

I preferred your other style of reply ! Some of us don't just read this NG
for the answers.

TMcD appreciation soc.




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

Date: Tue, 29 Oct 2002 01:23:09 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Cut characters from string
Message-Id: <1qlv9.11259$FS5.10421@nwrddc04.gnilink.net>

SlimClity wrote:
> I have a string that contains a filename like: squid-1.1.2.tar.gz and
> I want to cut off the .tar.gz. (squid-1.1.2.tar.gz --> squid-1.1.2) In

You may want to check out File::Basename.
This module dissects filenames into path, name, and extension, and even
respects OS-specific oddities.

> Visual Basic I can do this with the left command but I unable to find
> the perl command.

Because Perl has something better to offer.
If you insist on doing dull string manupulation yourself then check the
substr function, details see "perldoc -f substr".

jue




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

Date: 28 Oct 2002 15:06:43 -0800
From: paulmlieberman@alum.mit.edu (Paul M Lieberman)
Subject: diff that ignores newlines?
Message-Id: <cc064bc7.0210281506.5af78cf8@posting.google.com>

I'm looking for a utility, or perl code, that will compare two html
files such that , if the two files display identically, this diff
would consider them identical. Obviously, this means ignoring case
inside tags, but not in displayed text. Also, <a><b>text</a></b>
should match <b><a>text</b></a>. More critically, it means that
newlines should be ignored, but in a smart way.

For instance, the following two pieces of text would be considered
identical:

<H3>
<CENTER>Gergen's Promotion of Postmodernism </CENTER></H3>
 <P>As my quotation shows, <A
 href="#c9">Gergen (1991)
 </A></P>


<center>
<h3>Gergen's Promotion of Postmodernism</h3>
</center>
<p>As my quotation shows, <a href="#c9" name="cr9-4">Gergen (1991)</a>
</p>

Any ideas?

- Paul M Lieberman


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

Date: Tue, 29 Oct 2002 09:40:55 +0800
From: "Corin" <corin@cadaway.co.uk>
Subject: Dynamic fields in HTML with Database
Message-Id: <3dbde6ac@news02.imsbiz.com>

This is very easy, but I can't find out the best way.  I want to have a
paragraph of text on a page in html eg The quick [brown] [fox] jumps over
the [lazy] dog. I then want the reader to be able to input the data for
[brown] [fox] and [lazy] with their own words and then produce a fresh html
page with the new phrase. Ideally I'd like to have lots of phrases in a
database to chose from also.  The final stage would be to convert the new
html document into a pdf for emailing - tho' I'm getting ahead of myself
here I think.  Does anyone know the best way for me to do this - i'm only a
beginner - perhaps there is a script already written that I could utilise.
Thanks





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

Date: 28 Oct 2002 17:43:05 -0800
From: xonon@mindspring.com (X Onon)
Subject: filehandles in reference array within reference hash
Message-Id: <5c8c34fc.0210281743.4e4f1f43@posting.google.com>

With the following code:

my %FHS = (
     "LOG"   =>   [*LOG,1],
     "MAIL"  =>   [*MAIL,0],
     "ERROR" =>   [*ERROR,1],
);

&print_it(\%FHS,"A line of text to print to a filehandle\n");


sub print_it {
      local *FH = shift;
      my $line = shift;
      my $item;
         
      foreach $item ( keys %FH ) {
         if ($FH{$item}[1] > 0) {  # This works fine
             # how do I dereference the filehandle?
             # i was trying:
             print $FH{$item}[0] $line;
         }
      }
}


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

Date: Mon, 28 Oct 2002 20:50:04 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: X Onon <xonon@mindspring.com>
Subject: Re: filehandles in reference array within reference hash
Message-Id: <Pine.A41.3.96.1021028204758.48042A-100000@vcmr-104.server.rpi.edu>

[posted & mailed]

On 28 Oct 2002, X Onon wrote:

>my %FHS = (
>     "LOG"   =>   [*LOG,1],
>     "MAIL"  =>   [*MAIL,0],
>     "ERROR" =>   [*ERROR,1],
>);

I think it's preferred to use references to globs (\*LOG) rather than the
glob itself.

>&print_it(\%FHS,"A line of text to print to a filehandle\n");
>
>sub print_it {
>      local *FH = shift;
>      my $line = shift;
>      my $item;
>         
>      foreach $item ( keys %FH ) {
>         if ($FH{$item}[1] > 0) {  # This works fine
>             # how do I dereference the filehandle?
>             # i was trying:
>             print $FH{$item}[0] $line;

When you send a filehandle to print(), it has to be a simple expression --
either a filehandle or a simple scalar.

  print $fh[0] @list;

doesn't work.  Perl sees it as

  print $fh [0] @list;

that is, the [0] is a separate thing, and that's a syntax error.  Do:

  local *F = $FH{$item}[0];
  print F $line;

>         }
>      }
>}

-- 
Jeff "japhy" Pinyan      RPI Acacia Brother #734      2002 Acacia Senior Dean
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Mon, 28 Oct 2002 19:35:47 GMT
From: "TBN" <ihave@noemail.com>
Subject: flock question addendum
Message-Id: <mkgv9.49$S23b.7209068@news2.randori.com>

"TBN" <ihave@noemail.com> wrote in message
news:j%fv9.42$S23b.21692546@news2.randori.com...
> If a file is flock'd so that my script can not open it, is there a way for
> me to tell that it is flock'd?  In other words, if flock is the reason the
> file can not be opened, I may just have my script wait until the file is
> available, but if the file can not be opened for some other reason, I
don't
> want my script to waste resources waiting for a file that will become
> available.
>

Also, is there a way to use flock to keep other processes from writing to a
file, but still allow other processes to read the file?  I would think there
is, but didn't see that option anywhere.




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

Date: 28 Oct 2002 19:47:08 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: flock question addendum
Message-Id: <u9n0oycpmr.fsf@wcl-l.bham.ac.uk>

"TBN" <ihave@noemail.com> writes:

> "TBN" <ihave@noemail.com> wrote in message
> news:j%fv9.42$S23b.21692546@news2.randori.com...
> > If a file is flock'd so that my script can not open it, is there a way for
> > me to tell that it is flock'd?

No.  But then are you sure this is happening?

> >  In other words, if flock is the reason the
> > file can not be opened, I may just have my script wait until the file is
> > available, but if the file can not be opened for some other reason, I
> don't
> > want my script to waste resources waiting for a file that will become
> > available.

On most operating systems a flock() is merely advisory.  The open will
not fail.

> Also, is there a way to use flock to keep other processes from writing to a
> file, but still allow other processes to read the file?  I would think there
> is, but didn't see that option anywhere.

Well appart from the fact that flock() is merely advisory, yes.  You
can use flock() to tell other co-operating processes that they are
allowed to read but not write (aka a shared lock).

Have you read the manual at all?

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


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

Date: Mon, 28 Oct 2002 19:57:26 GMT
From: "TBN" <ihave@noemail.com>
Subject: Re: flock question addendum
Message-Id: <FEgv9.50$S23b.16580778@news2.randori.com>

"Brian McCauley" <nobull@mail.com> wrote in message
news:u9n0oycpmr.fsf@wcl-l.bham.ac.uk...
> "TBN" <ihave@noemail.com> writes:
>
> > "TBN" <ihave@noemail.com> wrote in message
> > news:j%fv9.42$S23b.21692546@news2.randori.com...
> > > If a file is flock'd so that my script can not open it, is there a way
for
> > > me to tell that it is flock'd?
>
> No.  But then are you sure this is happening?
>
> > >  In other words, if flock is the reason the
> > > file can not be opened, I may just have my script wait until the file
is
> > > available, but if the file can not be opened for some other reason, I
> > don't
> > > want my script to waste resources waiting for a file that will become
> > > available.
>
> On most operating systems a flock() is merely advisory.  The open will
> not fail.
>
> > Also, is there a way to use flock to keep other processes from writing
to a
> > file, but still allow other processes to read the file?  I would think
there
> > is, but didn't see that option anywhere.
>
> Well appart from the fact that flock() is merely advisory, yes.  You
> can use flock() to tell other co-operating processes that they are
> allowed to read but not write (aka a shared lock).
>
> Have you read the manual at all?

Yes, but my computer is down for the afternoon, so I'm working with pen and
paper *gasp* for a few hours and I was trying to work through the problem
while I waited for the I.S. goons to come fix my machine.  :-)




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

Date: Mon, 28 Oct 2002 19:13:20 GMT
From: "TBN" <ihave@noemail.com>
Subject: flock question
Message-Id: <j%fv9.42$S23b.21692546@news2.randori.com>

If a file is flock'd so that my script can not open it, is there a way for
me to tell that it is flock'd?  In other words, if flock is the reason the
file can not be opened, I may just have my script wait until the file is
available, but if the file can not be opened for some other reason, I don't
want my script to waste resources waiting for a file that will become
available.




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

Date: Tue, 29 Oct 2002 01:29:17 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Grep v Foreach
Message-Id: <Nvlv9.11314$FS5.9193@nwrddc04.gnilink.net>

Codmate wrote:
> Hi all - this is my first posting to a Perl newsgroup so please be
> kind  ;)
>
> It's a simple question really...
>
> I was just wondering which is faster - a grep such as:
> grep {$_ ne $entry} @list
>
> or an equivalent foreach loop searching for a value in a list.

That depends on your data and your query.
grep will always run through the whole list and it will return a list.
The for loop may terminate after the first element already (if the first
element matches already).

However, for practical applications it shouldn't matter much unless you have
really large lists.
In any case, a hash (if possible) is the better solution anyway.

jue




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

Date: Mon, 28 Oct 2002 21:16:09 +0000 (UTC)
From: ginak <gina02122000@yahoo.com>
Subject: Looking for a handy vanilla base class
Message-Id: <apk9ep$h21$1@reader1.panix.com>




Can someone recommend a module implementing a "Vanilla" base class
with standard goodies such as AUTOLOADed accessors, or the option of
positional or named arguments for the constructor, etc.?

Many thanks in advance!

Gina Klimt



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

Date: Mon, 28 Oct 2002 16:36:54 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Missing assignment operator
Message-Id: <3DBDADF6.4E3316E4@earthlink.net>

Daniel Pfeiffer wrote:
> 
> Hi,
> 
> looking at perlop with all its clever operators I feel that one is
> missing in Perl:
> 
> $x ?= 1 : 2
> 
> would be equivalent to the more redundant
> 
> $x = $x ? 1 : 2
> 
> Does anyone like this?

Well, I believe that perl6 has/will have it.  Not quite in that form,
though:
   $x ??= 1 :: 2;

(This is because in perl6, ?: is spelled ??::, for various reasons)

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Mon, 28 Oct 2002 17:42:41 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: newbie: Multiply picture lines in format doesn't work.
Message-Id: <3DBDBD61.F91CEBC3@earthlink.net>

uncle_ziba wrote:
> 
> Hello,  I've tried search and read through man perlform but I'm still
> having a mental block with the following.
[snip]
> What am I missing?  The code works OK if put a variable after each
> line with @ but then the code does not look readable.

Sadly, you need to have the variables right after the line of format
template which uses them.

Perhaps if you used Text::Reform, from CPAN, instead, you'll have better
luck writing stuff which is easy to read.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: 28 Oct 2002 23:16:18 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: OT Re: significance of 42 for perl, any?!?
Message-Id: <apkgg2$j8$1@canopus.cc.umanitoba.ca>

In article <3DBDBEBA.741A879D@qwest.com>,
Daniel Berger  <djberge@qwest.com> wrote:
:Bob Dover wrote:
:> Its the answer to the question about Life, the Universe, and Everything.  We
:> don't know what the question is, but when we do, its answer will be 42.

:I thought the question was, 'What is 8x7?'

"What do you get when you multiply 6 by 9?". But there are several
reasons for believing that that's not the right Question for this
Universe. [For example, if it were, then the Universe would have disappeared
and been replaced with something even more bizarre and inexplicable.]
--
Everyone has a "Good Cause" for which they are prepared to Spam.
   -- Roberson's Law of the Internet


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

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


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