[18105] in Perl-Users-Digest
Perl-Users Digest, Issue: 265 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 10 09:06:09 2001
Date: Sat, 10 Feb 2001 06:05:09 -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: <981813909-v10-i265@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 10 Feb 2001 Volume: 10 Number: 265
Today's topics:
Re: Best Way To Split & Initialize egwong@netcom.com
Re: chown not allowed (Chris Fedde)
Re: chown not allowed (Abigail)
Re: chown not allowed <bart.lateur@skynet.be>
Re: chown not allowed (Martien Verbruggen)
exec and shell meta characters <karra@burn.cs.utah.edu>
Flash SWF Files: How to find width and height <founder@pege.org>
glob versus readdir <jonni@ifm.liu.se>
Re: How to map (undef,undef) to (), but (undef,$y) to ( <joe+usenet@sunstarsys.com>
Re: insertion sort algorithm egwong@netcom.com
Re: insertion sort algorithm <johngros.NOSPAM@bigpond.net.au>
Re: insertion sort algorithm <johngros.NOSPAM@bigpond.net.au>
Re: insertion sort algorithm <johngros.NOSPAM@bigpond.net.au>
Re: Newbie's Stuck <krahnj@acm.org>
Re: Problem with regex and if/else expression <krahnj@acm.org>
Re: reposting a form <yuval@mypad.com>
Re: Start Batch-File .bat with Perl (Windows2000/IIS) <johngros.NOSPAM@bigpond.net.au>
Test if is a directory in DirHandle <lxq79@hotmail.com>
Re: Test if is a directory in DirHandle <kstep@pepsdesign.com>
Re: Test if is a directory in DirHandle <kstep@pepsdesign.com>
Re: Test if is a directory in DirHandle <lxq79@hotmail.com>
use pack() to uuencode long strings? <dshafer@mail.utexas.edu>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 09 Feb 2001 23:38:26 GMT
From: egwong@netcom.com
Subject: Re: Best Way To Split & Initialize
Message-Id: <Sb%g6.2192$y03.207135@news.flash.net>
redinger@maine.rr.com wrote:
> I'm wondering if there are any shortcuts that people use to split and
> initialize a list of values from a file at the same time?
> An example follows. My concern is, if one of the fields in the input
> file is empty, split will return undef. I'm wondering if there's a
> shortcut to changing that to '' without going through each field:
> $fld1 ||= ''; $fld2 ||= '', etc.
Dunno if it'll save you anything other than keystrokes, but you can
interposition a map in front of your split.
my ($fld1, ...) = map { defined($_) ? $_ : '' } split( ... );
------------------------------
Date: Sat, 10 Feb 2001 05:40:16 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: chown not allowed
Message-Id: <4v4h6.7$zN2.170610176@news.frii.net>
In article <7g398ts1ftgpaigghbuvabg663la1bd5nc@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>Forgive me if this is an off topic question.
>
>I have, on Un*x, a (read often, update now and then) file which I want
>to replace. In order not to spend too much time in locking a file when a
>script only want to read it, I use another way to update it: by writing
>to a new file, and then renaming that so it replaces the old file. The
>advantage is that programs that are currently reading the old file, can
>continue to do so, unhindered. So you never get to read an incomplete or
>currpted file. You just either get the old file, or the new one. (I
>assume that replacing a file by renaming another file to the same name,
>is atomic?).
>
>Of course, I still need some locking to make sure only one script
>updates the file at the same time.
>
>The problem is in the file permissions and the file ownership. This runs
>as a CGI script, so the owner of the new file is "www". Not me. It turns
>out that, if I don't watch out, the replacement file cannot be manually
>edited or removed by me, the owner of the web site. By chmod'ding the
>file so it's writable by anybody, I can take care of that.
>
>But I want the new file to have the same basic properties as the old
>file: same file permissions, and the same owner.
>
>How? Perlfunc says for chmod: "On most systems, you are not allowed to
>change the ownership of the file unless you're the superuser", which is
>precisely my problem. Is there a way around it?
>
>I'd prefer not to first make a copy of the old file, and overwrite the
>contents of the copy, and then renaming it to replace the old file.
>
I think I understand what you are looking for. This requires two files
with the right permissions but creates a small window when the file is not
available. Note that on unix file permissions are an attribute of their
inode. The file name maps to that inode. So we can do this with just a
little name juggling.
inode 1 is called 'visible'
inode 2 is called 'hidden'
At the start the system is reading from 'visible' at inode 1.
You cp your new stuff into 'hidden' then do this:
rename 'hidden', 'temp' # inode 2.
rename 'visible', 'hidden' # inode 1
rename 'temp', 'visible' # inode 2
Now you have the old 'visible' contents are 'hidden' and the new
'hidden' contents are 'visible'. You can flip flop this way for ever and
never change the permissions of 'visible' or 'hidden'.
The hole in this is between rename two and three. There is a tiny
window when there is no 'visible' file.
chris
--
This space intentionally left blank
------------------------------
Date: 10 Feb 2001 09:17:30 GMT
From: abigail@foad.org (Abigail)
Subject: Re: chown not allowed
Message-Id: <slrn98a1pa.r0f.abigail@tsathoggua.rlyeh.net>
Bart Lateur (bart.lateur@skynet.be) wrote on MMDCCXX September MCMXCIII
in <URL:news:7g398ts1ftgpaigghbuvabg663la1bd5nc@4ax.com>:
//
// How? Perlfunc says for chmod: "On most systems, you are not allowed to
// change the ownership of the file unless you're the superuser", which is
// precisely my problem. Is there a way around it?
No.
// I'd prefer not to first make a copy of the old file, and overwrite the
// contents of the copy, and then renaming it to replace the old file.
Make sure you never have to create a new file. Have two files, say,
'fnord' and 'frobnitz', and a symlink 'current'. Let current point
to one of the files. You reading processes read from 'current'.
Your writing program writes whatever file isn't pointed to by current.
If the writer is done, flip the symlink.
Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
|perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
|perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
|perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;
------------------------------
Date: Sat, 10 Feb 2001 11:24:00 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: chown not allowed
Message-Id: <s58a8t4v63ns0g4s9hs98ebmc0qq5kbm4q@4ax.com>
Abigail wrote:
>Make sure you never have to create a new file. Have two files, say,
>'fnord' and 'frobnitz', and a symlink 'current'. Let current point
>to one of the files. You reading processes read from 'current'.
>Your writing program writes whatever file isn't pointed to by current.
>If the writer is done, flip the symlink.
The problem is that you cannot create a symlink that already exists. So
you have to unlink it first. In that regard, the problem is similar to
Chris Fedde's solution.
A second problem they have in common, is that it may happen that two
consecutive updates come very fast, faster than one program needs to
finish to read and process the entire file. You'd end up writing over a
file that's still being read.
Oh, BTW: copying the file doesn't help, as it appears not to copy the
file permissions and file owner. Not with File::Copy, and not with `cp`.
--
Bart.
------------------------------
Date: Sun, 11 Feb 2001 00:36:50 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: chown not allowed
Message-Id: <slrn98agvi.vht.mgjv@martien.heliotrope.home>
On Sat, 10 Feb 2001 11:24:00 GMT,
Bart Lateur <bart.lateur@skynet.be> wrote:
> Abigail wrote:
>
>>Make sure you never have to create a new file. Have two files, say,
>>'fnord' and 'frobnitz', and a symlink 'current'. Let current point
>>to one of the files. You reading processes read from 'current'.
>>Your writing program writes whatever file isn't pointed to by current.
>>If the writer is done, flip the symlink.
>
> The problem is that you cannot create a symlink that already exists. So
> you have to unlink it first. In that regard, the problem is similar to
> Chris Fedde's solution.
>
> A second problem they have in common, is that it may happen that two
> consecutive updates come very fast, faster than one program needs to
> finish to read and process the entire file. You'd end up writing over a
> file that's still being read.
>
> Oh, BTW: copying the file doesn't help, as it appears not to copy the
> file permissions and file owner. Not with File::Copy, and not with `cp`.
Use two files for the content, a symlink (or hard link) for the access,
and another file as a semaphore. The writer work on the offline copy,
and grab a write lock on the semaphore file when they need to change the
link. Readers always grab a read lock on the semaphore. To prevent two
writers updating the offline copy, you could also grab a write lock on
that.
The logic to make sure that you never deadlock may be a bit more complex
than in other cases, but this would be a way to make it atomic.
Of course, if your OS supports it, you could also get another semaphore
lock, with one of the sem* functions. hat might be slightly faster.
Martien
--
Martien Verbruggen |
Interactive Media Division | I used to have a Heisenbergmobile.
Commercial Dynamics Pty. Ltd. | Every time I looked at the
NSW, Australia | speedometer, I got lost.
------------------------------
Date: 10 Feb 2001 03:34:50 -0700
From: Sriram Karra <karra@burn.cs.utah.edu>
Subject: exec and shell meta characters
Message-Id: <yz5d7cq6d2t.fsf@burn.cs.utah.edu>
Hi,
I have the following code that I use in a driver script:
sub do_1 {
$pid = fork();
if ($pid == 0) {
exec "./file < array.tan";
} else {
print "do_1(): pid of child = ", $pid, "\n";
wait();
print "Return value: ", ($? >> 8) " \n";
}
}
From what I read in the Camel book, the shell should be called in to
interpret the shell meta character '<'.
Running the above script on a SunOS and a Irix machine produces
differing behaviours. On the Irix, the "./file" gets the same pid as
$pid above, whereas on SunOS they are different.
So,
1. Is this to be expected?
2. When the shell is indeed brought into the picture, is there any
straight-forward way I can lay my hands on the return status info
of the "./file" process. (The shell syntax is so much easier to
write than opening pipes and such) in a standard way. This is
what I am really interested in - the $? that is returned by the
wait() function.
Oh, btw the builds are: 5.005_03 for sun4-solaris and 5.005_03 for
IP32-irix
thanks,
-Sriram.
------------------------------
Date: Sat, 10 Feb 2001 14:11:46 +0100
From: "Mösl Roland" <founder@pege.org>
Subject: Flash SWF Files: How to find width and height
Message-Id: <3a853de7$0$18098@SSP1NO25.highway.telekom.at>
I need to convert several 100 technical drwaings
from Corel Draw to Flash SWF files.
The next is to find out the height and width of
the SWF to find out is it portrait or landscape
to put it into the html code in an
<OBJECT
How to find in Perl the SFW parameters
--
Mösl Roland founder@pege.org
http://www.pege.org clear targets for a confused civilization
http://www.BeingFound.com web design starts at the search engine
------------------------------
Date: Sat, 10 Feb 2001 10:33:29 +0100
From: "Jonas Nilsson" <jonni@ifm.liu.se>
Subject: glob versus readdir
Message-Id: <9631ro$s21$1@newsy.ifm.liu.se>
I've run into a problem with perl on a webserver.
I use a construct like.
@files=glob('dir/filebase_*');
which returns an empty list. The readdir however works:
opendir(DIR,'dir');
while ($a=readdir(DIR)) {
next unless ($a=~m/filebase_/);
push(@files,'dir/'.$a);
}
Isn't glob function implemented on all builds of perl? I don't know the
version of perl running on this server.
(Both glob and readdir worked ok when I tried it on another webserver)
/jN
--
_____________________ _____________________
| Jonas Nilsson | | |
|Linkoping University | | Telephone |
| IFM | | --------- |
| Dept. of Chemistry | | work: +46-13-285690 |
| 581 83 Linkoping | | fax: +46-13-281399 |
| Sweden | | home: +46-13-130294 |
|_____________________| |_____________________|
------------------------------
Date: 10 Feb 2001 03:42:53 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: How to map (undef,undef) to (), but (undef,$y) to (undef,$y)?
Message-Id: <m3snlnlyia.fsf@mumonkan.sunstarsys.com>
"John Lin" <johnlin@chttl.com.tw> writes:
> sub foo {
> # some query here
> my($x,$y) = (undef,undef); # got undef results after query
> return map { if(defined) { s/^\s+//; s/\s+$// } $_ } ($x,$y);
> }
>
> if(my $found = my($x,$y) = foo) { print "found: $x,$y" }
> else { print "not found" }
I'm sorry; I don't understand what you expect this to do. Your
$found variable will always be the number of elements in the list
returned by foo (it's that "list assignment in a scalar context" mojo).
If you need to assign something to $y, you need at least two elements
in the list. The additional complexity you would add to foo to make
your if() statement work right isn't worth the trouble, IMHO.
Instead, you could try grepping on the definedness condition
after the foo assignments:
if ( my $found = grep { defined() } my ($x, $y) = foo ) { ...
Note that's quite ugly, and [cs]hould be broken across several lines
like
my ($x, $y) = foo;
my $found = grep {defined()} $x, $y;
if ($found) { ...
Perhaps that's what you want?
--
Joe Schaefer And today the great Yertle, that Marvelous he,
Is King of the Mud. That is all he can see.
-- Dr. Seuss
------------------------------
Date: Fri, 09 Feb 2001 23:29:50 GMT
From: egwong@netcom.com
Subject: Re: insertion sort algorithm
Message-Id: <O3%g6.2189$y03.207135@news.flash.net>
shogun415@my-deja.com wrote:
> I am a complete newbie learning algorithms to add to my arsenal of
> programming skills. I am using Introduction to Algorithms by Cormen,
> Leiserson and Rivest.
[ code snipped ]
Good book.
The problem is that, in perl, the index of the first element of an array
is 0, not 1. That means
for j <- 2 to length[A]
will translate to
for ( my $j=1; $j<scalar(@A); $j++) {
or, even better,
for ( my $j=$[+1; $j<=$#A; $j++ ) {
(note that the variable $[ is the first index of an array and $#A is the
last index.)
The while statement (line 5) also needs to be changed to reflect the
proper starting index.
HTH,
Eric
------------------------------
Date: Sat, 10 Feb 2001 13:01:16 GMT
From: "John Boy Walton" <johngros.NOSPAM@bigpond.net.au>
Subject: Re: insertion sort algorithm
Message-Id: <wYah6.11777$o85.59741@news-server.bigpond.net.au>
<shogun415@my-deja.com> wrote in message news:961rrl$qjm$1@nnrp1.deja.com...
> I am a complete newbie learning algorithms to add to my arsenal of
> programming skills. I am using Introduction to Algorithms by Cormen,
> Leiserson and Rivest.
>
> I am using PERL of course for the language.
>
> Here is my scenario, I have an @array of 20 integers ranging from 1-20,
> the algo works almost flawlessly EXCEPT that the number 5 is always the
> first number and the rest of the numbers fall into the correct order.
>
> I am enclosing the code, I would appreciate it if someone who knows
> algos could check my code and tell me where the error is in my version
> of the algo...
>
> p.s I know that I am not using strict...
>
> ##---------------------------------
> # code start
> ##---------------------------------
>
> #!/usr/bin/perl -w
>
> my @A = qw( 5 3 1 7 9 2 10 4 8 6 20 18 16 14 12 19 17 15 13 11);
>
> for( $j = 2; $j < scalar( @A ); $j++ ) {
Your problem is here you are checking the third item against the second and
then work your way to the end you never test the first element so the five
never will move.
Change it to for( $j = 1; $j < scalar( @A ); $j++ ) {
Arrays in perl run from subscript 0 so you were shooting a little high.
------------------------------
Date: Sat, 10 Feb 2001 13:11:08 GMT
From: "John Boy Walton" <johngros.NOSPAM@bigpond.net.au>
Subject: Re: insertion sort algorithm
Message-Id: <M5bh6.11795$o85.59905@news-server.bigpond.net.au>
"John Boy Walton" <johngros.NOSPAM@bigpond.net.au> wrote in message
news:wYah6.11777$o85.59741@news-server.bigpond.net.au...
> >
> > my @A = qw( 5 3 1 7 9 2 10 4 8 6 20 18 16 14 12 19 17 15 13 11);
> >
> > for( $j = 2; $j < scalar( @A ); $j++ ) {
> Your problem is here you are checking the third item against the second
and
> then work your way to the end you never test the first element so the five
> never will move.
> Change it to for( $j = 1; $j < scalar( @A ); $j++ ) {
> Arrays in perl run from subscript 0 so you were shooting a little high.
Crikey I'll have to look at this again in the morning, Steve is right and I
am wrong.
------------------------------
Date: Sat, 10 Feb 2001 13:15:09 GMT
From: "John Boy Walton" <johngros.NOSPAM@bigpond.net.au>
Subject: Re: insertion sort algorithm
Message-Id: <x9bh6.11801$o85.59977@news-server.bigpond.net.au>
"John Boy Walton" <johngros.NOSPAM@bigpond.net.au> wrote in message
news:M5bh6.11795$o85.59905@news-server.bigpond.net.au...
> > > my @A = qw( 5 3 1 7 9 2 10 4 8 6 20 18 16 14 12 19 17 15 13 11);
> > >
> > > for( $j = 2; $j < scalar( @A ); $j++ ) {
> > Your problem is here you are checking the third item against the second
> and
> > then work your way to the end you never test the first element so the
five
> > never will move.
> > Change it to for( $j = 1; $j < scalar( @A ); $j++ ) {
> > Arrays in perl run from subscript 0 so you were shooting a little high.
> Crikey I'll have to look at this again in the morning, Steve is right and
I
> am wrong.
Well we were both half right it needs both changes to run as you wish.
------------------------------
Date: Sat, 10 Feb 2001 06:02:12 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Newbie's Stuck
Message-Id: <3A84DA7C.4984805E@acm.org>
jlm wrote:
>
> How would I search for the presense of @ in a string?
> Assume an email addr. in variable $email - how do I test $email for an at
> sign.
if ( index $string, '@' >= 0 ) {
print "\@ found in $string\n";
}
John
------------------------------
Date: Sat, 10 Feb 2001 05:32:30 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Problem with regex and if/else expression
Message-Id: <3A84D386.D68502CB@acm.org>
LK wrote:
>
> I am trying to get the program below to search a file for a match with
> a regular expression. When it makes that match I want that line to be
> stored in the variable $ms. I though I had programed this properly,
> but I am wrong. When I run it this way, no matter what $num is, the
> "else" is executed and not the "if". If I take out the "else"
> portion, no matter what $num is the last line of the file is stored in
> $ms.
> I can't seem to get my head around this one. I am looking at it a
> certain way and am having trouble taking a different angle. If anyone
> could provide any help I would really appreciate it.
>
> $num = $FORM{'msnumber'};
> open(FILE, $file) || &dienice;
> while(<FILE>){
> if($_ !=~ /$num/){
> $ms = $_;
> }else{
> print "Content-type: text/html\n\n";
> print "<html><body>STUFF";
> print "</body></html>\n";
> exit;
> }
> }
> close(FILE);
my $ms;
my $num = $FORM{'msnumber'};
open( FILE, $file ) || &dienice;
while( <FILE> ) {
if( /\Q$num/ ) {
$ms = $_;
last;
}
}
close(FILE);
if ( $ms ) {
print "Content-type: text/html\n\n";
print "<html><body>STUFF";
print "</body></html>\n";
exit;
}
John
------------------------------
Date: Sat, 10 Feb 2001 12:56:16 GMT
From: Yuval <yuval@mypad.com>
Subject: Re: reposting a form
Message-Id: <963dpg$v13$1@nnrp1.deja.com>
> I don't think that was what the OP wanted; to me, it sounded like he
> wanted his form-processing script (which was invoked by a POST done
in the
> usual way) to pass some information on to a script on another site.
> Sounds to me like a simple matter of script A using LWP to make a
> connection to Site B and passing info to a script there. For some
reason,
> non-programmer Web developers seem to have a hard time envisioning
this sort of processing, and think in terms of repointing the browser,
often leading to an X-Y problem.
Eric, I must say you are right in every word. This is what i meant and
i'm an HTML writer.
Anyway after researching I found Win32::Internet. in it is two thing i
find usefull:
$http->Request([path, method, version, referer, accept, flags]);
$request->SendRequest("key1=value1&key2=value2&key3=value3");
For the meantime I can't get it to work yet. But just puting it here if
someone else wants to know...
--
Yuval
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sat, 10 Feb 2001 12:51:57 GMT
From: "John Boy Walton" <johngros.NOSPAM@bigpond.net.au>
Subject: Re: Start Batch-File .bat with Perl (Windows2000/IIS)
Message-Id: <NPah6.11764$o85.59489@news-server.bigpond.net.au>
"kurt elmiger" <ke@idm.ch> wrote in message news:3A7A5576.A57CFBF2@idm.ch...
> Hi there
>
> I had a Web solution which was running on NT/Apache-Webserver
> successfully. I moved the project on Windows2000/IIS platform with
> following problem. On the new platform rhe Perl scripts are running
> successfully but the call for the batch-file doesn't.
>
> print "<BODY>Fehler-";
>
> $cmd1 = 'berech.bat ';
> system($cmd1);
DOS requires a slightly diferent call I had the same problem only a few days
ago. Try system("START $cmd1");
Crossposting is frowned upon in most groups in Usenet, don't do it in
future. I left all the groups for my reply because I do not know which group
you are watching.
Post individually to each group you feel are relevant.
------------------------------
Date: Sat, 10 Feb 2001 17:16:49 +0900
From: LXQ <lxq79@hotmail.com>
Subject: Test if is a directory in DirHandle
Message-Id: <20010210171649.2f8c5e41.lxq79@hotmail.com>
Hi,
I am trying to view all the files in the directory, using DirHandle.
use DirHandle;
$d = new DirHandle ".";
if (defined $d) {
while (defined($_ = $d->read)){
print($_);
}
}
But the directories also show up. How can I filter it, so only files
prints? Thanks so much.
------------------------------
Date: Sat, 10 Feb 2001 04:16:20 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: Test if is a directory in DirHandle
Message-Id: <9630rk$dot$1@slb7.atl.mindspring.net>
"LXQ" <lxq79@hotmail.com> wrote in message
news:20010210171649.2f8c5e41.lxq79@hotmail.com...
> Hi,
>
> I am trying to view all the files in the directory, using DirHandle.
>
> But the directories also show up. How can I filter it, so only files
> prints? Thanks so much.
You want one of the -X file tests, in this case -f (See perldoc -f -X). The
code below uses grep -f to filter the list of files returned from $dh->read.
<< BEGIN CODE >>
use strict;
use warnings;
use DirHandle;
my $dir = ".";
my $dh = new DirHandle($dir) or
die "Can't open directory $dir: $!";
foreach (grep -f, $dh->read){
print "$_\n";
}
<< END CODE >>
HTH,
Kurt Stephens
------------------------------
Date: Sat, 10 Feb 2001 04:33:21 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: Test if is a directory in DirHandle
Message-Id: <9631sn$kn5$1@slb1.atl.mindspring.net>
"Kurt Stephens" <kstep@pepsdesign.com> wrote in message
news:9630rk$dot$1@slb7.atl.mindspring.net...
> "LXQ" <lxq79@hotmail.com> wrote in message
> news:20010210171649.2f8c5e41.lxq79@hotmail.com...
> << BEGIN CODE >>
>
> use strict;
> use warnings;
>
> use DirHandle;
>
> my $dir = ".";
> my $dh = new DirHandle($dir) or
> die "Can't open directory $dir: $!";
>
> foreach (grep -f, $dh->read){
> print "$_\n";
> }
>
> << END CODE >>
I forgot to mention, -f will only work for the current directory as used
above. For a more general case you will need something like:
my $dir = "/some/other/directory";
my $dh = new DirHandle($dir) or
die "Can't open directory $dir: $!";
chdir $dir or
die "Can't chdir to $dir: $!";
foreach (grep -f, $dh->read){
print "$_\n";
}
# Or, without changing directories
my $dh = new DirHandle($dir) or
die "Can't open directory $dir: $!";
foreach (grep {-f "$dir/$_"} $dh->read){
print "$_\n";
}
Kurt Stephens
------------------------------
Date: Sat, 10 Feb 2001 20:19:13 +0900
From: LXQ <lxq79@hotmail.com>
Subject: Re: Test if is a directory in DirHandle
Message-Id: <20010210201913.556291aa.lxq79@hotmail.com>
Thanks, it works :)
On Sat, 10 Feb 2001 04:33:21 -0500
"Kurt Stephens" <kstep@pepsdesign.com> wrote:
> "Kurt Stephens" <kstep@pepsdesign.com> wrote in message
> news:9630rk$dot$1@slb7.atl.mindspring.net...
> > "LXQ" <lxq79@hotmail.com> wrote in message
> > news:20010210171649.2f8c5e41.lxq79@hotmail.com...
> > << BEGIN CODE >>
> >
> > use strict;
> > use warnings;
> >
> > use DirHandle;
> >
> > my $dir = ".";
> > my $dh = new DirHandle($dir) or
> > die "Can't open directory $dir: $!";
> >
> > foreach (grep -f, $dh->read){
> > print "$_\n";
> > }
> >
> > << END CODE >>
>
> I forgot to mention, -f will only work for the current directory as used
> above. For a more general case you will need something like:
>
> my $dir = "/some/other/directory";
> my $dh = new DirHandle($dir) or
> die "Can't open directory $dir: $!";
>
> chdir $dir or
> die "Can't chdir to $dir: $!";
>
> foreach (grep -f, $dh->read){
> print "$_\n";
> }
>
> # Or, without changing directories
>
> my $dh = new DirHandle($dir) or
> die "Can't open directory $dir: $!";
>
> foreach (grep {-f "$dir/$_"} $dh->read){
> print "$_\n";
> }
>
> Kurt Stephens
>
>
>
------------------------------
Date: Sat, 10 Feb 2001 08:44:09 GMT
From: Drew Shafer <dshafer@mail.utexas.edu>
Subject: use pack() to uuencode long strings?
Message-Id: <e50a8tsm752jrdh08ucbh5onfoac94r3qs@4ax.com>
Is it possible to use pack() to UUEncode strings of more than 45
bytes? This seems to be a limitation I can't easily get around.
TIA,
Drew Shafer
------------------------------
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 V10 Issue 265
**************************************