[17752] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5172 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 21 14:05:42 2000

Date: Thu, 21 Dec 2000 11:05:17 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977425516-v9-i5172@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 21 Dec 2000     Volume: 9 Number: 5172

Today's topics:
    Re: [OT] Re: switch/case in Perl? <garryknight@bigfoot.com>
        ANNOUNCE: Locale-Codes 1.04 <neilb@cre.canon.co.uk>
    Re: automatic FAQ answerer idea (Logan Shaw)
    Re: bug in open() (Brandon Metcalf)
    Re: bug in open() <joe+usenet@sunstarsys.com>
    Re: Death and Jeopardy <a.v.a@home.nl>
    Re: help! "Bad file number" error (Garry Williams)
        IP address -> Host name using Perl <garcia868@yahoo.com>
    Re: IP address -> Host name using Perl <flavell@mail.cern.ch>
    Re: IP address -> Host name using Perl nobull@mail.com
    Re: IP address -> Host name using Perl (Michael Fuhr)
    Re: Language evolution C->Perl->C++->Java->Python (Is P <jason@harlequin.com>
        matching the previous line ermichael@my-deja.com
    Re: numbers to strings <juex@deja.com>
    Re: ok (Tad McClellan)
    Re: perl DBI <a.v.a@home.nl>
    Re: Probelm with Hash and loop msalerno@my-deja.com
        Reading a Directory Listing into an Array <!spammed@aye.net!>
    Re: Reading a Directory Listing into an Array <Lauri.Palokangas@Nokia.REMOVETHIS.COM.invalid>
    Re: Reading a Directory Listing into an Array (Abigail)
    Re: Rename File in Win32 Environment brockmajor@my-deja.com
    Re: Reorder array via for (Tad McClellan)
    Re: Select(2) and Term::Readkey <dorsettest@uk.insight.com>
    Re: switch/case in Perl? (Tad McClellan)
    Re: switch/case in Perl? (Tad McClellan)
    Re: switch/case in Perl? <smerr612@mailandnews.com>
    Re: trying to count words - not working <aqumsieh@hyperchip.com>
    Re: Understanding interpolation <bart.lateur@skynet.be>
    Re: using vi from within perl <David.Hiskiyahu@alcatel.be>
    Re: very strange thing with closures (Randal L. Schwartz)
    Re: very strange thing with closures (Tad McClellan)
    Re: very strange thing with closures patrick_k6801@my-deja.com
    Re: very strange thing with closures <b_nospam_ill.kemp@wire2.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 21 Dec 2000 18:08:55 +0000
From: "Garry Knight" <garryknight@bigfoot.com>
Subject: Re: [OT] Re: switch/case in Perl?
Message-Id: <91tgvn$3qh$1@taliesin.netcom.net.uk>

In article <m3elz2kc51.fsf_-_@mumonkan.sunstarsys.com> "Joe Schaefer"
<joe+usenet@sunstarsys.com> wrote:

> Adam Levenstein <cleon42@my-deja.com> writes:
> 
>> I never understood why Richie put the "break" in there.
> 
> So you can combine cases "easily":
> 
> switch (letter) {
> 
>   case 'a': case 'e': case 'i': case 'o': case 'u':
>         #vowel
>         break;
> 
>   default:
>         #consonant
> }

Since "break" is associated with looping constructs, I always thought
K&R should have done it more like this:

switch (letter) {
  case 'a': case 'e': case 'i': case 'o': case 'u': {
    #vowel
  }    
  default: {
    #consonant
  }
}

-- 
Garry Knight
garryknight@bigfoot.com


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

Date: Thu, 21 Dec 2000 16:19:55 GMT
From: Neil Bowers <neilb@cre.canon.co.uk>
Subject: ANNOUNCE: Locale-Codes 1.04
Message-Id: <t44c4arumjavf4@corp.supernews.com>

An updated version of the Locale-Codes distribution is making
it's way round CPAN:

	modules/by-module/Locale/Locale-Codes-1.04.tar.gz

This distribution contains two modules which can be used to process
ISO two letter codes for identifying language and country.

    Locale::Language
	Two letter codes for language identification (ISO 639).
	For example, 'en' is the code for 'English'.

    Locale::Country
	Two letter codes for country identification (ISO 3166).
	For example, 'bo' is the code for 'Bolivia'.

Changes in this version are:
    *	tweaks to language and country names to match relevant stds
    *	fixes to documentation

Neil




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

Date: 21 Dec 2000 11:21:04 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: automatic FAQ answerer idea
Message-Id: <91te60$iuh$1@boomer.cs.utexas.edu>

In article <slrn943tq7.4tk.tadmc@magna.metronet.com>,
Tad McClellan <tadmc@metronet.com> wrote:
>When Joe Gimme-Gimme gets pissed at the newsgroup, he starts
>making response-triggering postings just to watch the
>machine spew stuff...

But the response machine is written in Perl and uses these
magic things called "associative arrays" to keep track of Joe
Gimme-Gimme's last posting.  If he has posted in the last N
seconds (where N is something like 86400), then it doesn't
respond to him or it sends the response only to his e-mail.

Also, the robot limits itself to M postings per day as a failsafe.

I'm perfectly happy if the prevailing opinion is that people don't
want an FAQ robot, but I'm not too happy when people say "we don't
want an FAQ robot because of <problem with trivial solution>".  I
don't mean to be a pain, but that is what is happening so far.

  - Logan


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

Date: 21 Dec 2000 17:31:10 GMT
From: bmetcalf@nortelnetworks.com (Brandon Metcalf)
Subject: Re: bug in open()
Message-Id: <91teou$l29$1@bcarh8ab.ca.nortel.com>

joe+usenet@sunstarsys.com writes:

 > >  open() seems to have been broken in Perl 5.005_3 as well as the latest
 > >  ActivePerl.  In Perl 5.6.0 on solaris open() behaves as it should.
 > >   
 > >  Can anyone confirm this?
 > >  
 > >  $ cat ~/tmp/jj
 > >  open (DD, "lls|") || die "bad command: $!";
 > 
 > I think the bug is in 5.6 - try this line instead:
 > 
 > open(DD, "sleep 1 && lls |") || die "bad fork: $!";

Okay.  I get the same behavior from Perl 5.005_03 and Perl 5.6.0 which
is

$ perl -e 'open(DD, "sleep 1 && lls |") || die "bad fork: $!"'     
$ sh: lls: not found

So, die() is not being called and /bin/sh can't find lls.  I'm not sure
how to interpret this as 5.6.0 having a bug.

Thanks,
Brandon



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

Date: 21 Dec 2000 13:09:12 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: bug in open()
Message-Id: <m3r931hcjb.fsf@mumonkan.sunstarsys.com>

bmetcalf@nortelnetworks.com (Brandon Metcalf) writes:

> joe+usenet@sunstarsys.com writes:
> 
>  > >  open() seems to have been broken in Perl 5.005_3 as well as the latest
>  > >  ActivePerl.  In Perl 5.6.0 on solaris open() behaves as it should.
>  > >   
>  > >  Can anyone confirm this?
>  > >  
>  > >  $ cat ~/tmp/jj
>  > >  open (DD, "lls|") || die "bad command: $!";
>  > 
>  > I think the bug is in 5.6 - try this line instead:
>  > 
>  > open(DD, "sleep 1 && lls |") || die "bad fork: $!";
> 
> Okay.  I get the same behavior from Perl 5.005_03 and Perl 5.6.0 which
> is
> 
> $ perl -e 'open(DD, "sleep 1 && lls |") || die "bad fork: $!"'     
> $ sh: lls: not found
> 
> So, die() is not being called and /bin/sh can't find lls.  I'm not sure
> how to interpret this as 5.6.0 having a bug.

IMHO, it's because the 5.6 behavior is unpredictable.  The 
documentation I posted earlier says that open should succeed 
on a successful fork, and fail if the fork fails.  Here, and in
your original post, fork is succeeding, but exec(lls) is failing.  
In 5.6, something funny is happening that passes the exec failure
back to open, but I don't know enough about it to say any more.  
Someone else will have to take this up with you.

Best.
-- 
Joe Schaefer



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

Date: Thu, 21 Dec 2000 17:23:42 GMT
From: AvA <a.v.a@home.nl>
Subject: Re: Death and Jeopardy
Message-Id: <3A423CC9.75FC5C77@home.nl>

Tom Christiansen wrote:

> +------------------------------------------------------------------+
> | The short point is this: if you post crap, you will be killfiled |
> | at best, and excoriated at worst.  Cut it the frick out.  I will |
> | reinstate the cron job until the idiot-flups quit their crap.    |
> +------------------------------------------------------------------+
>
> EXECUTIVE SUMMARY:
>     To send better messages, please trim and summarize what you're
>     replying to, and integrate your quoted text with the body of your
>     message. Don't just put everything at the end.  This isn't Jeopardy.
>     People expect question-and-answer, not answer-and-question responses.
>

Thanks for the advice, not everybody is custom with policies in the
newsgroups.

If you permit me one comment: this newsgroup acts as a huge source of
knowledge for
alot of novices (like me) for whom reading the man pages seem difficult.
Not everyone has the ability to be a master in computerscience, but still
like to play
with perl on a lower level.
That sometimes gives stupid questions for the guru's im sure.
So be patient with us please.




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

Date: Thu, 21 Dec 2000 16:15:12 GMT
From: garry@zweb.zvolve.net (Garry Williams)
Subject: Re: help! "Bad file number" error
Message-Id: <k0q06.624$Kk5.34051@eagle.america.net>

On Thu, 21 Dec 2000 05:06:32 GMT, genie <djodrell00@home.com> wrote:
>Can anyone tell me why this doesn't work?
>
>I am trying to write a sinple client server app.  When I run this code
>in linux, everything works as it should.  When I run it in windows, I
>get a "Bad file number" error.  This code is right out of the O'reilly,
>"Advanced Perl Programming" book.
>
>Windows is running perl ver. 5.004_02, linux has perl ver. 5.6.0

[snip]

>use IO::Socket;
>$sock = new IO::Socket::INET (
>	PeerHost => 'localhost',
>	PeerPort => 2345,
>	Proto => 'tcp'
>);
>die "Socket could not be created. Reason: $!\n" unless $sock;
>
>print $sock "Msg $_: How are you?\n";
>close($sock);

The code works for me (although it doesn't use strict and the $_
variable is never initialized in the client): 

    d:/garry $ perl -v

    This is perl, v5.6.0 built for MSWin32-x86-multi-thread
    (with 1 registered patch, see perl -V for more detail)

    Copyright 1987-2000, Larry Wall

    Binary build 620 provided by ActiveState Tool Corp. htt

I think you need to upgrade.  

-- 
Garry Williams


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

Date: Thu, 21 Dec 2000 10:14:17 -0800 (PST)
From: J Garcia <garcia868@yahoo.com>
Subject: IP address -> Host name using Perl
Message-Id: <20001221181417.17871.qmail@web1602.mail.yahoo.com>

I use gethostbyaddr() to get host names for IP
addresses and it works well in most but not all cases.
Is there any other/better way in Perl to automatically
query host names where gethostbyaddr fails? Thanks for
helping out.

__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/


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

Date: Thu, 21 Dec 2000 19:31:42 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: IP address -> Host name using Perl
Message-Id: <Pine.LNX.4.30.0012211925040.9156-100000@lxplus003.cern.ch>

On Thu, 21 Dec 2000, J Garcia wrote:

> I use gethostbyaddr() to get host names for IP
> addresses and it works well in most but not all cases.

Let's see some concrete examples where you're having a problem.

We'll have to assume you're familiar with the documentation that's
given by perldoc -f gethostbyaddr , or equivalent.

> Is there any other/better way in Perl to automatically
> query host names where gethostbyaddr fails?

Whatever they were, they'd be querying the same underlying network
machinery.  I don't see why the Perl part should be the problem, but
there are plenty of other reasons (address not in DNS, network
timeout, whatever) that would result in the same problem - no matter
what syntactic sugar you put on top.

When you're encountering a problem, it really does help you to help
yourself if you'd show us the specific code you're using (including
the code which tests that the result was successful), and the specific
problem case(s) that you're having trouble with.  Vague hand-waving
stuff about "doesn't work in some cases" guarantees you a low-value
answer from the start.

Be sure to copy/paste that code, don't retype it.



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

Date: 21 Dec 2000 18:28:48 +0000
From: nobull@mail.com
Subject: Re: IP address -> Host name using Perl
Message-Id: <u93dfhzl0f.fsf@wcl-l.bham.ac.uk>

J Garcia <garcia868@yahoo.com> writes:

> I use gethostbyaddr() to get host names for IP
> addresses and it works well in most but not all cases.
> Is there any other/better way in Perl to automatically
> query host names where gethostbyaddr fails?

No.  

This really has nothing to do with Perl.

If there exists no rDNS entry for the host it doesn't matter what
language or tool you are using you won't be able to find one.

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


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

Date: 21 Dec 2000 11:54:08 -0700
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: IP address -> Host name using Perl
Message-Id: <91tjkg$qb8@flatland.dimensional.com>

J Garcia <garcia868@yahoo.com> writes:

> I use gethostbyaddr() to get host names for IP
> addresses and it works well in most but not all cases.
> Is there any other/better way in Perl to automatically
> query host names where gethostbyaddr fails? Thanks for
> helping out.

Are you sure the failure is gethostbyaddr's fault?  Perhaps the IP
address doesn't resolve (i.e., it doesn't have a PTR record in DNS)
or a remote nameserver is unreachable or misconfigured.  How is
gethostbyaddr failing?  Is it returning undef or an empty list?
Is it taking a long time before it returns?  How are you determining
that something else might work when gethostbyaddr fails?

