[30099] in Perl-Users-Digest
Perl-Users Digest, Issue: 1342 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 8 00:09:40 2008
Date: Fri, 7 Mar 2008 21:09:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 7 Mar 2008 Volume: 11 Number: 1342
Today's topics:
Re: a better code by foreach? <veatchla@yahoo.com>
Re: Crypt::CBC vs individual cipher module differs? <wgumgfy@gmail.com>
Re: FAQ 5.1 How do I flush/unbuffer an output filehandl <ben@morrow.me.uk>
Re: Perl, Apache and Certificates am500803@gmail.com
Re: Question on regex cyrusgreats@gmail.com
Re: Question on regex <noreply@gunnar.cc>
Re: Question on regex <m@rtij.nl.invlalid>
Re: Question on regex cyrusgreats@gmail.com
Re: Question on regex <szrRE@szromanMO.comVE>
Re: Question on regex <szrRE@szromanMO.comVE>
Re: Question on regex <szrRE@szromanMO.comVE>
Re: Question on regex <ben@morrow.me.uk>
Re: sample client server socket issue <ben@morrow.me.uk>
sort <todd@zoomcart.com>
Re: sort <ben@morrow.me.uk>
Re: sort <uri@stemsystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 07 Mar 2008 21:52:38 -0600
From: l v <veatchla@yahoo.com>
Subject: Re: a better code by foreach?
Message-Id: <13t43c75dguh63a@news.supernews.com>
Rose wrote:
> Is it possible for me to use "foreach" to make the following codes in a
> better way? I don't want to create subroutine and call. Because I can't use
> @%arr this time (%arr1 not equal to %arr[1]). Copying the %arr1, %arr2, ...,
> %arrn into a single large array is impractical, because %arr1, ...n is
> already very large each.
>
>
> while (($loc, $sub) = each(%arr1)) {
> print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
> }
>
> while (($loc, $sub) = each(%arr2)) {
> print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
> }
>
> ...
>
> while (($loc, $sub) = each(%arrn)) {
> print "$loc\tSub\t$sub\t$notes[0]\t$start\t$end\n";
> }
>
>
Can you explain why and how you are populating %arr1 - %arrn? There may
be a better way to populate %aarX which will make the while { print }
simpler.
--
Len
------------------------------
Date: Fri, 7 Mar 2008 17:12:34 -0800
From: "Waylen Gumbal" <wgumgfy@gmail.com>
Subject: Re: Crypt::CBC vs individual cipher module differs?
Message-Id: <63e7g5F27iah1U1@mid.individual.net>
Mark Pryor wrote:
> On Sun, 02 Mar 2008 16:01:42 -0800, Waylen Gumbal wrote:
>
>> I noticed that if I use a "CBC compatible" crypt module directly, I
>> get a normal expected result. But if I use CBC with the same cipher
>> type on the same key and plaintext I get a completely different
>> result.
>>
>> I've been up and down the perldoc for Crypt::CBC and just can't
>> figure out why the results differ so much. Because they differ so
>> much you can't use one method to decrypt the other.
>>
>> For example:
>>
>> use Crypt::CBC;
>> use Crypt::OpenSSL::AES;
>>
>> $key = 'secretpassphrase';
>> $text = 'Crypt Test #0001';
>>
>> my $en1 = new Crypt::OpenSSL::AES($key)->encrypt($text);
>>
>> my $en2 = new Crypt::CBC(
>> -key => $key, -cipher => 'Crypt::OpenSSL::AES'
>> )->encrypt($text);
>>
>> my $en1h = unpack('H*', $en1);
>> my $en2h = unpack('H*', $en2);
>>
>> print "OpenSSL AES\n[$en1h]\n\n";
>> print "AES via CBC\n[$en2h]\n\n";
>>
>>
>> __OUTPUT__
>> OpenSSL AES
>> [e1f461cdc00f4855b9b2c0367cd3a293]
>>
>> AES via CBC
>>
> [53616c7465645f5f36dd0b8d9b84e278382b8cd329f7020b545c3595c239284d37d4e3dc2d6a2fc97d375675b793b357]
>>
>
> Waylen,
>
> try -literal_key => 1,
>
> that way you prevent CBC from hashing your key. I don't have the info
> at hand, but I remember that for AES
>
> blocklength = 128
> and keysize is much longer than the 16 bytes from MD5 (used by CBC).
>
> Further your key length should be controlled, not simply some string.
> You can control by hashing outside of CBC and inline of your code.
Thank you for replying.
I added -literal_key => 1 and I got the error:
"Cannot use salt-based key generation if literal key is specified"
I went back to perldoc and so added -header => 'none' and now I get:
"You must provide an initialization vector using -iv when
using -header=>'none'"
I'm assuming I am going the right direction in using -header => 'none'
but if so, I'm not sure how to apply -iv so I get the same result I
would from the cipher class directly.
Thanks again.
--
WG
------------------------------
Date: Sat, 8 Mar 2008 04:00:11 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 5.1 How do I flush/unbuffer an output filehandle? Why must I do this?
Message-Id: <bjf9a5-o01.ln1@osiris.mauzo.dyndns.org>
Quoth PerlFAQ Server <brian@stonehenge.com>:
>
> 5.1: How do I flush/unbuffer an output filehandle? Why must I do this?
>
>
> Perl does not support truly unbuffered output (except insofar as you can
> "syswrite(OUT, $char, 1)"), although it does support is "command
> buffering", in which a physical write is performed after every output
> command.
>
> The C standard I/O library (stdio) normally buffers characters sent to
> devices so that there isn't a system call for each byte. In most stdio
> implementations, the type of output buffering and the size of the buffer
> varies according to the type of device. Perl's "print()" and "write()"
> functions normally buffer output, while "syswrite()" bypasses buffering
> all together.
Is it worth mentioning
binmode $HANDLE, ':unix';
somewhere here, which will make all prints equivalent to syswrites?
Ben
------------------------------
Date: Fri, 7 Mar 2008 16:58:24 -0800 (PST)
From: am500803@gmail.com
Subject: Re: Perl, Apache and Certificates
Message-Id: <431e2738-49e1-4906-805a-7b57a762acfd@n36g2000hse.googlegroups.com>
On Mar 5, 12:07=A0am, smallpond <smallp...@juno.com> wrote:
> On Mar 4, 5:05 pm, am500...@gmail.com wrote:
>
> > Hi !
>
> > I am using Apache2 with self-signed certificates. I also made client
> > certificates and everything is cool.
> > Of course, i am also using mod_ssl.
> > But somehow I cannot get DN of the certificate into perl CGI code. It
> > ought to be in an SSL... environment variables, but its not. If I set
> > SSLOptions in apache config to FakeAuth, I can see full certificate
> > description in access file, but yet not in a perl script. Do i need to
> > 'use' some special library ?
> > No direct documentation provided nowwhere, so any hint is appreciable.
>
> In http.conf you should have:
> SSLVerifyClient require =A0(or 2)
> SSLOptions +StdEnvVars
>
> In the CGI check
> =A0 $ENV{'SSL_CLIENT_DN'}
Thx. I didnt have +StdEnvVars :)
------------------------------
Date: Fri, 7 Mar 2008 15:31:09 -0800 (PST)
From: cyrusgreats@gmail.com
Subject: Re: Question on regex
Message-Id: <1c478167-fc0e-4b99-9ed5-a30500feb4b2@e6g2000prf.googlegroups.com>
> You still don't get it. Your original code did match these lines. You say
> it did not work. That does not add up. We're not clairvoyant here, so we
> cannot determine what the problem really is. Post a small _but_complete_
> program that shows your problem.
>
> F.i.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> while (my $line = <DATA>) {
> next if $line =~ /^\s0.0/; # skip 0.0
> print $line, "\n";
>
> }
>
> __DATA__
> 0.0 19968 admin /bin/bash -l
> 1.0 20037 admin /bin/bash -l
> 0.2 20085 admin /bin/bash -l
> 0.0 20363 admin /bin/bash -l
>
> This outputs:
>
> 1.0 20037 admin /bin/bash -l
>
> 0.2 20085 admin /bin/bash -l
>
> Which is exactly what I would expect. (Hint, you're missing a chomp
> somewhere).
>
> HTH,
> M4
Well, let's start over again:
from Linux if I send following command I get the following output:
[root@MyWorld]#ps -eo pcpu,pid,user,args
%CPU PID USER COMMAND
0.0 19968 admin /bin/bash -l
1.0 20037 admin /bin/bash -l
0.2 20085 admin /bin/bash -l
0.0 20363 admin /bin/bash -l
My script below supposed to match lines that are not 0.0 such as as
0.2 & 1.0.
#!/usr/bin/perl
use strict;
use warnings;
my $cmd = "ps -eo pcpu,pid,user,args";
my @output = `$cmd`;
foreach my $line (@output) {
next if $line =~ /^\s0.0/; # skip 0.0
print $line, "\n";
}
The out put I'm getting from the above code is:
%CPU PID USER COMMAND
0.0 19968 admin /bin/bash -l
1.0 20037 admin /bin/bash -l
0.2 20085 admin /bin/bash -l
0.0 20363 admin /bin/bash -l
I used the while loop as Martijn Lievaart suggested above but I don't
get any output at all!
Thanks in advance guys and be patient with me it's Friday..
------------------------------
Date: Sat, 08 Mar 2008 01:04:15 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Question on regex
Message-Id: <63e3kkF277t2fU1@mid.individual.net>
cyrusgreats@gmail.com wrote:
> from Linux if I send following command I get the following output:
> [root@MyWorld]#ps -eo pcpu,pid,user,args
> %CPU PID USER COMMAND
> 0.0 19968 admin /bin/bash -l
> 1.0 20037 admin /bin/bash -l
> 0.2 20085 admin /bin/bash -l
> 0.0 20363 admin /bin/bash -l
>
> My script below supposed to match lines that are not 0.0 such as as
> 0.2 & 1.0.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> my $cmd = "ps -eo pcpu,pid,user,args";
> my @output = `$cmd`;
>
> foreach my $line (@output) {
> next if $line =~ /^\s0.0/; # skip 0.0
> print $line, "\n";
> }
>
> The out put I'm getting from the above code is:
> %CPU PID USER COMMAND
> 0.0 19968 admin /bin/bash -l
> 1.0 20037 admin /bin/bash -l
> 0.2 20085 admin /bin/bash -l
> 0.0 20363 admin /bin/bash -l
I for one am not able to reproduce that result. For me, the script
filters lines with '0.0' as expected.
Of course, adding the * quantifier to the whitespace is advisable, and
you also want to escape the dot
next if $line =~ /^\s*0\.0/;
-------------------------^-^
or else it matches any character. Furthermore, since you don't chomp the
output, printing of the extra "\n" is redundant.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 8 Mar 2008 01:15:16 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Question on regex
Message-Id: <pan.2008.03.08.00.15.16@rtij.nl.invlalid>
On Fri, 07 Mar 2008 15:31:09 -0800, cyrusgreats wrote:
>> You still don't get it. Your original code did match these lines. You
>> say it did not work. That does not add up. We're not clairvoyant here,
>> so we cannot determine what the problem really is. Post a small
>> _but_complete_ program that shows your problem.
>>
>> F.i.
>>
>> #!/usr/bin/perl
>>
>> use strict;
>> use warnings;
>>
>> while (my $line = <DATA>) {
>> next if $line =~ /^\s0.0/; # skip 0.0 print $line, "\n";
>>
>> }
>>
>> __DATA__
>> 0.0 19968 admin /bin/bash -l
>> 1.0 20037 admin /bin/bash -l
>> 0.2 20085 admin /bin/bash -l
>> 0.0 20363 admin /bin/bash -l
>>
>> This outputs:
>>
>> 1.0 20037 admin /bin/bash -l
>>
>> 0.2 20085 admin /bin/bash -l
>>
>> Which is exactly what I would expect. (Hint, you're missing a chomp
>> somewhere).
>>
>> HTH,
>> M4
>
>
> Well, let's start over again:
>
>
> from Linux if I send following command I get the following output:
> [root@MyWorld]#ps -eo pcpu,pid,user,args %CPU PID USER COMMAND
> 0.0 19968 admin /bin/bash -l
> 1.0 20037 admin /bin/bash -l
> 0.2 20085 admin /bin/bash -l
> 0.0 20363 admin /bin/bash -l
>
> My script below supposed to match lines that are not 0.0 such as as 0.2
> & 1.0.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> my $cmd = "ps -eo pcpu,pid,user,args"; my @output = `$cmd`;
>
> foreach my $line (@output) {
> next if $line =~ /^\s0.0/; # skip 0.0 print $line, "\n";
> }
>
>
> The out put I'm getting from the above code is: %CPU PID USER
> COMMAND
> 0.0 19968 admin /bin/bash -l
> 1.0 20037 admin /bin/bash -l
> 0.2 20085 admin /bin/bash -l
> 0.0 20363 admin /bin/bash -l
I get completely different output (also on Linux):
%CPU PID USER COMMAND
6.3 3104 root X :0 -auth /home/martijn/.serverauth.3087
0.1 3256 martijn /usr/libexec/clock-applet --oaf-activate-
iid=OAFIID:GNOME_ClockApplet_Factory --oaf-ior-fd=19
0.7 3257 martijn /usr/libexec/multiload-applet-2 --oaf-activate-
iid=OAFIID:GNOME_MultiLoadApplet_Factory --oaf-ior-fd=25
0.1 3294 martijn gnome-terminal
0.1 5913 martijn ssh dexter
3.1 13381 martijn ./client/civclient
0.4 13623 martijn /usr/lib/ICAClient/wfica -display :0.0 -icaroot /usr/
lib/ICAClient -nosplash -desc Sanquin Desktop -startSCD 1204932778777
1.0 13719 martijn ps -eo pcpu,pid,user,args
4.8 18872 martijn /usr/lib64/firefox-2.0.0.10/firefox-bin http://
www.thinkgeek.com/geektoys/warfare/a1f7/?cpg=68T
1.7 20170 martijn gtk-gnutella
0.1 26130 martijn /usr/lib64/thunderbird-2.0.0.9/thunderbird-bin
0.1 27625 martijn ./server/civserver -r options.serv
Are you sure this is the program you use? My output is completely what I
expect it to be. All lines with 0.0 are surpressed and there is still an
extra \n due to the missing chomp.
Something is not adding up here, and my guess is that both your program
and your output are not what you are posting here. Or there is something
else, but I'm completely at a loss what that could be.
HTH,
M4
------------------------------
Date: Fri, 7 Mar 2008 17:04:19 -0800 (PST)
From: cyrusgreats@gmail.com
Subject: Re: Question on regex
Message-Id: <1ba4eb93-f4ef-42b5-95f4-57d17fe5216e@h11g2000prf.googlegroups.com>
>
> Something is not adding up here, and my guess is that both your program
> and your output are not what you are posting here. Or there is something
> else, but I'm completely at a loss what that could be.
>
> HTH,
> M4
found the problem, I print out @output and found that it is not an
array, I add the following and seems works fine now..
my $output = '$cmd';
my @stack = split /\n/, $output;
Thanks all of you guys and have great weekend and stay cool ;-)
------------------------------
Date: Fri, 7 Mar 2008 17:22:15 -0800
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Question on regex
Message-Id: <fqspo802dmh@news2.newsguy.com>
Martijn Lievaart wrote:
> On Fri, 07 Mar 2008 14:19:49 -0800, cyrusgreats wrote:
>
>> ok, how about this, what if and only if I want to match anything but
>> not
>> 0.0, since the above doesn't work..if the string as follows, I'm
>> interested in 0.2 not 0.0.
>> space 0.0 somewords
>> space 0.2 somewords
>
> You still don't get it. Your original code did match these lines. You
> say it did not work. That does not add up. We're not clairvoyant
> here, so we cannot determine what the problem really is. Post a small
> _but_complete_ program that shows your problem.
>
> F.i.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> while (my $line = <DATA>) {
Maybe make this:
while (chomp(my $line = <DATA>)) {
That will eat the trailing new line.
> next if $line =~ /^\s0.0/; # skip 0.0
Make that:
next if $line =~ /^\s0\.0/;
(note the \. which matches a literal period/decimal point :-) )
--
szr
------------------------------
Date: Fri, 7 Mar 2008 17:26:46 -0800
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Question on regex
Message-Id: <fqsq0n02e09@news2.newsguy.com>
cyrusgreats@gmail.com wrote:
>> You still don't get it. Your original code did match these lines.
>> You say it did not work. That does not add up. We're not clairvoyant
>> here, so we cannot determine what the problem really is. Post a
>> small _but_complete_ program that shows your problem.
>>
>> F.i.
>>
>> #!/usr/bin/perl
>>
>> use strict;
>> use warnings;
>>
>> while (my $line = <DATA>) {
>> next if $line =~ /^\s0.0/; # skip 0.0
>> print $line, "\n";
>>
>> }
>>
>> __DATA__
>> 0.0 19968 admin /bin/bash -l
>> 1.0 20037 admin /bin/bash -l
>> 0.2 20085 admin /bin/bash -l
>> 0.0 20363 admin /bin/bash -l
>>
>> This outputs:
>>
>> 1.0 20037 admin /bin/bash -l
>>
>> 0.2 20085 admin /bin/bash -l
>>
>> Which is exactly what I would expect. (Hint, you're missing a chomp
>> somewhere).
>>
>> HTH,
>> M4
>
>
> Well, let's start over again:
>
>
> from Linux if I send following command I get the following output:
> [root@MyWorld]#ps -eo pcpu,pid,user,args
> %CPU PID USER COMMAND
> 0.0 19968 admin /bin/bash -l
> 1.0 20037 admin /bin/bash -l
> 0.2 20085 admin /bin/bash -l
> 0.0 20363 admin /bin/bash -l
>
> My script below supposed to match lines that are not 0.0 such as as
> 0.2 & 1.0.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> my $cmd = "ps -eo pcpu,pid,user,args";
> my @output = `$cmd`;
>
> foreach my $line (@output) {
> next if $line =~ /^\s0.0/; # skip 0.0
> print $line, "\n";
> }
>
>
> The out put I'm getting from the above code is:
> %CPU PID USER COMMAND
> 0.0 19968 admin /bin/bash -l
> 1.0 20037 admin /bin/bash -l
> 0.2 20085 admin /bin/bash -l
> 0.0 20363 admin /bin/bash -l
>
> I used the while loop as Martijn Lievaart suggested above but I don't
> get any output at all!
> Thanks in advance guys and be patient with me it's Friday..
What you're trying to do can more easily be accomplished with this one
liner:
ps -eo pcpu,pid,user,args | egrep -v '^ 0.0'
Enjoy :-)
--
szr
------------------------------
Date: Fri, 7 Mar 2008 17:31:54 -0800
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Question on regex
Message-Id: <fqsqab02ea8@news2.newsguy.com>
patrick wrote:
>> my $cmd = "ps -eo pcpu,pid,user,args";
>
> On AIX I get two leading spaces before the 0.0
> On RHL I get only one space.
>
> You can always change to ps -eo pcpu,pid,user,args | grep -v '^ 0.0'
>
> ====>Patrick
Or: ps -eo pcpu,pid,user,args | egrep -v '^ *0.0'
Which allows for a variable amount of leading spaces (or none at all.)
--
szr
------------------------------
Date: Sat, 8 Mar 2008 03:56:46 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Question on regex
Message-Id: <ucf9a5-o01.ln1@osiris.mauzo.dyndns.org>
Quoth cyrusgreats@gmail.com:
>
> >
> > Something is not adding up here, and my guess is that both your program
> > and your output are not what you are posting here. Or there is something
> > else, but I'm completely at a loss what that could be.
> >
> > HTH,
> > M4
>
> found the problem, I print out @output and found that it is not an
> array, I add the following and seems works fine now..
>
> my $output = '$cmd';
You mean `` here. Please stop getting this wrong, or stop retyping code
and copy-paste it instead.
> my @stack = split /\n/, $output;
`` in list context splits the results on $/. If this doesn't appear to
be happening, then you must have set $/ to something funny earlier in
the script. This is why you are asked to post a complete script you have
actually run, rather than just fragments.
Ben
------------------------------
Date: Sat, 8 Mar 2008 00:17:18 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: sample client server socket issue
Message-Id: <eh29a5-qi03.ln1@osiris.mauzo.dyndns.org>
Quoth jm <jm@nospam.fr>:
>
> When debugging the code, I had replaced sysread, by recv and read methods.
>
> I moved back to the sysread, and it looks like working fine.
>
> However, I am not sure documentation clearly explain why $sock->send for
> sending, and why sysread for reading...
$sock->send with at most two arguments (plus $sock itself) ends up
calling send(2), which (under Unix, at any rate) is exactly equivalent
to write(2), which is what syswrite calls. $sock->send with three
arguments calls sendto(2), which is quite different; also, I believe
there are operating systems where send(2) and write(2) are different,
though I think perl deals with that for you if it needs to.
The same applies to recv/sysread. Perl's read, however, calls fread(3),
(or rather PerlIO's equivalent) which is buffered. Buffered reads do
behave exactly as you described: they will wait for ever (or until EOF,
or error) for a full buffer if the underlying file descriptor is in
blocking mode. So don't do that: stick to sysread or recv.
Alternatively, if you're using 5.8 you can push a :unix layer
binmode $sock, ':unix';
which will let you use <> and so on in unbuffered mode. It probably
isn't as efficient as doing your own buffering, but it's a lot more
convenient.
Ben
------------------------------
Date: Fri, 7 Mar 2008 19:03:28 -0800 (PST)
From: asgweb <todd@zoomcart.com>
Subject: sort
Message-Id: <68a2477c-bf42-4815-941a-9d5b4cec4169@u10g2000prn.googlegroups.com>
hello. i have code (below) that sorts the contents of a directory. it
works fine, but i need to show only files that start with an 'R'.
thanks in advance for your help.
opendir(STOCKBACKGROUND, ".") || &error("STOCKBACKGROUND");
@stockbackgrounds = readdir(STOCKBACKGROUND);
@stockbackgrounds = sort {lc($a) cmp lc($b)} @stockbackgrounds;
closedir(STOCKBACKGROUND);
------------------------------
Date: Sat, 8 Mar 2008 04:08:46 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: sort
Message-Id: <e3g9a5-o01.ln1@osiris.mauzo.dyndns.org>
Quoth asgweb <todd@zoomcart.com>:
> hello. i have code (below) that sorts the contents of a directory. it
> works fine, but i need to show only files that start with an 'R'.
> thanks in advance for your help.
perldoc -f grep
> opendir(STOCKBACKGROUND, ".") || &error("STOCKBACKGROUND");
Use lexical filehandles in non-ancient versions of Perl (since 5.6.0).
Don't call subs with & unless you need the special effects that causes.
Include the system error and what you were trying to do in the error
message.
I would recommend using 'or' instead of '||', as you can then drop the
parens. You may not like that style, though.
opendir my $STOCKBACKGROUND, "." or error "can't opendir '.': $!";
> @stockbackgrounds = readdir(STOCKBACKGROUND);
You should have
use strict;
at the top of your script; this line will the need to become
my @stockbackgrounds = readdir($STOCKBACKGROUND);
> @stockbackgrounds = sort {lc($a) cmp lc($b)} @stockbackgrounds;
> closedir(STOCKBACKGROUND);
I would do this all in one go, without the intermediate assignments;
also, if you use lexical filehandles they close themselves at the end of
the block they are in, so you can simply write
my @stockbackgrounds = do {
opendir my $D, '.' or error "can't opendir '.': $!";
sort { lc($a) cmp lc($b) }
grep /^R/, readdir $D;
};
You may find that too compressed, though.
Ben
------------------------------
Date: Sat, 08 Mar 2008 04:48:35 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: sort
Message-Id: <x7zlt9es7x.fsf@mail.sysarch.com>
>>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:
BM> my @stockbackgrounds = do {
BM> opendir my $D, '.' or error "can't opendir '.': $!";
BM> sort { lc($a) cmp lc($b) }
BM> grep /^R/, readdir $D;
BM> };
even though File::Slurp is a pretty popular module, it also has a lesser
known read_dir sub that cleans up that code a bit:
use File::Slurp ;
my @stockbackgrounds = sort { lc($a) cmp lc($b) } grep /^R/, read_dir '.';
one day i will add a filter option and it would look something like
this:
my @stockbackgrounds = sort { lc($a) cmp lc($b) } read_dir '.', qr/^R/;
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
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 V11 Issue 1342
***************************************