[9470] in Perl-Users-Digest
Perl-Users Digest, Issue: 3064 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 5 13:09:11 1998
Date: Sun, 5 Jul 98 10:00:29 -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 Sun, 5 Jul 1998 Volume: 8 Number: 3064
Today's topics:
Re: Alternative solution ? <alf@orion.it>
Re: Alternative solution ? (Larry Rosler)
Re: attachment to email <quednauf@nortel.co.uk>
Re: attachment to email (Jeremy D. Zawodny)
Re: better way of getting the last modified file? (Larry Rosler)
Re: clearing screen/curses (Sitaram Chamarty)
Re: How to check variables exists in a string (Sitaram Chamarty)
Re: How to check variables exists in a string <tchrist@mox.perl.com>
Re: how to replace ... <tonylabb@infonline.net>
Re: Length and stripping function <rootbeer@teleport.com>
limitation of sort (Boson)
Re: limitation of sort <rootbeer@teleport.com>
Re: limits of glob() ? <dtbaker_@flash.net>
Re: limits of glob() ? <dtbaker_@flash.net>
Re: limits of glob() ? (Bob Trieger)
package available to search local HTML pages? Re: limit <dtbaker_@flash.net>
package for searching local docs? WAS Re: limits of gl <dtbaker_@flash.net>
Re: passing javascript var in perl cgi (Larry Rosler)
Re: Perl download (acting as a Browser) (Bbirthisel)
Re: PUZZLE: dutree (new) <tchrist@mox.perl.com>
Re: question about objects <tlk@irt.net>
Re: question about objects (Jeremy D. Zawodny)
Re: question about objects <rra@stanford.edu>
Re: question about objects <tchrist@mox.perl.com>
Re: Reading in GIFs <rootbeer@teleport.com>
Why can't I do this? <jc_cann@ix.netcom.com>
Re: Why can't I do this? <merlyn@stonehenge.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 30 Jun 1998 17:57:01 +0200
From: Alessandro Forghieri <alf@orion.it>
Subject: Re: Alternative solution ?
Message-Id: <35990ACD.414D8735@orion.it>
Greetings.
Andrew MacInnes wrote:
>
> I am trying to get information from a file and have written the
> following script using perl FAQ's and tutorials. This works fine,
> however I would like a more efficient way to get the data into the
> array. Could someone please give me an idea for a better solution which
> does not mean me having to create a temp file each time.
>
You can do your matches directly in perl (that's what the m!!! stuff
does.
You will usually see written it as /.../.../ - no m, delimiter is '/',
but I choose the less usual form because of all the \. in the regexp).
>From your example, I suspect ypu might wnat to give a closer look at
what hashes can do for you (Hint: IP addresses can be used as keys into
a hash).
#!/usr/local/bin/perl -w
open(LOG, "log.dat") or die "No log, no luck:$!";
while (<LOG>) {
if ( m!130\.246\.12\.22! && m!130\.246\.180\.131! ) {
push @data_array, $_;
)
}
# Remove all final newlines (you probably do not want them)
chomp @data_array;
[...]
No doubt there are shorter and/or more efficient ways to do it.
Cheers,
Alessandro
------------------------------
Date: Sun, 5 Jul 1998 08:27:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Alternative solution ?
Message-Id: <MPG.10093b219b682846989714@nntp.hpl.hp.com>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <35990ACD.414D8735@orion.it> on Tue, 30 Jun 1998 17:57:01
+0200, Alessandro Forghieri <alf@orion.it> says...
...
> You can do your matches directly in perl (that's what the m!!! stuff
> does.
> You will usually see written it as /.../.../ - no m, delimiter is '/',
> but I choose the less usual form because of all the \. in the regexp).
Using a delimiter other than '/' saves backslashes only when the regex
contains '/'. It has no effect on '\.' in the regex, as in this case.
> if ( m!130\.246\.12\.22! && m!130\.246\.180\.131! ) {
> push @data_array, $_;
Using a regex for a complete literal match (which is wanted here -- each
of those regexes should be anchored by '^' and '$') is not as good a
choice as simply doing a match with 'eq'. Without the anchors (i.e., to
see if the literal string is *contained* within the string being tested),
the 'index' function is a better choice. In general, unless you *must*
write the regex with at least one metacharacter (see 'perlre' for
definitions), find another way of doing the match. ('.' is not wanted as
a metacharacter in the example, hence the backslashes.)
> No doubt there are shorter and/or more efficient ways to do it.
Yes. :-)
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sun, 05 Jul 1998 14:04:34 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: attachment to email
Message-Id: <359F79E2.22B69DE7@nortel.co.uk>
Jeremy D. Zawodny wrote:
> LOAD "LINUX",8,1
Does it exist ?? *gasp in awe* :)
--
____________________________________________________________
Frank Quednau
http://www.surrey.ac.uk/~me51fq
________________________________________________
------------------------------
Date: 05 Jul 1998 10:37:10 -0400
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: attachment to email
Message-Id: <m3yau8e549.fsf@peach.z.org>
"F.Quednau" <quednauf@nortel.co.uk> writes:
> Jeremy D. Zawodny wrote:
>
> > LOAD "LINUX",8,1
>
> Does it exist ?? *gasp in awe* :)
I wish...
About the closest one could expect is
LOAD "MINIX",8,1
but it wasn't ever "ported" to the 6502. Well, not that I know of.
It has been amusing to see how many folks remember the C=64 and
comment on the .sig. I think it's a keeper. :-)
Jeremy
--
Jeremy D. Zawodny Web Geek, Perl Hacker, etc.
http://www.wcnet.org/~jzawodn/ jzawodn@wcnet.org
LOAD "LINUX",8,1
------------------------------
Date: Sun, 5 Jul 1998 08:47:32 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: better way of getting the last modified file?
Message-Id: <MPG.10093ff12a871673989715@nntp.hpl.hp.com>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <359f5135.769059@news.btinternet.com> on Sun, 05 Jul 1998
12:04:10 GMT, Jonathan Stowe <Gellyfish@btinternet.com> says...
...
> There is also a typo as Larry so rightly (and unerringly he does so
> ;-}) points out in the pattern to get rid of the . and .. directories
> - there should be a "\" before the . otherwise you will get rid of all
> 1 or two character named files (actually that would be alright for me
> as I tend to always call junk files with 1 or two character names).
Careful -- only the default 'Larry' around these parts is unerring (as
well as all-seeing and omnipotent)! Mere mortal 'Larry's require fuller
qualification (in two senses of that word).
> While I think of it you probably want to ignore directories as well,
> and if you put a full path in opendir like that you will have to
> prepend that to the filename you got from readdir as that only returns
> the filename not the full path.
>
> This is beginning to look bad - shall we start again :-?
>
> That will be of course:
>
> #!perl -w
> use diagnostics;
> use strict;
Dropping '-w' and 'use strict;' from production code is like removing
one's lifejacket as soon as the ship leaves the harbor and goes out to
sea. On the other hand, 'use diagnostics;' takes a while to load and
adds only tutorial value to other messages.
> use vars qw($pathname $file $lastfile $moddate $lastmod);
Belt and suspenders. 'my' is sufficient in this single-file example.
...
> Now that *does* work
It ought to, by now! :-)
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 5 Jul 98 16:28:48 GMT
From: sitaram@diac.com (Sitaram Chamarty)
Subject: Re: clearing screen/curses
Message-Id: <slrn6puuad.hef.sitaram@ltusitaram.unidata.com>
On 04 Jul 1998 22:28:31 -0700, Russ Allbery <rra@stanford.edu> wrote:
>Victoria Yee-Mui Chiu <vicchiu@leland.Stanford.EDU> writes:
>
>> Does anyone know how to clear the screen using perl? I tried running
>> system command `clear` and that didn't work. What I wanted to do is
>> write information out to the screen, wait couple of seconds, clear the
>> screen and rewrite to screen.
>
>Running clear should work, but you don't want to run it in backticks
>(since you're then capturing the output rather than letting it clear the
>screen). Try:
>
> system 'clear';
Also, if you're going to do this in a loop (like repeating the
sequence you mentioned for a while), it might actually be better
to use backticks once at the start of the program to save the
sequence, then spit it out whenever you want to clear the screen.
------------------------------
Date: 5 Jul 98 16:28:45 GMT
From: sitaram@diac.com (Sitaram Chamarty)
Subject: Re: How to check variables exists in a string
Message-Id: <slrn6puu0k.hef.sitaram@ltusitaram.unidata.com>
On 29 Jun 1998 16:18:01 GMT, Tom Christiansen <tchrist@mox.perl.com> wrote:
> [courtesy cc of this posting sent to cited author via email]
>
>In comp.lang.perl.misc,
> cberry@cinenet.net (Craig Berry) writes:
>:In other words, suppose we posit a subroutine named
>:find_undefs_in_string, or fuis() for short. If I call
>:
>: fuis('Hi $person this is $app and your bill is $bill');
>:
>:what is the return value you want, if (say) $app is defined but the other
>:two aren't?
>
>This is unsolvable in the general case. Lexicals.
I'm afraid I dont understand. "perldoc -f defined" only has
caveats about using it on aggregates, not scalars. So why wont a
defined($lexical) work?
Thanks...
------------------------------
Date: 5 Jul 1998 16:37:33 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to check variables exists in a string
Message-Id: <6noa4d$lob$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
sitaram@diac.com (Sitaram Chamarty) writes:
:>: fuis('Hi $person this is $app and your bill is $bill');
:>:
:>:what is the return value you want, if (say) $app is defined but the other
:>:two aren't?
:>
:>This is unsolvable in the general case. Lexicals.
:
:I'm afraid I dont understand. "perldoc -f defined" only has
:caveats about using it on aggregates, not scalars. So why wont a
:defined($lexical) work?
Because you passed a string with variables' _names_ down into another
scope, from which you'll never be able to find them if they're lexicals.
You can't write an expand() function that would print out Fido
in this case:
{
my $dog = 'Fido';
expand('This is my friend, $dog.')
}
--tom
--
There is no reason for any individual to have a computer in their home. --Ken Olsen, 1977
------------------------------
Date: Sun, 05 Jul 1998 11:05:55 -0400
From: Tony Labbiento <tonylabb@infonline.net>
Subject: Re: how to replace ...
Message-Id: <359F9653.FA9AFE7A@infonline.net>
If your string is in a variable like $addresses then try this: $address
=~ s/<.*?>/,/g
PONG Hay Chi wrote:
> Hi,
> i want to replace all characters between '<' and '>' and including
> '<' and '>'
> by a comma
> in the following line, would somebody help me?
>
> before :
> <content1 ....><content2 ....>this is data<content3..><content4..>
>
> after :
> ,,this is data,,
>
> Many thanks.
> rgds.
> alanpong@hkstar.com
--
****************************************
* Tony Labbiento *
* Infinity Online, Inc. *
****************************************
------------------------------
Date: Sun, 05 Jul 1998 16:23:25 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Length and stripping function
Message-Id: <Pine.GSO.3.96.980705092226.16157B-100000@user2.teleport.com>
On Sun, 5 Jul 1998, Terry wrote:
> open(LIST,">>$list_file");
Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.
Thanks!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sun, 05 Jul 1998 16:01:09 GMT
From: boson@earthlink.net (Boson)
Subject: limitation of sort
Message-Id: <359f9ebf.2503366@news.earthlink.net>
Hi,
I have a hash structure which basically looks like this:
$h{'number'} = {'foo1' => 'bar1',
'foo2' => 'bar2',
'foo3' => 'bar3', # numerical
'foo4' => 'bar4',
'foo5' => 'bar5',
'foo6' => 'bar6',
'foo7' => 'bar7',
'foo8' => 'bar8',
'foo9' => 'bar9',
'foo10' => 'bar10',
'foo11' => 'bar11',
'foo12' => 'bar12',
'foo13' => 'bar13',
'foo14' => 'bar14',
'foo15' => 'bar15'
};
Then I use a sorting on 6 of these hashes, such as
foreach ( sort { $h{$a}{'foo3'} <=> $h{$b}{'foo3'} } keys %h )
I get a runtime error saying: "Sort subroutine didn't return single
value".The odd thing is that this error disappears when I reduce the
size of the hash by one (now 14 entries). Is this hash really too big
to be handle by the built-in sort function (qsort)? If so, is there a
a way to overcome this limitation?
Thanks in advance.
Boson
------------------------------
Date: Sun, 05 Jul 1998 16:35:49 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: limitation of sort
Message-Id: <Pine.GSO.3.96.980705093242.17225A-100000@user2.teleport.com>
On Sun, 5 Jul 1998, Boson wrote:
> I have a hash structure which basically looks like this:
>
> $h{'number'} = {'foo1' => 'bar1',
> 'foo2' => 'bar2',
> 'foo3' => 'bar3', # numerical
What does that comment mean? Does it mean that your hash has something
different that you're telling us?
> Then I use a sorting on 6 of these hashes, such as
> foreach ( sort { $h{$a}{'foo3'} <=> $h{$b}{'foo3'} } keys %h )
>
> I get a runtime error saying: "Sort subroutine didn't return single
> value".
That looks like a bug in perl or in your code. You're comparing the values
as numbers; are they numbers?
> The odd thing is that this error disappears when I reduce the
> size of the hash by one (now 14 entries).
If you can come up with a stand-alone example which shows this behavior
under current Perl releases, you may post it here or file it as a bug
report. Try to keep it down to a dozen lines or fewer. Thanks!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sun, 05 Jul 1998 09:30:59 -0500
From: Dan Baker <dtbaker_@flash.net>
Subject: Re: limits of glob() ?
Message-Id: <359F8E23.48BF@flash.net>
Bbirthisel wrote:
>
> Hi Dan:
>
> >> : What IS the limit?
> >>
> >> It depends on the shell, not on perl.
> >-------
> >how about on win32?
>
> Still depends on the shell. Vanilla Win95 is just under 128 (126).
> Others differ.
-------------
wow, thats a lot smaller than I expected! I was hoping it was something
like maxint or something pretty big. I guess in most cases where you
expect just a handful of matches for the glob it would be ok. In this
case I want to use it to list all files in a particular folder that
could have up to 1000 items.
>
> >> : i.e. when should I
> >> : consider using opendir(), readdir(), closedir()?
> >>
> >> Always.
>
> >sorry, haven't memorized the docs yet! I have 5 different books I look
> >at, and none of them had good answers on these topics, so I thought I'd
> >ask. The problem is WHICH doc to look at!
>
> The ones that come up with the above answer should be consulted
> first (easy test). And since you mention the Gecko, try pages 142-143.
------------
hhhmmm, I just read 139-143... there is good info on glob and readdir,
but no details on the limitations of glob, or why
opendir/readdir/closedir might be better than glob other than the
ability to return filenames beginning with ".".
Dan
------------------------------
Date: Sun, 05 Jul 1998 09:20:23 -0500
From: Dan Baker <dtbaker_@flash.net>
Subject: Re: limits of glob() ?
Message-Id: <359F8BA7.2B3F@flash.net>
Tom Christiansen wrote:
>
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc,
> dtbaker_@flash.net writes:
> :sorry, haven't memorized the docs yet! I have 5 different books I look
> :at, and none of them had good answers on these topics, so I thought I'd
> :ask. The problem is WHICH doc to look at!
>
> The first stop should *always* be grepping the standard docset that's
> included with every Perl distribution and electronically searchable.
> The second stop should be some book with Larry's name on it. :-)
>
> --tom
------------------
hhhmmm, sounds like sage advice! Now all I have to do is figure out the
best way to search thru the docs on win32.
Dan
------------------------------
Date: Sun, 05 Jul 1998 14:56:27 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: limits of glob() ?
Message-Id: <6no4at$7s5$1@ligarius.ultra.net>
[ posted and mailed ]
dtbaker_@flash.net wrote:
-> hhhmmm, sounds like sage advice! Now all I have to do is figure out the
-> best way to search thru the docs on win32.
Use the find function in win32 and do an advanced search on files ending in
pod in the perl/lib directory for files containing your inquiry.
If you have the standard port of perl for win32, you have all the
documentation in html format. You can combine them all into one document and
then use `cntl-f' to search that document in your browser.
HTH
Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-286-0591
and let the jerk that answers know that his
toll free number was sent as spam. "
------------------------------
Date: Sun, 05 Jul 1998 11:55:15 -0500
From: Dan Baker <dtbaker_@flash.net>
Subject: package available to search local HTML pages? Re: limits of glob() ?
Message-Id: <359FAFF3.5688@flash.net>
Bob Trieger wrote:
>
> [ posted and mailed ]
>
> dtbaker_@flash.net wrote:
> -> hhhmmm, sounds like sage advice! Now all I have to do is figure out the
> -> best way to search thru the docs on win32.
>
> Use the find function in win32 and do an advanced search on files ending in
> pod in the perl/lib directory for files containing your inquiry.
>
> If you have the standard port of perl for win32, you have all the
> documentation in html format. You can combine them all into one document and
> then use `cntl-f' to search that document in your browser.
--------------
not a bad idea.... but it must make a MONSTER HTML page! I'm thinking
that it may be a good project to build a little search engine to zip
thru the docs looking for a word or phrase. Unless of course someone
else has already done it and has a package they would like to share?!
Dan
------------------------------
Date: Sun, 05 Jul 1998 11:42:22 -0500
From: Dan Baker <dtbaker_@flash.net>
Subject: package for searching local docs? WAS Re: limits of glob() ?
Message-Id: <359FACEE.4B42@flash.net>
Bob Trieger wrote:
>
> [ posted and mailed ]
>
> dtbaker_@flash.net wrote:
> -> hhhmmm, sounds like sage advice! Now all I have to do is figure out the
> -> best way to search thru the docs on win32.
>
> Use the find function in win32 and do an advanced search on files ending in
> pod in the perl/lib directory for files containing your inquiry.
>
> If you have the standard port of perl for win32, you have all the
> documentation in html format. You can combine them all into one document and
> then use `cntl-f' to search that document in your browser.
-----------
whew, that would make one MONSTER HTML page?! I am thinking it may be a
good practice project to see if I can build a simple Perl search engine
to zip thru all the local docs. Of course, if anyone already has one
that will look through HTML pages for a word or phrase, I'd be glad to
use it rather than re-invent! ;)
Dan
------------------------------
Date: Sun, 5 Jul 1998 08:50:14 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: passing javascript var in perl cgi
Message-Id: <MPG.10094090127d6963989716@nntp.hpl.hp.com>
In article <359F5FC4.227B6570@nortel.co.uk> on Sun, 05 Jul 1998 12:13:08
+0100, F.Quednau <quednauf@nortel.co.uk> says...
> Jonathan Stowe wrote:
>
> > Did you know that they took Alphabetti Spaghetti off the market
> > because you could get BSE from it?
> >
> Now, this one I don't get at all :)
Bovine Spongiform Encephalitis (Mad Cow Disease). I thought all you
Brits were very sensitive about this :-)
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 5 Jul 1998 13:08:11 GMT
From: bbirthisel@aol.com (Bbirthisel)
Subject: Re: Perl download (acting as a Browser)
Message-Id: <1998070513081100.JAA17941@ladder01.news.aol.com>
Hi Jonathan and Douglas:
>Go to CPAN grab yourself libwww-perl (LWP) unpack and install it and
>read the documentation, which is copious, this can do all that you
>want and more and relatively simply.
You'll want version 0.012 to go with the GS perl.
>I would suggest that you get rid of that ActiveState thing and get the
>"standard" binary distribution for Win32 from www.perl.com which is at
>5.004.02 and has the full(ish) documentation set and a far more
>comprehensive set of modules.
The public beta of 5.004_69 is also available from ActiveState (since
last week). You will still be better off learning on the 5.004.02
distribution which is more mature and has more modules available
today. Stuff will transfer easily to 5.005 from that.
BTW: ActiveState has updated the Win32-specific FAQ. And they
did an excellent job. Grab a copy at the ActiveState site. I'm not
sure it's on CPAN yet - if so, just in the last 48 hours.
-bill
Making computers work in Manufacturing for over 25 years (inquiries welcome)
------------------------------
Date: 5 Jul 1998 13:58:50 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: PUZZLE: dutree (new)
Message-Id: <6no0qq$86q$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
sitaram@diac.com (Sitaram Chamarty) writes:
:Other than that - I give up. After a couple of days, how about an
:answer to your puzzle? I'm sure there's a more specific answer
:you were looking to get...
What I was looking for mostly was that bouncing through the
symbol table for everything in a quirky form of symbolic
dereferencing is a lot slower than using real references.
But that's not enough to account for 3x, I suspect. The
frequent splitting of string data is certainly a prime
culprit.
--tom
--
"Make is like Pascal: everybody likes it, so they go in and change it. "
--Dennis Ritchie
------------------------------
Date: Sun, 05 Jul 1998 10:44:20 -0400
From: Tim Kramer <tlk@irt.net>
Subject: Re: question about objects
Message-Id: <359F9144.B69AF496@irt.net>
Charlie Stross wrote:
> I dislike reliance on idiom; the implicit use of $_ and @_ in
> particular. Yeah, they're handy -- but it's a royal pain in the ass
> when you have to hand over code to someone who, in the phrase of
> someone I had to deliver to, "has not yet been assimilated by the perl
> hive mind".
Huh?!? $_ and @_ are staples of the language. It's like speaking without
using contractions. You can be understood but people tend to avoid you
after awhile. (Psst! That guy is weird. He talks funny!).
------------------------------
Date: 05 Jul 1998 11:15:11 -0400
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: question about objects
Message-Id: <m3ogv4e3cw.fsf@peach.z.org>
Tim Kramer <tlk@irt.net> writes:
> Charlie Stross wrote:
>
> > I dislike reliance on idiom; the implicit use of $_ and @_ in
> > particular. Yeah, they're handy -- but it's a royal pain in the ass
> > when you have to hand over code to someone who, in the phrase of
> > someone I had to deliver to, "has not yet been assimilated by the perl
> > hive mind".
>
> Huh?!? $_ and @_ are staples of the language. It's like speaking without
> using contractions. You can be understood but people tend to avoid you
> after awhile. (Psst! That guy is weird. He talks funny!).
Yes, but your analogy hardly applies to the case that the original
poster had in mind: *implicit* use. Using a contraction is explicit.
The difference between:
while(<blah>) {
print;
}
and
while(<blah>) {
print $_;
}
is really one of style IHMO. They both work, and *most* Perl hackers
don't think twice about it. But if someone has to maintain your code
and they're not nearly as comfortable with Perl and all of its
shortcuts (maybe they're used to writing COBOL), the second case makes
their life a tad bit easier without making yours a pain.
I've been there. I tend to write the second case.
But, strangely, I'm a big fan of "$blah = shift;" instead of
"$blah = shift(@_);"
Jeremy
--
Jeremy D. Zawodny Web Geek, Perl Hacker, etc.
http://www.wcnet.org/~jzawodn/ jzawodn@wcnet.org
LOAD "LINUX",8,1
------------------------------
Date: 05 Jul 1998 08:27:38 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: question about objects
Message-Id: <m3u34w48t1.fsf@windlord.Stanford.EDU>
Jeremy D Zawodny <jzawodn@wcnet.org> writes:
> The difference between:
> while(<blah>) {
> print;
> }
> and
> while(<blah>) {
> print $_;
> }
> is really one of style IHMO. They both work, and *most* Perl hackers
> don't think twice about it. But if someone has to maintain your code and
> they're not nearly as comfortable with Perl and all of its shortcuts
> (maybe they're used to writing COBOL), the second case makes their life
> a tad bit easier without making yours a pain.
Ew. I'd never write either. It saves so much typing to just write:
print while <blah>;
;)
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 5 Jul 1998 15:25:51 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: question about objects
Message-Id: <6no5tv$eeb$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
jzawodn@wcnet.org (Jeremy D. Zawodny) writes:
:The difference between:
: while(<blah>) { print; }
:and
: while(<blah>) { print $_; }
:
:is really one of style IHMO. They both work, and *most* Perl hackers
:don't think twice about it. But if someone has to maintain your code
:and they're not nearly as comfortable with Perl and all of its
:shortcuts (maybe they're used to writing COBOL), the second case makes
:their life a tad bit easier without making yours a pain.
You shouldn't be writing the second case unless you also like to write:
while (defined($_ = <ARGV>)) {
if ($_ =~ /^\s*#/) {
next;
}
$_ =~ s/left/right/g;
$_ =~ tr/A-Z/a-z/;
print $_;
}
Instead of this:
while (<>)) {
next if /^\s*#/;
s/left/right/g;
tr/A-Z/a-z/;
print;
}
The second one is clearly preferable, being easier to understand and
maintain.
You wouldn't want people who didn't know how to drive behind the wheel
of your kids' school bus, now would you? There's something to be said
for learning a skill. If someone doesn't know Perl, they shouldn't be
maintaining Perl code.
--tom
--
No, I'm not going to explain it. If you can't figure it out, you didn't
want to know anyway... :-)
--Larry Wall in <1991Aug7.180856.2854@netlabs.com>
------------------------------
Date: Sun, 05 Jul 1998 16:29:22 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Reading in GIFs
Message-Id: <Pine.GSO.3.96.980705092449.16157C-100000@user2.teleport.com>
On Sun, 5 Jul 1998, Stephan Magnus wrote:
> I just programmed some code to read in parts of a GIF and then all
> append the parts to one file. I did it as follows:
>
> open(ANFANG, "anfang.gif") || die;
> binmode(ANFANG);
> $anfang=<ANFANG>;
> close (ANFANG);
It's not generally correct to read just one line of a binary file, since
binary files aren't made of lines. :-) If you've set the magical $/
variable properly, this might be correct code, but I would recommend using
read() instead. (Or even File::Copy, perhaps.) Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sun, 05 Jul 1998 10:01:30 -0600
From: Jeffery Cann <jc_cann@ix.netcom.com>
Subject: Why can't I do this?
Message-Id: <359FA35A.E537DA1D@ix.netcom.com>
Given the 'Person.pm' package (see bottom of post), I can do this:
----------------------- test.pl -----------
#!/usr/bin/perl -w
use diagnostics;
use strict;
use Person;
my $him;
# these 2 statements are equivalent and they both compile
$him = Person->new();
$him = Person::new();
# I *think* these statements are equivalent -- but I am wrong!
# the compiler lets me send "Jason" to the name() method
$him->name("Jason");
$him = Person::name("Jason");
--------------------------------- end
The second statement is flagged by the compiler? Why aren't the second set of statements
equivalent?
Thanks
Jeff
-------------------- Person.pm----------
package Person;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
$self->{NAME} = undef;
bless ($self, $class);
return $self;
}
##############################################
## methods to access per-object data ##
## ##
## With args, they set the value. Without ##
## any, they only retrieve it/them. ##
##############################################
sub name {
my $self = shift;
if (@_) { $self->{NAME} = shift }
return $self->{NAME};
}
-------------------------------- end
--
+--------------------------+-------------------------+
| Jeffery Cann | This message sent from |
| JCDS Managing Developer | a Linux Workstation |
+--------------------------+-------------------------+
http://www.netcom.com/~jcds
------------------------------
Date: Sun, 05 Jul 1998 16:58:40 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Why can't I do this?
Message-Id: <8cogv4grpq.fsf@gadget.cscaper.com>
>>>>> "Jeffery" == Jeffery Cann <jc_cann@ix.netcom.com> writes:
Jeffery> # these 2 statements are equivalent and they both compile
No.
Jeffery> $him = Person->new();
Method call on class method. Uses inheritance, passes "Person" as first
argument to ultimately found subroutine.
Jeffery> $him = Person::new();
Ordinary subroutine call. No inheritance. Doesn't pass anything as
first arg.
Jeffery> # I *think* these statements are equivalent -- but I am wrong!
Jeffery> # the compiler lets me send "Jason" to the name() method
Jeffery> $him->name("Jason");
Jeffery> $him = Person::name("Jason");
Again, you're missing the automatic first argument (class/instance) if
you use an ordinary subroutine invocation.
$him->name("Jason");
is equivalent to:
SOMECLASS::name($him, "Jason");
where SOMECLASS is the first class found that has a "name" method in
the inheritance tree, beginning at the class of $him.
That's why methods are cool... they do some neat stuff behind the
scenes to permit some limited code reuse.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 57 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
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 3064
**************************************