You could try Net::DNS, but it's intended for low-level DNS tasks, not
for simple lookups.  You can use it for that, but it'll probably be
slow.  It also requires knowledge of how DNS works and the structure of
a DNS packet.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


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

Date: Thu, 21 Dec 2000 16:56:27 +0000
From: Jason Trenouth <jason@harlequin.com>
Subject: Re: Language evolution C->Perl->C++->Java->Python (Is Python the ULTIMATE oflanguages??)
Message-Id: <k9d44tsk04h46ijb6c2t5maf55aaabe5ar@4ax.com>

On Thu, 21 Dec 2000 15:09:17 GMT, mexicanmeatballs@my-deja.com wrote:

> Not quite, inaccurate yes, but there are object wrappers for the
> primitives in java..

I think that is stretching the word "inaccurate" too far given the discussion.
:-j

__Jason


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

Date: Thu, 21 Dec 2000 18:13:21 GMT
From: ermichael@my-deja.com
Subject: matching the previous line
Message-Id: <91th7q$h25$1@nnrp1.deja.com>

The statement:

if (/start/ .. /finish/)

will match from the first line containing the string 'start' to a line
containing finish inclusively.  How do I match from the line
containing 'start' to the line *immediately preceeding* the one that
contains 'finish'?

Thank you

