[19377] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1572 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 20 18:05:42 2001

Date: Mon, 20 Aug 2001 15:05:10 -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: <998345109-v10-i1572@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 20 Aug 2001     Volume: 10 Number: 1572

Today's topics:
    Re: -w pragma (Abigail)
        Assigning every element of array but the first to a has <miscellaneousemail@yahoo.com>
    Re: Assigning every element of array but the first to a <miscellaneousemail@yahoo.com>
    Re: Assigning every element of array but the first to a <miscellaneousemail@yahoo.com>
    Re: Assigning every element of array but the first to a <joe+usenet@sunstarsys.com>
    Re: Assigning every element of array but the first to a <samneric@tigerriverOMIT-THIS.com>
    Re: Assigning every element of array but the first to a <miscellaneousemail@yahoo.com>
        Best Perl shops? (Clarence Johnson)
    Re: Best Perl shops? <comdog@panix.com>
        Best places for posting Perl projects? (Clarence Johnson)
    Re: Call for Bids - C/Perl bridge using XSUBS (David H. Adler)
    Re: Counters (Abigail)
        How to find out whether a certain class implements a me (Tassilo v. Parseval)
    Re: How to find out whether a certain class implements  <ilya@martynov.org>
    Re: How to remove duplicate records in a huge file?? (Abigail)
    Re: How to remove duplicate records in a huge file?? (Mario Rizzuti)
    Re: Is element in array <cpryce@pryce.net>
        Page Updated Email Script (Forti2ude)
        Perl (find a file older then 45mins) (Quenten)
    Re: Perl (find a file older then 45mins) <jurgenex@hotmail.com>
    Re: Perl (find a file older then 45mins) <cberry@cinenet.net>
    Re: Perl (find a file older then 45mins) (Tad McClellan)
    Re: Perl (find a file older then 45mins) (Abigail)
        Perl rookie question!  Setting up perl to work with IIS (Melvin Morris)
        Perl script to update smbpasswd <wschow@Comp.HKBU.Edu.HK>
    Re: perldoc is like Greek to a beginner?? <goldbb2@earthlink.net>
    Re: Reporting Questionable Programming Activity <fty@mediapulse.com>
        select question <goldbb2@earthlink.net>
    Re: Unexplained process killing <goldbb2@earthlink.net>
    Re: unique values in an array - broken algorithm <gnarinn@hotmail.com>
    Re: unique values in an array - broken algorithm (Abigail)
    Re: unique values in an array - broken algorithm (Abigail)
    Re: Web page as a filehandle? <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 20 Aug 2001 19:01:17 GMT
From: abigail@foad.org (Abigail)
Subject: Re: -w pragma
Message-Id: <slrn9o2nkc.45j.abigail@alexandra.xs4all.nl>

Nkhouri (circuller@yahoo.com) wrote on MMCMXI September MCMXCIII in
<URL:news:64ffc63e.0108192310.11330575@posting.google.com>:
:) i used the -w pragma in my FCGI program ,i get many harmless warnings
:) like
:)  used of unintialized values . now if i remove the -w from the shebang
:) line,
:)  the program stops responding and writes an error : program terminated
:) with  exits status 2 . in other words , i cant run the program without
:) the -w pragma anymore !


Think of it as a feature.


Abigail
-- 
perl -wle 'print sub {} -> ("Just another Perl Hacker")'
#    Two young girls contend
#    near Bill Clinton's office. A
#    young girl skips. A thief.


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

Date: Mon, 20 Aug 2001 18:17:43 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Assigning every element of array but the first to a hash??
Message-Id: <MPG.15eb01be9217dbde98977f@news.edmonton.telusplanet.net>

Hi everyone,

In the following code how do I assign all but the first element of the 
@temp array to %hash($key)?  Without limit the generality of the 
add_contents sub by specifying a definite index number?  Such as 
@temp[1...5]?  

I included more code than this question would warrant in the hopes that 
you all would critique my code again and give me any pointers you might 
have on how to write it better. 

Thanks. 

The code: 

#!/usr/bin/perl
use strict;
use diagnostics;

my %hash;
my @temp = ("jack\@ardvark.com,Jack,020010812 18:34,Canada,Yellow 
Knife,Yes",
"tammy\@kangaroo.com,Tammy,20010812 18:34,United States,Chicago,Yes");

add_contents(\@temp);
print_contents();

sub add_contents
{
  my ($arrayref) = @_;
  my ($string, @temp, $key);
  foreach $string (@$arrayref) {
    @temp = split(/,/,$string);
    ($key) = @temp;
    $hash{$key} = join(",", @temp[1...5]); # <<---- HERE
  }
}

sub print_contents
{
  # if @_ is empty *STDOUT will be used instead.
  my ($io_handle) = (@_, *STDOUT);
  my ($key, $value);
  while (($key, $value) = each %hash)
  { 
    printf $io_handle "%-20.20s %-10.10s %-15.15s %-13.13s %-12.12s %-
3.3s\n", 
      $key, split(/,/,$value);
  }	
}

