[18615] in Perl-Users-Digest
Perl-Users Digest, Issue: 783 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 27 18:06:14 2001
Date: Fri, 27 Apr 2001 15:05:19 -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: <988409118-v10-i783@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 27 Apr 2001 Volume: 10 Number: 783
Today's topics:
"return" from a "require"? <xris@dont.send.spam>
Re: Appending to files and flock. <taka@yarn.demon.co.uk>
Re: Appending to files and flock. (Anno Siegel)
Re: Appending to files and flock. nobull@mail.com
Re: best way to evaluate $1 so it's not read-only? <xris@dont.send.spam>
Can't seem to create class data <durrett@xilinx.com>
Re: Can't seem to create class data (John Joseph Trammell)
Re: Can't seem to create class data <joe+usenet@sunstarsys.com>
Re: Can't seem to create class data (Anno Siegel)
Re: Can't seem to create class data <Jonathan.L.Ericson@jpl.nasa.gov>
Re: CGI::header is a filehandle? (Tad McClellan)
Re: CGI::header is a filehandle? (Jay Tilton)
Re: Chicago Perl Consultants Needed (David H. Adler)
Compile Check On Procedurenames (Alexander Fuchs)
Re: Compile Check On Procedurenames <sharding@ccbill.com>
creating an array of all filenames <magrav@wnt.sas.com>
Re: creating an array of all filenames <Jonathan.L.Ericson@jpl.nasa.gov>
dynamic creation of classes? (F. Xavier Noria)
Re: extracting hostname from a url? <comdog@panix.com>
Re: Finding all elements in an array matching a certian (Tad McClellan)
Re: Finding all elements in an array matching a certian nobull@mail.com
Re: Functional equivant to =~ operator? <gtoomey@usa.net>
Re: Help Me Obi One You're my Only Hope <tuan.ngo1@home.com>
Re: Help: PPM on unix? <pne-news-20010427@newton.digitalspace.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 27 Apr 2001 16:09:28 -0500
From: xris <xris@dont.send.spam>
Subject: "return" from a "require"?
Message-Id: <xris-D8DCAC.16092827042001@news.evergo.net>
Is there any way to return early from a "require" - like return() allows
you to from a subroutine?
------------------------------
Date: 27 Apr 2001 20:11:04 +0100
From: Paul the Nomad <taka@yarn.demon.co.uk>
Subject: Re: Appending to files and flock.
Message-Id: <871yqeb1kn.fsf@euterpe.yarn.demon.co.uk>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> According to Paul the Nomad <taka@yarn.demon.co.uk>:
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> [oops, lost an attribution there]
>
> > > > lock it. In fact, a quick look at my system's man page shows that the
> > > > C system call 'open' doesn't support locking. It does say, however,
> > > > that if two or more people try to append to a file at the same time it
> > > > could corrupt the file.
> > >
> > > Not if the individual bits written aren't exceedingly large. This has
> >
> > Sounds like programming by wishful thinking.
>
> Is Rabin/Miller prime testing programming by wishful thinking?
>
> It's called choosing the right tool for a task. Nothing stops
> you from additionally locking if the application is critical.
This thread is really appalling. When I originally asked this, I was
referred rudely to a document which didn't answer the question.
Before telling people to RTFM, might it not be preferable to ensure
that the FM has the information requested? If not, it would be better
to STFU.
So far the totally inadequate answer I've got in this sub-thread is:
"It's fine. No really it is. But anyway it depends on how Perl
implements open() and anyway might not work and anyway we can't refer
you to any documentation you've just got to trust us."
It would make used car salesmen blush.
Meanwhile on another sub-thread the message is clearly that it might
not work and flock should be used.
Is there *any* documentation *anywhere* written by someone who knows
what they are talking about that covers having one file open by many
processes for appending?
>
> Anno
--
-----------
Paul
http://www.seditiousdiaries.com/Donald10.html
------------------------------
Date: 27 Apr 2001 19:22:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Appending to files and flock.
Message-Id: <9ccgua$gfu$2@mamenchi.zrz.TU-Berlin.DE>
According to Paul the Nomad <taka@yarn.demon.co.uk>:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>
> > According to Paul the Nomad <taka@yarn.demon.co.uk>:
> > > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> > [oops, lost an attribution there]
> >
> > > > > lock it. In fact, a quick look at my system's man page shows that the
> > > > > C system call 'open' doesn't support locking. It does say, however,
> > > > > that if two or more people try to append to a file at the same time it
> > > > > could corrupt the file.
> > > >
> > > > Not if the individual bits written aren't exceedingly large. This has
> > >
> > > Sounds like programming by wishful thinking.
> >
> > Is Rabin/Miller prime testing programming by wishful thinking?
> >
> > It's called choosing the right tool for a task. Nothing stops
> > you from additionally locking if the application is critical.
>
> This thread is really appalling. When I originally asked this, I was
> referred rudely to a document which didn't answer the question.
It did, if you read Abigail's advice right.
> Before telling people to RTFM, might it not be preferable to ensure
> that the FM has the information requested? If not, it would be better
> to STFU.
>
> So far the totally inadequate answer I've got in this sub-thread is:
>
> "It's fine. No really it is. But anyway it depends on how Perl
> implements open() and anyway might not work and anyway we can't refer
> you to any documentation you've just got to trust us."
>
> It would make used car salesmen blush.
>
> Meanwhile on another sub-thread the message is clearly that it might
> not work and flock should be used.
>
> Is there *any* documentation *anywhere* written by someone who knows
> what they are talking about that covers having one file open by many
> processes for appending?
You are confused, and arrogant in your confusion. An unpalatable
mixture.
This is not your personal help desk, this is a Usenet discussion
group. You bring up a question, and people reply (or don't). It's
up to you to pick out what you can use.
Now read this group for a while and see what goes on here. Ask
again (or don't) when you know how things work. Or better yet,
just piss off.
Anno
------------------------------
Date: 27 Apr 2001 21:06:23 +0100
From: nobull@mail.com
Subject: Re: Appending to files and flock.
Message-Id: <u9u23af6ps.fsf@wcl-l.bham.ac.uk>
Paul the Nomad <taka@yarn.demon.co.uk> writes:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>
> > According to Paul the Nomad <taka@yarn.demon.co.uk>:
> > > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> > [oops, lost an attribution there]
> >
> > > > > lock it. In fact, a quick look at my system's man page shows that the
> > > > > C system call 'open' doesn't support locking. It does say, however,
> > > > > that if two or more people try to append to a file at the same time it
> > > > > could corrupt the file.
> > > >
> > > > Not if the individual bits written aren't exceedingly large. This has
> > >
> > > Sounds like programming by wishful thinking.
> >
> > Is Rabin/Miller prime testing programming by wishful thinking?
> >
> > It's called choosing the right tool for a task. Nothing stops
> > you from additionally locking if the application is critical.
>
> This thread is really appalling.
Yes, I know, it wasn't much better last time either (about 5 weeks
ago). Perhaps if you'd gone read that thread you'd have saved us all
a lot of grief.
The interaction between locking, OSs that do or do not implement
O_APPEND correctly, buffering and so on brings out the worst in
people.
> So far the totally inadequate answer I've got in this sub-thread is:
>
> "It's fine. No really it is. But anyway it depends on how Perl
> implements open() and anyway might not work and anyway we can't refer
> you to any documentation you've just got to trust us."
OK here's the truth.
If you are on a system that correctly implements flock() and you use
the example appending code from "perldoc -f flock" everything will be
OK even if the OS you are on doesn't implement append mode correctly.
So if you are happy to restrict yourself to OSs that implement flock()
(and that's not really much of a restriction) then that is what you
should do.
If you know you are only going to use a system that does correctly
implement appending (i.e. not Win32) then you can omit the seek() from
the above code.
If you know are only writting code to run on an OS and filesystem that
does implement append mode correctly (a local filesystem on a modern
Unix for example), and you keep the file in block-buffered mode and
you write less than one buffer-full of output between each manual
flushing of the buffer then each bufferload is almost garanteed to be
written to the end of the file in one chunk without getting
intermingled with anyone else's output.
There is still a small threoretical chance that a signal will
interrupt the system level write() operation before completion. There
is also a pssibility that some STDIO implementations may call multiple
system level write()s even if the buffer was empty to start. There
may be some systems where this probability is reduced to zero.
I do not know how in Perl you can find the default size of the buffer,
but IO::Handle does provide a way to change it.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 27 Apr 2001 13:18:45 -0500
From: xris <xris@dont.send.spam>
Subject: Re: best way to evaluate $1 so it's not read-only?
Message-Id: <xris-63C25E.13184427042001@news.evergo.net>
In article <3AE985DB.7572A2CF@home.com>,
Michael Carman <mjcarman@home.com> wrote:
> You could wrap the modification in an eval{}. If it succeeds,
> everything is rosy. If it fails, you could switch to back to the old
> "return a copy" behavior. It might make an interesting exercise, but I
> don't really recommend it. For one, the dual-behavior would probably
> confuse anyone except the original programmer. Aside from that, it
> would probably just slow your little micro-optimization down.
well, I'd be the only one ever using this.. but I guess it sounds like
it's probably just smarter to add some built-in support for
distinguishing between passed-in refs and strings, and treat them
accordingly...
Thanks for all the help.. I'll just go back to my old way of doing
things, which was apparently the best way of doing it, anyway.
-Chris
------------------------------
Date: Fri, 27 Apr 2001 11:54:12 -0600
From: Derrell Durrett <durrett@xilinx.com>
Subject: Can't seem to create class data
Message-Id: <3AE9B244.20AE546@xilinx.com>
My real problem is obviously more complicated than this, but here's an
example of me trying to create class data for package Doh:
package Doh;
use strict;
our $Default = 'Doh!';
sub new
{
return bless {};
}
sub say_it
{
shift;
my $new = shift;
$new ||= $Default;
print $new,$nl;
}
In my code, I say this:
#! /devl/perl/bin/perl5.6 -w
use strict;
use English;
our $nl = "\n";
my $homer = Doh->new();
$homer->say_it();
$homer->say_it( 'Mmmmm, Beeeerrrr!' );
$homer->say_it();
And here's the output I get. I was expecting it to say 'Doh!'
Use of uninitialized value in print at t2 line 27.
Mmmmm, Beeeerrrr!
Use of uninitialized value in print at t2 line 27.
Any idea what absolutely stupid thing I did?
Derrell
--
Derrell Durrett Xilinx, Inc. Productivity Engineering
Boulder, Colorado
303.544.5498
------------------------------
Date: Fri, 27 Apr 2001 18:32:10 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: Can't seem to create class data
Message-Id: <slrn9ejcie.i7.trammell@bayazid.hypersloth.net>
On Fri, 27 Apr 2001 11:54:12 -0600, Derrell Durrett <durrett@xilinx.com> wrote:
> package Doh;
[snip]
> sub say_it
> {
> shift;
> my $new = shift;
> $new ||= $Default;
> print $new,$nl;
> }
[snip]
> #! /devl/perl/bin/perl5.6 -w
> our $nl = "\n";
[snip]
> Use of uninitialized value in print at t2 line 27.
[snip]
> Any idea what absolutely stupid thing I did?
You expected $main::nl to become $Doh::nl.
--
Just Another Perl Hacker.
------------------------------
Date: 27 Apr 2001 14:51:44 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Can't seem to create class data
Message-Id: <m3k846mb0f.fsf@mumonkan.sunstarsys.com>
Derrell Durrett <durrett@xilinx.com> writes:
> My real problem is obviously more complicated than this, but here's an
> example of me trying to create class data for package Doh:
>
> package Doh;
>
> use strict;
> our $Default = 'Doh!';
>
> sub new
> {
> return bless {};
> }
>
> sub say_it
> {
> shift;
> my $new = shift;
> $new ||= $Default;
> print $new,$nl;
^^^
A clue...
Global symbol "$nl" requires explicit package name at - ...
Execution of - aborted due to compilation errors.
> }
>
> In my code, I say this:
>
> #! /devl/perl/bin/perl5.6 -w
>
> use strict;
> use English;
How did you load package Doh?
> our $nl = "\n";
>
> my $homer = Doh->new();
> $homer->say_it();
> $homer->say_it( 'Mmmmm, Beeeerrrr!' );
> $homer->say_it();
>
> And here's the output I get. I was expecting it to say 'Doh!'
>
> Use of uninitialized value in print at t2 line 27.
>
> Mmmmm, Beeeerrrr!
> Use of uninitialized value in print at t2 line 27.
>
> Any idea what absolutely stupid thing I did?
Contrary to what your post indicates, you actually appended
package Doh;
...
to the *bottom* of your script, and are now confused about
the difference between a compile-time
our $Default
declaration versus its run-time initialization of 'Doh!'. See
perldoc -f use
for help.
--
Joe Schaefer "What kills a skunk is the publicity it gives itself."
-- Abraham Lincoln
------------------------------
Date: 27 Apr 2001 19:12:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Can't seem to create class data
Message-Id: <9ccga2$gfu$1@mamenchi.zrz.TU-Berlin.DE>
According to Derrell Durrett <durrett@xilinx.com>:
> My real problem is obviously more complicated than this, but here's an
> example of me trying to create class data for package Doh:
>
> package Doh;
>
> use strict;
> our $Default = 'Doh!';
>
> sub new
> {
> return bless {};
> }
>
> sub say_it
> {
> shift;
> my $new = shift;
> $new ||= $Default;
> print $new,$nl;
> }
>
> In my code, I say this:
>
> #! /devl/perl/bin/perl5.6 -w
>
> use strict;
> use English;
> our $nl = "\n";
>
> my $homer = Doh->new();
> $homer->say_it();
> $homer->say_it( 'Mmmmm, Beeeerrrr!' );
> $homer->say_it();
>
> And here's the output I get. I was expecting it to say 'Doh!'
>
> Use of uninitialized value in print at t2 line 27.
>
> Mmmmm, Beeeerrrr!
> Use of uninitialized value in print at t2 line 27.
>
> Any idea what absolutely stupid thing I did?
I'll assume you have reasons why you put "\n" in a variable, and
why $Default and $nl must be package variables.
Your immediate problem is that those variables are only initialized
after you use them. That they appear before the subroutine definitions
that use them doesn't change that, because sub definitions happen
at compile time (long before the assignment). Put BEGIN blocks
around the initializations, or place them before the calls.
Anno
------------------------------
Date: 27 Apr 2001 18:57:42 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Can't seem to create class data
Message-Id: <868zkmb26x.fsf@jon_ericson.jpl.nasa.gov>
Derrell Durrett <durrett@xilinx.com> writes:
> package Doh;
Not to be confused with the famous D'oh module on CPAN.
> use strict;
> our $Default = 'Doh!';
>
> sub new
> {
> return bless {};
> }
>
> sub say_it
> {
> shift;
> my $new = shift;
> $new ||= $Default;
> print $new,$nl;
^^^
Global symbol "$nl" requires explicit package name at Doh.pm line 16.
> }
>
> In my code, I say this:
>
> #! /devl/perl/bin/perl5.6 -w
>
> use strict;
> use English;
use Doh; # Did you forget, or is this not copy & pasted?
> our $nl = "\n";
This `our' allows $nl to be referenced in the current lexical scope
similar to `my'. Unlike `my', other lexical scopes can access the
_value_ of $nl with their own `our' decaration. Read all about it in
perlfunc/our.
Jon
------------------------------
Date: Fri, 27 Apr 2001 12:53:06 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: CGI::header is a filehandle?
Message-Id: <slrn9ej8vi.4av.tadmc@tadmc26.august.net>
Rudolf Polzer <eins@durchnull.de> wrote:
>Look at the following script:
>
>
>#!/usr/bin/perl -w
>
>use CGI;
>
>{
> print "1:\n";
> print (CGI::header (-type => 'text/html'));
>
> print "2:\n";
> print scalar (CGI::header (-type => 'text/html'));
>}
>Do you find the error without executing?
Yes.
Do I get a biscuit?
>The problem is: 1. does not work because Perl thinks CGI::header was a
>file handle. But doesn't CGI.pm define it as a sub?
>
>2. solves the problem because scalar is not a file handle.
>
>Interestingly, the problem does not occur when importing the CGI
>namespace which is what I do _not_ want. Can you explain to me what
>the difference between the two occurances of CGI::header is?
Perl's DWIMery involves guessing what you mean. Sometimes it guesses wrong.
Help it guess correctly:
print (CGI::header(-type => 'text/html'));
^^
^^ no space, problem solved!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 27 Apr 2001 19:08:43 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: CGI::header is a filehandle?
Message-Id: <3ae9b7c6.40513456@news.erols.com>
On Fri, 27 Apr 2001 18:51:08 +0200, eins@durchnull.de (Rudolf Polzer)
wrote:
>#!/usr/bin/perl -w
>use CGI;
>{
> print "1:\n";
> print (CGI::header (-type => 'text/html'));
>The problem is: 1. does not work because Perl thinks CGI::header was a
>file handle. But doesn't CGI.pm define it as a sub?
&CGI::header is a sub.
CGI::header is not.
Perl is capable of interpreting the latter as a sub, but it has to
look like one. Here, simply because of how print's syntax is defined,
it looks like a filehandle.
From perlstyle,
* No space between function name and its opening parenthesis.
Sometimes that's more than just a style concern.
print (CGI::header(-type => 'text/html'));
> print "2:\n";
> print scalar (CGI::header (-type => 'text/html'));
In that example, there's no way to misinterpret 'scalar' as a
filehandle.
------------------------------
Date: 27 Apr 2001 19:31:14 GMT
From: dha@panix2.panix.com (David H. Adler)
Subject: Re: Chicago Perl Consultants Needed
Message-Id: <slrn9eji82.sib.dha@panix2.panix.com>
In article <slrn9ebl8k.qhi.tadmc@tadmc26.august.net>, Tad McClellan wrote:
>
> He seems as perceptive as a potato.
Hey! Don't insult the potatoes that way!
:-)
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
I'm going to start off talking by about postmodernism. After that,
I'll switch to talking about postmodernism. And at the conclusion,
I'll return to the subject of postmodernism. - Larry Wall
------------------------------
Date: 27 Apr 2001 21:07:46 GMT
From: alexf@slice.uni-koblenz.de (Alexander Fuchs)
Subject: Compile Check On Procedurenames
Message-Id: <slrn9ejnt2.tkj.alexf@slice.uni-koblenz.de>
Hello,
is there a way to secure during compiling that any function called
in the program is defined? All functions I want to use are already
defined at compile time, modules are imported with use and I just
want to avoid those annoying spelling mistakes that terminate
the program with an error message like
Undefined subroutine &main::a called at ./mytest.pl line 11.
Please give me a hint if this check is possible/impossible
in perl or a reference to the appropriate documentation.
Thanks,
Alexander Fuchs
------------------------------
Date: Fri, 27 Apr 2001 14:54:54 -0700
From: "Shay Harding" <sharding@ccbill.com>
Subject: Re: Compile Check On Procedurenames
Message-Id: <9ccpah$12o6$1@node17.cwnet.frontiernet.net>
"Alexander Fuchs" <alexf@slice.uni-koblenz.de> wrote in message
news:slrn9ejnt2.tkj.alexf@slice.uni-koblenz.de...
> Hello,
>
> is there a way to secure during compiling that any function called
> in the program is defined? All functions I want to use are already
> defined at compile time, modules are imported with use and I just
> want to avoid those annoying spelling mistakes that terminate
> the program with an error message like
I am guessing by 'during compiling', you refer to using 'perl -c' on your
script.
If that is the case, the simplest thing I can think of is to wrap the entire
script in a
BEGIN{ } block and then run 'perl -c script.pl'. Will kick out the errors
for you.
------------------------------
Date: Fri, 27 Apr 2001 16:04:35 -0400
From: Max Gravitt <magrav@wnt.sas.com>
Subject: creating an array of all filenames
Message-Id: <rojjet0g3g1ms075i0qqs5ofo83i28d2f2@4ax.com>
I'm trying to create an array that contains all of the filenames in a
directory tree (recursive). I'm almost there. The below function is
called with the directory where to start looking.
It traverses the directory tree until it finds a directory that
contains no directories, but it does not add the files that that are
in other subdirectories.
For example, if the tree is like this:
+>com
-> file.txt
-> file2.txt
+> dir1
+>dir2
-> foo.txt
-> bar.txt
+> dir3
-> end_of_tree.txt
-> another_file.txt
Files that are missed are foo.txt, bar.txt, and any files that are in
dir2.
sub get_files{
# the next three lines gets all files (and directories) in the
dir
$local_dir = $_[0];
opendir(DIR, $local_dir) || die "can't opendir $local_dir:
$!";
@file_collection = (@file_collection, grep(!/^\.\.?$/,
readdir(DIR)));
foreach (@file_collection) {
if (-d $local_dir . "\\" . $_) {
get_files($local_dir . "\\" . $_);
}
}
}
Does anyone see what the problem is?
thanks
Max
------------------------------
Date: 27 Apr 2001 20:52:16 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: creating an array of all filenames
Message-Id: <86wv86dq0v.fsf@jon_ericson.jpl.nasa.gov>
Max Gravitt <magrav@wnt.sas.com> writes:
> I'm trying to create an array that contains all of the filenames in a
> directory tree (recursive). I'm almost there. The below function is
> called with the directory where to start looking.
Any reason you're not using File::Find?
Jon
------------------------------
Date: Fri, 27 Apr 2001 21:14:08 GMT
From: fxn@isoco.com (F. Xavier Noria)
Subject: dynamic creation of classes?
Message-Id: <3ae9de34.1263677@news.iddeo.es>
Is there a way to create classes dynamically? Something with
this semantics?
$class = 'Foo::Bar';
use $class;
$object = $class->new;
-- fxn
------------------------------
Date: Fri, 27 Apr 2001 15:32:56 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: extracting hostname from a url?
Message-Id: <comdog-D3126A.15325627042001@news.panix.com>
In article <9cc93d$ji8$1@charity.cs.utexas.edu>, logan@cs.utexas.edu
(Logan Shaw) wrote:
> In article <comdog-007CA4.01432127042001@news.panix.com>,
> brian d foy <comdog@panix.com> wrote:
> >In article <9cav87$i47$1@charity.cs.utexas.edu>, logan@cs.utexas.edu
> >(Logan Shaw) wrote:
> >> In article <3AE8CA05.A9B2697C@cs.tamu.edu>,
> >> Neeraj Khandelwal <neerajk@cs.tamu.edu> wrote:
> >> >I need to extract the hostname from a url. what would be a neat regular
> >> >expression to do this? for example given url
> >> Anyway, one way to do what you're talking about is something like this:
> >> m<^(http://[^/]+/?)>i
> >why use a regular expression when a URI module exists?
> IMHO, sometimes a module is overkill. If all you need is to do this
> one thing, then typing "m<^(http://[^/]+/?)>i" is much easier and more
> efficient than installing the URI module on every machine that will
> ever use the script.
define "more efficient" though. you're method isn't very efficient
because you make an error. you include the scheme and potentially
part of the scheme-specific part.
it is certainly much more clear and maintainable to say something
like:
URI->new("http://www.perl.com")->host
if that is really what you want. the module is tested, has a well
understood API, is freely available and easy to get, and does
the job correctly. more importantly, it shows the maintainer
exactly what you were trying to do. :)
--
brian d foy <comdog@panix.com>
------------------------------
Date: Fri, 27 Apr 2001 12:39:05 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Finding all elements in an array matching a certian criteria
Message-Id: <slrn9ej859.4av.tadmc@tadmc26.august.net>
Ron Hill <hillr@ugs.com> wrote:
>
>I am trying to extract filenames from a directory based on userid.
^^^^^^^^^^^^^^^
I do not see any userids anywhere in your code, I see only filenames.
>I
>figured that the perl grep function
>would work. However I am unabe to extract the filenames that I want. I
>have constructed a hash with
>the keys as the userid's. I retrive the dir listing and I want to
>extract all filenames that contain
>the userid. I have included a script of what I have tried. the array
>@wanted is empty. Can anyone
>tell me how this can be done?
>
>Thanks
>
>Ron Hill
>
>
>#!/app/perl5.005_03_static/bin/perl -w
>use strict;
>
>my %systems = ( 'riches' =>'1',
> 'loder' =>'1',
> 'yamaguch'=>'1',
> 'gerlich' =>'1');
Do you get paid by the character? :-)
my %systems = ( riches => 1,
loder => 1,
yamaguch=> 1,
gerlich => 1);
>my @allfiles=();
>while (<DATA>) {
>chomp;
>push (@allfiles,$_);
>}
Padding the ol' paycheck huh? You can replace those 4 lines with:
my @allfiles=<DATA>;
chomp(@allfiles);
>my @wanted = grep { /keys %systems_(.*)/ } @allfiles;
my @wanted = grep { my $id = $1 if /^([^_]+)/; $systems{$id} } @allfiles;
or
my $pattern = join '|', sort {$b cmp $a} keys %systems;
my @wanted = grep { /^$pattern/ } @allfiles;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 27 Apr 2001 19:59:36 +0100
From: nobull@mail.com
Subject: Re: Finding all elements in an array matching a certian criteria
Message-Id: <u93daugodj.fsf@wcl-l.bham.ac.uk>
tadmc@augustmail.com (Tad McClellan) writes:
> Ron Hill <hillr@ugs.com> wrote:
> >my %systems = ( 'riches' =>'1',
> > 'loder' =>'1',
> > 'yamaguch'=>'1',
> > 'gerlich' =>'1');
>
> Do you get paid by the character? :-)
> my @wanted = grep { my $id = $1 if /^([^_]+)/; $systems{$id} } @allfiles;
Tad, are _you_ being paid by the character?
my @wanted = grep { /^([^_]+)/ && $systems{$1} } @allfiles;
> my $pattern = join '|', sort {$b cmp $a} keys %systems;
sort? Do you also get paid a bonus for using sort? Double if you use
a comparison function?
> my @wanted = grep { /^$pattern/ } @allfiles;
I think you meant:
my @wanted = grep { /^($pattern)_/ } @allfiles;
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Sat, 28 Apr 2001 07:42:57 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: Functional equivant to =~ operator?
Message-Id: <nwlG6.12793$482.64667@newsfeeds.bigpond.com>
Well it's obvious great minds think alike!
After reading the earlier thread , I've tested the following and it works:
Wanted: function composition using tr, s, etc. operators:
$var2 = s/123/456/g (tr/a-z/A-Z/ ($var));
Perl Solution:
sub apply (&$) {
local $_ = $_[1];
$_[0]->();
$_;
}
$var2= apply {s/123/456/g; tr/a-a/A-Z/} $var;
Is the underlying issue: lc, uc, etc. are functions; s// and tr// are
'operators'?
This would appear to be a Perl design issue.
gtoomey
----------------
<nobull@mail.com> wrote in message news:u9zod2ha35.fsf@wcl-l.bham.ac.uk...
> "Gregory Toomey" <gtoomey@usa.net> writes:
>
> > Maybe I've missed something in my Perl readings, but this has me
confused.
> >
> > We can use the assignment
> > $var1 =~ tr/a-z/A-Z/;
>
> That is not an assignment. That is a mutator.
>
> > Is there an equivalent tr function? Something like
> > $var2 = tr/a-z/A-Z/ ($var1);
>
> You can do:
>
> ($var2 = $var1) =~ tr/a-z/A-Z/;
>
> Or, of course, in this specific case:
>
> $var2 = uc $var1; # Also handles accented chatacters!
>
> If you wish that the =~ syntax could adopt an idiom more like a
> conventional function call...
>
> $var2 = apply { tr/a-z/A-Z/ } $var1;
>
> ...then please see the extensive thread earlier this week where many
> of the leading lights of this newsgroup discuss this exact same
> question at length.
>
> Subject: Idiom: the expression of a copied & substituted string
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
------------------------------
Date: Fri, 27 Apr 2001 19:29:52 GMT
From: "Tuan" <tuan.ngo1@home.com>
Subject: Re: Help Me Obi One You're my Only Hope
Message-Id: <QMjG6.4773$9X6.354652@news1.bnapk1.occa.home.com>
Obi,
I knew you were out there... Being new to Perl Scripting, I am diving into
the Perl tutorials but it is going slowly but surely. Unfortunately time is
running out... I can afford $50 for assistance in understanding how the
particular tool you generate works... I am more interested in the creative
process...
Thank You,
Tuan:)
Obi One <Obi_One@whkjcssss.com> wrote in message
news:9c9ff8$ctu$1@sshuraac-i-1.production.compuserve.com...
> Hello Tuan,
> There is no worry.
> You need a tool, naming them by hand will take too long.
> Tools Are Great. Tools Are Expensive.
> You've told me what you would like your tool to do.
> Tell me what you want to spend for your new tool.
> Then I will tell you how great Tuan's New Tool will or will not be.
>
> Obi Wan Kenobi
>
> Tuan Ngo <tuan.ngo1@home.com> wrote in message
> news:N7RF6.3914$9X6.318353@news1.bnapk1.occa.home.com...
> > Need assistance with writing a Perl Script for the following problem...
> Any
> > help will be much appreciated... I may be able to provide
> compensation.....
> >
> > You've just loaded a CD's worth of reference images from an outside
> company.
> > The images are grouped in "packets" of ten frames each, and are named
> > "DSCN-1.JPG, DSCN-2.JPG ... DSCN-10.JPG," then jump up by a count of 90
to
> > the next "hundreds" place-marker: "DSCN-101.JPG, DSCN-102.JPG ...
> > DSCN-110.JPG," and continue up through the sequence "DSCN-2301.JPG,
> > DSCN-2302.JPG ... DSCN-2310.JPG" giving a total of 240 frames. The
frames
> > were brought online in somewhat of a "random" order, so that frame 8 may
> > have been loaded before frame 2, and "packet" 801-810 may have loaded
> before
> > 301-310.
> > Although the frames were stored in separate "folders" on the CDROM from
> > which they were loaded, all of the frames have now been placed into a
> single
> > directory named: /shots/spi/home/pix/out/home_test_v1/misc_bg8/
> >
> > The structure of the directory you've loaded them into is this:
> >
> > /shots/$SHOWNAME/$SHOTNAME/pix/out/$ELEMENTNAME/$RESOLUTION_$COLORSPACE
> >
> >
>
> --------------------------------------------------------------------------
> --
> > ----
> >
> > Your task is to rename the frames in accordance with SPI standard naming
> > conventions. These include:
> >
> >
> > 1. No capital letters in the filenames
> > 2. No dashes are allowed in the filenames
> > 3. Frame numbers need to be "padded" to four-digits. ie, "1" becomes
> "0001"
> > This is denoted by the symbol # so a range of 1-240 would read 1-240#.
> > 4. The frames should be renamed to match the directory in which they are
> > placed in the following manner:
> >
> >
> > $ELEMENTNAME_$RESOLUTION_$COLORSPACE.#.$EXTENSION
> > So, in other words, each frame should read:
> >
> >
>
/shots/spi/home/pix/out/home_test_v1/misc_bg8/home_test_v1_misc_bg8.0001.jpg
> >
>
/shots/spi/home/pix/out/home_test_v1/misc_bg8/home_test_v1_misc_bg8.0002.jpg
> >
>
/shots/spi/home/pix/out/home_test_v1/misc_bg8/home_test_v1_misc_bg8.0003.jpg
> > ...
> >
>
/shots/spi/home/pix/out/home_test_v1/misc_bg8/home_test_v1_misc_bg8.0240.jpg
> >
> >
> >
> > You have a limited timeframe to rename these frames, as they are going
to
> be
> > sent overseas to another house before the end of their working day. You
> also
> > have good reason to suspect that there will be many more requests just
> like
> > this one.
> >
> >
> >
> >
>
> --------------------------------------------------------------------------
> --
> > ----
> >
> >
> > The challenge is, then:
> >
> >
> > Sitting at a UNIX (Irix 6.5.8) terminal, use whatever methods you prefer
> to
> > rename and resequence these frames into their acceptable naming
> conventions
> > and proper sequential order. You may use any means at your disposal,
> > including most basic scripting languages.
> >
> >
> >
> >
>
>
------------------------------
Date: Fri, 27 Apr 2001 21:35:32 +0200
From: Philip Newton <pne-news-20010427@newton.digitalspace.net>
Subject: Re: Help: PPM on unix?
Message-Id: <5dijet4sut2odaeahek85tja559pdkmr6p@4ax.com>
[Newsgroups trimmed]
On Thu, 26 Apr 2001 19:33:57 GMT,
u518615722@spawnkill.ip-mobilphone.net wrote:
> On windows NT, we have a PPM to
> manager the module,
You do if you have ActivePerl. If you compiled your Perl from scratch,
you wouldn't -- it's not part of the standard Perl distribution.
> do you have similar utility on unix?
ActivePerl (including PPM) also exists for Linux and Solaris.
And, as others have suggested, try 'perl -MCPAN -e shell', which is
pretty much the standard under Unix.
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: 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 783
**************************************