Eric Smith


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 21 Dec 2000 09:46:47 -0800
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: numbers to strings
Message-Id: <3a424221@news.microsoft.com>

"bentman" <bentmon@my-deja.com> wrote in message
news:91b71c$9ac$1@nnrp1.deja.com...
> what function would I use to convert a number to a string?

Your question is essentially meaningless because there is neither a datatype
"number" nor "string" in Perl.
The datatype is called "scalar" and it will behave as a number or as a
string depending on the context it is being used in.

jue




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

Date: Thu, 21 Dec 2000 10:16:36 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: ok
Message-Id: <slrn9447mk.536.tadmc@magna.metronet.com>

Michael Carman <mjcarman@home.com> wrote:
>AP wrote:
>> 
>> just refer me to the document/resource instead of 
>> going out and doing it for me

>Heh. If only more of the newcomers to this group felt that way.
>Unfortunately, most of them seem to get downright indignant when someone
>refers them to the docs instead of giving them an answer directly. It's
>nice to see that someone wants to learn to fish. Welcome to clpmisc,
>you'll do fine here. :)


Here is an opportunity to point out that negative scores are
not the only scores assigned to individuals.

Just as folks who want others to do their work for them are scored
down, folks that actually want to learn Perl can be scored up.

AP's post got him scored _up_, a rare thing indeed.


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


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