---
Carlos 
www.internetsuccess.ca
*NOTE*: Internet Success is NOT yet fully operational so please don't 
subscribe.  Thanks.


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

Date: Mon, 20 Aug 2001 18:36:56 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Assigning every element of array but the first to a hash??
Message-Id: <MPG.15eb06c129b5bc00989780@news.edmonton.telusplanet.net>

Carlos C. Gonzalez at miscellaneousemail@yahoo.com said...

>     ($key) = @temp;
>     $hash{$key} = join(",", @temp[1...5]); # <<---- HERE

I finally figured out how to do it by using the following code in place 
of the above...

$key = shift(@temp);
$hash{$key} = join(",", @temp); # <<---- HERE

I suppose this might work too....

($key) = @temp;
$hash{$key} = join(",", shift(@temp)); # <<---- HERE

Still is there some way to return everything in @temp without affecting 
@temp as the shift function does??  And short of running a seperate for 
loop itenerating through @temp to build a string to pass to $hash{$key}?  

Critique of my code snippets is especially welcomed.

Thanks.

---
Carlos 
www.internetsuccess.ca
*NOTE*: Internet Success is NOT yet fully operational so please don't 
subscribe.  Thanks.


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

Date: Mon, 20 Aug 2001 18:48:32 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Assigning every element of array but the first to a hash??
Message-Id: <MPG.15eb08fdb1303a37989781@news.edmonton.telusplanet.net>

Carlos C. Gonzalez at miscellaneousemail@yahoo.com said...

> ($key) = @temp;
> $hash{$key} = join(",", shift(@temp)); # <<---- HERE

Never mind this version of the snippet.  Only the first element of @temp 
will be assigned to the hash on this one. 

Thanks.

---
Carlos 
www.internetsuccess.ca
*NOTE*: Internet Success is NOT yet fully operational so please don't 
subscribe.  Thanks.


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

Date: 20 Aug 2001 14:54:34 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Assigning every element of array but the first to a hash??
Message-Id: <m366bief4l.fsf@mumonkan.sunstarsys.com>

Carlos C. Gonzalez <miscellaneousemail@yahoo.com> writes:

> I suppose this might work too....
> 
> ($key) = @temp;
> $hash{$key} = join(",", shift(@temp)); # <<---- HERE
                          ^^^^^^^^^^^^

I doubt this will do what you want.

> Still is there some way to return everything in @temp without affecting 
> @temp as the shift function does??  And short of running a seperate for 
> loop itenerating through @temp to build a string to pass to $hash{$key}?  
> 
> Critique of my code snippets is especially welcomed.

