[12144] in Perl-Users-Digest
Perl-Users Digest, Issue: 5744 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 21 14:07:24 1999
Date: Fri, 21 May 99 11:00:25 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 21 May 1999 Volume: 8 Number: 5744
Today's topics:
Re: -> Folkert Meeuw: Write errors and correction (Larry Rosler)
Re: -> Folkert Meeuw: Write errors and correction <emschwar@rmi.net>
Re: Access and Web (I'm lost and tried everything: HELP (Pedro Miguel Raposo)
Re: Can't use string as a hash ref... <aqumsieh@matrox.com>
Re: Dereferencing a filehandle. (Larry Rosler)
Re: Dereferencing a filehandle. <cassell@mail.cor.epa.gov>
Grab string from STDIN <johnny@pahv.xerox.com>
How do I use a regular expression to ignore Java style <jyacken@ibm.net>
Re: Perl "constructors" <jdporter@min.net>
Re: Perl "constructors" <jdporter@min.net>
Re: Perl "constructors" <jdporter@min.net>
Re: Perl "constructors" <emschwar@rmi.net>
Re: Perl "constructors" <jdporter@min.net>
Re: Perl compiler...If or when <gbartels@xli.com>
Re: Process pipe output immediately? (Michel Dalle)
Sorry about the formatting on "What Perl programming bo (anonymous)
Re: Sorting a Multi-dimensional array by specific eleme <aqumsieh@matrox.com>
Re: stripping text with regex <emschwar@rmi.net>
Re: Usin IF gives Internal Server Error?? (I R A Aggie)
Re: Usin IF gives Internal Server Error?? (Larry Rosler)
Re: Utterly poor perl!! (using index) (Andrew Johnson)
Re: Which Perl programming book should I buy? (I R A Aggie)
Re: Which Perl programming book should I buy? (Larry Rosler)
Re: Which Perl programming book should I buy? <cassell@mail.cor.epa.gov>
Re: while ( <FILE> && /match/ ) (I R A Aggie)
Writing a HTML page with perl <efcoelho@123_rio.com>
Re: Writing a HTML page with perl (Pedro Miguel Raposo)
Your good deed for the day <a.currie@macmillan.co.uk>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 21 May 1999 09:57:24 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: -> Folkert Meeuw: Write errors and correction
Message-Id: <MPG.11af30501ec49826989ad8@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <3742C8ED.65FAAEE7@lfi.uni-hannover.de> on Wed, 19 May 1999
16:21:33 +0200, Folkert Meeuw <fmee@lfi.uni-hannover.de> says...
> #!/usr/local/bin/perl -w
> # 1.8 Listings
>
> open (IN, "friends") or die "couldn't open friends $!";
Great start so far!
> @friends = <IN>;
my @friends = <IN>;
> close IN;
> chomp @friends;
> print "Whats your name:\n";
> $name = <STDIN>;
my $name = <STDIN>;
> chomp $name;
> foreach $friend (@friends)
foreach my $friend (@friends)
> {
> if ($name eq $friend)
> {
> print "Hallo $name, good old boy\n";
> }
> else
> {
> print "Hallo, $name\n";
> }
> }
>
> so far so good !
>
> But elsewise, when I write in too: use strict;
> save the scrpit again and I type in a shell: perl -d 1.8.pl
> to run it, the run of the script failed.
See above. Using 'use strict;' is a Good Thing. One of the Good Things
about it is that it helps you protect yourself against typos or
inadvertant clobbering of global variables, by forcing you to declare
all of them.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 21 May 1999 11:16:17 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: -> Folkert Meeuw: Write errors and correction
Message-Id: <xkf3e0qibry.fsf@valdemar.col.hp.com>
Folkert Meeuw <fmee@lfi.uni-hannover.de> writes:
> But elsewise, when I write in too: use strict;
> save the scrpit again and I type in a shell: perl -d 1.8.pl
> to run it, the run of the script failed.
> I don't know why, I'm a newby in perl.
Of course you know why. Perl itself tells you. Now, it's quite possible
you don't understand what those messages mean. For that,
'perldoc perldiag' will give you the meaning behind any error messages
Perl will return.
I would suggest that if you have the program logic working correctly, you
don't need to run it with -d any longer. That will also make it faster to
correct the errors brought to light by 'use strict;'.
-=Eric
------------------------------
Date: Fri, 21 May 1999 17:31:00 GMT
From: Pedro.Raposo@tmn.pt (Pedro Miguel Raposo)
Subject: Re: Access and Web (I'm lost and tried everything: HELP ME!)
Message-Id: <7i458k$1e04i_004@news.telepac.pt>
In article <373F430A.D177EAE9@mail.cor.epa.gov>, "David L. Cassell" <cassell@mail.cor.epa.gov> wrote:
>I'll assume (contrary to Charles' assumption) that you're on a
>win32 box. Otherwise you shouldn't be anywhere near MS Access.
Me too ...
>
>If so, look into the following modules, which are either already
>on your system or readily available and installable from
>www.activestate.com using the ppm program that comes with
>ActiveState Perl. If you don't have this already, you're going
>to have real problems installing stuff properly. If you do
>have this, you should either: [1] already know how to use ppm;
>or [2] be able to read the HTML docs on your system to see how.
>
>You'll want to make sure your system has these modules:
>DBI
>DBD::ODBC
>
>and then you can talk to MS Access using ODBC, just like any
>other ODBC-compliant program.
Been there, done that ... hey, it works!
>> Do I have to use SQL? And what is it? (now you will think what a morron, he
>> should have learned that, well I've read all the stuff, and most programmers
>> dont even try keeping it simple for newbees).
>
>You will have to use SQL to phrase your queries. I suggest you
>go to a computer book store and buy a book on SQL, in addition
>to one on Perl.
I would suggest creating a few queries on Access, assuming you know how to use
those "neat" visual queries (duhhh!), and using the SQL view to get the SQL
code ... fairly simple.
It would help if you told us what OS you're running your Web server (and your
per) on ... Your Access is on a Windows machine, of course.
David, don't give the man a fish, teach him how to catch fish ... but you
don't need to start with sharks :o))
Buy the book on Perl, though ... even if you don't get the hang of it, these
are generally nice books to read ... those guys are really funny, and the
books look really nice on any shelf.
Hope this helped,
Pedro Miguel Raposo
DSI/INF
------------------------------
Date: Fri, 21 May 1999 11:05:30 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Can't use string as a hash ref...
Message-Id: <x3yiu9m1n0n.fsf@tigre.matrox.com>
danielp@best.com (Daniel Parish) writes:
> 'Can't use string ("nk2.2-1.17-RA") as a HASH ref while
> "strict refs" in use at test.pl line 16, <FITFILE> chunk 1.'
> $$i{$ro} = $fitvalue;
>From the piece of code you showed, the only advice I can give is to
replace the above line with:
${$i{$ro}} = $fitvalue;
You had a priblem with precedence.
HTH,
Ala
------------------------------
Date: Fri, 21 May 1999 10:04:20 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Dereferencing a filehandle.
Message-Id: <MPG.11af31ea85d7fab3989ad9@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7i3q8b$ccp$1@bmerhc5e.ca.nortel.com> on Fri, 21 May 1999
10:24:24 -0400, Keith <keithp@comnet.ca> says...
> Can anyone tell me how to show the value of a filehandle in my output?
> I have something like this:
> print "FILE: $_\n";
>
> Where FILE is the filehandle defined earlier in the program.
> I want FILE to show up as the real file name.
That can't be done.
In general, there is no way of recovering the name under which a file
was opened from the filehandle. The file may even have been renamed or
unlinked in the meantime (under some thirty-year-old operating systems).
You opened the file, so presumably you know the name you used to open
it. Use it again!
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 21 May 1999 10:47:23 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Dereferencing a filehandle.
Message-Id: <37459C2B.3A5E81C9@mail.cor.epa.gov>
Keith wrote:
>
> Can anyone tell me how to show the value of a filehandle in my output?
> I have something like this:
> print "FILE: $_\n";
>
> Where FILE is the filehandle defined earlier in the program.
> I want FILE to show up as the real file name.
> Thanks,
Well then, grab a copy of Tom Christiansen's perlopentut and
read through it. This is specifically explained there.
This was posted in this ng about 3 weeks ago, with the word
FMTEYEWTK in the subject line. So you should be able to track
it down through DejaNews (even after they changed their name).
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Fri, 21 May 1999 10:44:36 -0700
From: "Hall, Johnny" <johnny@pahv.xerox.com>
Subject: Grab string from STDIN
Message-Id: <37459B84.2DE0954D@pahv.xerox.com>
O.K. I'm new to perl and this list and almost afraid to ask this
question after seeing some replies to newby's here. Anyway, here
goes...
My first project with perl turned out to be quite complex (for me) as I
am trying to solve our Y2K situation with it. We are a Sun env and what
I need to do is run a tool called sunscan, grab the Y2K patches needed
for $HOST, run wget to "ftp" them from sunsolve, uncompress and untar
them and install them. Everything here is pretty simple for me except I
don't know how to (a) open the output of sunscan in the script (b)
snatch the patch number from the list. Here is a sample from the output
of sunscan.
blah, blah, blah...
Y2K patches needed for this system
----------------------------------
104854-02: SunOS 5.5.1: troff macro patch
104820-01: SunOS 5.5.1: /usr/lib/saf/listen patch
104822-01: SunOS 5.5.1: usr/lib/libadm.so.1 and usr/lib/libadm.a patch
------------------------------------------------------------
H A R D W A R E I N F O R M A T I O N
------------------------------------------------------------
blah, blah, blah...
In this case I want to run sunscan and grab these patches. The append
".tar.Z" to the end and call wget.
Anyway, if someone is feeling like a good Samaritan I would greatly
appreciate it, or you could read this post again and have another laugh
at my ignorance.
Thanks,
Johnny
--
"All you need is ignorance and confidence; then success is sure." --
Mark Twain
------------------------------
Date: Fri, 21 May 1999 13:28:43 -0400
From: "Jacob Yackenovich" <jyacken@ibm.net>
Subject: How do I use a regular expression to ignore Java style comments in a file?
Message-Id: <374597b2@news1.us.ibm.net>
I have close to 30,000 Java files that need to be checked for certain bits
of information. If a line of code is commented out (by using // to comment
the line), I would like to ignore that line completely, and move onto the
next.
Example:
public class myclass extends ListResourceBundle
....
{ "a_key","the value"},
// { "b_key","the other value},
....
In this example the line that contains a_key would be used (so would any
other that does not have a commented line), and the line that contains b_key
needs to be ignored. I have tried to use regular expressions to pattern
match //, but seeing as how the contents of the pattern to be matched are
bounded by / and /, I have ran into somewhat of a brick wall. The Perl books
that I have referenced (Cookbook, Programming, Learning, Nutshell, 21 days,
etc...) all turn up empty to a solution. Any ideas on how to overcome this
one?
Thanks in advance,
Jacob Yackenovich
Research Triangle Park, NC
------------------------------
Date: Fri, 21 May 1999 16:58:28 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Perl "constructors"
Message-Id: <7i43bj$332$1@nnrp1.deja.com>
In article <7hm0qp$d91$1@nnrp1.deja.com>,
armchair@my-dejanews.com wrote:
> I will assume that open() also returns undef on error...
Why assume? From perldoc -f open:
Open returns nonzero upon success, the undefined value otherwise.
> ...as I cannot do
> the following when an invalid filename is given.
>
> my $scalar = open(HANDLE,"my_file");
> if ( $scalar > 0 )
> {
> ... good
> }
> else
> {
> ... error
> }
> The above generates a warning saying that a variable was used as if it
> has already been defined. It was interpreted as "" or 0, but maybe it
> was a mistake.
Not quite.
> To supress this warning assign an initial value to your variables.
That won't help, because
$scalar = open...
completely reassigns the value.
> but I can do: if ( $scalar )
> and get no warnings.
> My question is, what does assigning undef to a variable do - cause it
to
> go away?? Does it undefine the variable, not giving it an undefined
(or
> in SQL terms NULL) value?
undef is very much like the null of sql. It's a special value which is
neither a string, number, or reference, and so generates a warning if
used as such (assuming -w). But undef *is* a valid boolean value,
equivalent to false. You can always test a scalar to see if its
value is the undef value, using the defined() operator. But this is
really only useful for distinguishing undef from other values which
are defined but still false, namely 0, '0', and ''.
--
John Porter
Put it on a plate, son. You'll enjoy it more.
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Fri, 21 May 1999 17:11:24 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Perl "constructors"
Message-Id: <7i443q$3k3$1@nnrp1.deja.com>
In article <7hjs52$190$1@nnrp1.deja.com>,
armchair@my-dejanews.com wrote:
> > :So in effect, Perl has a capability to "overload" a classes
> constructors
> > :then, I take it.
> >
> > No, that's not it. Again you fail to understand.
>
> However you want to term it, if there is more than one constructor for
a
> class, they are "overloaded" to use a C++ term.
Maybe I'm responding this a little late, but anyway --
as you know, constructors can be named anything (any legal identifier,
that is), so it's possible to have more than one without overloading,
because they'll have different names.
> I see:
> package Abc; in Abc.pm
> and in test.pl I see
> use Abc;
> where it is stated that Abc is assumed to be in Abc.pm.
>
> if in Abc.pm I had
> package Xyx;
> how do I use that in test.pl?
It is only a convention that a module define a class with the same
name. So in that example, you could go right ahead and use the
symbols defined in package Abc in your script. If Abc effectively
defines a class, then you can instantiate objects of Abc, even
though the definitions are in Xyz.pm. Perl doesn't care.
use Xyz;
my $xyz = new Xyz;
my $abc = new Abc;
> Perl certainly does not have exceptions that I have seen or are you
> calling die exceptions?
Yes, die is Perl's equivalent of "throw", and eval is analogous to
"try". The main difference in Perl's exceptions is that you have to
deal with every exception generated in an eval; if an exception turns
out to be one you're not interested in, you need to propagate it up
(by calling die again), or it will be discarded. This is in contrast
to C++, Java, etc. in which "uninteresting" exceptions are automatically
propagated.
--
John Porter
Put it on a plate, son. You'll enjoy it more.
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Fri, 21 May 1999 17:33:06 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Perl "constructors"
Message-Id: <7i45ci$4h2$1@nnrp1.deja.com>
In article <7hjerk$p8g$1@nnrp1.deja.com>,
armchair@my-dejanews.com wrote:
> When I am reading
> someone's code, I want to be rolling along and see a new() and know
> immediately that's the constructor, not see Barney() here and Fred()
> there and BamBam() there and have to keep referring to documentation
to
> see what the constructor name was.
As someone mentioned in another msg -- it turns out, in Perl, that
you don't care about this nearly as often as you might in C++.
Also, any well-written class will have constructors with reasonable
names, e.g. new, new_copy, new_from_remote, CreateBlah, etc.
In practice, the vast majority use "new" as the constructor name for
the normal case.
> my $reference = my_class->connect();
>
> So you are saying that one can do:
>
> if ( $reference == undef )
> to see if the object was created (i.e. made a successful connection)
Yes, almost. To test "definedness", you would use the defined()
operator:
if ( defined( $reference ) )
Actually, since undef is a valid boolean value, you can just say:
if ( $reference )
> > A constructor indicates the error with undef. That allows the user
to
> simply
> > say || die "Unable to connect" or whatever.
>
> Where's the rest of the statement?
>
> $my_reference = my_class->connect() || or die "see ya";
>
> Is that it??
Yes!
(But take out the double-bar. Use the low-precedence 'or' only, for
this sort of thing.)
> And in the constructor you do:
>
> if ( connection_made )
> {
> return bless $self;
> }
> else
> {
> return undef;
> }
>
> Is that what you are saying?
Right on. Although I personally might make the constructor itself
die, rather than return undef.
> Since there
> is some internal structure that each uses, there must be some internal
> structure or variable that is holding (or could hold) the number of
> entries in the hash and that could be QUICKLY returned via a Perl
> internal C subroutine. Not to mention people wanting to see how to get
> the number of entries in a hash (probably to determine if it is empty
or
> not in most cases) can find that info in discussions about hashes in
> books or perldata or perlfunc and not have to be chastised for not
> looking at a faq which reveals slow and expensive code that is based
on
> a non-intuitive and confusing concept - "context significance".
In case any confusion remains on this question:
To get the number of entries in a hash quickly, call keys(%hash)
in a scalar context. In fact, this can be thought of as a method
of the object which stores a hash. It does NOT count the entries,
just like scalar(@array) does not count the length of an array, and
length($string) doesn't calculate the length of a string. These
data are stored internally.
--
John Porter
Put it on a plate, son. You'll enjoy it more.
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: 21 May 1999 11:45:43 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: Perl "constructors"
Message-Id: <xkfzp2ygvug.fsf@valdemar.col.hp.com>
John Porter <jdporter@min.net> writes:
> In article <7hjs52$190$1@nnrp1.deja.com>,
> armchair@my-dejanews.com wrote:
> > Perl certainly does not have exceptions that I have seen or are you
> > calling die exceptions?
>
> Yes, die is Perl's equivalent of "throw", and eval is analogous to
> "try". The main difference in Perl's exceptions is that you have to
> deal with every exception generated in an eval; if an exception turns
> out to be one you're not interested in, you need to propagate it up
> (by calling die again), or it will be discarded. This is in contrast
> to C++, Java, etc. in which "uninteresting" exceptions are automatically
> propagated.
It's not only that, though. Perl really only has one type of exception:
$@. It's not even *possible* for Perl to automatically propogate
"uninteresting" exceptions, because there's only one kind. Another
annoying thing is that a subroutine can raise an exception, and the
caller is not forced to deal with it. This severely limits the
usefulness of eval/die as an exception handling mechanism, to my mind.
I'm more than a little uncomfortable with the description of eval/die as
"exception handling", for those very reasons. Error handling, yes. And
don't get me wrong, it's a very useful idiom. But it lacks some of the
basic functionality behind the other exception handling mechanisms I've
used, and there doesn't seem to be an easy way of putting that back in.
-=Eric
------------------------------
Date: Fri, 21 May 1999 17:39:27 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Perl "constructors"
Message-Id: <7i45of$4rm$1@nnrp1.deja.com>
In article <7hmcef$jtk$1@nnrp1.deja.com>,
armchair@my-dejanews.com wrote:
> Yes, I have seen that code as in:
>
> my $scalar = "100";
> $scalar += 10;
> print $scalar; # prints 110
>
> very disturbing indeed.
Man, if this is the sort of thing you find disturbing, then I guess
you are unfamiliar with REAL programming languages, like, say, Scheme,
which would probably make you suicidal.
You really need to get out more.
--
John Porter
Put it on a plate, son. You'll enjoy it more.
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Fri, 21 May 1999 12:18:31 -0400
From: Greg Bartels <gbartels@xli.com>
Subject: Re: Perl compiler...If or when
Message-Id: <37458757.EF2C4F4F@xli.com>
Tom Christiansen wrote:
>
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc,
> Corus <corus@my-dejanews.com> writes:
> :I don't hide my *personal* reason for wanting a compiler. (One without
> :the decompiler) [SCREWED UP WRAPPING BY BROKEN NEWSREADER]
> :It is to hide my code from evil eyes. Or at least make it considerably
> :harder to get at. [SCREWED UP WRAPPING BY BROKEN NEWSREADER]
> :If someone has the skills to succesfully de-compile code that wasn't
> :intended to be "decompileable", then they probably would equally have
> :the skill to not have resort to doing it.
>
> 1. Revise your notion of evil.
> 2. Get a real newsreader.
>
> What is it about this horrible Microsoft world that is so cupiditous?
> Follow the leader, I guess.
>
> Avarice:1 Science:0
>
> --tom
> --
> Those who do not fight the demons within themselves are destined to fight them
> outside themselves...
My reason for wanting a compiler would be that someone could
run my program without having any perl stuff installed.
perl is not yet a universal language, and I have people at
work who have not installed perl on their PC's because
its too much work. We have no system administrator.
and we're an engineering company...
getting off perl specific topic,
as far as revising someone's definition of evil goes,
I've never found a nice, short, concise bit of text
which goes through the pros of open source and the cons
of proprietary code. if someone knows of one, please
email the URL to me.
it seems that there is a lot of 'inertia' to the notion
of ideas as things that can be owned by a singular person
or corporation.
Some people are concerned that Linux might lose some
of its open-source status, as companies start using it,
and developing software for it, and wanting to capitalize
on any additions they make to linux. then you might
get Microsofts version of Linux, for $300, or a
free version from the web, and they are incompatible
with one another.
slightly back to perl topic:
my concern is that there IS a 'sugar daddy' out there,
and they put down the money to have a perl compiler
developed, and then they slap a proprietary copyright
on the code. one-two punch. any open source perl
compiler would have to be written without borrowing
any code from the proprietary code. and any new code on
CPAN that matches their code could be forced to be
removed.
but then, I'm the paranoid type, and always think worst case.
getting on soap box:
if open source is going to flourish to the point
where linux and perl comes installed on every new PC,
then we need to enroll the rest of the world into
the benifits of open-source, not just make them
bad and wrong if they dont support it yet.
Greg
"a pc in every home, and linux and perl on every hard drive."
(open source linux and perl)
------------------------------
Date: Fri, 21 May 1999 17:02:56 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Process pipe output immediately?
Message-Id: <7i43ie$10f$1@xenon.inbe.net>
In article <7i3o0e$qb3$1@nnrp1.deja.com>, Daniel Pfeiffer <occitan@esperanto.org> wrote:
>Hi!
[snip]
>So I want to write a Perl script that automates this, so that I can
>consult crash immediately when tcpdump barks. My problem is, if I read
>in the tcpdump output via a pipe, it will be buffered, making it
>useless. How can I prevent this or what alternatives are there? I
>imagine, this could be achieved with pseudo-terminals, but how do I open
>and connect one from Perl?
I haven't tested this, but couldn't you simply set off buffering ($|=1) on
your pipe and read it in ? Or use a select() loop ?
For what it's worth,
Michel.
------------------------------
Date: Fri, 21 May 1999 17:35:59 GMT
From: quikscor@ix.netcom.com (anonymous)
Subject: Sorry about the formatting on "What Perl programming book should I buy"
Message-Id: <37459910.7237748@nntp.ix.netcom.com>
I cut and pasted that message from another location. I apologize, I
won't do it again. Didn't mean to hurt anybody's eyes....
Thanks for the suggestions (Cookbook). I'm off to Amazon....
- j
------------------------------
Date: Fri, 21 May 1999 11:07:46 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Sorting a Multi-dimensional array by specific element
Message-Id: <x3yhfp61mwt.fsf@tigre.matrox.com>
David Lindsay <david.lindsay@columbian.com> writes:
> "ADV" "Cash" 1999 "100320000000" 04/01/99 412.3
>
> I want to sort the array by the 2nd element, then the 4th.
> To load the array I use:
> while (defined ($inrec = <INFILE>))
> {
> chomp $inrec;
> push @gl, [ split ' ', $inrec ];
> }
@gl = sort {
$a->[1] cmp $b->[1]
||
$a->[3] <=> $b->[3]
} @gl;
HTH,
Ala
------------------------------
Date: 21 May 1999 11:08:30 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: stripping text with regex
Message-Id: <xkf675mic4x.fsf@valdemar.col.hp.com>
Anand <anand@my-dejanews.com> writes:
> tadmc@metronet.com (Tad McClellan) wrote:
> > No, you need an operator to do that.
> > A regex is not enough.
>
> Why? This regex will do it.
>
> $str="chris";
> if ($str =~ /^\W*(.)/) {
> print $1;
> }
>
> It prints "c" for me like the original poster wanted.
Yes, but it relies on the *operators* =~ and m// (the 'm' here is
implicit) to do the work. Your regex is simply '^\W*(.)'. By itself,
not too helpful. But when combined with the aforementioned operators,
happy things come about.
-=Eric
------------------------------
Date: 21 May 1999 17:09:53 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Usin IF gives Internal Server Error??
Message-Id: <slrn7kb50f.aku.fl_aggie@thepentagon.com>
On Fri, 21 May 1999 08:49:00 -0700, LEB <airman@inreach.com>, in
<3745806C.BBE2A7B5@inreach.com> wrote:
+ IF ($mediaurl ne "") {
Hmmm...
IF ne if, if you know what I mean...the conditional 'if ()' construct is
lower case...
James
------------------------------
Date: Fri, 21 May 1999 10:09:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Usin IF gives Internal Server Error??
Message-Id: <MPG.11af3311d7c41f96989adb@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <3745806C.BBE2A7B5@inreach.com> on Fri, 21 May 1999 08:49:00
-0700, LEB <airman@inreach.com> says...
> When I add the IF statement as below, I start getting Internal Server
> Error.??? Any ideas? Without the IF statement, all works fine. I am
> trying to say that IF the varialble MEDIAURL is not EMPTY print the
> following line to the file.
>
> Thanks for any input.
In Perl, the 'if' statement is not the 'IF' statement. There isn't any
of the latter! (In fact, all Perl keywords are lower-case only.)
Run your programs first from the command line to make sure thay compile
correctly, before throwing them into the CGI pot.
> open(LIST,">$path") || &error("Can't open $path");
Use $! in your diagnostic.
> print LIST "<HTML>\n";
> print LIST "<HEAD>\n";
>
> IF ($mediaurl ne "") {
> print LIST "$mediaurl \n";
> }
>
> print LIST "TEST \n";
> print LIST "</HEAD>\n";
> print LIST "<TITLE></TITLE>\n";
> print LIST "<BODY>\n";
> print LIST "</BODY>\n";
> print LIST "</HTML>\n";
> close(LIST);
Use a 'here-document' instead of all those print statements.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 21 May 1999 17:03:38 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: Utterly poor perl!! (using index)
Message-Id: <Klg13.1052$Q_5.36249@news2.rdc1.on.home.com>
In article <7i4097$pp$1@nnrp1.deja.com>,
Richard Lawrence <ralawrence@my-dejanews.com> wrote:
! Here is some utterly poor code to take each line from a file txt.txt
! and see if that line contains the words on the command line ie.
!
! prog.pl fish -- will list all lines with fish in it
! prog.pl fish chips -- will list all lines with fish AND chips in it
!
! Two problems:
!
! 1. Its case sensitive - the only way I can think of making it case
! insensitive is by copying both bits of text to temp variables,
! lowercasing them and then compairing but that is HORRIBLE. Can anyone
! suggest a better solution?
[snip]
Use regular expressions...
Here's one way by mapping your keywords into a
pattern of look-aheads:
#!/usr/bin/perl -w
use strict;
my @requests = qw/fish chips/;
my $pattern = join('',map{"(?=.*\Q$_\E)"}@requests);
while(<DATA>){
print if m/^$pattern/oi;
}
__END__
blah fish and chips
blah just fish
ChiPs blah fish blah
This may not be the most efficient solution, but it's simple and
may suffice for your purposes.
regards
andrew
--
Andrew L. Johnson http://members.home.com/andrew-johnson/
"Where the hell are my fries, kid?"
-Tom Christiansen, on comp.lang.perl.misc
------------------------------
Date: 21 May 1999 16:59:59 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Which Perl programming book should I buy?
Message-Id: <slrn7kb4dt.aku.fl_aggie@thepentagon.com>
On Fri, 21 May 1999 15:43:57 GMT, anonymous <quikscor@ix.netcom.com>, in
<37457f1c.592487@nntp.ix.netcom.com> wrote:
+ database tasks I want to perform. And it seems to be a good reference
+ book, but not a good technique book, which is what I need.
If you're looking for code snippets + explainations, you probably want
the Ram book (aka Perl Cookbook).
James
------------------------------
Date: Fri, 21 May 1999 10:05:52 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Which Perl programming book should I buy?
Message-Id: <MPG.11af324ab1c6e8a4989ada@nntp.hpl.hp.com>
In article <37457f1c.592487@nntp.ix.netcom.com> on Fri, 21 May 1999
15:43:57 GMT, anonymous <quikscor@ix.netcom.com> says...
>
> "Learning Perl" and it's a good intro for me. I
> already program in C++ and Java and am
> familiar with UNIX commands.
>
> I haven't purchased "Programming Perl" because of what
> I've read in the Amazon
> reviews. Apparently there's nothing to help me with
> the database tasks I want to
> perform. And it seems to be a good reference book,
> but not a good technique book, which
> is what I need. I may also need to take an OO
> approach to what I'm designing, I'm not sure
> at this point.
>
> Any suggestions on what Perl programming book I should
> buy?
The Perl Cookbook.
What the heck is wrong with your line formatting???
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 21 May 1999 10:57:33 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Which Perl programming book should I buy?
Message-Id: <37459E8D.BA8118CC@mail.cor.epa.gov>
anonymous wrote:
>
> "Learning Perl" and it's a good intro for me. I
> already program in C++ and Java and am
> familiar with UNIX commands.
Good. With your background, you'd probably get a lot out of
"Programming Perl". You may also want to take the time to read
the extensive docs which come with your Perl install.
> I haven't purchased "Programming Perl" because of what
> I've read in the Amazon
> reviews. Apparently there's nothing to help me with
> the database tasks I want to
> perform. And it seems to be a good reference book,
> but not a good technique book, which
> is what I need. I may also need to take an OO
> approach to what I'm designing, I'm not sure
> at this point.
Well, there is some good OO stuff in the camel. But you can
get all the OO you need from reading the on-line docs.
perldoc perl
will give you a list of sections (and their subjects).
If you're comfortable enough with references and data structures
(and a few other things) in Perl, you'll want to read
the perltoot (OO tutorial), perlobj, perltie, and perlbot
manpages.
> Any suggestions on what Perl programming book I should
> buy?
Check out the ram book, the "Perl Cookbook" by Tom Christiansen
and Nathan Torkington. It's heavy on technique and example,
and covers at least part of the database tasks you want.
It is also *correct*, which is more than one can say about
a lot of the computer language books out there.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 21 May 1999 17:06:37 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: while ( <FILE> && /match/ )
Message-Id: <slrn7kb4qb.aku.fl_aggie@thepentagon.com>
On 21 May 1999 11:58:24 -0400, Victor Eijkhout <eijkhout@prancer.cs.utk.edu>, in
<omyaiipg7z.fsf@prancer.cs.utk.edu> wrote:
+ Ok, so that doesn't work. Why?
Because you're not understanding how to use while() with filehandles...
+ $_=<FILE>;
+ while ( /match/ ) { .... ; $_=<FILE>; }
+
+ which is ugly.
No kidding. What you mean to say is this:
while(<FILE>) { # primes $_ if <FILE> has something
if (/match/) {
#do your match stuff here
}else{
last;
}
}
Better, yes? If I'm groking your code correctly, if you don't have a match,
you want to exit the loop? yes? if not, then zap the 'else{ ... }' chunk
of the if condtional.
James
------------------------------
Date: Fri, 21 May 1999 14:07:39 -0300
From: "Eng. Edilson Francioni Coelho" <efcoelho@123_rio.com>
Subject: Writing a HTML page with perl
Message-Id: <374592DB.A45B2C6E@123_rio.com>
Hi,
I'm a newbie and I'd like to write a HTML page from perl.
I have once once done it starting with
print "Content-type: text/html\n\n";
and then printing everything else line by line, making the special
characters preceded by the backslash.
It worked fine, but it gave me a lot of work preparing everything. I
have once seen such a script doing things differently, reprinting a
whole block of HTML without regards to special characters in about the
same way that the tags <pre></pre> works in HTML. I have not been able
to find it in my hard disk and in the lots of perl tutorials I've been
searching today.
Can anyone tell me how it's done?
Also, can a block of text be added to the middle of an ordinary HTML
page in the same way an image can be? If so, how should I do it? For
adding a script, I have added the header
print "Content-type: image/jpg\n";
to the script and made my script look like a simple image file in the
HTML file with:
<img src="../cgi/script.pl">
Despite I know the header should read "text/txt", what should (or could)
be used in the HTML file to call the script and print a text there?
TIA
Edilson
(should anyone want to e-mail me, please change the "_" for "-" in my
domain name)
------------------------------
Date: Fri, 21 May 1999 17:44:18 GMT
From: Pedro.Raposo@tmn.pt (Pedro Miguel Raposo)
Subject: Re: Writing a HTML page with perl
Message-Id: <7i461i$1e04i_006@news.telepac.pt>
In article <374592DB.A45B2C6E@123_rio.com>, "Eng. Edilson Francioni Coelho" <efcoelho@123_rio.com> wrote:
>Hi,
>
>I'm a newbie and I'd like to write a HTML page from perl.
>
>I have once once done it starting with
>
> print "Content-type: text/html\n\n";
>
>and then printing everything else line by line, making the special
>characters preceded by the backslash.
>
>It worked fine, but it gave me a lot of work preparing everything. I
>have once seen such a script doing things differently, reprinting a
>whole block of HTML without regards to special characters in about the
>same way that the tags <pre></pre> works in HTML. I have not been able
>to find it in my hard disk and in the lots of perl tutorials I've been
>searching today.
>
>Can anyone tell me how it's done?
Sure ... use "here-documents":
# ---------------
print <<EndOfText;
Content-type: text/html
<html>
<head>Header Text</head>
<body>
This is normal text
</body>
</html>
EndOfText;
# ---------------
>
>Also, can a block of text be added to the middle of an ordinary HTML
>page in the same way an image can be? If so, how should I do it? For
>adding a script, I have added the header
>
> print "Content-type: image/jpg\n";
>
>to the script and made my script look like a simple image file in the
>HTML file with:
>
> <img src="../cgi/script.pl">
>
>Despite I know the header should read "text/txt", what should (or could)
>be used in the HTML file to call the script and print a text there?
>
Aren't your overlooking the <blockquote></blockquote> tag ?
HTH,
Pedro Miguel Raposo
DSI/INF
------------------------------
Date: Fri, 21 May 1999 18:12:43 +0100
From: "Aidan Currie" <a.currie@macmillan.co.uk>
Subject: Your good deed for the day
Message-Id: <hug13.118$uh.2945@newreader.ukcore.bt.net>
Hey guys,
I was hoping somebody could give me (a sad Perl dimwit) a hand.
I have a Word doc that is 4 chapters long and would like to write some Perl
(I think it's appropriate) so that when I save my Word doc as HTML, and open
it in my browser, the chapters will automatically be set up in my favorites.
I'd really appreciate some direction on this.
Many thanks,
Aidan
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5744
**************************************