[26367] in Perl-Users-Digest
Perl-Users Digest, Issue: 8539 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 18 21:05:20 2005
Date: Tue, 18 Oct 2005 18:05:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 18 Oct 2005 Volume: 10 Number: 8539
Today's topics:
Re: idiom for managing passed arguments? <jgibson@mail.arc.nasa.gov>
Re: Perl Script Question - Working with Directories <someone@example.com>
Re: why the perl docs suck <Fred@fred.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 18 Oct 2005 16:12:23 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: idiom for managing passed arguments?
Message-Id: <181020051612239956%jgibson@mail.arc.nasa.gov>
In article <43552aa5$0$3764$39cecf19@news.twtelecom.net>, AC
<clarke@n_o_s_p_a_m_hyperformix.com> wrote:
> Greetings. I was wondering if there is an idiomatic way to handle passed
> arguments to a subroutine. The "wanted" example below is shows what I'd
> like, and the "works" example shows what I do right now...
>
> sub wanted
> {
> my ($arg1, @args2to9, $arg10) = @_;
> ...
> }
>
> sub works
> {
> my ($arg1, @args2to9) = @_;
> my $arg10 = splice(@args2to9, -1, 1);
> ...
> }
Perl being Perl, there are several idiomatic ways to pass arguments to
subroutines. Some have already been mentioned. Here are two others:
1. Make a copy of the entire list of arguments:
sub also_works
{
my @args = @_;
my $arg1 = $args[0];
my $arg10 = $args[9];
...
}
2. Use named arguments:
sub works_with_a_hash
{
my %args = @_;
my $arg1 = $args{arg1};
my $arg10 = $args{arg10};
...
}
which may be called as:
works_with_a_hash( arg10 => 10, arg1 => 1 );
or with any number of arguments in any order. This works well if many
of your arguments have default values if they are not included in the
subroutine call and you can leave them out of the call. In this case,
you can replace line 4 of works_with_a_hash with:
my $arg1 = $args{arg1} || 'default_for_arg_1';
etc.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Wed, 19 Oct 2005 00:20:38 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Perl Script Question - Working with Directories
Message-Id: <qjg5f.43125$ir4.36447@edtnps90>
Rich Barnes wrote:
> OK... This may seem like a dumb question, but I haven't figured out a way to
> do this yet...
>
> Given a directory, I want to be able to distinguish which entries are files
> and which are directories... Actually I only want to list the directories in
> my output.
>
> In a shell script I can easily accomplish this:
>
> *******************************
> #!/bin/sh
>
> cd /home/rbarnes
>
> ls > /tmp/workfile
>
> cat /tmp/workfile | \
> while read VAR
> do
>
>
> if [ -d $VAR ]
> then
> echo $VAR
> fi
> done
>
> rm /tmp/workfile
> ********************************************
>
> How can I accomplish the same task in PERL... basically, if I had the TEST
> command equiv in PERL I believe I could do this.
#!/usr/bin/perl
use warnings;
use strict;
my $dir = '/home/rbarnes';
opendir DIR, $dir or die "Cannot open $dir: $!";
while ( my $file = readdir DIR ) {
print "$dir/$file\n" if -d "$dir/$file";
}
__END__
Or perhaps:
#!/usr/bin/perl
use warnings;
use strict;
print map "$_\n", grep -d, </home/rbarnes/*>;
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 18 Oct 2005 18:18:53 -0500
From: "Fred@fred.net" <Fred@fred.net>
Subject: Re: why the perl docs suck
Message-Id: <fg0bl1lhs0aoh7n0nj4k8t3vsi1bprcmed@4ax.com>
On Wed, 12 Oct 2005 21:19:44 -0500, Tad McClellan
<tadmc@augustmail.com> wrote:
>Fred@fred.net <Fred@fred.net> wrote:
>
>> I was never welcome.
>
>
>Yes you were.
>
>Everybody is welcome here (until they do something socially unacceptable).
>
>
>So, what was it that you did that got people mad that first time?
Were it that it was only once.
Your good cop right?
I assert that people are not welcome here save for a set of procedures
desribing the most tortured sets of considerations that one might
never be able to ascertain for certain once and for all whether a
given message should be even composed much less posted.
So if ya call that welcome....
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 8539
***************************************