It seems to me that what you need to know is how to get the last index
of the @temp array- $#temp will do that.  I also think you should be
looking at using an anonymous array for the hash entry's value instead
of writing join and split everywhere.  Maybe something like this will
make more sense:

  # use anonymous array(ref) for hash value
  $hash{$temp[0]} = [ @temp[1..$#temp] ]; # see perlreftut for details

  ...
  
  # grab the array from the arrayref with @{}
  printf  $iohandle "...(format string)..." , @{ $hash{$temp[0]} };

HTH
-- 
Joe Schaefer    "The opposite of a correct statement is a false statement. The
                  opposite of a profound truth may well be another profound
                                           truth."
                                               -- Niels Bohr



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

Date: Mon, 20 Aug 2001 15:00:31 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: Assigning every element of array but the first to a hash??
Message-Id: <MPG.15eb283cd4d73d98968c@news.usit.net>

Carlos C. Gonzalez wrote:
> $key = shift(@temp);
> $hash{$key} = join(",", @temp); # <<---- HERE

Yes, this works.

> I suppose this might work too....
> ($key) = @temp;
> $hash{$key} = join(",", shift(@temp)); # <<---- HERE

No.
shift(@temp) only returns $temp[0].

> Still is there some way to return everything in @temp without affecting 
> @temp as the shift function does?? And short of running a seperate for 
> loop itenerating through @temp to build a string to pass to $hash{$key}?  

But you don't need to build the string, since it's already "built". You only 
need to remove the email field from it and use it as the hash key, right?

foreach $string (@$arrayref) {
   ($key, $rest) = split(/,/, $string, 2);
   $hash{$key} = $rest; # no join needed
}

OR:

for (@$arrayref) {
   /(.*?),(.*)/ and ($hash{$1} = $2);
}



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

Date: Mon, 20 Aug 2001 21:58:16 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Assigning every element of array but the first to a hash??
Message-Id: <MPG.15eb35699cc6550a989782@news.edmonton.telusplanet.net>

Joe Schaefer at joe+usenet@sunstarsys.com said...

>   # use anonymous array(ref) for hash value
>   $hash{$temp[0]} = [ @temp[1..$#temp] ]; # see perlreftut for details
> 
>   ...
>   
>   # grab the array from the arrayref with @{}
>   printf  $iohandle "...(format string)..." , @{ $hash{$temp[0]} };
> 

Boy.  Just when I's thinks that I am doing it as well as could be done 
y'all give me some more meat to chew on!  Yum, yum.  (chewing your all's 
code snippets with delight)  Anonymous arrays heh?  I'll have to look 
that one up.  

Samneric posted some good stuff too.  Yummy, yum, yum!  

Thanks.

---
Carlos 
www.internetsuccess.ca
*NOTE*: Internet Success is NOT yet fully operational so please don't 
subscribe.  Thanks.


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

Date: 20 Aug 2001 14:01:14 -0700
From: clarencewjohnson@yahoo.com (Clarence Johnson)
Subject: Best Perl shops?
Message-Id: <928b6bc8.0108201301.72307097@posting.google.com>

Can anyone recommend consulting firms (smaller size) that have very
strong Perl expertise (for a reasonable price)?


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

Date: Mon, 20 Aug 2001 17:54:44 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: Best Perl shops?
Message-Id: <comdog-1A76F1.17544420082001@news.panix.com>

In article <928b6bc8.0108201301.72307097@posting.google.com>, 
clarencewjohnson@yahoo.com (Clarence Johnson) wrote:

> Can anyone recommend consulting firms (smaller size) that have very

why small?

> strong Perl expertise (for a reasonable price)?

it depends on what a reasonable price is, but i think i could
recoomend one ;)

what sort of Perl work is it that you need?  some Perl support
and training firms are listed on www.perl.org.

-- 
brian d foy <comdog@panix.com>
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html



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

Date: 20 Aug 2001 13:59:07 -0700
From: clarencewjohnson@yahoo.com (Clarence Johnson)
Subject: Best places for posting Perl projects?
Message-Id: <928b6bc8.0108201259.75b19e6d@posting.google.com>

What are the best places for posting Perl projects, if one wants to solicit bids?


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

Date: 20 Aug 2001 21:45:16 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: Call for Bids - C/Perl bridge using XSUBS
Message-Id: <slrn9o317c.c4i.dha@panix2.panix.com>

In article <a271d2a4.0108161603.1ed6dcce@posting.google.com>, Allen C wrote:
> We are currently seeking contractors/programmers

You have posted a job posting or a resume in a technical group.

Longstanding Usenet tradition dictates that such postings go into
groups with names that contain "jobs", like "misc.jobs.offered", not
technical discussion groups like the ones to which you posted.

Had you read and understood the Usenet user manual posted frequently to
"news.announce.newusers", you might have already known this. :)  (If
n.a.n is quieter than it should be, the relevent FAQs are available at
http://www.faqs.org/faqs/by-newsgroup/news/news.announce.newusers.html)
Another good source of information on how Usenet functions is
news.newusers.questions (information from which is also available at
http://www.geocities.com/nnqweb/).

Please do not explain your posting by saying "but I saw other job
postings here".  Just because one person jumps off a bridge, doesn't
mean everyone does.  Those postings are also in error, and I've
probably already notified them as well.

If you have questions about this policy, take it up with the news
administrators in the newsgroup news.admin.misc.

http://jobs.perl.org may be of more use to you

Yours for a better usenet,

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"We are the Borg. You will be assimilated! Nah, only kidding. We're
just the Sontarans. Care to take part in some 'medical research'?"


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

Date: 20 Aug 2001 19:16:41 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Counters
Message-Id: <slrn9o2oh8.45j.abigail@alexandra.xs4all.nl>

John J. Trammell (trammell@haqq.hypersloth.invalid) wrote on MMCMXI
September MCMXCIII in <URL:news:slrn9o2mh0.rcj.trammell@haqq.hypersloth.net>:
[] On Mon, 20 Aug 2001 14:58:07 +0100, GBs wrote:
[] > This may confuse you, but do you know of a graphical access counter
[] > script...
[] 
[] Man, page hit counters are *so* 1999.


They were 3 years passe by 1999.

Hit counters were "hot" in 1995 and targetted to people too stupid
to run 'grep -c'.


Abigail
-- 
   my $qr =  qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
      $qr =~  s/$qr//g;
print $qr, "\n";


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

Date: 20 Aug 2001 19:50:12 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo v. Parseval)
Subject: How to find out whether a certain class implements a method?
Message-Id: <9lrplk$om3$1@nets3.rz.RWTH-Aachen.DE>

Hi,

I am currently working on a class that formerly inherited methods from
some other classes. However, it is obvious that the object blessed into
my class does not always fit to a particular method that gets
automatically inherited from a base-class. Therefore I intended to
remove the statically given base-classes in @ISA and replace those 
with $AUTOLOAD since I want to let AUTOLOAD filter my call to a 
inherited method so that I can make some conversions before doing the 
call.
Starting thus:

sub AUTOLOAD {
	    my $self = shift;
	    (my $call = $AUTOLOAD) =~ s/.*\:\://;
		?
}

What I now need to do is find out, which class (or perhaps even classes) 
implement $call so that I can derive an instance of such a class from my 
object stored in $self.

So, in pseudo-code, it should look like:

sub AUTOLOAD {
	my ($self, @args) = @_;
	(my $call = $AUTOLOAD) =~ s/.*\:\://;
	my @classes = qw(Mail::Internet MIME::Entity);
	
	for my $c (@classes) {
	
		if ($c implements $call) {
		
			my $obj;
			
			if ($c eq 'Mail::Internet') {
				$obj = Mail::Internet->new($self->{field});		
			}
			
			if ($c eq 'MIME::Entity') {
				$obj = MIME::Parser->new()->parse_data($self->{string});
			}
			
			no strict "refs";
			$obj->$call(@args);
			last;
			
		}		
	}	
}

I hope that someone here understood what I am asking...it is hard for a
non-native speaker to define such matters clearly and concisely.

Basically, all I am looking for is the Perl-equivalent to 'implements'
as demonstrated in the above code.

I'd be infinitely thankful for any advice that I could get!

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: 21 Aug 2001 00:43:01 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: How to find out whether a certain class implements a method?
Message-Id: <87elq6fooa.fsf@abra.ru>


TvP> Hi,
TvP> I am currently working on a class that formerly inherited methods from
TvP> some other classes. However, it is obvious that the object blessed into
TvP> my class does not always fit to a particular method that gets
TvP> automatically inherited from a base-class. Therefore I intended to
TvP> remove the statically given base-classes in @ISA and replace those 
TvP> with $AUTOLOAD since I want to let AUTOLOAD filter my call to a 
TvP> inherited method so that I can make some conversions before doing the 
TvP> call.
TvP> Starting thus:

TvP> sub AUTOLOAD {
TvP> 	    my $self = shift;
TvP> 	    (my $call = $AUTOLOAD) =~ s/.*\:\://;
TvP> 		?
TvP> }

TvP> What I now need to do is find out, which class (or perhaps even classes) 
TvP> implement $call so that I can derive an instance of such a class from my 
TvP> object stored in $self.

TvP> So, in pseudo-code, it should look like:

TvP> [..skip..]

Answer is $class->can('method'). See 'perldoc UNIVERSAL'.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 20 Aug 2001 18:58:13 GMT
From: abigail@foad.org (Abigail)
Subject: Re: How to remove duplicate records in a huge file??
Message-Id: <slrn9o2nej.45j.abigail@alexandra.xs4all.nl>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMCMXI September
MCMXCIII in <URL:news:9lr7qu$11d$1@mamenchi.zrz.TU-Berlin.DE>:
:) According to Eric Bohlman <ebohlman@omsdev.com>:
:) > Wim <smitw1@hotmail.com> wrote:
:) > > How can I remove duplicate records in a huge file?
:) > > The file contains about 3.000.000 records (=800Mb)
:) > 
:) > Whenever you see "duplicate," think "hash."  The simplest way would be to 
:) > read each record, use the entire record as a key into a hash, and check if 
:) > there's already an entry for that key.  That, however, will likely use up 
:) > way to much memory with the amount of data you have.  Therefore, I'd 
:) > compute a "checksum" (e.g. an MD5 digest) for each record and use that as 
:) > the hash key instead.
:)  
:) Ah, MD5...  I like that.  To be absolutely waterproof, one might store
:) the file position(s) with each key to seek and check duplicates.

