[18962] in Perl-Users-Digest
Perl-Users Digest, Issue: 1157 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 19 06:08:52 2001
Date: Tue, 19 Jun 2001 03:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <992945108-v10-i1157@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 19 Jun 2001 Volume: 10 Number: 1157
Today's topics:
Re: 2 questions about flock <m.grimshaw@salford.ac.uk>
Re: [ map { @{ $_ || [ ] } } @$to ] (what does this mea <iltzu@sci.invalid>
Re: Can't locate Fcntl.pm in @INC <admin@the-piper.net>
Re: cursor positioning <andrew@mvt.ie>
Re: Get info about stored procedures - and SQL prettypr <Jenda@Krynicky.cz>
Re: help with regexp? (Dave Bailey)
Re: help with the perl scripts <goldbb2@earthlink.net>
Re: help with the perl scripts <goldbb2@earthlink.net>
how can I read lines from file compare it and write it <gadys@modem-art.com>
Re: how can I read lines from file compare it and write <gnarinn@hotmail.com>
how to validate email address (chih-chieh, Huang)
Re: how to validate email address <hafner-usenet@ze.tu-muenchen.de>
Re: how to validate email address <krahnj@acm.org>
Re: MAJOR perl bug <pne-news-20010619@newton.digitalspace.net>
Re: Performance Advice: CGI servers files <goldbb2@earthlink.net>
Perl Tutorials or E-Books <coder@binbash.net>
Re: Perl Tutorials or E-Books <peb@bms.umist.ac.uk>
redirection to a file <mos@pine.dk>
Re: Scrubbing path and fragment from url <goldbb2@earthlink.net>
Re: Sorting hash <goldbb2@earthlink.net>
Re: Sorting hash <goldbb2@earthlink.net>
unlink fails in list context <simon.andrews@bbsrc.ac.uk>
Re: unlink fails in list context <goldbb2@earthlink.net>
Re: unlink fails in list context (Anno Siegel)
Re: windows 2000 <bmannikko@yahoo.com>
Re: windows 2000 (Helgi Briem)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 19 Jun 2001 09:20:01 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: 2 questions about flock
Message-Id: <3B2F0B31.E1C44467@salford.ac.uk>
Garry Williams wrote:
>
> On Fri, 15 Jun 2001 11:55:33 +0100, Mark Grimshaw
> <m.grimshaw@salford.ac.uk> wrote:
>
> > I'm curious why strict would not complain if I attempted to call an
> > undefined method sync() as I originally did.
>
> This has nothing to do with `strict'. It's a run-time exception no
> matter what:
>
> $ perl -we 'package A; sub new{return bless{}}package main;' \
> -e 'my $x=A->new;$x->nope'
> Can't locate object method "nope" via package "A" (perhaps you forgot
> to load "A"?) at -e line 2.
>
> --
> Garry Williams
I use -w as a matter of course and still did not get warnings/errors.
------------------------------
Date: 19 Jun 2001 09:47:38 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: [ map { @{ $_ || [ ] } } @$to ] (what does this mean?)
Message-Id: <992943148.8197@itz.pp.sci.fi>
In article <3B2E1D4B.235BFF22@sfs.nphil.uni-tuebingen.de>, Dale Gerdemann wrote:
>
> [ map { @{ $_ || [ ] } } @$to ]
>
>is used to concatenate the bins in a radix sort (p. 146). At
>least the comment says that's what it does, but I don't have
>a clue how this works. Help, anyone?
Okay. Well, that's what it does indeed, but I bet it could've been
written a bit more clearly. Let's start from the inside:
[ map { $_ ? @$_ : () } @$to ]
Is that better? If $_ is true, the block assumes it to be a reference
to an array and returns the contents of that array. If $_ is false, it
returns an empty list. ("@{[]}" is an obfuscated way to write "()".)
What else? The expression you give doesn't show what happens to its
value, but let's assume it gets assigned to a variable:
my $foo = [ map { $_ ? @$_ : () } @$to ];
I can now write the same a bit more verbosely:
my $foo = [];
for (@$to) {
push @$foo, @$_ if $_;
}
..and now the implicit use of $_ can be avoided too:
my $foo = [];
foreach my $bin (@$to) {
push @$foo, @$bin if $bin;
}
Did that help any?
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: Tue, 19 Jun 2001 08:48:39 GMT
From: "Tom Klinger" <admin@the-piper.net>
Subject: Re: Can't locate Fcntl.pm in @INC
Message-Id: <HlEX6.12741$m17.272893@news2.nokia.com>
"Neil Sandow" <rx@rxlist.com> wrote in message
news:3B2EE2A8.F8B1B0EB@rxlist.com...
> I'm getting the following error on a new script:
>
> Can't locate Fcntl.pm in @INC (@INC contains:
> /usr/libdata/perl/5.00503/mach /usr/libdata/perl/5.00503
> /usr/local/lib/perl5/site_perl/5.005/i386-freebsd
> /usr/local/lib/perl5/site_perl/5.005 .) at
> /usr/home/rxlist/public_html/rxboard/webbbs_basic.pl line 192.
> BEGIN failed--compilation aborted at
> /usr/home/rxlist/public_html/rxboard/webbbs_basic.pl line 192.
>
>
Try to find it. Normally it comes as standard with the Perl distribution.
If it is installed somewhere in a path not in @INC try to add it with:
use lib '/path/to/fnctl.pm';
which unshifts the path to @INC.
Another possible reason is that the name of that module you have installed
is written in a different way used in the script ( Fnctl.pm != fnctl.pm )
hth, Tom
------------------------------
Date: Tue, 19 Jun 2001 10:54:39 +0100
From: "Andrew" <andrew@mvt.ie>
Subject: Re: cursor positioning
Message-Id: <9gn7h2$6ah$1@kermit.esat.net>
"Mike" <mbowden@nj.rr.com> wrote in message
news:3b293d79.1626653@news-server.nj.rr.com...
> Does anybody know how to position the cursor on the screen under
> Windows NT? I have tried Term::Cap, but can't get it to work. This
> seems like a very basic problem ,but I can't find any solid
> documentation on it, especially under NT.
You need to use Win32::Console
It's included with ActivePerl, and there's HTML documentation for it too.
Andrew
------------------------------
Date: Tue, 19 Jun 2001 08:05:11 GMT
From: Jenda Krynicky <Jenda@Krynicky.cz>
Subject: Re: Get info about stored procedures - and SQL prettyprinter
Message-Id: <1103_992937911@JENDA>
That's great, replying to my own post ...
On Fri, 15 Jun 2001 11:09:23 GMT, Jenda Krynicky <Jenda@Krynicky.cz> wrote:
> I need to read information about stored procedures in a MS SQL database within a program.
>
> I can get the list of procedures, their parameters, types and sizes of parameters via Win32::OLE
> "SQLDMO.SQLServer".
>
> I can't find a way to find out two more things.
>
> 1) I can't find how to check whether some parameter has a default value.
> I don't mind what the value is, I just need to know what parameters are required.
I'd realy want to know this pretty please !
> 2) I'd like to know whether the function returns a recordset/resultset (call it however you like).
Well ... I guess this is more "What do I want from the procedure" that "What does the procedure".
I guess it will be better to let the "user" specify whether he wants a recordset back.
> Or if I have to parse the procedure definition ... is there a parser?
And what about SQL prettyprinter?
I'm generating a documentation to the object and would want to include the stored procedure definition
but the code often doesn't look too good.
> Thanks for any suggestions, Jenda
>
> P.S.: I'm autogenerating a COM wrapper around the procedures so that I can write
> err = obj.SomeStoredProcedure( 1, "Hello", world, rset)
> in ASPs. The autogeneration script is of course Perl, the generated code is VB.
> The client wants me to use VB so that's what he will see ;-)
If you want to see the results (well it's still being modified, but it's working already)
you can find them on http://Jenda.Krynicky.cz/perl/SP_COM_generator.1.1.zip
It's Win32 only of course.
Jenda
------------------------------
Date: 19 Jun 2001 07:52:26 GMT
From: dave@sydney.daveb.net (Dave Bailey)
Subject: Re: help with regexp?
Message-Id: <slrn9itn04.7v7.dave@sydney.daveb.net>
On Tue, 19 Jun 2001 01:10:36 -0400, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:
>Dave Bailey wrote:
[...]
>> CGI.pm is a nasty module to use if all you need is CGI arguments.
>> Using CGI.pm under mod_perl increases the size of your Apache
>> processes by around 2 MB compared with something simpler like
>> Apache::Request, which also provides a param() method. In any case,
>> the point is moot since the OP is migrating his site's CGI content to
>> PHP, not Perl.
>
>No, the point would be moot if PHP was unable to access the PATH_INFO
>environment variable.
The point I was referring to was my own point about CGI.pm. Sorry
for the confusion.
>> As for the argument scheme, it's not superior, it's just different.
>> In some situations the CGI arguments have a natural hierarchy such
>> as /chapter/section/paragraph which lends itself nicely to directory
>> style naming. In other situations this is not the case, such as
>> ?x=14&y=7&z=5. Which one is more suitable depends on what the
>> arguments represent, IMHO.
>
>True. But, for for *most* static content, path_info is better, IMHO.
>For example, if an ordinary [non cgi-generated] html file were
>referencing a cgi with fixed xyz, I would probably prefer something like
>"/14/7/5" to "?x=14&y=7&z=5". It's kinda like the difference between
>using $cgi->header("text/html") and $cgi->header(-TYPE=>"text/html").
Many CGI scripts have a (possibly long) list of arguments they can take,
and are often called with a small subset of those arguments. PATH_INFO
is awkward in those cases, and also in cases where the same CGI is linked
to in the HTML output of other CGI scripts which construct the CGI
arguments in different orders for reasons which can't be avoided.
It is better to have one scheme for passing arguments to a CGI than two,
so after a few tens of thousands of lines of CGI/Perl development I've
settled on using PATH_INFO only in cases where you really have a single
CGI argument which also happens to be either a file/directory path or
a module/object path. I recognize your desire for brevity but I think
in many cases it can make the guts more complicated than they need to be.
--
Dave Bailey
davidb54@yahoo.com
------------------------------
Date: Tue, 19 Jun 2001 04:24:54 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: help with the perl scripts
Message-Id: <3B2F0C56.D48EDC6F@earthlink.net>
Chris Fedde wrote:
>
> In article <l.992889174.1843963623@[198.138.198.252]>,
> <u518615722@spawnkill.ip-mobilphone.net> wrote:
> >We need to run the following scripts to change phone #s once a while.
> >
> >perl -pi.bak -e 's/string1/string2/g' `find /opt2/oracle/product/
> >8.1.7/dba/ -name "*" -print`
> >
> >because we have hundreds of files and sub-directories so we can not
> >change them one by one. Sometimes somebody put a huge dmp files w/o let
> >us know, so we will run out of spaces by running this scripts.
> >
> >How can we make smarter that it will only make a copy of the files
> >that get changed and do not make copy of those that are not changed?
> >
>
> Several ideas here. One is to re-order your command line:
>
> find mumble | xargs perl -pi.bak frotz
>
> This prevents you from creating command lines that are bigger than the
> shell command buffer. It also lets you be more flexible with finds
> arguments.
The OP's problem is not with the length of the command, but with all
the backups created by -i.bak filling up the filesystem. However, your
suggestion of piping find to xargs perl is still a good one, even if it
doesn't address his problem.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Tue, 19 Jun 2001 04:32:01 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: help with the perl scripts
Message-Id: <3B2F0E01.795C1FC4@earthlink.net>
Benjamin Goldberg wrote:
>
> u518615722@spawnkill.ip-mobilphone.net wrote:
[snip]
> > How can we make smarter that it will only make a copy of the files
> > that get changed and do not make copy of those that are not changed?
[snip]
> This untested code opens a file, does an in-memory edit, makes a
> backup, writes the new version, then deletes the backup. If no
> changes are made by the edit, no backup is made, and nothing is
> written to disk. If it encounters a failure while editing, the backup
> is not deleted.
Having only just now noticed that you are willing to have the backup
stick around, if there was an actual change made, you can change my code
in the following way:
>
> #! perl -w
> use strict;
> use File::Find;
> use File::Copy;
>
> find sub {
> return if /\.bak$/;
> return unless !-l && -f _ && -r _ && -w _;
>
> unless( open my $fh, "+<", my $fn = $_ ) {
> warn "open(FH, +<, $File::Find::dir/$_): $!\n"
> return;
> }
> local $_ = do { local $/ = \ -s $fh; <$fh>; };
> /string1/string2/msg or return;
No change needed with this line, just pointing out that it's what causes
the no-backup-if-no-changes behaviour.
> unless( my $made_backup = copy( $fn, "$fn.bak" ) ) {
> warn "$File::Find::dir copy($fn,$fn.bak): $!\n";
> }
Replace the above unless block with:
unless( copy( $fn, "$fn.bak" ) ) {
warn "Couldn't backup $File::Find::dir/$_: $!\n";
return;
}
This means that if we couldn't make the backup, we don't try to make
changes.
> unless ( seek( $fh, 0, 0 ) ) {
> warn "seek($File::Find::dir/$fn,0,0): $!\n";
> return;
> }
> print $fh $_; # print always succeeds, right?
> unless( truncate $fh, my $len = length $_ ) {
> warn "truncate($File::Find::dir/$fn,$len): $!\n";
> return;
> }
> if( $made_backup and not unlink( "$fn.bak" ) ) {
> warn "unlink($File::Find::dir/$fn.bak): $!\n";
> }
Remove the above if block, since we don't remove the backup copy.
> # filehandle in lexical automatically closed at end of scope.
> } "/opt2/oracle/product/8.1.7/dba/";
> __END__
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Tue, 19 Jun 2001 10:49:00 +0200
From: "gady" <gadys@modem-art.com>
Subject: how can I read lines from file compare it and write it to another file
Message-Id: <9gn00e$hp5$1@news.netvision.net.il>
------------------------------
Date: Tue, 19 Jun 2001 09:24:03 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: how can I read lines from file compare it and write it to another file
Message-Id: <992942643.233269852120429.gnarinn@hotmail.com>
In article <9gn00e$hp5$1@news.netvision.net.il>,
gady <gadys@modem-art.com> wrote nothing
perl -n -e'print if /somestring/;' infile > outfile
gnari
------------------------------
Date: 19 Jun 2001 00:58:09 -0700
From: h155@ms37.hinet.net (chih-chieh, Huang)
Subject: how to validate email address
Message-Id: <a488b3e.0106182358.15571672@posting.google.com>
Dear All:
I have seen some scripts describing how to validate email address.
I have another point of view and I don't know whether it will work.
My idea is to check the domain name from email address, i.e.
if email=abc@abc.com
then, use ping or nslookup to check whether domain name (abc.com) is valid.
In using "Ping", system's response will be "abc.com is alive" if this domain
does exist.
Then, I am sure "abc.com" exists, but I still can't make sure whether
"abc@abc.com" is valid.
What do you think about my idea?
Thanks for your opinion.
------------------------------
Date: 19 Jun 2001 10:13:29 +0200
From: Walter Hafner <hafner-usenet@ze.tu-muenchen.de>
Subject: Re: how to validate email address
Message-Id: <srj1yogopjq.fsf@w3proj1.ze.tu-muenchen.de>
h155@ms37.hinet.net (chih-chieh, Huang) writes:
> Dear All:
> I have seen some scripts describing how to validate email address.
> I have another point of view and I don't know whether it will work.
>
> My idea is to check the domain name from email address, i.e.
> if email=abc@abc.com
> then, use ping or nslookup to check whether domain name (abc.com) is valid.
>
> In using "Ping", system's response will be "abc.com is alive" if this domain
> does exist.
>
> Then, I am sure "abc.com" exists, but I still can't make sure whether
> "abc@abc.com" is valid.
>
> What do you think about my idea?
> Thanks for your opinion.
The correct way ist to do a DNS lookup and check for the presence of a
MX record for the domain. Read the RFCs for details.
Have a look at Mail::CheckUser in CPAN. Does all you want and more.
-Walter
------------------------------
Date: Tue, 19 Jun 2001 08:17:33 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how to validate email address
Message-Id: <3B2F0A9B.FB2194B3@acm.org>
"chih-chieh, Huang" wrote:
>
> Dear All:
> I have seen some scripts describing how to validate email address.
> I have another point of view and I don't know whether it will work.
>
> My idea is to check the domain name from email address, i.e.
> if email=abc@abc.com
> then, use ping or nslookup to check whether domain name (abc.com) is valid.
>
> In using "Ping", system's response will be "abc.com is alive" if this domain
> does exist.
>
> Then, I am sure "abc.com" exists, but I still can't make sure whether
> "abc@abc.com" is valid.
perldoc -q 'valid mail address'
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 19 Jun 2001 09:16:25 +0200
From: Philip Newton <pne-news-20010619@newton.digitalspace.net>
Subject: Re: MAJOR perl bug
Message-Id: <quutitsvsfk5ifa34dmt735fjelivak0fp@4ax.com>
On 18 Jun 2001 16:53:29 -0700, pohanl@aol.com (None) wrote:
> the version of perl i am using is activeperl.
Others have commented on your logic; let me add that "activeperl" is not
very helpful, either. ActiveState has produced several builds of
ActivePerl. AFAIK, some correspond to 5.003, some to 5.005_03, some to
5.6.0, and I think they have one out for 5.6.1, as well. So knowing
which version you have would be interesting if you did encounter a bug,
because if, say, you found a bug in 5.005_03, it might be a known bug
that's fixed in 5.6.0.
perl -V should give you the version and, with ActivePerl, also the
ActiveState build number.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Tue, 19 Jun 2001 04:20:14 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Performance Advice: CGI servers files
Message-Id: <3B2F0B3E.EC5EC445@earthlink.net>
Dave Bailey wrote:
[snip]
> BTW, if using Apache/mod_perl to serve files, you can use the Apache
> request object's send_fd method, which essentially does what Ben
> is doing here, but with a blocksize of 8192 bytes. For example:
>
> use Apache;
> use Apache::Constants qw(NOT_FOUND OK);
>
> ...
>
> open(FH, $file) || return NOT_FOUND;
> $r->content_type('application/x-whatever');
> $r->header_out('Content-Length'=>(stat($file))[7]);
> $r->send_http_header;
> $r->send_fd(\*FH);
> close(FH);
> return OK;
I would prefer to do the stat on the filehandle, rather than on the file
name. Also, using the -s operator might be clearer than an explicit
stat.
$r->header_out('Content-Length'=>-s FH);
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Tue, 19 Jun 2001 02:27:49 -0700
From: "[coder]" <coder@binbash.net>
Subject: Perl Tutorials or E-Books
Message-Id: <tiu6lup4vk40f6@corp.supernews.com>
Hey
anyone know where i can find some perl tutorials or free e-books?
thx
[coder]
------------------------------
Date: Tue, 19 Jun 2001 11:01:16 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Perl Tutorials or E-Books
Message-Id: <3B2F22EC.ACED12F4@bms.umist.ac.uk>
"[coder]" wrote:
>
> Hey
>
> anyone know where i can find some perl tutorials or free e-books?
>
funnily enough, a google search (http://www.google.com) found 211, 000
pages with the words 'Perl' and 'tutorial' in them. I'm sure one of
those would be just fine.
HAND
Paul
------------------------------
Date: Tue, 19 Jun 2001 10:23:08 +0200
From: "Michael Schmidt" <mos@pine.dk>
Subject: redirection to a file
Message-Id: <992939065.762864@pine>
Hello
Can anyone help me.
I'm working on porting a system from NT to Win2000 and I've got strange
perl problem.
I've got this command that fails.
$command="d:\\test\\test.exe 1 2 >>d:\\test\\log\\hest2.log";
if ($ret = system("$command")!=0) {
print "Execution of $command failed $ret\n";
}
If i change the command to :
"$command="d:\\test\\test.exe 1 2 " it works fine.
I've tried to make the testprg. generate a file in the same library using
the open command,
to test for permissions, and that works fine.
I've tried with three versions of perl : perl4. perl5.004 and perl5.6.
It only works on perl4 why ????
Please help
Michael Schmidt
------------------------------
Date: Tue, 19 Jun 2001 04:09:47 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Scrubbing path and fragment from url
Message-Id: <3B2F08CB.7434DA81@earthlink.net>
Craig Berry wrote:
>
> I am using the URI.pm module to...well, manipulate some URIs,
> amazingly enough. One trick I need to pull is to take an existing
> absolute URI and strip away any query or fragment parts from the end.
> Here's how I'm doing it now (code snipped from context, $res is
> another URI):
>
> my $url = URI->new_abs($_->[2], $res->base);
> my $path = $url->path || '/';
>
> if ($url->scheme =~ m!^https?$! &&
> $url->authority =~ m!$domain$!io &&
> $path =~ m!(\.html?|/)$!i) {
> push @pending, $url->scheme . '://' . $url->authority . $path;
> }
>
> Is there a better way to build the no-query-or-fragment URI I'm
> pushing onto the pending list?
How about:
my $url = URI->new_abs($_->[2], $res->base);
if ($url->scheme =~ m!^https?$! &&
$url->authority =~ m!$domain$!io &&
$url->path =~ m!(\.html?|/)$!i) {
$url->fragment(undef); $url->query(undef);
push @pending, $url;
}
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Tue, 19 Jun 2001 04:39:48 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sorting hash
Message-Id: <3B2F0FD4.A8B91456@earthlink.net>
Anno Siegel wrote:
>
> According to Benjamin Goldberg <goldbb2@earthlink.net>:
>
> > Wouldn't a Schwartzian Transform or Guttman Roswieler Transform be
> ^^^^^^^^^
> s/Roswieler/Rosler/
>
> Anno
Maybe I should just stick to typing GRT? :)
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Tue, 19 Jun 2001 04:42:08 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sorting hash
Message-Id: <3B2F1060.314D0B53@earthlink.net>
Ren Maddox wrote:
>
> On Mon, 18 Jun 2001, krahnj@acm.org wrote:
>
> > Benjamin Goldberg wrote:
> >>
> >> Wouldn't a Schwartzian Transform or Guttman Roswieler Transform be
> >> faster here?
> >>
> >> foreach (map {(unpack 'Z* a*')[1]} sort map {
> > ^^^^^^^
> > You didn't pass an expression to unpack (it doesn't default to $_)
> > and in the template 'Z* a*' Z* grabs everything so the a* is
> > superfluous.
>
> Yeah... bummer on how "Z*" works on unpack, isn't it. This works
> instead:
>
> foreach (map {(split /\0/)[1]} sort map { # rest is the same
>
> And, of course, unlike unpack, split *does* default to $_. :)
Hmm, or even better:
foreach (map {/\0(.*)/s} sort map { # rest is the same
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Tue, 19 Jun 2001 09:13:49 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: unlink fails in list context
Message-Id: <3B2F09BD.F1367311@bbsrc.ac.uk>
I've come across a strange behaviour with unlink when used in list
context, which although I have sorted out, I don't quite understand why
it happens. I'm trying to clean up after a program which generates a
series of files of the form
pregap.this
pregap.that
pregap.whatever
..and I was trying to remove them using a glob as described in the
unlink documentation, ie: unlink <pregap.*>;
The problem comes when I tried to be good and do some error checking.
An example is shown below (the system command probably wraps);
--------
#!/usr/bin/perl -w
use strict;
system("touch pregap.passed;touch pregap.failed;touch pregap.whatever");
my @filelist = <pregap.*>;
print "Filelist is\n" . join("\n",@filelist) . "\n\n";
unlink <pregap.*> || warn "** Couldn't unlink files: $!\n";
my @newfilelist = <pregap.*>;
print "New Filelist is\n" . join("\n",@newfilelist) . "\n\n";
---------
Running this under v5.005_02 (alpha-dec_osf), produces;
Filelist is
pregap.failed
pregap.passed
pregap.whatever
New Filelist is
pregap.passed
pregap.whatever
..and no warnings. Removing the "|| warn....." allows all the files to
be unlinked. Explicitly putting the glob in list context using
(<pregap.*>) also works.
So my questions are: Why does adding the error check stop the glob from
completing? Also, if I put brackets round the glob then is the error
checking I'm doing still going to protect me in the way I think it
does? Are there any circumstances where unlink(<whatever.*>) wouldn't
work as expected?
Is this something that could be added to the unlink documentation given
that error checking should be considered a good thing, or is it
something I was expected to be able to figure out for myself?
Any enlightenment appreciated
Simon.
------------------------------
Date: Tue, 19 Jun 2001 05:01:44 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: unlink fails in list context
Message-Id: <3B2F14F8.3276B0DC@earthlink.net>
Simon Andrews wrote:
>
> I've come across a strange behaviour with unlink when used in list
> context, which although I have sorted out, I don't quite understand why
> it happens. I'm trying to clean up after a program which generates a
> series of files of the form
>
> pregap.this
> pregap.that
> pregap.whatever
>
> ..and I was trying to remove them using a glob as described in the
> unlink documentation, ie: unlink <pregap.*>;
>
> The problem comes when I tried to be good and do some error checking.
> An example is shown below (the system command probably wraps);
>
> --------
> #!/usr/bin/perl -w
> use strict;
>
> system("touch pregap.passed;touch pregap.failed;touch pregap.whatever");
>
> my @filelist = <pregap.*>;
>
> print "Filelist is\n" . join("\n",@filelist) . "\n\n";
>
> unlink <pregap.*> || warn "** Couldn't unlink files: $!\n";
>
> my @newfilelist = <pregap.*>;
>
> print "New Filelist is\n" . join("\n",@newfilelist) . "\n\n";
> ---------
>
> Running this under v5.005_02 (alpha-dec_osf), produces;
>
> Filelist is
> pregap.failed
> pregap.passed
> pregap.whatever
>
> New Filelist is
> pregap.passed
> pregap.whatever
>
> ..and no warnings. Removing the "|| warn....." allows all the files to
> be unlinked. Explicitly putting the glob in list context using
> (<pregap.*>) also works.
>
> So my questions are: Why does adding the error check stop the glob from
> completing?
It's not the error checking per se, it's the fact that || introduces a
scalar context, causing glob to behave differently. Try "or" instead,
as it has a lower precedence than unlink, which is a list operator.
See perlop for details.
> Also, if I put brackets round the glob then is the error
> checking I'm doing still going to protect me in the way I think it
> does? Are there any circumstances where unlink(<whatever.*>) wouldn't
> work as expected?
When <whatever.*> is called in a different context (list/scalar) than
you expect, then it won't behave as you expect.
> Is this something that could be added to the unlink documentation
> given that error checking should be considered a good thing, or is it
> something I was expected to be able to figure out for myself?
It's not unlink's fault...
You should have figured out that the glob was being put in scalar
context by the || when you noted: "Explicitly putting the glob in list
context using (<pregap.*>) also works."
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: 19 Jun 2001 09:22:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: unlink fails in list context
Message-Id: <9gn5k2$1un$1@mamenchi.zrz.TU-Berlin.DE>
According to Simon Andrews <simon.andrews@bbsrc.ac.uk>:
> I've come across a strange behaviour with unlink when used in list
> context, which although I have sorted out, I don't quite understand why
> it happens. I'm trying to clean up after a program which generates a
> series of files of the form
>
> pregap.this
> pregap.that
> pregap.whatever
>
> ..and I was trying to remove them using a glob as described in the
> unlink documentation, ie: unlink <pregap.*>;
>
> The problem comes when I tried to be good and do some error checking.
> An example is shown below (the system command probably wraps);
>
>
> --------
> #!/usr/bin/perl -w
> use strict;
>
> system("touch pregap.passed;touch pregap.failed;touch pregap.whatever");
>
> my @filelist = <pregap.*>;
>
> print "Filelist is\n" . join("\n",@filelist) . "\n\n";
>
> unlink <pregap.*> || warn "** Couldn't unlink files: $!\n";
Here is your problem: The precedence of "||" is relatively high, so
this is parsed as
unlink ( <pregap.*> || warn "** Couldn't unlink files: $!\n");
This puts the glob in scalar context, so it returns only the first
file. The boolean value of that is true, so the warn() isn't executed,
and the first file is all unlink ever sees.
Use the low-precedence "or" instead of "||", or use parentheses to
force the right precedence.
[snip]
Anno
------------------------------
Date: Tue, 19 Jun 2001 08:07:36 GMT
From: B Mannikko <bmannikko@yahoo.com>
Subject: Re: windows 2000
Message-Id: <8j1uits7u2ls6360r45pv2uui9052sog6f@4ax.com>
On Mon, 18 Jun 2001 14:37:53 GMT, Bart Lateur <bart.lateur@skynet.be>
wrote:
>Philip Newton wrote:
>
>>Or get IndigoPerl ( http://www.indigostar.com/indigoperl.htm ) which
>>comes with an Apache web server (with mod_perl, even). Possibly easier
>>than downloading ActivePerl and Apache separately and configuring them.
>>However, I have no experience with IndigoPerl.
>
>I have. Good stuff. Only, it's still 5.6.0. I don't know if 5.6.1 is in
>the works.
It's here. IndogoSTAR's site says 5.6, but binary is 5.6.1
F:\perl\bin>.\perl -v
This is perl, v5.6.1 built for MSWin32-x86-multi-thread
^^^^^
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2001, Larry Wall
Binary build 626 provided by IndigoSTAR Software.
http://www.indigostar.com
Built 21:37:25 May 6 2001
------------------------------
Date: Tue, 19 Jun 2001 09:59:25 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: windows 2000
Message-Id: <3b2f21bd.1732613587@news.isholf.is>
On Mon, 18 Jun 2001 16:04:13 +0200, Philip Newton
<pne-news-20010618@newton.digitalspace.net> wrote:
>On Mon, 18 Jun 2001 08:59:17 -0500, Chris <cpryce@pryce.net> wrote:
>
>> In addition to ActivePerl, you'll also need a Web server if you are using
>> Perl as a CGI scripting environment. I haven't tested apache on Win2k, but
>> there will be information at http://httpd.apache.org.
>
>Or get IndigoPerl ( http://www.indigostar.com/indigoperl.htm ) which
>comes with an Apache web server (with mod_perl, even). Possibly easier
>than downloading ActivePerl and Apache separately and configuring them.
>However, I have no experience with IndigoPerl.
Or get Perl Builder, a Perl IDE for Win that simulates a web
server for testing and debugging CGI scripts. Not free,
though, but worth the low price (149$). Available from
www.solutionsoft.com
Regards,
Helgi Briem
------------------------------
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.
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 1157
***************************************