[13785] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1195 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 27 23:02:41 1999

Date: Wed, 27 Oct 1999 20:02:29 -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: <941079749-v9-i1195@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 27 Oct 1999     Volume: 9 Number: 1195

Today's topics:
    Re: Q: Truncate string length? (Charles DeRykus)
        Question about opendir and recursion. jamdagni@my-deja.com
    Re: Question about opendir and recursion. (Bart Lateur)
    Re: Question about opendir and recursion. <rootbeer@redcat.com>
    Re: Question about opendir and recursion. <gellyfish@gellyfish.com>
    Re: Question about opendir and recursion. (Steve Driscoll)
    Re: Question about opendir and recursion. <newsposter@cthulhu.demon.nl>
        quiet warnings while distinguishing zero from undef for (Alan Mead)
    Re: quiet warnings while distinguishing zero from undef <aqumsieh@matrox.com>
    Re: quiet warnings while distinguishing zero from undef (Tad McClellan)
        quite and dirty date conversion (Vladimir Gershkovich)
        quoting confusion in system calls (Eric Smith)
    Re: quoting confusion in system calls <aqumsieh@matrox.com>
    Re: quoting confusion in system calls <rootbeer@redcat.com>
    Re: Random Number (Peter J. Kernan)
    Re: Random Number <lr@hpl.hp.com>
    Re: Random Number (Peter J. Kernan)
        receive mail and redirect it elsewhere <lzu99dk@rdg.ac.uk>
    Re: receive mail and redirect it elsewhere <rootbeer@redcat.com>
        Recursive file/folder indexing (Scott Edward Skinner)
    Re: Recursive file/folder indexing (Sam Holden)
    Re: Reference challenge (Abigail)
    Re: Reference challenge (Abigail)
    Re: Reference challenge (Tramm Hudson)
    Re: Reference challenge (Abigail)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 25 Oct 1999 23:08:18 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Q: Truncate string length?
Message-Id: <FK6LLu.n4v@news.boeing.com>

In article <s0qgnv8sr018@corp.supernews.com>,
Craig Berry <cberry@cinenet.net> wrote:
>Charles DeRykus (ced@bcstec.ca.boeing.com) wrote:
>: I'm suprised that C<s> hasn't been mentioned:
>: 
>: $TheField =~ s/(.{500}).*/$1/; 
>
>I included this possibility in my benchmarking post, several days ago.
>This wtdi was slower by more than a factor of two compared to the
>second-to-the-worst variant (using a match).  substr (in either lvalue or
>rvalue forms) wins handily on speed.
>

Thanks. Suprising results. 

Looks as if the closest competitor 'substr_lv' outperforms 
if the trucation point is near string size; but, 'substr_rv' 
steadily reverses the trend as the string lengthens. 

--
Charles DeRykus


my $sample = 'a' x ( shift || 1_000);
warn "length = ", length $sample, "\n";
timethese( 100_000, {
  substr_lv  => sub { $_ = $sample; substr($_, 500) = '' },
  substr_rv  => sub { $_ = $sample; $_ = substr($_, 0, 500) },
} ); 
__END__

length = 550
Benchmark: timing 100000 iterations of substr_lv, substr_rv...
 substr_lv: 21 wallclock secs (19.21 usr +  0.00 sys = 19.21 CPU)
 substr_rv: 22 wallclock secs (19.59 usr +  0.00 sys = 19.59 CPU)

length = 600
Benchmark: timing 100000 iterations of substr_lv, substr_rv...
 substr_lv: 21 wallclock secs (19.33 usr + -0.01 sys = 19.32 CPU)
 substr_rv: 22 wallclock secs (20.34 usr +  0.00 sys = 20.34 CPU)

length = 800
Benchmark: timing 100000 iterations of substr_lv, substr_rv...
 substr_lv: 24 wallclock secs (21.27 usr +  0.00 sys = 21.27 CPU)
 substr_rv: 22 wallclock secs (20.50 usr +  0.00 sys = 20.50 CPU)



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