800 Mb isn't much disk space - don't forget, it's for a system that
already has a file of 800 Mb. One could use a dbm file and store the
hash on disk - I wouldn't be too sure many systems would be able to keep
3,000,000 MD5 strings as Perl string in memory.

Or one could just hand the stuff of to a database.

:) > If the file has already been sorted, then you merely need to go through it 
:) > record by record and compare each record to the previous one.
:) 
:) In a Unix environment, Perl would probably only play a minor part:
:) 
:)   1) Add record numbers in front of each line.  These will be ignored
:)      in most of the steps, but will allow to restore the original order.
:)      Perl can do this, but other Unix utilities can too.
:) 
:)   2) Sort the file (Unix sort), ignoring the first field (record number).
:) 
:)   3) Use "uniq" to get rid of duplicates, again ignoring the record number.
:) 
:)   4) Sort again, this time using the record numbers, restoring the original
:)      order.
:) 
:)   4) Remove the record numbers.  Again, a Perl one-liner or another Unix
:)      utility.


Sort is O (n log n). Using hashes is O (n) (expected) time.
There are 3 million records.


Abigail
-- 
use   lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";


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

Date: 20 Aug 2001 13:58:14 -0700
From: mariorizzuti@yahoo.com (Mario Rizzuti)
Subject: Re: How to remove duplicate records in a huge file??
Message-Id: <42f3ee2.0108201258.7b4e2962@posting.google.com>

