[8396] in Perl-Users-Digest
Perl-Users Digest, Issue: 2013 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 3 18:07:31 1998
Date: Tue, 3 Mar 98 15:00:26 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 3 Mar 1998 Volume: 8 Number: 2013
Today's topics:
Re: [Q] How to redirect STDERR to a subroutine? (Mark W. Schumann)
Re: [Q] How to redirect STDERR to a subroutine? (Kevin Reid)
Re: Conflict in this Newsgroup (Mike Heins)
Re: Controlling TWO input files (merging) (Greg Bacon)
Re: Easy Unix Problem (4 U Guys) (Elf Sternberg)
Re: Easy Unix Problem (4 U Guys) (Elf Sternberg)
http:// replacement <kelby@mplx.com>
Re: http:// replacement <jdf@pobox.com>
Re: http:// replacement <uri@sysarch.com>
Re: http:// replacement (Craig Berry)
Re: NOT matching a string, part ii miko@idocs.com
Re: NOT matching a string, part ii (Jim Allenspach)
Re: Open file as a result of form input !! (Andrew M. Langmead)
Re: Open file as a result of form input !! (I R A Aggie)
Re: Perl performs a second miracle. Prepare for canoni <mishra.aditya@emeryworld.com>
Re: Perl QRG(Quick Reference Guide) (Jack Ostroff)
special characters in PRINT <russwyte@pcisys.net>
Re: special characters in PRINT (Andrew M. Langmead)
subdirectory search? <mrpc1@hotmail.com>
Re: subdirectory search? (Kevin B Cohen)
Re: Summing Up Array Values - How Do I? (Craig Berry)
Re: Summing Up Array Values - How Do I? <uri@sysarch.com>
Re: The -w switch (was Re: better way to do this?) (Craig Berry)
Re: The -w switch (was Re: better way to do this?) <jsd@hudsucker.gamespot.com>
tr question <wbpatto@wmccmsvr.ssr.hp.com>
Re: tr question (Andy Lester)
Re: tr question <jdf@pobox.com>
Re: tr question (Craig Berry)
Re: webserver configuration/cgi.pm/nt (Curtis)
Re: What is PERL? Learn JAVA instead? (Greg Bacon)
Re: What is PERL? Learn JAVA instead? (Frank)
Re: What is PERL? Learn JAVA instead? <mrpc1@hotmail.com>
Re: Why doesn't "tr/\x0D//d" work? (Dave Till)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 3 Mar 1998 16:46:42 -0500
From: catfood@apk.net (Mark W. Schumann)
Subject: Re: [Q] How to redirect STDERR to a subroutine?
Message-Id: <6dhto2$kq6@junior.apk.net>
In article <34FC2645.1C13@min.net>, John Porter <jdporter@min.net> wrote:
>What an excellent and worthy question!
I bow.
>I hope you have at least perl 5.4, because if you do, you have
>the TIEHANDLE capability of tie. As with other ties, you need
>to make a new class to implement your desired functionality.
>Here's and extremely simple example which approximates your need:
And I bow again. This is exactly the help I needed. Thank you.
--
Mark W. Schumann | catfood@apk.net
Why should I change or hide my return address to deter spammers?
I just loop the garbage right back at 'em.
------------------------------
Date: Tue, 3 Mar 1998 17:10:17 -0500
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: [Q] How to redirect STDERR to a subroutine?
Message-Id: <1d5b9eu.15lzq6a1h76l4wN@slip166-72-108-197.ny.us.ibm.net>
Mark W. Schumann <catfood@apk.net> wrote:
> the Log::write method. The idea is for
>
> print STDERR "We print anything";
>
> to be equivalent to
>
> $logobject->write ("We print anything");
See "perltie" in your documentation for information about tying
filehandles.
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: 3 Mar 98 22:09:12 GMT
From: mikeh@minivend.com (Mike Heins)
Subject: Re: Conflict in this Newsgroup
Message-Id: <34fc7f88.0@news.one.net>
NerveGas <NerveGas@see_signature.com> wrote:
>
> I saw a very good quote today, that went more or less like this:
> "Learners inherit the world when it changes, the 'learned' find
> themselves beautifully prepared to survive in a world that no longer
> exists." Sometimes, I wonder wether the "experts" are not in the latter
> category, when all of this ranting and raving takes place.
I tend to agree, but the people best positioned to be learners are
those who listen to the learned and apply their fresh perspective to
the result.
And it is very possible to be learned and a learner at the same time --
it is a matter of attitude. I hope I fall into both categories.
Regards,
Mike Heins http://www.minivend.com/ ___
Internet Robotics |_ _|____
There ain't nothin' in this world 131 Willow Lane, Floor 2 | || _ \
that's worth being a snot over. Oxford, OH 45056 | || |_) |
--Larry Wall <mikeh@minivend.com> |___| _ <
513.523.7621 FAX 7501 |_| \_\
------------------------------
Date: 3 Mar 1998 20:47:59 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: Rich Pinder <rpinder@usc.edu>
Subject: Re: Controlling TWO input files (merging)
Message-Id: <6dhq9v$t0s$1@info.uah.edu>
[Posted and mailed]
In article <34FC2C8D.643DA5AF@usc.edu>,
Rich Pinder <rpinder@usc.edu> writes:
: I'm trying to read two files at the same time, keeping file pointer in
: sync on records of each file, and end up 'merging' info from line 1 of
: file A with line 1 of file B.
:
: i tried adding a second file handle in the while statement...but it
: didnt like that !!
That's because
while (<HANDLE>) {
is equivalent to
while (defined($_ = <HANDLE)) {
It's unfortunate for you that there's not convenient shorthand notation
for merging two files, so you'll have to do it manually:
while (defined($a = <FIRST>) && defined($b = <SECOND>)) {
chomp($a, $b);
print "$a $b\n";
}
## catch files of differing lengths
if (defined $a and not defined $b) {
print $a, <FIRST>;
}
elsif (not defined $a and defined $b) {
print <SECOND>;
}
See if you can figure out the reason for the asymmetry in the
if/elsif pair at the end.
Hope this helps,
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: 3 Mar 1998 21:16:41 GMT
From: elf@halcyon.com (Elf Sternberg)
Subject: Re: Easy Unix Problem (4 U Guys)
Message-Id: <6dhrvp$aab$1@brokaw.wa.com>
In article <6dh8qi$skp$1@redwood.shu.ac.uk>
djsuther@pine.shu.ac.uk (Darius Sutherland) writes:
>I wonder if any of u unix gurus can help me with a small problemo...
>I have a file with data as such :
>9600012301FDTF02FTDT03FFTF04TFDD05TDFF06TTTT*
>Using the unix tools such as awk, grep cmp, sed e.t.c i wish to seperate this
>data into the format :
>96000123
>01FDTF
>02FTDT
>03FFTF
>04TFDD
>05TDFF
>06TTTT
#!/usr/local/bin/perl
while(<STDIN>) {
($key, $fields) = (m{^(\d{8})(.*)});
print "$key\n";
$i = 0; @fields = ();
while ($i < length($fields)) { for(0..5) { @fields[$i / 6] .= substr($fields, $i++, 1) } }
foreach (@fields) { print "$_\n" }
print "\n";
}
__END__
>Thats basically it
>
>If its not too much trouble another step would be to format the data as :
>
>96000123
>01 FF DF TT FF
>02 FF TT DF TT
>03 FF FT TT FF
>04 TF FT DT DT
>05 TF XF FT FF
>06 TT TF TF FF
Where did that extra data every line come from? Assuming it's just
a typo (as it corresponds to nothing in your exemplary data line), the answer
is:
#!/usr/local/bin/perl
while(<STDIN>) {
($key, $fields) = (m{^(\d{8})(.*)});
print "$key\n";
$i = 0; @fields = ();
while ($i < length($fields)) { for(0..5) { @fields[$i / 6] .= substr($fields, $i++, 1) } }
foreach $field (@fields) {
$i = 0; @res = ();
while ($i < length($field)) { for(0..1) {
@res[$i / 2] .= substr($field, $i++, 1) }
}
print join(' ', @res), "\n";
}
print "\n";
}
__END__
Summary? Learn Perl. It'll make your life soooo much easier.
And these days it's as standard a Unix tool as AWK. And better than
AWK at so many thing. I'm sure there are ways serious Perl hackers
could turn this into a couple of one liners, but my laziness[1]
extended to not wracking my brains too hard for the solution...
To those reading this on comp.lang.perl, is there an easier
way to split a line 'every nth character' without the cockamamie
while/for/substr construction I've got up there? I actually have
wracked my brains on this before without coming up with a satisfactory
answer.
Elf
[1] According to Perl programmers, the three virtues of programming
are hubris ("The world needs that and *I* can supply it!"), impatience
("... now!"), and laziness ("... without re-inventing the wheel!").
--
It is forbidden to laugh again Elf M. Sternberg
We maim our joys or hide them www.halcyon.com/elf
Horses are made of chromium steel
And little fat men shall ride them. - T.S. Eliot
------------------------------
Date: 3 Mar 1998 21:46:17 GMT
From: elf@halcyon.com (Elf Sternberg)
Subject: Re: Easy Unix Problem (4 U Guys)
Message-Id: <6dhtn9$bjr$1@brokaw.wa.com>
Yes, I know, it's tacky to follow up one's own postings,
but thinking about it, I came up with these:
#!/usr/local/bin/perl
while(<STDIN>) {
($key, @fields) = unpack("A8" . "A6" x ((length($_) - 8) / 6), $_);
print "$key\n", join("\n", @fields), "\n\n";
}
__END__
and to do the space-seperate version:
#!/usr/local/bin/perl
while(<STDIN>) {
($key, @fields) = unpack("A8" . "A6" x ((length($_) - 8) / 6), $_);
@fields = map { join(' ', unpack("A2" x (length($_) / 2), $_)) } @fields;
print "$key\n", join("\n", @fields), "\n\n";
}
__END__
Elf
--
It is forbidden to laugh again Elf M. Sternberg
We maim our joys or hide them www.halcyon.com/elf
Horses are made of chromium steel
And little fat men shall ride them. - T.S. Eliot
------------------------------
Date: Tue, 3 Mar 1998 16:14:52 -0500
From: "Kelby Valenti" <kelby@mplx.com>
Subject: http:// replacement
Message-Id: <6dhrvd$6rl@aaron.hamilton.edu>
I want to replace a link within a body of text with it's actual link. For
example:
"Look at http://~~~~~~~~~~~ for more info."
would be "Look at <a
href=http://~~~~~~~~~~~~~~~>http://~~~~~~~~~~~~~~</a> for more info."
I would like to replace http://~~~~~~~ with <a
href=http://~~~~~~~~~>http://~~~~~~~~</a>. Is there any way to do this?
Thank you everybody,
Kelby
------------------------------
Date: 03 Mar 1998 16:51:23 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: http:// replacement
Message-Id: <7m6be944.fsf@news.concentric.net>
"Kelby Valenti" <kelby@mplx.com> writes:
> I want to replace a link within a body of text with it's actual link.
I'm sorry to frustrate you, but this newsgroup is really oriented
towards helping you with specific problems you might encounter in your
use of Perl. I'm guessing that you haven't yet learned Perl. If
that's indeed the case, you might want to point your web browser at
http://www.perl.com/
and find out what resources are best for absolute beginners.
If you DO already know Perl, then please post some code that isn't
working the way you think it's supposed to, and I (for one) will be
happy to help you.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: 03 Mar 1998 17:18:48 -0500
From: Uri Guttman <uri@sysarch.com>
To: "Kelby Valenti" <kelby@mplx.com>
Subject: Re: http:// replacement
Message-Id: <x77m6bzad3.fsf@sysarch.com>
"Kelby Valenti" <kelby@mplx.com> writes:
> I want to replace a link within a body of text with it's actual link. For
> example:
> "Look at http://~~~~~~~~~~~ for more info."
> would be "Look at <a
> href=http://~~~~~~~~~~~~~~~>http://~~~~~~~~~~~~~~</a> for more info."
> I would like to replace http://~~~~~~~ with <a
> href=http://~~~~~~~~~>http://~~~~~~~~</a>. Is there any way to do this?
yes. read about it in the perl books or the parlfaq or perlre
when you have done that and still can't do it, repost the question
uri
--
Uri Guttman SYStems ARCHitecture and Software Engineering
uri@sysarch.com Have Perl, Will Hack
http://www.sysarch.com (781) 643-7504 x*2 FAX: (781) 643-2710
Try the Best Search Engine on the Net --------> http://www.northernlight.com
------------------------------
Date: 3 Mar 1998 22:18:05 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: http:// replacement
Message-Id: <6dhvit$l76$3@marina.cinenet.net>
Kelby Valenti (kelby@mplx.com) wrote:
: I want to replace a link within a body of text with it's actual link. For
: example:
: "Look at http://~~~~~~~~~~~ for more info."
: would be "Look at <a
: href=http://~~~~~~~~~~~~~~~>http://~~~~~~~~~~~~~~</a> for more info."
: I would like to replace http://~~~~~~~ with <a
: href=http://~~~~~~~~~>http://~~~~~~~~</a>. Is there any way to do this?
Your big problem is figuring out where the end of the ~~~ part is; this is
difficult to do in a fully general way. If we presume that it will
*always* be whitespace (as in your example), then
s!(http://\S*)!<a href="$1">$1</a>!g;
If the url can be terminated by things other than whitespace, you've got
a more complicated problem.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Tue, 03 Mar 1998 14:54:19 -0600
From: miko@idocs.com
Subject: Re: NOT matching a string, part ii
Message-Id: <6dhqko$tl8$1@nnrp1.dejanews.com>
In article <6dhhn7$jhl$1@nnrp1.dejanews.com>, miko@idocs.com (that's me)
wrote:
[a bunch of stuff about parts of an expression NOT matching a string]
In response to an early, uh, response, I thought I'd head off one line of
thought about this question. /(X.*)test/ is not what I'm looking for.
This expression is too greedy. I need something would work for these
examples:
For the string "X whatever test test" it would find "X whatever "
For the string "X hi there temp test" it would find "X hi there temp "
For the string "Xtest" it would find "X"
Much thanks to the early respondent who had the (alas not quite what I needed)
abovementioned idea.
-miko
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 3 Mar 1998 15:30:05 -0600
From: jima@MCS.COM (Jim Allenspach)
Subject: Re: NOT matching a string, part ii
Message-Id: <6dhsot$q7h@Jupiter.Mcs.Net>
>In response to an early, uh, response, I thought I'd head off one line of
>thought about this question. /(X.*)test/ is not what I'm looking for.
>This expression is too greedy.
Try a minimal match, then:
/(X.*?)test/
Check out perlre in your local Perl documentation for info on this and
other helpful RE features.
>Much thanks to the early respondent who had the (alas not quite what I needed)
>abovementioned idea.
You're welcome. HTH.
jma
--
Jim Allenspach Hacking Perl since 1994.
jima at mcs dot com Perl: Live free or die $!;
Chicago IL
------------------------------
Date: Tue, 3 Mar 1998 20:54:58 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Open file as a result of form input !!
Message-Id: <Ep9GrM.8y7@world.std.com>
bsafwat@egyptonline.com (Baher M. Safwat) writes:
>I am new to Perl,
>I use netscape enterprise server as a web server
>runninig on Solaris 2.5.1
>I designed a simple page to get users input
>as a result of that input I will open some file and add to it
>but ...
>it generate a server error
>when I comment the "open" line and "close" line
>the program return default result Correctly!
Check the documentation on what the die() function does. It may not be
what you want for a script that communicates with the server using the
CGI protocol.
But I'd advise against trying to to fix this error by simply omitting
the die() term. You still want to ensure that the program has
succeeded in getting access to the file. You probably just want to
change the "die()" to some other sort of error reporting.
If you were using the CGI.pm module, instead of reimplenting its
functionality for yourself, you could use the "CGI::Carp
'fatalsToBrowser' mode so that error messages get written to the
browser instead of being deposited wherever the server decides to put
them. (Probably some sort of error log. Check with the servers
documentation to be sure.)
--
Andrew Langmead
------------------------------
Date: Tue, 03 Mar 1998 17:15:57 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Open file as a result of form input !!
Message-Id: <fl_aggie-0303981715580001@aggie.coaps.fsu.edu>
In article <6dho2o$ahn$2@flotsam.uits.indiana.edu>, bdwheele@indiana.edu
(Brian Wheeler) wrote:
+ As a hint, your open statement is really gross. I'd use:
+ open(HAND1,">$filename") or die "ouch.";
Additional 2 cents: let 'die' print out the contents of $! as well:
open(HAND1,">$filename") or die "ouch. $!";
It'll provide the system diagnostic error in a human-readable form.
James - like "file not found" or "permission denied"
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: Tue, 3 Mar 1998 14:20:53 -0800
From: "Mishra, Aditya" <mishra.aditya@emeryworld.com>
Subject: Re: Perl performs a second miracle. Prepare for canonizaton!
Message-Id: <6dhtqj$2ejk@ljcqs003.cnf.com>
Get your perl code checked by a vet
(It probably has developed dengue fever from the symptoms you describe.)
Also for sick code you should post to the doctor's newsgroup.
I hope it is ok in the morning
Lotsa luck
------------------------------
Date: 3 Mar 1998 21:49:22 GMT
From: jack_h_ostroff@groton.pfizer.com (Jack Ostroff)
To: allen@glenturret.co.uk
Subject: Re: Perl QRG(Quick Reference Guide)
Message-Id: <6dhtt2$p6h1@mascagni.pfizer.com>
In article <34FC6C18.C1471B27@glenturret.co.uk>, Allen W Hutcheson <allen@glenturret.co.uk> writes:
> Hi,
>
> Does anyone know of a Perl quick reference guide they could point me to
> ? Preferably in typical quick reference guide format. Any file format
> will do.
>
First, please try to avoid posting in MIME. It produces a lot of clutter
which makes it hard for many of us to see the bit of message in the midst.
I have a Perl Quick Reference Guide (postscript) with the following
author info:
---------------------------- author info -----------------------------
Johan Vromans jvromans@squirrel.nl
Squirrel Consultancy Haarlem, the Netherlands
http://www.squirrel.nl http://www.xs4all.nl/~jvromans
----------------------------------------------------------------------
I just tried and failed to connect to that web site. I don't remember
where I got the original (www.perl.org?)
------------------------------
Date: Tue, 3 Mar 1998 14:29:39 -0700
From: "Russell White" <russwyte@pcisys.net>
Subject: special characters in PRINT
Message-Id: <6dhscu$7sp$1@newman.pcisys.net>
Please excuse this obviously simple question, but I am having a terrible
time finding an answer.
I have only been using Perl for about a week now, and have implemented a
guestbook that generates some HTML on the fly. My problem is that when I run
the script I usually have a load of errors because I am using special
characters in my PRINT statements that I should be marking with the '\'
character. I have found a partial fix by using the qq! method in my PRINT
statements, but that only helps for quotes. Are '#''s and "@"'s also
reserved characters? I have yet to find any documentation that spells out
which characters must be flagged with the '\' tag. Example code follows.
print qq!
<HTML>
<HEAD>
<TITLE>No Comments</TITLE>
</HEAD>
<BODY BACKGROUND="http://www.pcisys.net/~russwyte/images/033.jpg"
TEXT="#003399" BGCOLOR="#FFFBF0">
<FORM ACTION="http://www.pcisys.net/~russwyte/cgi-bin/guestbook.cgi"
METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
<P ALIGN="CENTER"><FONT SIZE="7" COLOR="#000000">Comments Blank</FONT></P>
<P ALIGN="CENTER"><FONT SIZE="5" COLOR="#000000">The Comments section of the
form must be completed.</FONT></P>
<P ALIGN="CENTER"><FONT SIZE="5" COLOR="#000000">Please include a comment in
your entry.</FONT></P>
<CENTER>
<P>
<TABLE BORDER="10" WIDTH="496" HEIGHT="286" BGCOLOR="#000000">
<TR>
<TD WIDTH="159" HEIGHT="36" BGCOLOR="#66CCCC">Name:</TD>
<TD WIDTH="307" HEIGHT="36" BGCOLOR="#006666"><INPUT TYPE="TEXT"
NAME="realname" SIZE="25"></TD>
</TR>
<TR>
<TD WIDTH="159" BGCOLOR="#66CCCC">E-Mail Address:</TD>
<TD WIDTH="307" BGCOLOR="#006666"><INPUT TYPE="TEXT" NAME="username"
SIZE="25"></TD>
</TR>
<TR>
<TD WIDTH="159" BGCOLOR="#66CCCC">Home Page URL:</TD>
<TD WIDTH="307" BGCOLOR="#006666"><INPUT TYPE="TEXT" NAME="url"
SIZE="25"></TD>
</TR>
<TR>
<TD WIDTH="159" BGCOLOR="#66CCCC">City:</TD>
<TD WIDTH="307" BGCOLOR="#006666"><INPUT TYPE="TEXT" NAME="city"
SIZE="25"></TD>
</TR>
<TR>
<TD WIDTH="159" BGCOLOR="#66CCCC">State:</TD>
<TD WIDTH="307" BGCOLOR="#006666"><INPUT TYPE="TEXT" NAME="state"
SIZE="25"></TD>
</TR>
<TR>
<TD WIDTH="159" BGCOLOR="#66CCCC">Country:</TD>
<TD WIDTH="307" BGCOLOR="#006666"><INPUT TYPE="TEXT" NAME="country"
SIZE="25"></TD>
</TR>
<TR>
<TD WIDTH="159" HEIGHT="175" VALIGN="TOP" BGCOLOR="#66CCCC">Comments:<BR>
<BR>
<BR>
</TD>
<TD WIDTH="307" HEIGHT="175" BGCOLOR="#006666"><TEXTAREA NAME="comments"
ROWS="7" COLS="23"></TEXTAREA></TD>
</TR>
<TR>
<TD WIDTH="159" BGCOLOR="#66CCCC"><INPUT TYPE="SUBMIT" NAME="Submit"
VALUE="Re-Submit"><INPUT TYPE="RESET" NAME="Reset" VALUE="Reset"></TD>
<TD WIDTH="307" BGCOLOR="#006666"> </TD>
</TR>
</TABLE>
</CENTER>
<P>
</FORM>
</BODY>
</HTML>
!
Any help would be appreciated.
Thanks for your patience
------------------------------
Date: Tue, 3 Mar 1998 22:38:57 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: special characters in PRINT
Message-Id: <Ep9LKy.1G4@world.std.com>
"Russell White" <russwyte@pcisys.net> writes:
> My problem is that when I run
>the script I usually have a load of errors because I am using special
>characters in my PRINT statements that I should be marking with the '\'
>character. I have found a partial fix by using the qq! method in my PRINT
>statements, but that only helps for quotes. Are '#''s and "@"'s also
>reserved characters?
The characters aren't reserved for print(), but rather for any double
quoted string.
If your script doesn't need to interpolate variables, or interpret
backslash sequences, then you may want to use single quoted string or
the "q" operator. (Single quoted strings are just a convenience for
the programmer to access the more generalized q'' operator.)
If your script needs to interpolate variables, but still has many
characters that need escaping, you may want perform your own
interpolation, rather than relying on perl's method.
If you want to do that, you may get some ideas on how from
<URL:http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq4
/How_can_I_expand_variables_in_te.html>
or maybe the Text::Template module may be of use to you:
<URL:http://www.perl.com/CPAN/modules/by-module/Text/
Text-Template-0.1b.tar.gz>
> I have yet to find any documentation that spells out
>which characters must be flagged with the '\' tag.
<URL:http://www.perl.com/CPAN/doc/manual/html/pod/
perlop.html#Quote_and_Quote_like_Operators>
--
Andrew Langmead
------------------------------
Date: Tue, 03 Mar 1998 17:27:53 -0500
From: John Guisson <mrpc1@hotmail.com>
Subject: subdirectory search?
Message-Id: <34FC83E7.4F8ED131@hotmail.com>
how do i get a list of subdirectories of a given directory? would i
just use the same method as if i were listing files?
------------------------------
Date: 3 Mar 1998 17:43:42 -0500
From: kcohen@julius.ling.ohio-state.edu (Kevin B Cohen)
Subject: Re: subdirectory search?
Message-Id: <6di12u$fqa@julius.ling.ohio-state.edu>
In article <34FC83E7.4F8ED131@hotmail.com>,
John Guisson <mrpc1@hotmail.com> wrote:
>how do i get a list of subdirectories of a given directory? would i
>just use the same method as if i were listing files?
>
almost the same method---but you want to differentiate between files
and directories.
opendir(DIR, 'dashwood'); @everything = readdir(DIR);
# @everything has a list of files and subdirectories in the directory
'dashwood'
now you want to make use of the -d "filetest operator":
foreach $thing (@everything) {
unless (-d $thing) {
next;
}
else {
push (@subdirectories, $thing);
}
}
when you're done, @subdirectories contains a list of the
subdirectories, for you to do with as you please.
if it was me, i would put in before the unless clause something like
($thing =~ /\.$/) && (next); # short-circuit logic
so that the current and parent directory thingies wouldn't get added
to @subdirectories.
if this isn't clear, see chapter 13, "more on files and directories,"
of "perl 5 for dummies", by paul hoffman.
kevin
------------------------------
Date: 3 Mar 1998 21:36:32 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Summing Up Array Values - How Do I?
Message-Id: <6dht50$l76$2@marina.cinenet.net>
Uri Guttman (uri@sysarch.com) wrote:
: let's go schwartzian on the newbie!
:
: @yards = (2,3);
: $sum = 0 ;
: map { $sum += $_ } @yards ;
Thou shalt not use map in a void context! :) The foreach form is clearer
and more efficient:
my $sum = 0;
foreach (@yards) { $sum += $_; }
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 03 Mar 1998 17:44:06 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Summing Up Array Values - How Do I?
Message-Id: <x74t1fz96x.fsf@sysarch.com>
cberry@cinenet.net (Craig Berry) writes:
> Uri Guttman (uri@sysarch.com) wrote:
> : let's go schwartzian on the newbie!
> :
> : @yards = (2,3);
> : $sum = 0 ;
> : map { $sum += $_ } @yards ;
>
> Thou shalt not use map in a void context! :) The foreach form is clearer
> and more efficient:
i agree. i was just showing another way to do it, schwartzian style.
> my $sum = 0;
> foreach (@yards) { $sum += $_; }
uri
--
Uri Guttman SYStems ARCHitecture and Software Engineering
uri@sysarch.com Have Perl, Will Hack
http://www.sysarch.com (781) 643-7504 x*2 FAX: (781) 643-2710
Try the Best Search Engine on the Net --------> http://www.northernlight.com
------------------------------
Date: 3 Mar 1998 21:17:30 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: The -w switch (was Re: better way to do this?)
Message-Id: <6dhs1a$l76$1@marina.cinenet.net>
Art Cohen (upsetter@shore.net) wrote:
: Perhaps, I find it amusing that even though there's supposed to be "more
: than one way to do it", a lot of people on this group act as if I'm an
: idiot, an infidel, or a closet Friend of Bill Gates if I don't use -w and
: "use strict" in every single Perl script I write.
Not at all! What you do in the privacy of your own office with a
consenting toolset is entirely your own business. I/we wouldn't dream of
criticizing you for such.
What *will* cause abuse to be heaped upon your head is if you ask for
help in c.l.p.m without using at least -w and preferably strict as well.
That's because these will typically flush out most problems with your
script before you need to ask us for help. Posting a problematic script
which does not use at least -w shows that you've put little or no effort
into solving the problem yourself -- and that makes us less inclined to
spend our own time and effort doing so.
: Most of the scripts I
: write are less than 200 hundred lines or so, and I save a lot more time in
: the long run by *not* doing everything "strictly" than I've ever lost due
: to typographical errors. (I've been writing perl professionally for
: almost two years).
Well, good for you, sounds like you've hit your own comfort point. (I'd
be inclined to suspect that you're fooling yourself, but that's another
issue.)
: : + However, if I turn the -w switch on, I get warnings about them!
[them == uninitialized variables]
:
: : Why? If it is the warning that I think it is, once you use the variable a
: : second time, the warning goes away. If you simply declare them with a my ();
: : statement, the warning goes away. If you need a $junk variable, you can
: : simply undef the variable, and the warning goes away.
:
: True, but I'm just too lazy. And in scripts the the relatively small
: scripts I usually write, I've never had a problem. If I ever write a large
: project with many thousands of lines of perl code, I'll probably use them.
: To imply that anyone who doesn't use them in every single perl script is
: an idiot is ridiculous.
Getting into the habit on small scripts makes it far easier to use them
on the large scripts. And again, nobody is calling you an idiot for not
using them -- rather, it's for not using them and then expecting us to
approve and help you out. (Not aimed at you in particular, but rather at
anyone posting code to c.l.p.m -- I don't recall if you specifically have
posted -wless code and asked for help with it.)
: Now, I'm not arguing that the -w switch or "use strict" are bad things.
: But I just find it bizarre and slightly unsettling the number of people --
: supposedly knowledgeable about perl if not "gurus" -- who are eager to
: jump all over anyone who dares to suggest that certain "orthodoxies"
: aren't always necessary.
If I am a car mechanic, and someone asks me for advice on repairing their
car, I might ask if they change the oil regularly. If the answer is 'why
bother?', I will be less inclined to think my more complex advice specific
to their problem will do any good. I might even say they are foolish not
to change their oil. But unless the person approaches me for advice,
they'll never hear a word about my opinion of their car maintenance
practices.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 3 Mar 1998 21:15:50 GMT
From: Jon Drukman <jsd@hudsucker.gamespot.com>
Subject: Re: The -w switch (was Re: better way to do this?)
Message-Id: <6dhru6$hdk$1@its.hooked.net>
Uri Guttman <uri@sysarch.com> wrote:
: i don't call it a production program or module
: if it doesn't work under -w and usually use strict.
just to pick nits...
note that the book "effective perl programming" by joseph hall and
randal schwartz says you should probably turn -w off for production
programs. (-w is a speed hit and also you don't want your end users
seeing your warnings.)
personally i always develop with use strict and -w on but take them
out when the program is ready to be used by others.
-j-
------------------------------
Date: Tue, 03 Mar 1998 14:52:36 -0600
From: Wayne Patton <wbpatto@wmccmsvr.ssr.hp.com>
Subject: tr question
Message-Id: <34FC6D94.630B@wmccmsvr.ssr.hp.com>
#!/usr/local/bin/perl
#
$_="0000301";
print "before -> $_\n";
tr/^0//d;
print "after -> $_\n";
This should strip the leading zeros right?
wayne
--
---------------
Wayne Patton, T/501-271-5446
Email: wbpatto@wmccmsvr.ssr.hp.com
Wal*Mart Account Support Delivery Team
------------------------------
Date: 3 Mar 1998 21:43:13 GMT
From: petdance@maxx.mc.net (Andy Lester)
Subject: Re: tr question
Message-Id: <6dhthh$7t3$1@usenet50.supernews.com>
: $_="0000301";
: print "before -> $_\n";
: tr/^0//d;
: print "after -> $_\n";
: This should strip the leading zeros right?
No. It would strip ALL zeroes. What you're looking for is:
s/^0+//;
which means:
^: at the beginning match
0: the character "0"
+: one or more times
and replace it with:
: nothing
tr/// is for replacing all characters throughout a string.
xoxo,
Andy
--
--
Andy Lester: <andy@petdance.com> http://tezcat.com/~andy/
Chicago Shows List: <shows@ChicagoMusic.com> http://ChicagoMusic.com/
------------------------------
Date: 03 Mar 1998 16:55:55 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: tr question
Message-Id: <67lve8wk.fsf@news.concentric.net>
Wayne Patton <wbpatto@wmccmsvr.ssr.hp.com> writes:
> tr/^0//d;
> This should strip the leading zeros right?
No; tr takes a literal list of characters, and you are therefore
deleting all haceks and zeros from $_. You want
s/^0//;
Please see "perlop" and "perlre."
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: 3 Mar 1998 22:26:14 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: tr question
Message-Id: <6di026$l76$4@marina.cinenet.net>
Jonathan Feinberg (jdf@pobox.com) wrote:
: Wayne Patton <wbpatto@wmccmsvr.ssr.hp.com> writes:
:
: > tr/^0//d;
: > This should strip the leading zeros right?
:
: No; tr takes a literal list of characters, and you are therefore
: deleting all haceks and zeros from $_. You want
:
: s/^0//;
Actually s/^0+//; to get the leading zeros (plural).
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Tue, 03 Mar 1998 21:05:19 GMT
From: someguy@knick-knack.com (Curtis)
Subject: Re: webserver configuration/cgi.pm/nt
Message-Id: <34fc7041.8621882@news.alt.net>
Using Sarathay's Win32 port I had many problems with scripts that used cgi-lib.
I sat down with the perldocs and learned to use CGI.pm and all of my problems
went away. Not sure what the problem was, but cgi-lib seems to be the root of
it...
--Curtis
On Tue, 03 Mar 1998 15:57:11 GMT, Bill Jones <webmaster@fccjmail.fccj.cc.fl.us>
wrote:
>See! I told you I was wrong before :-)
>
>Anyways, sometimes you just have to rewrite code...
>
>Sorry :-(
>
>
>
>anne_lee@mailexcite.com wrote:
>
>> NT SP 3 did not solve the problem
>> The script was written for cgi-lib.pl under unix, I am porting it to NT by
>> trying to do as little change as possible and narrow down the problem by doing
>> simple task.
>>
>> In article <34F78276.1226EB25@fccjmail.fccj.cc.fl.us>,
>> bill@astro.fccj.cc.fl.us wrote:
>> >
>> > Service Pack 3 is available and highly recommended.
>> > Why are you mimicing cgi-lib functionality?
>> >
>> > CGI.pm allows html output, headers and all.
>> >
>> > I say the problem is - service Pack 3 required...
>> > (I've been wrong before :-)
>> >
>> > HTH,
>> > Bill
>>
>> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
>> http://www.dejanews.com/ Now offering spam-free web-based newsreading
>
>
------------------------------
Date: 3 Mar 1998 21:12:45 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <6dhrod$t0s$2@info.uah.edu>
In article <34FC5A59.5F2EB29D@earthlink.net>,
Brian Slone <bslone@earthlink.net> writes:
: I really don't know crap about PERL. How is it different from JAVA?
The difference between Perl and languages like Java is similar to the
difference between coffee filtered through dirty underwear and its
more sanitary cousin. :-)
: Which one is better?
See <URL:http://language.perl.com/versus/index.html>.
: What can I use it for?
Using the sizes of Perl's and Java's respective user bases as a basis
for comparison, Perl seems to be much more useful for everything, not
just the simple task of crippling someone's machine with rogue code.
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Tue, 03 Mar 1998 22:25:39 GMT
From: FHeasley@chemistry.com (Frank)
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <34fc82b1.41395223@news.halcyon.com>
On Tue, 03 Mar 1998 13:30:33 -0600, Brian Slone <bslone@earthlink.net>
wrote:
>I really don't know crap about PERL. How is it different from JAVA?
>Which one is better?
>What can I use it for?
>
I think the answer is that each has its' own strengths and weaknesses.
There's stuff you can do in PERL that would be difficult, or
impossible, to do with JAVA. And vice versa.
A treatise on these would be a waste of time here. I suggest you
figure out what it is that you're trying to accomplish, then take a
cursory look at the two languages and decide which one looks more
likely to get you to your goal first.
Frank
------------------------------
Date: Tue, 03 Mar 1998 17:53:16 -0500
From: John Guisson <mrpc1@hotmail.com>
To: Greg Bacon <gbacon@cs.uah.edu>
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <34FC89D7.371491BC@hotmail.com>
>Greg Bacon wrote:
> In article <34FC5A59.5F2EB29D@earthlink.net>,
> Brian Slone <bslone@earthlink.net> writes:
> : I really don't know crap about PERL. How is it different from JAVA?
>
> The difference between Perl and languages like Java is similar to the
> difference between coffee filtered through dirty underwear and its
> more sanitary cousin. :-)
funny man. but seriously the difference is that java is a true
object-oriented language. typically, the only thing you should use java
on the Web is for multimedia applets, but anything else can usually be
done with perl.
>
>
> : Which one is better?
>
> See <URL:http://language.perl.com/versus/index.html>.
java is young and has some setbacks, but at the same time it is a very
promising language. some of its key advantages are its cross-platform
capabilites, lightweightness, object-oriented capabilities, and ease of
use. java's main cons are that it is immature, and it is (for now at
least) VEEEERYYYY SLOOOOOWWWWWW...
>
>
> : What can I use it for?
>
> Using the sizes of Perl's and Java's respective user bases as a basis
> for comparison, Perl seems to be much more useful for everything, not
> just the simple task of crippling someone's machine with rogue code.
i'd suggest perl for anything that does not require multi-media and goes
on the web. java isn't a toy language anymore, but it is somewhat
limited. java can be used for stand-alone database applications and
anything that has to do with networks and sockets. but again, it is
slowww. before producing a major app in it, wait for java 1.2.
>
>
> Greg
> --
> open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
> f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
> d2ac158c84c4ece4d22d1000118a8d5491000000
> EOF
------------------------------
Date: 3 Mar 1998 17:08:09 -0500
From: davet@interlog.com (Dave Till)
Subject: Re: Why doesn't "tr/\x0D//d" work?
Message-Id: <6dhv09$gna@shell1.interlog.com>
In article <slrn6fm1ho.ie7.Tom.Grydeland@mitra.phys.uit.no>,
Tom Grydeland <Tom.Grydeland@phys.uit.no> wrote:
>> Is "while ($line = <INFILE>)" now considered Bad Perl?
>
>In the sense that a broken9 input file can stop your script prematurely;
>yes. A lone "0" (without the "\n") on the final line of a text file
>will stop your script at that point. Hence the warning, and the
>suggestion from perldiag.
>
>> The Camel uses this looping construct rather frequently
>
>Yes, that has baffled me as well.
My point is this: if the Camel (considered the definitive Perl reference work
on the subject) uses the "while ($line = <INFILE>)" construct, c.l.p.m.
posters who use this construct should not be unduly criticized for doing so.
>> (indeed, it sometimes goes whole hog and uses "while (<>)").
>
>Which, OTOH, is perfectly OK, as Mike Stok has already pointed out.
There's a whiff of arbitrariness about this decision. At present, the line
while (<INFILE>) # case 1
doesn't get flagged by -w, whereas the line
while ($_ = <INFILE>) # case 2
does. The decision to automagically add a hidden call to defined() in case 1
but not in case 2 seems somewhat arbitrary to me. (Presumably, there are
a lot of examples of case 1 already out in the world, which is why it was
done this way.)
>Apart from that, I quite like having references to $_ running like an
>invisible thread through my programs. I find this makes them easier to
>read and harder to break than programs cluttered with variable
>assignments, =~s and excessive punctuation.
Clearly, whoever is creating the warning messages these days agrees with
you, given the above. :-)
>2Paraphrasing and contradicting the statements of Dave Till in
> _Teach yourself PERL 5 in 21 days_, 2/e
It's a matter of what you're used to, I guess. I don't like the idea
of hidden side effects (such as modifying $_). I want everything to
be right there where I can see it. To each their own, I suppose.
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 2013
**************************************