Date: Tue, 26 Oct 1999 15:43:00 GMT
From: jamdagni@my-deja.com
Subject: Question about opendir and recursion.
Message-Id: <7v4i63$69c$1@nnrp1.deja.com>

Hi:

    I've got a question about the effects of recursion on an open
directory handle. I'm trying to write a program that recurses
thru' directories and prints out filenames whose size is greater
than a given value. For this I'm using a recursive subroutine, in
which I do a opendir for the given directory. Then, I 'readdir'
through the directory entries, ignoring '.' and '..'. For files,
I just check the size and add them to a hash if they satisfy the
size condition. For directories, I call the function recursively
with the new path. I'm finding that the program does a
depth-first traversal into the directory tree and after
processing the files in the "lowest" directory, exits. It doesn't
return up the recursed path and do the files/directories in the
higher directories. Am I unaware of some feature of the directory
handle namespace or directory handles is general? Or, am I making
some other mistake? I know that there may be packages/modules
that already do this task (traversing directory trees), but I'm a
newbie Perl programmer trying to learn.

Thanx in advance for any help,
Swaroop (skumar@concentric.net)


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 27 Oct 1999 10:55:01 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Question about opendir and recursion.
Message-Id: <3818d425.1594472@news.skynet.be>

jamdagni@my-deja.com wrote:

>   I've got a question about the effects of recursion on an open
>directory handle. I'm trying to write a program that recurses
>thru' directories and prints out filenames whose size is greater
>than a given value. For this I'm using a recursive subroutine, in
>which I do a opendir for the given directory. Then, I 'readdir'
>through the directory entries, ignoring '.' and '..'. For files,
>I just check the size and add them to a hash if they satisfy the
>size condition. For directories, I call the function recursively
>with the new path. I'm finding that the program does a
>depth-first traversal into the directory tree and after
>processing the files in the "lowest" directory, exits.

Try 

	local *DIR;

in your sub.

But actually, if I were you, I'd buffer at least the directory paths,
finish the whole current directory scan level, close the directory, and
then process the lis of directories.

For example:

#! perl -w
    sub scandirs {
        local($_, *DIR);
        while(@_) {
            my $dir = shift;
            opendir(DIR, $dir);
            $dir =~ tr!\\!/!; # uniformitis
            $dir =~ s!/$!!;  # drop trailing slash
            while(defined($_ = readdir DIR)) {
                next if $_ eq '.' or $_ eq '..';
                if(-d "$dir/$_") {
                    unshift @_, "$dir/$_"; 
                    #use push() if you want breadth-first
                } elsif (-f _) {
                    # it's a file
                    print "$dir/$_ -> @{[-s _]} bytes\n";
                }
            }
            closedir DIR;
        }
    }

    scandirs("c:/windows", "a:/");


Reinventing wheel can be fun!  ;-)

-- 
	Bart.


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

Date: Tue, 26 Oct 1999 14:47:32 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Question about opendir and recursion.
Message-Id: <Pine.GSO.4.10.9910261446070.29843-100000@user2.teleport.com>

On Tue, 26 Oct 1999, Steve Driscoll wrote:

> I encountered this problem trying to traverse a file system and
> concluded that FILEHANDLES cannot be recursively used.  I tried
> to use "my FILEHANDLE" but that didn't work either.  So here's my
> nonrecursive solution to walking a directory tree:

STOP! You're reinventing a particularly square wheel.

Since your solution doesn't take symlinks into account, it'll get lost in
an infinite loop sooner or later. :-P

Use File::Find. 

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 26 Oct 1999 21:21:40 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Question about opendir and recursion.
Message-Id: <7v5614$is4$1@gellyfish.btinternet.com>

On Tue, 26 Oct 1999 15:43:00 GMT jamdagni@my-deja.com wrote:
> Hi:
> 
>     I've got a question about the effects of recursion on an open
> directory handle. 