"Wim" <smitw1@hotmail.com> schrieb im Newsbeitrag
news:vk60otcm719i1q8qutk4cvmhk9iuhqtuad@4ax.com...

> > How can I remove duplicate records in a huge file?
> > The file contains about 3.000.000 records (=800Mb)

"Steffen M?ler" <tsee@gmx.net> wrote in message news:<9lp60b$t36$03$1@news.t-online.com>...

> I usually use the following code for arrays:
> 
> @array = sort @array;
> {
>   my $prev = '';
>   @array = grep($_ ne $prev && ($prev = $_), @array);
> }
> 
> But that won't be all that fast for such a large file.
> You'd have to read the records into an array first anyway. Do you have 800Mb
> memory to spare? The sort'd take hours (at the least, I guess). The quickest
> step would be the actual removal of the duplicates.
> 
> I'm sure there's a better way to do this, but it won't be quick either.

I am assuming that in real-world time sorting X arrays of Y elements
each is faster than sorting 1 array of X*Y elements at least for big
arrays.

If that's true, I would split the original database in some smaller
files based on a field value or maybe the first 2 chars of a field
value (adding a LINE_NUM field if there isn't one).

ITERAT_ORIGIN_FILE {
   * read record @REC
   * add LINE_NUM field to @REC
   * AB = first 2 chars of field N
   * append @REC to AB.txt 
}

2 or more duplicate records always fall in the same file, since they
are identic in the N field too. I would then use your code (or an
hash) on each file to just detect the duplicates.

At this point, having a list of LINE_NUM that needs to be removed (an
hash (DUPLICATED_LINE_NUMBER => '1'), it's easy to iterate over the
original file and ignore the duplicates.

N = -1
ITERAT_AGAIN {
   * N++
   * defined($DUPLICATED_LINE_NUMBER{'N'}) ? append to <CLEAN_COPY> :
next
}

---
Mario Rizzuti


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

Date: Mon, 20 Aug 2001 15:48:41 -0500
From: "cp" <cpryce@pryce.net>
Subject: Re: Is element in array
Message-Id: <hGeg7.7910$x84.2619687@ruti.visi.com>


"Guy" <guymal@__NOSPAM__hotmail.com> wrote in message
news:3b7f7695$1@news.barak.net.il...
> How can test a scalar to see if it is an element in a given array?
> Example:
> @bla=("one","two","three");
>
> if ("two" IS IN @bla) #returns true
> {
>     #this code would be executed
> ....
> }
>
> if ("four" IS IN @bla)#returns false
> {
>     #this code would not be executed
> }
>
>

Read the FAQs, please. perlfaq4 (" How can I tell whether a list or array
contains a certain element?" ) covers this nicely.

Briefly, and not tested for syntax (or benchmarked) ...

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

@bla = qw(one two three);
%seen = map {$_ =>1 } @bla;
while (<DATA>) {
chomp;
    if ($seen{'$_'} ) {
        print "$_ is in \@bla\n";
    } else {
        print "$_ NOT in \@bla\n";
    }
}

__DATA__
one
two
four






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

Date: 20 Aug 2001 11:52:52 -0700
From: rottinam@yahoo.com (Forti2ude)
Subject: Page Updated Email Script
Message-Id: <a4424021.0108201052.6716285f@posting.google.com>

Anyone know of a script that will email a group of users that sign up,
when a page is updated? Please don't tell me about
http://www.netmind.com/ either! ;-)


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

Date: 20 Aug 2001 11:24:42 -0700
From: qgriffith@edm1.com (Quenten)
Subject: Perl (find a file older then 45mins)
Message-Id: <de41f866.0108201024.5e304b58@posting.google.com>

Ok is there a way to use perl to find a file that is older then 45mins
 with a certain extension.  Example I have a directory that has a list
of files with diffrent extensions, but I only want to monitor files
with an extension like .trl and see if they have been any files there
with that extension longer then 45mins, and have it ignore any other
file in that directory.  I know how to use perl to check for days, or
even the find command to check for days, but how can you do it for
minutes?

Thanks


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

Date: Mon, 20 Aug 2001 11:44:11 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl (find a file older then 45mins)
Message-Id: <3b815a7b$1@news.microsoft.com>

"Quenten" <qgriffith@edm1.com> wrote in message
news:de41f866.0108201024.5e304b58@posting.google.com...
> Ok is there a way to use perl to find a file that is older then 45mins
>  with a certain extension.  Example I have a directory that has a list

Well, the Find::file man page states:
    use File::Find;
    find(\&wanted, '/foo','/bar');
    sub wanted { ... }

Inside of wanted() you can do pretty much whatever you want, including but
not limited to testing the file name against a pattern or checking any of
the "stat" properties of a file.

jue




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

Date: Mon, 20 Aug 2001 20:14:29 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: Perl (find a file older then 45mins)
Message-Id: <Xns910386B3192FDcberrycinenetnet1@207.126.101.92>

qgriffith@edm1.com (Quenten) wrote in news:de41f866.0108201024.5e304b58
@posting.google.com:

> Ok is there a way to use perl to find a file that is older then 45mins
>  with a certain extension.  Example I have a directory that has a list
> of files with diffrent extensions, but I only want to monitor files
> with an extension like .trl and see if they have been any files there
> with that extension longer then 45mins, and have it ignore any other
> file in that directory.  I know how to use perl to check for days, or
> even the find command to check for days, but how can you do it for
> minutes?

Nothing magical about minutes; a minute is just 1/1440 day.  This will 
produce a list of all files in the current directory which have the 
extension '.trl' and are more than 45 minutes old:

  @old_trls = grep { -M > 45/1440 } glob('*.trl');

-- 
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake



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

Date: Mon, 20 Aug 2001 16:41:30 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl (find a file older then 45mins)
Message-Id: <slrn9o2tfq.s3m.tadmc@tadmc26.august.net>

Quenten <qgriffith@edm1.com> wrote:
>Ok is there a way to use perl to find a file that is older then 45mins
> with a certain extension. 


Untested:

------------------------
#!/usr/bin/perl -w
use strict;
use File::Find;

my $limit = time - 60 * 45;   # epoch time 45 minutes ago

find \&too_old, '/some/dir';

sub too_old {
   return unless /\.trl$/;
   my($mtime) = (stat)[9];     # epoch time since last mod

   print "$File::Find::name is too old\n" if $mtime < $limit;
}
------------------------


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


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

Date: 20 Aug 2001 21:35:11 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Perl (find a file older then 45mins)
Message-Id: <slrn9o30kt.45j.abigail@alexandra.xs4all.nl>

Quenten (qgriffith@edm1.com) wrote on MMCMXI September MCMXCIII in
<URL:news:de41f866.0108201024.5e304b58@posting.google.com>:
,, Ok is there a way to use perl to find a file that is older then 45mins
,,  with a certain extension.  Example I have a directory that has a list
,, of files with diffrent extensions, but I only want to monitor files
,, with an extension like .trl and see if they have been any files there
,, with that extension longer then 45mins, and have it ignore any other
,, file in that directory.  I know how to use perl to check for days, or
,, even the find command to check for days, but how can you do it for
,, minutes?


Well, if you mean "is there a file with the .trl extension that hasn't
been modified (or accessed) for at least 45 minutes", then the answer
is simple: use find. If you insist in using Perl, use find anyway, and
use find2pl for translation.

"Have there been any files there with that extension longer then 45
minutes" is a different question, and it's not clear how to answer it.

If I created a file "foo.ext" one hour ago, and moved "foo.ext" to 
"foo.trl" half an hour ago, does that mean the question you want 
to have answered is yes or no? What if I create a new file with the 
extension ".trl" every minute, but 5 minutes later I throw away the
file. Do you get a "yes" 45 minutes after the first file was created,
or never?



Abigail
-- 
perl -we'$;=$";$;{Just=>another=>Perl=>Hacker=>}=$/;print%;'
#    Ten cows beside a
#    pond. A dove cooing. A spider
#    crouches beside a dam.


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

Date: 20 Aug 2001 14:21:03 -0700
From: mmorris@nas-corp.com (Melvin Morris)
Subject: Perl rookie question!  Setting up perl to work with IIS or Personal Web Server
Message-Id: <2863b571.0108201321.36779ba@posting.google.com>

Greetings,

I'm brand new with Perl and CGI, and I'm trying to set it up to work
with either my IIS server (on my home PC) or Personal web server.  I
know IIS works fine with HTML docs, and I set up the file association,
but every time I try to open a page that contains perl scripting, the
page just hangs and eventually times out.  I'm doing a really basic
script that looks like this:

#!/usr/bin/perl
use strict;
use CGI qw(:standard);
print header;
print"<b>Test</b>";


All I can figure is that there's something wrong with my file
association, but I don't know what it could be.  If anybody could help
me and offer suggestions, it would truly kick ass!


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

Date: 20 Aug 2001 15:08:46 GMT
From: "Mr. Chow Wing Siu" <wschow@Comp.HKBU.Edu.HK>
Subject: Perl script to update smbpasswd
Message-Id: <9lr95u$lne$1@net44p.hkbu.edu.hk>

Hi,

I would like to know if there's any perl script to update
samba's smbpasswd directly?  Thanks in advance.

-- 
Johnson Chow


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

Date: Mon, 20 Aug 2001 15:24:26 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <3B8163EA.FB3DB164@earthlink.net>

Bernie Cosell wrote:
> 
> Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> 
> } Bernie Cosell wrote:
> } >
> } > abigail@foad.org (Abigail) wrote:
> } >
> } > } Could you give examples from some well known languages, like C,
> } > } Java and ADA that proves they are not truely context free?
> } >
> } > How about something like:
> } > ---------------------
> } > typedef int x ;
> } >
> } > x *y();
> } > ---------------------
> } >
> } > Does it parse into an expression with a function call, or a
> } > declaration?
> }
> } For it to be a funcion call, you would need an extra pair of parens:
> }       (x)*y();
> 
> No, no -- the question is whether the parser can figure out whether
> the second line is an expression [to be evaluated for its side effect]
> or a declaration [of 'y' being a function that returns a pointer to an
> 'x']