Date: Thu, 21 Dec 2000 16:45:29 GMT
From: AvA <a.v.a@home.nl>
Subject: Re: perl DBI
Message-Id: <3A42340C.472A317F@home.nl>

"Randal L. Schwartz" wrote:

> >>>>> "AvA" == AvA  <a.v.a@home.nl> writes:
>
> AvA> pff that makes an easy readible language like perl very hard to
> AvA> understand.  i prefer to use as little as modules as possible for
> AvA> learning purposes.  have to get it to work raw first.
>

there was a "thank you " following that

>
> So you started with assembler, or perhaps wirewrapping your own boards?
>
> pff to you too.
>
> :(
>
> If you want to be hireable, learn the modules first.  Then delve into
> them to figure out why they do what they do.  *Then* write your own,
> only after understanding why the module author did everything they did.
>
> Just another member of the "don't needlessly reinvent the wheel" committee,
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



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

Date: Thu, 21 Dec 2000 17:42:50 GMT
From: msalerno@my-deja.com
Subject: Re: Probelm with Hash and loop
Message-Id: <91tfeo$feg$1@nnrp1.deja.com>

In article <u9hf3yzwco.fsf@wcl-l.bham.ac.uk>,
  nobull@mail.com wrote:
> msalerno@my-deja.com writes:
>
> > I am having problems creating a hash
>
> I can never understand why this mistake comes up so often - typically
> at least every other week or so.
>
> %hash = ( $key => $value );
>
> This assigns a value to %hash.  In general, assigning a value to a
> variable destroys any previous value.  It replaces the whole of %hash
> with a hash containing only a single entry.
>
> $hash{$key} = $value;
>
> This updates a single entry in %hash without effecting other
> entries.
>
> Of course if, as in your program, the keys of the hash are consecutive
> integers starting at zero one has to ask why you used a hash rather
> than an array.
>
> I'll now go on to point out other mistakes:
>
> > #!/usr/bin/perl -w
> > use strict;
>
> Very good so far.
>
> > use vars qw( $cnt $search %pwlist $o );
>
> Do you have a good reason for declaring each those as package
> variables rather than lexicals in their respective minimal enclosing
> scopes?
>
> > $search = "oot";
>
> Some people would criticise you for using " where ' would do.  I won't
:-)
>
> > open(PASSWD, "</etc/passwd") || die "ERROR: Cannot open\n";
>
> You forgot to include $! in the error message.
>
> > my @pwq = <PASSWD>;
> > $cnt = 0;
> > for (my $i = 0; $i < @pwq; $i++)
>
> Not very Perlish! One would usually say:
>
> for my $i ( 0 .. $#pwq )
>
> Or, since I doubt you really need $i:
>
> for (@pwq)
>
> Or even
>
> while (<PASSWD>)
>
> > {
> >
> > if (lc($pwq[$i]) =~ /\Q$search/ ){
>
> Rather than lc() the string why not /i the pattern?  Of course if
> you've taken the above advice the variable will be $_ so the =~
> binding clause can be ommited.
>
>  if ( /\Q$search/i ){
>
> Or maybe:
>
>  if ( index(lc,$search) >= 0 ) {
>
> >         my($user, $pword, $uid, $gid, $comment, $home, $shell) =
> > split(/:/, $pwq[$i]);
>
> Again, if you use $_ as the variable it can be ommitted.
>
> You only need to specify variable on the LHS if you intend to use it:
>
>         my ($user, undef, undef, undef, $comment ) =  split /:/;
>
> Or
>         my ($user, $comment) =  (split /:/)[0,4];
>
> >         %pwlist = ("$cnt" => ["$user", "$comment"]);
>
> You meant:
>
>      $pwlist{$cnt} = [ $user, $comment];
>
> Note I've removed the redundant "" from all your variables.
>
> Of course since $cnt is just an integer you'd be better off with an
> array than with a hash:
>
>      $pwlist[$cnt] = [ $user, $comment];
>
> And since $cnt is always one more than the last subscript it would be
> even more Perlish to say:
>
>      push @pwlist => [ $user, $comment];
>
> (The use of => rather than comma in push is my personal taste.)
>
> >         $o = $i;
>
> I have no idea why you did that.  Perhaps you did need $i after all.
>
> >         print "$cnt\t$user\t$comment\n";
> >         print "Catalog # $cnt\tUser: $user\tComments: $comment\n";
> >         $cnt++;
>
> Of course using a simple array there's no need to keep a sepatate
> $cnt variable, you can simply use scalar(@pwlist).
>
>          print "Catalog # " . scalar(@pwlist). "\tUser:
$user\tComments: $comment\n";
>
> Or, prehaps less readably:
>
>          print "Catalog # ${\scalar @pwlist}\tUser: $user\tComments:
$comment\n";
>
> > if ($cnt >= 1){
> > print "HERE\n";
> > print $pwlist{1}[0];
>
> Huh?  I think you meant 0 not 1 there since $cnt started at 0.
>
> >         }
>
> --
>      \\   ( )
>   .  _\\__[oo
>  .__/  \\ /\@
>  .  l___\\
>   # ll  l\\
>  ###LL  LL\\
>
Wow !  Those were some of the best replies that I have ever gotten.
After reading all of those posts I realized how convoluted my script
was.  It has been almost completely rewritten, and I used bits and
pieces of everyone's advice.  Almost everything works fine.

I need to have each entry numbered.  The thing is that I will not be the
only one using the script and I want to make it as fool proof as
possible.  So rather than having the user enter a username, they will
enter a name to search for and then the script produces a list of
matches, and each match will have a number.  The user will then enter
the corresponding number rather than the username.  The UID's are not
unique in this passwd file.  I know that I can number them with a loop
that increments a var, but I was looking at something like keys %pwlist.
Below is the updated script.  I am not sure what is the best way to
attach a unique numerical record to the current hash.
$pwlist{$cnt} = [$user,$comment];
I had problems finding the correct syntax to print out the above hash.

Thanks for all the help,

Matt

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

open(PASSWD, "</etc/passwd2") || die "ERROR: Cannot open $!\n";

my $search = "ern";
my %pwlist;
my $cnt = 0;

while (<PASSWD>) {
        my($user, $comment) = (split /:/)[0,4];    # An array slice
        if (lc($user) =~ /\Q$search/ or lc($comment) =~ /\Q$search/ ) {
                        $pwlist{$user} = $comment;
                        $cnt++;
                        }
                }
my $count = keys %pwlist;

if ($count < 1){
        print "No Users found with current search criteria -
\"$search\"\n";
        }

print "User: $_\tComment: $pwlist{$_}\n" foreach sort keys %pwlist;
print $count;


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 21 Dec 2000 12:45:23 -0500
From: "Some_Indiana_Guy" <!spammed@aye.net!>
Subject: Reading a Directory Listing into an Array
Message-Id: <t44gefl45kjp53@corp.supernews.com>

Does anyone know a simple function to read a directory listing into an
array?
(using FreeBSD)





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

Date: Thu, 21 Dec 2000 17:58:38 GMT
From: Lauri Palokangas <Lauri.Palokangas@Nokia.REMOVETHIS.COM.invalid>
Subject: Re: Reading a Directory Listing into an Array
Message-Id: <3A4252D3.5FD153B0@Nokia.REMOVETHIS.COM.invalid>

Some_Indiana_Guy wrote:

> Does anyone know a simple function to read a directory listing into an
> array?

I don't know the easier way than:
--- CLIP ---
 my ($path,@filelist);
 $path="/path/to/dir";
 opendir(PATH,$path) or die "Can't open dir: $!\n";
 @filelist=readdir(PATH);
 closedir PATH;
--- CLIP ---

If you wan't to do processing for each element, you may consider reading
the directory entries in scalar context:
--- CLIP ---
 my ($path,$filename,@filelist);
 $path="/path/to/dir";
 opendir(PATH,$path) or die "Can't open dir: $!\n";
 while (defined($filename=readdir(PATH))) {
  push @filelist, $filename if (!(-d $path."/".$filename));
 }
 closedir PATH;
--- CLIP ---

> (using FreeBSD)
I don't think this will change the situation in any way (if we live in
unixland).

-- 
Lapa
Lauri Palokangas Osakk FI
040-552-9679


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

Date: 21 Dec 2000 18:07:40 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Reading a Directory Listing into an Array
Message-Id: <slrn944hnc.ed9.abigail@tsathoggua.rlyeh.net>

Lauri Palokangas (Lauri.Palokangas@Nokia.REMOVETHIS.COM.invalid) wrote on
MMDCLXIX September MCMXCIII in <URL:news:3A4252D3.5FD153B0@Nokia.REMOVETHIS.COM.invalid>:
`` Some_Indiana_Guy wrote:
`` 
`` > Does anyone know a simple function to read a directory listing into an
`` > array?
`` 
`` I don't know the easier way than:
`` --- CLIP ---
``  my ($path,@filelist);
``  $path="/path/to/dir";
``  opendir(PATH,$path) or die "Can't open dir: $!\n";
``  @filelist=readdir(PATH);
``  closedir PATH;
`` --- CLIP ---


Much simpler:

    @list = `ls`;  # or `ls -a`;



Abigail
-- 
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
                                      print } sub __PACKAGE__ { &
                                      print (     __PACKAGE__)} &
                                                  __PACKAGE__
                                            (                )


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

Date: Thu, 21 Dec 2000 18:02:44 GMT
From: brockmajor@my-deja.com
Subject: Re: Rename File in Win32 Environment
Message-Id: <91tgjv$gg7$1@nnrp1.deja.com>

In article <91r84u$gl5$1@hermes.nz.eds.com>,
  "Peter Sundstrom" <peter.sundstrom@eds.com>
wrote:
>
> Mike Mesarch <me@me.com> wrote in message
> news:91r485$8es$1@sshuraab-i-
1.production.compuserve.com...
> > rename($file, $newfile);
> >
> > This doesn't work in a win32 environment.
Does anyone have any other
> > recommendations?
>
> perldoc File::Copy
>
>

I did this with:
use File::Copy;
 ...
move("foo.txt", $filname) or die print FILE "No
file to rename  $filname : $!\n";

Brock Major


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 21 Dec 2000 10:19:12 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Reorder array via for
Message-Id: <slrn9447rg.536.tadmc@magna.metronet.com>

[ Jeopardectomy performed ]

Mark Kuin <mkuin@globalrangers.com> wrote:
>
>
>"Drew Myers" <bh_ent@my-deja.com> wrote in message
>news:91t653$6u9$1@nnrp1.deja.com...

>> my $x = @name;
>> --$x;
>> my $c;
>> for ($c = 0; $c = $x; $c++) {


>You might want to try $c <= $x instead of $c = $x.........


Or, better yet, eliminate the temporary variable altogether:

   for ($c = 0; $c < @name; $c++) {


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


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

Date: Thu, 21 Dec 2000 16:23:48 +0000
From: Kelly Dorset <dorsettest@uk.insight.com>
Subject: Re: Select(2) and Term::Readkey
Message-Id: <3A422E94.66F89A20@uk.insight.com>

delanthear@my-deja.com wrote:
> 
> Is it possible to use both the Term::Readkey and use Select(2) at the
> same time?
> 
> Check this example:
> 
> LISTENER is one half of a paidsocket to child process.  Basically the
> idea is to while loop until either there is some waiting on <LISTENER>
> or a key has been pressed.  I can't get them to both work as the same
> time.

<snipped from code segment>
>     $nfound = select($rout=$rin, undef, undef, 0);
</snip>

I've played with this and increased the timeout time (from 0) and am
getting different, but still not ideal results.

Does anyone have any suggestions as to a better way of getting the
effect I'd like?

k
--


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

Date: Thu, 21 Dec 2000 09:59:18 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: switch/case in Perl?
Message-Id: <slrn9446m6.536.tadmc@magna.metronet.com>

Adam Levenstein <cleon42@my-deja.com> wrote:
>In article <91svoh$1pe$1@nnrp1.deja.com>,
>  trwww <trwww@my-deja.com> wrote:
>
>> Lets say you wrote documentation. Lets even say you were getting paid
>> for it. How would you feel if you spent months, or even years, writing
>> documentation and then the day after you give it to your customer they
>> call you and say, "How do I turn this thing on?" Then tomorrow, they
>> call you back and ask the exact same thing? How would you feel?
>
>Difference: I didn't call him. I didn't email him. My posting wasn't
>directed at him. 


Right. It was directed at hundreds/thousands of people!

And that makes asking an already-answered question "better"
in some way?

We can see that your time is hundreds/thousands of times
more important than our time. That explains why it is
OK for us to look things up for you.


You seem to be striving with some diligence for that last
score point.

Congratulations! You got it. The very first to reach that
lauded level without using vulgarity.


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


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

Date: Thu, 21 Dec 2000 09:42:12 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: switch/case in Perl?
Message-Id: <slrn9445m4.536.tadmc@magna.metronet.com>

Alan J. Flavell <flavell@mail.cern.ch> wrote:
>On Wed, 20 Dec 2000, Adam Levenstein wrote:
>
>(to tchrist@perl.com , of all people...)
>
>> But gee, then we'd miss your oh-so-polite, well-mannered responses. In
>> fact, putting in a killfilter would undoubtedly take less time than
>> making such a polite response every time someone asks a fairly simple
>> question.
>
>Your application for entry to the killfile has been enthusiastically
>approved.


Now the count is at least three killfile entries.

And that is only the publicly announced ones. There are likely
at least that many silent ones.

You are now in at least a half dozen killfiles of the 
newsgroup regulars.  These are people who have proven a
willingness to answer people's questions, exactly the
kind of people that you would want to read your future
postings. They will not be doing that.


See any "diminishing" yet?


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


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

Date: Thu, 21 Dec 2000 18:06:56 GMT
From: Steven Merritt <smerr612@mailandnews.com>
Subject: Re: switch/case in Perl?
Message-Id: <91tgrp$grb$1@nnrp1.deja.com>

In article <91t1ph$3aq$1@nnrp1.deja.com>,
  Adam Levenstein <cleon42@my-deja.com> wrote:
> In article <91svoh$1pe$1@nnrp1.deja.com>,
>   trwww <trwww@my-deja.com> wrote:

> > You are even using deja... right below the post button is a button
to
> > search every posting for the last 5 years. Do you not think ayone
else
> > has asked this question?
>
> You're absolutely right, and I apologize for not doing so. It seems
that
> someone asked this question back in June, and he went without
> Christiansen throwing a hissy fit.

Tom took a hiatus from the NG(if you'll search for postings from him
during that period you probably won't find _any_, rude or otherwise).
I'm willing to venture the reason was floods of people asking him to
teach them Perl without reading the docs for themselves.  Either a Deja
search, perldoc -q or lurking in the group for a while would have given
you the information you needed.  All of these are considered "first
steps" when you run into either a programming problem or a new
newsgroup.  Skipping these steps and asking others to do your research
is considered rude and is a good way to get ostracised.

> Now, with that over with, I'm going to spend my time doing more
> intellectually profitable things than talking about politeness on a ng

Like reading Docs?  Good idea.  Like continuing this flamewar?  Bad
Idea.

> such as putting my hand in a meat grinder.

Mmmm, Cocktail weenie.

Steven
--
King of Casual Play
The One and Only Defender of Cards That Blow


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 21 Dec 2000 16:07:04 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: trying to count words - not working
Message-Id: <7an1dpep1y.fsf@merlin.hyperchip.com>


trwww <trwww@my-deja.com> writes:

> $body = 'you go <left> and you go ';
> $body .= '<left> but you go <left> and you go <left>';
> 
> for ($body =~ m/<left>/g) {
>        $leftcnt++;
> }
> 
> print($leftcnt);
> 
> works dandy for me......
> I would probably do it like this though:
> 
> $leftcnt = ($body =~ s/<left>/<left>/g);
> 
> in scalar context, s/ returns how many times the replacement was made.

Yes, but it does some unnecessary substitutions, which is a bit
slow. Why not just:

	$leftcnt = () = $body =~ /<left>/g;

--Ala


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

Date: Thu, 21 Dec 2000 17:32:34 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Understanding interpolation
Message-Id: <1ve44tg13uq3k0vetto1nughovmpold2f8@4ax.com>

John Lin wrote:

>I saw this string interpolation and tried to understand it.
>
>my $row = 1;
>print <<EOF;
>    <TD BGCOLOR = "${\($row%2? 'Green': 'Yellow')}">
>EOF
>
>__END__
>    <TD BGCOLOR = "Green">
>
>Hmm...  What does it do?

Note that this trick has a brother:

  print <<EOF;
    <TD BGCOLOR = "@{[$row%2? 'Green': 'Yellow']}">
  EOF

Maybe you get this better? No? Well, the basis is the same: the stuff
between braces, the "block", gets executed. You only need to be abble to
use the value. Two ways:

	${SCALARREF}		# dereferences a reference to a scalar
	@{ARRAYREF}		# dereferences a reference to an array

So we need to create a reference to a scalar or to an array,
respectively. Here's one way to create an array reference:

	[ STUFF ]	# anonymous array -> array reference

So how can you get a reference to a scalar? By using a backslash:

	\$stuff		# reference to variable $stuff
	\"foo"		# reference to string "foo"
	\1		# reference to number 1
	\(EXPR)		# reference to whatever EXPR returns

If you combine all this info, first creating a reference and then
dereferencing it, then you get what you're trying to understand: a way
to execute code inside a doublequotish string.

Note that stuff between array indexing brackets, and hash indixing
braces, gets executed too. For example:

    @number = qw(zero one two three fout five);
    print "$number[1] plus $number[2] is $number[1+2]\n";
    %greek = ( A => 'alpha', B => 'beta');
    print "$greek{$letter = 'A'} is followed by $greek{++$letter}\n";
-->
	one plus two is three
	alpha is followed by beta

-- 
	Bart.


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

Date: Thu, 21 Dec 2000 18:20:06 +0100
From: David Hiskiyahu <David.Hiskiyahu@alcatel.be>
Subject: Re: using vi from within perl
Message-Id: <3A423BC6.B9881D71@alcatel.be>

Thanks a lot, now it is clear to me how these I/O 
pipes are plugged into each other in the two cases.

Carl Wu wrote:
> 
> There are fundamental differences between these two commands:
> 1. $status = `vi $filename`;
> 2. $status = system("vi $filename");
> 
> In the first command, the $status will get the standard output of the
> command "vi $filename". And the vi process will get the standard input (your
> keyboard) from its parent process ("perl"), but its standard output has been
> redirected to some system area to be assigned to $status variable of your
> program. So you can type any command to the vi process but you won't see
> anything from vi until you quit vi, after that if you print $status from
> perl program you will see what you should have seen with a normal vi.
> 
> In the second command, the $status will get the exit status of the command
> "vi $filename". And the vi process will inherite both standard input (your
> keyboard) and standart output (your monitor) from its parent process
> ("perl"), the vi works fine. And the $status will be an integer which is the
> exit status of vi, completely different with the first case.
> 
> Hope this helps.
> 
> Carl Wu
> 
> David Hiskiyahu wrote in message <3A40F8F2.D57D2DCD@alcatel.be>...
> >...
> >> > I know that this is not good practice but though that I would be able
> >> > to do the following:
> >> >
> >> >    $status = `vi $filename`  ;
> >> >
> >> > However, this seems to put me in vi mode, but the screen stays as it
> >> > is until I exit vi, I cannot see the file contents.
> >...
> >
> >mike_solomon@lineone.net wrote:
> >>
> >> try:
> >>
> >> system("vi filename");
> >>
> >> this will open the file to edit
> >>
> >> when you exit vi it will return you to the script
> >>
> >...
> >
> >Mike, any clue why 'system' works ok here while the backticks fails?
> >
> >I wonder if there is some written info on the difference between the two,
> >which most of time behave just the same.
> >
> >I can guess that 'system' causes the perl parent process to fork a child
> >process and wait for it to exit, while backticks probably runs the system
> >command under the same process, which must mess up the i/o, which must be
> >the reason for backticks failing to show the vi window.
> >
> >'%man perlfunc' in the section of 'system' does clearly say that 'system'
> >forks a child and waits, but I couldn't find a clear description of how
> >backticks work ...

-- 
***   David Hiskiyahu, Alcatel SRD, 1 Fr.Wellesplein,  Antwerp  ***
***    Phone/Fax: +32 3 240 7965/9820, private +32 3 290 0912   ***

Quote of the day:

"He doesn't know the meaning of the word 'fear'. 
 Of course, there are lots of other words he
 doesn't know either."

- San Diego Chargers coach Sid Gilman on one of his first year players.


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

Date: 21 Dec 2000 08:13:09 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: very strange thing with closures
Message-Id: <m1g0jhwy5m.fsf@halfdome.holdit.com>

>>>>> "patrick" == patrick k6801 <patrick_k6801@my-deja.com> writes:

patrick> Hi, James !
patrick> Perl should establish closure variables that are packed with the two
patrick> subs. As sub this_is_fucking demonstrates, the variable
patrick> fucking_variable is existing in two independent instances after the for-
patrick> loop in this_is_fucking. (one for each sub in fucking_list). The
patrick> closures are produced in the line

patrick> push @fucking_list , sub { print $fucking_variable; };

patrick> What i simply do not understand is: Why does this work correctly in the
patrick> second sub but not in the first one ?

Ignoring the fact that you sound like a sailor (and that will offend
even some of my ex-navy friends)...

In the first one, your variable doesn't go out of scope between creating
the first and second coderef, so they both share the SAME variable.

Remember, a closure is not closed until its variables go out of scope.

Consider the difference between these:

    { my $x;

      @a = (\$x);
      @b = (\$x);
    }

and

  { my $y; @c = (\$y) }
  { my $y; @d = (\$y) }

In @a and @b, we share the same reference to $x, so it's the same var,
and changes in one are really changes in the other.  In @c and @d,
we have two different $y variables, so the references are different.

Closures are nothing more than a coderef holding a reference to an
item so that it stays around even if it would otherwise be destroyed.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 21 Dec 2000 10:03:12 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: very strange thing with closures
Message-Id: <slrn9446tg.536.tadmc@magna.metronet.com>

Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>On Thu, 21 Dec 2000 12:25:26 GMT,
>	patrick_k6801@my-deja.com <patrick_k6801@my-deja.com> wrote:

>> I am desperately
>
>*sigh* I just don't know why I thought it would be a good idea to clean
>up my score file, and let my-deja through again. 3/4 of the irritating
>posts today came from there. Time to fix that again, and to all my-deja
>users who are not idiots: get a decent newsreader and news provider.


That is too weird. I just did the same thing 20 minutes ago.

I put hotmail back in too.


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


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

Date: Thu, 21 Dec 2000 16:47:54 GMT
From: patrick_k6801@my-deja.com
Subject: Re: very strange thing with closures
Message-Id: <91tc7m$cko$1@nnrp1.deja.com>


> Ignoring the fact that you sound like a sailor (and that will offend
> even some of my ex-navy friends)...

Well english is a foreign language to me - or do you talk about
that "fucking_"-prefix/postfix ?

> Closures are nothing more than a coderef holding a reference to an
> item so that it stays around even if it would otherwise be destroyed.

If that is true: why does sub "this_is_fucking" work in the expected
way. There is exactly one itaration variable. Or does perl put it into
an inner scope and instantate and destroy it each iteration ?

Ahoi,
  Patrick



Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 21 Dec 2000 17:50:30 -0000
From: "W K" <b_nospam_ill.kemp@wire2.com>
Subject: Re: very strange thing with closures
Message-Id: <977421072.3011.0.nnrp-13.c3ad6974@news.demon.co.uk>


>> Ignoring the fact that you sound like a sailor (and that will offend
>> even some of my ex-navy friends)...
>
>Well english is a foreign language to me - or do you talk about
>that "fucking_"-prefix/postfix ?


Yes, it is far more offensive than many other naughty words.

Perhaps instead of perl golf or modules to write perl in latin, perhaps we
should have gratuitously bad language perl?
However, SQL is better in this regard, tempting you from the start in MySQL
with the good old 'insert into users .....'




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

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


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