Dirhandles like Filehandle are global - as soon as you recurse and open
a new directory on the same filehandle thats it - there is no going back.
The Dirhandle module will allow you to 'localize' the handle instances
within a lexical scope - or (better IMO) you could read the entire
directory into a lexically scoped array and iterate over that rather
than an open filehandle - I and others have posted examples that do this
before.

The recommended method of course is to use File::Find.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>


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

Date: Tue, 26 Oct 1999 17:40:01 GMT
From: sdriscol@oclc.org (Steve Driscoll)
Subject: Re: Question about opendir and recursion.
Message-Id: <3815e595.2147049133@24.95.45.103>

On Tue, 26 Oct 1999 15:43:00 GMT, jamdagni@my-deja.com wrote:

I encountered this problem trying to traverse a file system and
concluded that FILEHANDLES cannot be recursively used.  I tried
to use "my FILEHANDLE" but that didn't work either.  So here's my
nonrecursive solution to walking a directory tree:

my @dirlist;  # will contain a list of directories to scan

push @dirlist, "/directory/at/top/of/tree";

while ( $#dirlist >= 0 )
   {
   my ( $dir ) = pop @dirlist;
   opendir ( DIR,  $dir ) or die "Can't open directory $dir, $!\n";
   my (@dentry) = readdir DIR;
   closedir DIR;
   foreach  my  $entry  ( @dentry )
     {
     if ( ( $entry eq ".") || ( $entry eq ".." ))
        {
        print "   FYI2:  Skipping $entry \n";
        next;
        }
     $entry = "$dir/$entry";
     if ( -f $entry )
        {
        print "   $entry, a file\n";
        }
     elsif ( -d $entry )
        {
        print "    $entry, a directory\n";
        push  @dirlist, $entry ;
        }
     else
        {
        print "$entry, unknown \n";
        }
     }
   }


>Hi:
>
>    I've got a question about the effects of recursion on an open
>directory handle. I'm trying to write a program that recurses
>thru' directories and prints out filenames whose size is greater
>than a given value. For this I'm using a recursive subroutine, in
>which I do a opendir for the given directory. Then, I 'readdir'
>through the directory entries, ignoring '.' and '..'. For files,
>I just check the size and add them to a hash if they satisfy the
>size condition. For directories, I call the function recursively
>with the new path. I'm finding that the program does a
>depth-first traversal into the directory tree and after
>processing the files in the "lowest" directory, exits. It doesn't
>return up the recursed path and do the files/directories in the
>higher directories. Am I unaware of some feature of the directory
>handle namespace or directory handles is general? Or, am I making
>some other mistake? I know that there may be packages/modules
>that already do this task (traversing directory trees), but I'm a
>newbie Perl programmer trying to learn.
>
>Thanx in advance for any help,
>Swaroop (skumar@concentric.net)
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.



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

Date: 26 Oct 1999 18:05:08 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Question about opendir and recursion.
Message-Id: <7v4qgk$jde$1@internal-news.uu.net>

jamdagni@my-deja.com wrote:
> Hi:

> For directories, I call the function recursively
> with the new path.

  I assume you have something like this:

sub scan
{
  opendir (DIR, xxx)
  while $path = readdir (DIR)
  {
    if -d $path  _do recursive call ();
  }
  closedir DIR
}

You probably want the DIR handle to be local to your sub. As
someone else mentioned, my does not work. See perlfaq5
  ''How can I make a filehandle local to a subroutine?''

Erik





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

Date: Tue, 26 Oct 1999 15:56:18 GMT
From: adm@ipat.com (Alan Mead)
Subject: quiet warnings while distinguishing zero from undef for SQL
Message-Id: <3815cc91.92671786@news.soltec.net>

I am parsing CSV to insert into an SQL table.  CSV distinguishs
between zero (and other values) and undef.  But apparently SQL (e.g.,
MySQL) won't let me insert NULL values.  So I guess I need to test the
parsed values and leave out NULL values and the associated field
label. 

I can distinguish zero from undef but when I run the script using -w I
get a warning for every test involving an undef value.  Is there a way
to do this so that no warnings are generated?  Otherwise, I will need
to run without the -w which everyone discourages.

This is the bit that does the compare:

for ($i=0; $i<@headers-1; $i++) {
  # only include if col's value non-NULL
  if ( ($data[$i]) || ($data[$i] eq '0') ){          # warning here
        $sql_insert .= $headers[$i] . ",";
        $sql_temp   .= "'" . $data[$i] . "',";
  }
}
# later I pout $sql_insert and $sql_temp togather to form
# an SQL insert statement


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

Date: Tue, 26 Oct 1999 17:27:48 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: quiet warnings while distinguishing zero from undef for SQL
Message-Id: <x3yvh7t95il.fsf@tigre.matrox.com>


adm@ipat.com (Alan Mead) writes:

> I can distinguish zero from undef but when I run the script using -w I
> get a warning for every test involving an undef value.  Is there a way
> to do this so that no warnings are generated?  

You say you know how to distinguish between a zero and an undef. So
why don't you do that in your program?

Perhaps, you should also stick a defined() somewhere in your code.

HTH,
--Ala



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

Date: Tue, 26 Oct 1999 08:43:40 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: quiet warnings while distinguishing zero from undef for SQL
Message-Id: <sl74v7.20b.ln@magna.metronet.com>

Alan Mead (adm@ipat.com) wrote:

: I can distinguish zero from undef but when I run the script using -w I
: get a warning for every test involving an undef value.  Is there a way
: to do this so that no warnings are generated?  


   You should use defined() to test for definedness.


: Otherwise, I will need
: to run without the -w which everyone discourages.

: This is the bit that does the compare:

: for ($i=0; $i<@headers-1; $i++) {
:   # only include if col's value non-NULL
:   if ( ($data[$i]) || ($data[$i] eq '0') ){          # warning here


      if ( !defined($data[$i]) || ($data[$i] eq '0') ){ 


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 27 Oct 1999 23:21:47 GMT
From: vlad@tiac.net (Vladimir Gershkovich)
Subject: quite and dirty date conversion
Message-Id: <7v81eb$mh6@news-central.tiac.net>



Howdy...

  I've been struggling for some today on what should be an easy thing
  to do - covert ONE date_time format to another using standard POSIX 
  strftime module.. (no Date::Manip CPAN module).

  From format: "Mon Nov 17 13:35:04 1997" 
  To format:    "1997/11/17 17:35:04" 

  The best I could come up with is:
    $FORMAT = "%Y-%m-%d %H:%M:%S";
    $STRING = strftime($FORMAT, 04, 35, 13, 17, 10, 1997-1900);

  But this way the input parmeters to strftime are "hardwired" and 
  can only by digits. All I need to do is take one date format, massage the date
  and produce a diff. format of the same date.

  Any bright ideas/pointers/solutions?

mucho thanks

vlad


P.S. if could directly email me, that would be much better.
	 thanks again
-- 
+-----------------------------+ 
| mailTo:vlad@tiac.net        |
+-----------------------------+


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

Date: 27 Oct 1999 01:33:20 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: quoting confusion in system calls
Message-Id: <slrn81clj0.ut8.eric@plum.fruitcom.com>

I am wasting much time on fiddling with quoting especially in system calls
like this one:

system "mv /d/e/erwin/* '/d/e/erwin/' . $erwin . '_CheckTo_' . $user .  $myd"

Once I have used the `"' to surround the system command then I cannot use
it again, which is most inconvenient when mixing literals and variables.
Should I be using the q and qq operators?

Thanx
-- 
Eric Smith
eric@fruitcom.com
www.fruitcom.com



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

Date: Wed, 27 Oct 1999 11:17:25 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: quoting confusion in system calls
Message-Id: <x3yr9ig96kb.fsf@tigre.matrox.com>


eric@fruitcom.com (Eric Smith) writes:

> system "mv /d/e/erwin/* '/d/e/erwin/' . $erwin . '_CheckTo_' . $user .  $myd"
> 
> Once I have used the `"' to surround the system command then I cannot use
> it again, which is most inconvenient when mixing literals and variables.
> Should I be using the q and qq operators?

Yes. Or you can escape any double quotes inside your string.

But ... why don't you just try and see for yourself? There is nothing
wrong with that. Just set your argument to system() to some harmless
string like:

	system qq(echo "Hello");

and knock yourself out :)

HTH,
--Ala



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

Date: Tue, 26 Oct 1999 21:12:24 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: quoting confusion in system calls
Message-Id: <Pine.GSO.4.10.9910262103330.29843-100000@user2.teleport.com>

On 27 Oct 1999, Eric Smith wrote:

> I am wasting much time on fiddling with quoting especially in system calls
> like this one:
> 
> system "mv /d/e/erwin/* '/d/e/erwin/' . $erwin . '_CheckTo_' . $user .  $myd"

Well, first of all, have you seen the File::Copy module, and similar
utilities which you'll find come installed with perl? Maybe you should be
using them instead of system().

But if you do need a system call to 'mv', here's one sure way to do it.

    system 'mv', $from_name, $to_name;

No worries about quoting funny characters in the names. You can even have
spaces or newlines in a filename! But that's not recommended....

Still, it looks as if you want to do globbing in the call. That's another
matter. Maybe you'll want to do the globbing from within perl, then call
File::Copy's mv (or maybe simply rename()?) in a loop.

But if you still want system(), here's one way to take care of that.
First, write your code something like this.

    my $command = # Yes, this is the same command as above
	"mv /d/e/erwin/* '/d/e/erwin/' . $erwin . '_CheckTo_' . $user . $myd";
    print "For debugging, the command is:\n$command\n";
    # system $command;

Now you can fiddle with the line with the command until it comes up
right, then comment out the print() and uncomment the system().

One last hint: Operators like the period and single quotes don't work when
they themselves are quoted. 

Good luck!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 26 Oct 1999 21:22:23 GMT
From: pete@theory2.phys.cwru.edu (Peter J. Kernan)
Subject: Re: Random Number
Message-Id: <slrn81c6se.6po.pete@theory2.phys.cwru.edu>

On Mon, 25 Oct 1999 23:46:45 -0700, Larry Rosler <lr@hpl.hp.com> wrote:
 .=In article <slrn819vhr.6sm.pete@theory2.phys.cwru.edu> on 26 Oct 1999 
 .=01:04:59 GMT, Peter J. Kernan <pete@theory2.phys.cwru.edu> says...
 .=> On Sun, 24 Oct 1999 20:24:30 -0700, Larry Rosler <lr@hpl.hp.com> wrote:
 .=> .=I posted this in another thread today.  Modified for your needs:
 .=> .=
 .=> .=my %hash;
 .=> .=$hash{1 + int rand 14}++ while keys %hash < $however_many_you_need;
 .=> 
 .=> I suppose this is ok as one does not mind if the order of the 'random'
 .=> numbers returned does not need to be 'random'.
 .=
 .=What do you mean by this?  Is there any order of 'random' numbers other 
 .=than 'random'?  Why would the order of the 'random' numbers returned not 
 .=be 'random'?
 .=
 .=>  e.g. try this with $however_many_you_need= 14 and you may see some
 .=> patterns.
 .=
 .=What do you mean by this?  If $however_many_you_need = 14, the pattern I 
 .=would see would be all of the 14 integers between 1 and 14, inclusive, 
 .=added to the hash in some 'random' order.
 .=

well i like your idiom, but was considering the possibility of using it
in the wrong way. if one knows that all of ones M array elements are
unique and one wants to draw N from M without replacement where N << M,
then your code above is a cute and efficient way to do it, guaranteeing,
by the nature of perl hashes that there is no duplication (implementing
the "without replacement" part of the problem).  all well and good so
far. the only problem is if the order of the values drawn is important,
this information is lost when the hash is constructed (though a small
modification can remedy this, i.e.  perhaps setting the keys to $i++).
perhaps the following use of your technique was not intended by you, but
it is possible that someone would try, to whit;


sub hash_it {
  my ($a,$n) = @_;
  return undef if $n > @$a;
  my $hash;
  $hash{$a->[rand @$a]}++ while keys %hash < $n;
  keys %hash;
}

#wasteful routine here :-) but
sub map_it {
  my ($a,$n) = @_;         #same interface
  return undef if $n > @$a;
  my @a = @$a;             #dont clobber orig
  map {splice @a, rand @a, 1} 1..$n;
}

#send in array, return hash order
sub hash_it_noran {
  my $a = shift;
  my %hash;
  @hash{@$a} = () x $#$a;
  keys %hash;
}

@a = (1..10);
@b = map_it(\@a,5);

for (0..20) {
  @b = map {splice @b, rand @b, 1} 1..@b;
  print "@b: @{[hash_it_noran(\@b,5)]}";

}


the for loop shows that if by some chance the hash_it sub were to
generate the same random elements in any order that the sequences
returned will have strong correlations, and perhaps always be in the
same order (i consider the hashing algorithm a 'black box' and thus
assume no guarantee that the order will not vary). this is the point i
was trying to make, but not for your benefit. i have the feeling that
you would not use it this way. maybe no one would. but ...

-- 
  Pete


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

Date: Mon, 25 Oct 1999 23:46:45 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Random Number
Message-Id: <MPG.127eee3388e10eeb98a12a@nntp.hpl.hp.com>

In article <slrn819vhr.6sm.pete@theory2.phys.cwru.edu> on 26 Oct 1999 
01:04:59 GMT, Peter J. Kernan <pete@theory2.phys.cwru.edu> says...
> On Sun, 24 Oct 1999 20:24:30 -0700, Larry Rosler <lr@hpl.hp.com> wrote:
> .=I posted this in another thread today.  Modified for your needs:
> .=
> .=my %hash;
> .=$hash{1 + int rand 14}++ while keys %hash < $however_many_you_need;
> 
> I suppose this is ok as one does not mind if the order of the 'random'
> numbers returned does not need to be 'random'.

What do you mean by this?  Is there any order of 'random' numbers other 
than 'random'?  Why would the order of the 'random' numbers returned not 
be 'random'?

>  e.g. try this with $however_many_you_need= 14 and you may see some
> patterns.

What do you mean by this?  If $however_many_you_need = 14, the pattern I 
would see would be all of the 14 integers between 1 and 14, inclusive, 
added to the hash in some 'random' order.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 26 Oct 1999 01:04:59 GMT
From: pete@theory2.phys.cwru.edu (Peter J. Kernan)
Subject: Re: Random Number
Message-Id: <slrn819vhr.6sm.pete@theory2.phys.cwru.edu>

On Sun, 24 Oct 1999 20:24:30 -0700, Larry Rosler <lr@hpl.hp.com> wrote:
 .=I posted this in another thread today.  Modified for your needs:
 .=
 .=my %hash;
 .=$hash{1 + int rand 14}++ while keys %hash < $however_many_you_need;
 .=

I suppose this is ok as one does not mind if the order of the 'random'
numbers returned does not need to be 'random'.

 e.g. try this with $however_many_you_need= 14 and you may see some
patterns.
-- 
  Pete


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

Date: Mon, 25 Oct 1999 11:06:48 +0100
From: Dimitrios Kremmydas <lzu99dk@rdg.ac.uk>
Subject: receive mail and redirect it elsewhere
Message-Id: <38142BB8.C6DF53AC@rdg.ac.uk>

I 've added this line to my /etc/aliases file
list:"|/usr/bin/velocity.pl"
[I also have made newaliases, in case anyone doubts]

I guess that whenever I sent mail to list@bla.bla.com the velocity.pl
should be run (as nobody user ?).
The velocity.pl is a simple perl programm that opens the sendmail
open(SNDMAIL,"|/usr/bin/sendmail -t -n"); #Got it from the FAQ
And then redirects the <STDIN> (I guess that is the hole mail message I
send to list@bla.bla.com) to the receipient(s) I want.
[Lets suppose I extract somehow only the mail message, not the headers]
print A<<EOF #Got it Also from the FAQ
To:
[..]

THE PROBLEM:
is that althought it doesn't seem to me to make any mistake, IT DOES NOT
WORK. 
THE QUESTION:
Do you know any way I can have for <STDIN> of a perl programm, the mail
message (with the headers), but in real time (that means when the mail
is received)


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

Date: Mon, 25 Oct 1999 13:52:23 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: receive mail and redirect it elsewhere
Message-Id: <Pine.GSO.4.10.9910251350510.29843-100000@user2.teleport.com>

On Mon, 25 Oct 1999, Dimitrios Kremmydas wrote:

> I 've added this line to my /etc/aliases file
> list:"|/usr/bin/velocity.pl"
> [I also have made newaliases, in case anyone doubts]

> THE PROBLEM:
> is that althought it doesn't seem to me to make any mistake, IT DOES NOT
> WORK. 

It sounds as if your sendmail isn't doing what you want. Perhaps you
should search for the docs, FAQs, and newsgroups about sendmail. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 27 Oct 1999 19:10:51 -0400
From: sskinner@cloud9.net (Scott Edward Skinner)
Subject: Recursive file/folder indexing
Message-Id: <sskinner-2710991910520001@sskinner.dialup.cloud9.net>

I'm looking for a simple example of a Perl script that takes a folder path
as an argument and iterates through every nested file and folder in that
path, all the way down.

I don't need a complete program, just the minimum necessary to illustrate
the basic recursive concepts.

All help is appreciated.

-S


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

Date: 27 Oct 1999 23:45:24 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Recursive file/folder indexing
Message-Id: <slrn81f3kj.f28.sholden@pgrad.cs.usyd.edu.au>

On Wed, 27 Oct 1999 19:10:51 -0400,
	Scott Edward Skinner <sskinner@cloud9.net> wrote:
>I'm looking for a simple example of a Perl script that takes a folder path
>as an argument and iterates through every nested file and folder in that
>path, all the way down.
>
>I don't need a complete program, just the minimum necessary to illustrate
>the basic recursive concepts.
>
>All help is appreciated.

Here's a complete program that doesn't do much except print everything out:

perl -lMFile::Find -e'find(sub{print},$ARGV[0])' <insert directory path here>

I suggest you look at the File::Find code if you want to see the basic
concepts (though it does the advanced things as well... checking for
symlinks, etc).


-- 
Sam

If your language is flexible and forgiving enough, you can prototype
your belief system without too many core dumps.
	--Larry Wall


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

Date: 25 Oct 1999 15:12:53 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Reference challenge
Message-Id: <slrn819edc.fji.abigail@alexandra.delanet.com>

Bart Lateur (bart.lateur@skynet.be) wrote on MMCCXLVI September MCMXCIII
in <URL:news:3814fa70.1003205@news.skynet.be>:
() Larry Rosler wrote:
() 
() >One example is the *fact* that 
() >the value of a Boolean expression in arithmetic context is 1 or 0 (as in 
() >C).  Yet every time I suggest this, I am told that 'it might change 1n 
() >the future'.
() 
() grep() in a scalar context might be considered as a boolean. Any true
() values? Yes. It even tells you how many.
() 
() I think it's a pity that index(), in that sense, doesn't return a
() boolean value.


I find the return value of index more useful than a potential boolean
value would be. And going from the current return value to a boolean
is easy - the other way wouldn't be.



Abigail
-- 
sub f{sprintf$_[0],$_[1],$_[2]}print f('%c%s',74,f('%c%s',117,f('%c%s',115,f(
'%c%s',116,f('%c%s',32,f('%c%s',97,f('%c%s',0x6e,f('%c%s',111,f('%c%s',116,f(
'%c%s',104,f('%c%s',0x65,f('%c%s',114,f('%c%s',32,f('%c%s',80,f('%c%s',101,f(
'%c%s',114,f('%c%s',0x6c,f('%c%s',32,f('%c%s',0x48,f('%c%s',97,f('%c%s',99,f(
'%c%s',107,f('%c%s',101,f('%c%s',114,f('%c%s',10,)))))))))))))))))))))))))


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: 25 Oct 1999 15:20:54 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Reference challenge
Message-Id: <slrn819esc.fji.abigail@alexandra.delanet.com>

Tramm Hudson (hudson@swcp.com) wrote on MMCCXLVI September MCMXCIII in
<URL:news:7v1t0j$gtc@llama.swcp.com>:
-- Abigail <abigail@delanet.com> wrote:
--
-- The mathematicians are already up in arms against the use of the
-- prefix ! to mean negation instead of the product of 1*2*3*..*n.
-- Since the standard recursive code written by students is to
-- compute the factorial, they point to incredible amount of code
-- reuse that would be possible if the language had a built in !
-- operator that did the right thing.


Strange. I guess the mathematicians are at least 25 years to late.
Furthermore, ! is used as a prefix operator, while the use of ! as
a factorial is a postfix operator.

Suppose we had ! as a postfix operator; could one find a Perl statement
with an ambigious use of !?


I strongly doubt the usefulness of a build in factorial operator though.
There are only a handful of integers whose factorial gives a 32bit (or
for that matter, a 64bit) result.



Abigail
-- 
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: 25 Oct 1999 09:29:23 -0600
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: Reference challenge
Message-Id: <7v1t0j$gtc@llama.swcp.com>

[posted and cc'd to cited author for humor value only]

Abigail <abigail@delanet.com> wrote:
> Rick Delaney (rick.delaney@home.com) wrote on MMCCXLVI September MCMXCIII
> in <URL:news:3813E285.A11F59E1@home.com>:
> `` 
> `` Do you have any other examples where depending on values of 1 and 0
> `` would be useful?  Watch that they're not too gimmicky, now.
> 
> 
>    $b = f () + g () * h ();
> 
> instead of:
> 
>    $b = f () + (g () ? h () : 0);

Expect that the first always evaluates both g() and h().  So
while the result in $b is likely to be the same, h() may have
side effects that are unwanted.

[snip]
> In fact, all that would be needed is that '!' would return either 1
> or 0. Then !!(expression) would always be 1 or 0.

The mathematicians are already up in arms against the use of the
prefix ! to mean negation instead of the product of 1*2*3*..*n.
Since the standard recursive code written by students is to
compute the factorial, they point to incredible amount of code
reuse that would be possible if the language had a built in !
operator that did the right thing.

Tramm
[snip the rest]
-- 
  o   hudson@swcp.com                 tbhudso@cs.sandia.gov   O___|   
 /|\  http://www.swcp.com/~hudson/          H 505.323.38.81   /\  \_  
 <<   KC5RNF @ N5YYF.NM.AMPR.ORG            W 505.284.24.32   \ \/\_\  
  0                                                            U \_  | 


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

Date: 25 Oct 1999 03:06:40 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Reference challenge
Message-Id: <slrn8183ro.fji.abigail@alexandra.delanet.com>

Rick Delaney (rick.delaney@home.com) wrote on MMCCXLVI September MCMXCIII
in <URL:news:3813E285.A11F59E1@home.com>:
`` 
`` Do you have any other examples where depending on values of 1 and 0
`` would be useful?  Watch that they're not too gimmicky, now.


   $b = f () + g () * h ();

instead of:

   $b = f () + (g () ? h () : 0);

or:

   $b = f (); $b += h () if g ();


In fact, all that would be needed is that '!' would return either 1
or 0. Then !!(expression) would always be 1 or 0.

But the description of '!' in perlop is horrible. All it says is that
it performs ``logical negation'', whatever that is. It then points to
'not', which is descriped as doing a ``logical negation'', pointing
back to '!'.


Abigail
-- 
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 1195
**************************************


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