Of course it's a declaration, not an expression.

> } Simply saying "int" doesn't do a cast, you have to do "(int)"
> 
> I think you're not understanding what typedef does in C.

Hmm?  I think I see what you're saying...

You think it might be parsed either ["'y' is a function which returns a
pointer to an int"], or as ["give the value of 'x' multiplied by the
result of calling function 'y'"]...  where it might possibly be seen as
the second if there is already declared some variable 'x'.

Funky.  I guess I dunno which it should be.

-- 
I'm not a programmer but I play one on TV...


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

Date: Mon, 20 Aug 2001 19:50:51 GMT
From: "Jay Flaherty" <fty@mediapulse.com>
Subject: Re: Reporting Questionable Programming Activity
Message-Id: <vSdg7.79478$ai2.5655604@bin2.nnrp.aus1.giganews.com>


"David Combs" <dkcombs@panix.com> wrote in message
news:9l0774$lh8$2@news.panix.com...
> In article <hkxa7.207864$2O6.13515289@news2.aus1.giganews.com>,
> Jay Flaherty <fty@mediapulse.com> wrote:
> >"Smiley" <gurm@intrasof.com> wrote in message
> >news:3b672381.218715906@news1.on.sympatico.ca...
> >> The company I'm working for purchased a Perl CGI Script that turns out
> >> to be seriously faulty - so much so that my boss asked me to
> >> investigate whether there's any international agency or organization
> >> set up that we can report this kind of thing to.
> >>
> >> Does anybody know?  Thanks :)
> >>
> >
> >Like an *International* lemon law?  :-)
> >
> >
>
> I thought a "lemon law" made it *illegal* to complain
> in an extremely-public way, eg by driving around in
> a (buggy) car with a big lemon painted on each door.
>
> It was a *long* time ago that I read that -- and
> I might have gotten it wrong, eg by 180 degrees.

Don't have a clue but the first lemon law was in Connecticut in 1982:
The "Lemon Law" is a nickname for Connecticut General Statute Chapter 743b,
"Automotive Warranties". It establishes arbitration as an informal process
for resolving disputes between consumers and automobile manufacturers. This
does not cover extended warranties you buy separately.

Jay





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

Date: Mon, 20 Aug 2001 17:59:36 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: select question
Message-Id: <3B818848.B46D708@earthlink.net>

This should probably go to a unix group, or something, but...
If I have a pipe [made with, eg, pipe()], and there's no data currently
in it [ie, the writing end is writable, but the reading end is not
readable, and would block, 'cause there's nothing there to read], and I
close the writing end, does that cause the reading end's state to change
to be "readable" or "exceptional"?

I had thought that it would, and maybe I'm doing something wrong, but it
seems that it doesn't.

-- 
I'm not a programmer but I play one on TV...


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

Date: Mon, 20 Aug 2001 16:15:05 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Unexplained process killing
Message-Id: <3B816FC9.B854E57E@earthlink.net>

Moran Goldstein wrote:
> 
> Hi,
> I'm working on a script that loops through large arrays and modifies
> numeric values. Specifically, hashes of 3D-arrays (ie -
> $hash{key}[Z][Y][X]). The problem is that, depending on the size of
> the array, it's likely to get killed(running on FreeBSD). The arrays
> can get up to 200,000 values, usually of floating-point numbers.

Just offhand, how many key/value pairs are there in that hash?
If there's many, you might be able to reduce memory usage by tying the
hash to a file [via DB_File or BerkeleyDB or somesuch], so that only the
particular 3D-array you're looking at is in memory.

Of course, you'll need to use filter_store_value and filter_fetch_value
to convert the flat strings which a database handles to and from three
dimensional arrays, but that shouldn't be too hard.

> I'm guessing that the script is being killed because of memory usage,
> but I can't be sure. What I am sure about is that the higher the
> amount of values, the higher the possibility of it being killed.
> Anything below ~40,000 values usually passes through, but if values
> exceed 200,000, there's almost a %50 chance of the process being
> killed.
> 
> When it gets killed, it just says "killed", with no details. Is there
> any way I can get more information from the script about why it's
> being killed? Any error-checking methods? Also, isn't 200,000 values
> actually a small amount, relative to the huge amounts of database
> strings Perl so easily deals with?

You can get a tiny bit more information about the cause of death by
looking at the exit code, usually $? in shell which ran the program.

As Logan Shaw said, the problem isn't exactly the number of floating
point numbers -- it's the number of scalar values.  The machine normally
represents a single "double" value as 8 bytes, but a perl SV value is
rather larger than that.  So you're not dealing with 200_000*8 bytes, as
a program written in C or C++ would be for this data, you're dealing
with over 200_000*25 bytes [that number would be *if* it was just a
simple flat array -- it's much more since it's a 3D array], since each
double is in it's own SV.  Note that having it in a 3D array does not
affect how much memory would be used if it were a C/C++ program -- only
in perl does making it multidimensional cause it to use more memory.

Perl does handle huge strings, but a string is one single SV.

If you changed how your data was managed from being a list of lists of
lists, to being a tied array which stores data internally as a flat
string, and generates and stores the sub-lists or the doubles as
necessary, you could reduce memory usage quite a bit.  This is sort of
like the substr/pack/unpack solution Logan Shaw suggested, but those
details would be hidden inside the tied object.

> By the way -- in case it's of any relevance to the problem, large
> arrays take up to 15 seconds to process (when the script isn't killed,
> that is).

Hmm, that implies that they aren't *really* very large...

It's possible that your problem is even a bug in perl [memory corruption
or somesuch]... what version of perl are you using?  5.6?

-- 
I'm not a programmer but I play one on TV...


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

Date: Mon, 20 Aug 2001 18:05:00 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: unique values in an array - broken algorithm
Message-Id: <998330700.844904870260507.gnarinn@hotmail.com>

In article <3B810A67.3B2DDCE4@uswest.com>,
Mr Sunblade  <djberge@uswest.com> wrote:

>Someone posted this technique for extracting unique elements out of an
>array, but there's a syntax error somewhere.  I've futzed with it a bit,
>couldn't get it right.  Any takers?
>
>my @array = qw(1 2 3 4 5 2 3 4);
>my @uniq = keys %{ map { $_, 1 } @array};
>
>Ambiguous use of %{map{...}} resolved to %map{...} at ./maptest.pl line

just un-futz it:
  my @array = qw(1 2 3 4 5 2 3 4);
  my %seen= map { $_, 1 } @array;
  my @uniq = keys %seen;


gnari



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

Date: 20 Aug 2001 19:12:39 GMT
From: abigail@foad.org (Abigail)
Subject: Re: unique values in an array - broken algorithm
Message-Id: <slrn9o2o9l.45j.abigail@alexandra.xs4all.nl>

Mr Sunblade (djberge@uswest.com) wrote on MMCMXI September MCMXCIII in
<URL:news:3B810A67.3B2DDCE4@uswest.com>:
`` Hi all,
`` 
`` Someone posted this technique for extracting unique elements out of an
`` array, but there's a syntax error somewhere.  I've futzed with it a bit,
`` couldn't get it right.  Any takers?
`` 
`` my @array = qw(1 2 3 4 5 2 3 4);
`` my @uniq = keys %{ map { $_, 1 } @array};
`` 
`` Ambiguous use of %{map{...}} resolved to %map{...} at ./maptest.pl line
`` ...


%{ } takes a hashreference. Hash references are constructed with { }.
Hence:

    my @uniq = keys %{{map { $_, 1 } @array}};


Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'


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

Date: 20 Aug 2001 19:13:58 GMT
From: abigail@foad.org (Abigail)
Subject: Re: unique values in an array - broken algorithm
Message-Id: <slrn9o2oc5.45j.abigail@alexandra.xs4all.nl>

Tad McClellan (tadmc@augustmail.com) wrote on MMCMXI September MCMXCIII
in <URL:news:slrn9o21ia.pt9.tadmc@tadmc26.august.net>:
!! Mr Sunblade <djberge@uswest.com> wrote:
!! >
!! >Someone posted 
!! 
!! Why rely on some random Usenaut who might be wrong or make a mistake
!! instead of taking a validated and peer-reviewed solution that
!! is already on your very own hard disk?


Because that looked very much like code I have posted in the past? ;-)
Except that I included the extra braces.


Abigail
-- 
use   lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";


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

Date: Mon, 20 Aug 2001 16:25:40 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Web page as a filehandle?
Message-Id: <3B817244.B6C4DAF7@earthlink.net>

David Scarlett wrote:
> 
> Is it possible to open a webpage as a filhandle in perl? I want to be
> able to grab data off a web page, and I was wondering if it would be
> possible to somehow open the website as a filehandle and grab the
> source code one line at a time.... is it?

open HANDLE, q[ perl -MLWP::Simple -e'getprint(http://www.perl.com)' |]
	or die "Couldn't popen 'perl ...': $!";
print while( <HANDLE> );
close HANDLE
	or die "Couldn't close popened 'perl': $? $!";


you could also do:
open HANDLE, "-|" or do {
	require LWP::Simple;
	getprint("http://www.perl.com");
	exit;
};
 ... same code follows ...

To do it without a fork might be a bit harder.

-- 
I'm not a programmer but I play one on TV...


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

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


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