[12912] in Perl-Users-Digest
Perl-Users Digest, Issue: 322 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 31 13:07:16 1999
Date: Sat, 31 Jul 1999 10:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 31 Jul 1999 Volume: 9 Number: 322
Today's topics:
Re: <<END_OF_TEXT function (Tad McClellan)
Re: [Summary] Korn Shell or Perl? (Michael Wang)
Re: Announcement: "CRAP" <tchrist@mox.perl.com>
Re: Beginner-friendly group as cultural adaptation? (Eric Bohlman)
Re: big Oh of sort() func (Tad McClellan)
cgi-lib.pl-unknown content-type when cgi-bin passworded <k.benson@johnabbott.qc.ca>
Re: Code as an argument (Tad McClellan)
for (1..60) {print ((-M "/etc/passwd")*86400); print "n (Michael Wang)
Re: for (1..60) {print ((-M "/etc/passwd")*86400); prin (Matthew Bafford)
Re: for (1..60) {print ((-M "/etc/passwd")*86400); prin (Larry Rosler)
General question about CHMOD <webmaster@roleplayinggames.net>
Re: Hey, that's pretty neat! (Tad McClellan)
Re: is process still running? (Anno Siegel)
Re: Newbie alert !! (Anno Siegel)
Re: NEWSFLASH: Supremes rule anti-advert-ware illegal (John G Dobnick)
Re: NEWSFLASH: Supremes rule anti-advert-ware illegal (Eric Bohlman)
Re: Perl bug? <pheuvel@optusnet.com.au>
Re: Perl bug? <flavell@mail.cern.ch>
Re: Perl bug? <uri@sysarch.com>
Re: Perl bug? <kenhirsch@myself.com>
Re: pipes vs csv <kenhirsch@myself.com>
Re: print with an inline " (Tad McClellan)
Re: Problems with use/require .... (Anno Siegel)
Re: returning to beginning of a file (Tad McClellan)
Re: running programs from inside perl (Tad McClellan)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 31 Jul 1999 06:37:23 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: <<END_OF_TEXT function
Message-Id: <3ljun7.ge1.ln@magna.metronet.com>
Eric The Read (emschwar@rmi.net) wrote:
: Eric The Read <emschwar@rmi.net> writes:
: > If you're on a PC, go to <URL:http://www.activstate.com/>
: That should be <URL:http://www.activestate.com/>, of course.
: -=Eric, thinking it's maybe time to go home early :^)
If it was that time, then you would have typed this instead:
-=ric, thinking it's mayb tim to go hom arly :^)
So keep working!
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 31 Jul 1999 15:23:11 GMT
From: mwang@mindspring.com (Michael Wang)
Subject: Re: [Summary] Korn Shell or Perl?
Message-Id: <37a314df@news3.us.ibm.net>
brian d foy <brian@pm.org> wrote:
>gees. are you going to learn some Perl or not?
Yep.
>all of this can be
>easily done with tie. either open a file or pipe and retreive the next
>line from it, or iterate through the DBM file. the FETCH decides where
>to get the next value.
I used tie, well I use dbmopen which I think is the same as tie. That is how
I get %beeper_byname:
dbmopen(%::beeper_byname, $beeper_byname, 0666);
After that I need to select the stream via if/else, for loop from
keys(%::beeper_byname) and `ypcat ...` and then "pipe" to a common
processing block. Well Perl does not support the notion of "pipe",
that is why I have to struggle very hard to find the best alternatives.
I do not know how "FETCH" will solve the problem.
>i didn't see any mention of %beeper_byname in your shell script, so
>i didn't include it in my translation.
The problem specification was changed (not by me). %beeper_byname was in your
Perl-to-Perl translation at the beginning.
# brian suggested code to emulate shell pipelines, or isn't it not?
map (
{ $_ } # or some manipulation on $_
grep (
{ ! /^YP_/ }
( $opt_d eq "all" ?
map(
{ if ( /local/ ) { keys(%beeper_byname); }
elsif ( /yp/ ) { map( { /(\w+)/ } `ypcat -k beeper.byname`); }
} split(/,/, $opt_b)
) : split(/,\s*/, $opt_d)
)
)
if this is accepted real life code, then the "out of memory" can be
easily solved by replacing
map( { /(\w+)/ } `ypcat -k beeper.byname`);
with
open (FH, "ypcat -k beeper.byname |");
map( { /(\w+)/ } <FH>;
I just wonder if this is the best Perl alternative for the shell pipeline
situation.
>again, if you don't like Perl, don't use it, but quit whining about
>your personal shortcomings in using it.
I like Perl, and I do use it. I do not have personal shortcomings in using
it in general. I have "personal shortcomings" in pipeline situation, and this
"personal shortcomings" is shared by many. Look at the code cited above, and
see how much you have to struggle to emulate shell pipelines.
Besides I am not whining, I am making objective comments.
>ah, the true motivation comes out! you're just a leech! you thought you
>could get somebody else to do your work for you. send a check and i'll
>write the code, but now that i know you're a deceptive parasite i have
>absolutely no desire to help you. had you said all of this before you
>would have most likely gotten a completely satisfactory answer right
>away. see how much trouble your deception has caused?
I do not know what is the basis for your comments. At the beginning I
made it clear that I need Perl alternatives for shell pipelines.
"Another Larry" provided me solutions, and one of them is to use
for (nested do{}, grep{}, map{}). Then I came up with code that Randal
and you modified. While I like both of your code, I pointed out that
both have "out of memory" problems when applied to large amount of data.
Your comments indicate ("send a check") that it takes a lot effort
to find the solution for the problem. So again it is not a "personal
shortcomings".
>what happened to your love of the Korn shell? why not just use that?
>i'm guessing that you don't know how do it in shell either.
My love for Korn shell is still there. Sure I can do in Shell, and it
has no "out of memory" problem and it is about 3 times faster in real time.
I have attached the code below, but what is exactly your point here?
I know I can do in Shell, but I need Perl solution since this is only
a piece of code in a larger Perl program.
#!/usr/local/bin/ksh
opt_d="all"
opt_b="yp"
typeset -A beeper_byname
beeper_byname["YP_a"]=0
beeper_byname["a"]=1
beeper_byname["b"]=2
beeper_byname["YP_b"]=9
if [[ $opt_d == "all" ]]; then
for i in ${opt_b//,/ /}
do
if [[ $i == "local" ]]; then
for k in ${!beeper_byname[@]}; do echo $k; done
elif [[ $i == "yp" ]]; then
ypcat -k beeper.byname
fi
done
else
echo ${opt_d//,/ /}
fi | while read j
do
j=${j%% *}
case $j in
*YP_*) ;;
*) echo $j;;
esac
done
# real 0m0.42s
# user 0m0.16s
# sys 0m0.17s
#!/usr/local/bin/perl -w
use strict;
use diagnostics;
my $opt_d = "all";
my $opt_b = "yp";
my %beeper_byname=("YP_a", 0, "a", 1, "b", 2, "YP_z", 9);
my @hits;
if ($opt_d eq "all") {
for ( split /,/, $opt_b ) {
if (/local/) {
push @hits, keys %beeper_byname;
} elsif (/yp/) {
push @hits, map /(\w+)/, `ypcat -k beeper.byname`;
}
}
} else {
@hits = split /,\s*/, $opt_d;
}
for (@hits) {
next if /YP_/;
print "$_\n";
}
# real 0m1.18s
# user 0m0.88s
# sys 0m0.22s
#!/usr/local/bin/perl -w
use strict;
use diagnostics;
my $opt_d = "all";
my $opt_b = "yp";
my %beeper_byname=("YP_a", 0, "a", 1, "b", 2, "YP_z", 9);
for (
grep (
{ ! /^YP_/ }
( $opt_d eq "all" ?
map(
{ if ( /local/ ) { keys(%beeper_byname); }
elsif ( /yp/ ) { map( { /(\w+)/ } `ypcat -k beeper.byname`); }
} split(/,/, $opt_b)
) : split(/,\s*/, $opt_d)
)
)
) {
print "$_\n";
}
# real 0m1.19s
# user 0m0.93s
# sys 0m0.13s
------------------------------
Date: 31 Jul 1999 09:24:11 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Announcement: "CRAP"
Message-Id: <37a3151b@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, japhy+crap@pobox.com writes:
:WHAT IS CRAP?
: Have you seen a program written by someone else, and sighed,
: saying:
Does this mean that you're going to attack that festering hellhole
of eternal damnation known as "Matt's Script Archive"? If so, hurray.
--tom
--
I don't know if it's what you want, but it's what you get. :-)
--Larry Wall in <10502@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: 31 Jul 1999 16:58:02 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Beginner-friendly group as cultural adaptation?
Message-Id: <7nv9uq$e3n@dfw-ixnews5.ix.netcom.com>
Andrew Fry (andrewf@beausys.demon.co.uk) wrote:
: If I had to read these, and the couple of Perl books I now have, and
: various papers/articles at various websites every time I had a problem
: ... well, I'd never get anything done! Also, we all know that documents
: dont always answer the precise question one has in mind.
:
: BTW. I am *NOT* for one moment suggesting that it is never worth reading
: the FAQ and documentation. I am just saying that us newbies are under
: time pressures also, and we dont always have the luxury of time to
: plough through manuals (even if we knew our way around them!).
What you're really saying is that you don't have enough time to do your
own work, so you'd rather have other people do it for you for free. It's
a truism that the easiest job is always the one you don't have to do
yourself.
Have you ever considered using searching/indexing tools? They exist
*precisely* because they eliminate the need to read through volumes of
documentation in search of what you're looking for. If you put in the
relatively small amount of time needed to learn to use them, you'll get
an *enormous* payback; you'll be able to find answers to your questions
almost *instantly*, and you'll have a great deal of assurance that the
answers you find will be correct. Claiming you don't have the time to
learn them is like claiming you don't have time to do it right, but you
do have time to do it over. It's short-sighted. Penny-wise and
pound-foolish. Software development is definitely one of those areas
where spending a little bit of time up front saves you a lot of time down
the road.
------------------------------
Date: Sat, 31 Jul 1999 05:54:37 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: big Oh of sort() func
Message-Id: <t4hun7.0b1.ln@magna.metronet.com>
Ryan Ngi (ryanngi@hotmail.com) wrote:
: what kind of sort is sort() function ? (selection sort, quick sort !?)
perl -ne 'print "$ARGV: $_" if /quick/i and /sort/i' *.pod
perldelta.pod: =head2 Quicksort is internally implemented
perlmodlib.pod: (though having 23 called Sort::Quick is only marginally better :-).
perltoc.pod: =item Quicksort is internally implemented
You could have answered that one yourself too.
Stop it!
Your time is NOT more valuable than everyone else's.
Spend _some_ of yours before asking others to spend their's.
: if the input List is a kind of Large will it very slow !?
It depends on how you are doing the sorting.
It has a Very Good Chance of being slower than it needs to be.
(especially since you seem to be unwilling to spend a few
minutes of your own time to read up on sort()ing in Perl)
perldoc -f sort
perldoc -q sort
See also:
"A Fresh Look at Efficient Perl Sorting":
<URL:http://www.hpl.hp.com/personal/Larry_Rosler/sort/>
"Far More Than Everything You've Ever Wanted to Know About Sorting"
<URL:http://www.perl.com/CPAN/doc/FMTEYEWTK/sort.html>
"Unix Review Column 6 (January 1996)"
<URL:http://www.stonehenge.com/merlyn/UnixReview/col06.html>
[ those last 2 were found by typing "sorting" in the little
"Search" box at http://www.perl.com.
*You* could have done that yourself, if you were not so selfish...
]
: what's Big-Oh of sort()?
Nobody knows.
Perl's sorting doesn't even _have_ a time complexity.
In fact, Perl cannot even _do_ sorting.
Perl is a very poor programming language. Only those who can
read can program in Perl.
Give up on Perl and go learn Visual Basic instead.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 31 Jul 1999 11:47:51 -0400
From: Kent Benson <k.benson@johnabbott.qc.ca>
Subject: cgi-lib.pl-unknown content-type when cgi-bin passworded
Message-Id: <37A31AA7.AEBE9344@johnabbott.qc.ca>
I am using cgi-lib.pl (ver2.8) in a custom script. The script runs fine
in IE and Netscape. However when I password prodect my cgi directory
with.htaccess I get an error when using IE (cgi-lib: Unknown
Content-type: application/x-www-form-urlencoded). Netscape gives no
error. Has anyone else experienced this and what can I do to correct
this.
Thanks
kbenson
------------------------------
Date: Sat, 31 Jul 1999 06:48:37 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Code as an argument
Message-Id: <5akun7.ge1.ln@magna.metronet.com>
Jack Applin (neutron@bamboo.verinet.com) wrote:
: This works fine, printing "hi\n" three times:
: sub many(&$) { &{$_[0]} for 1..$_[1] }
: many {print "hi\n"} 3;
: If I reverse the order of the arguments to many(), compilation fails:
: sub many($&) { &{$_[1]} for 1..$_[0] }
: many 3 {print "hi\n"};
: Can't use subscript on constant item at ./y line 4, near ""hi\n"}"
: Not enough arguments for main::many at ./y line 4, near "};"
: Adding a comma to the call doesn't help:
: sub many($&) { &{$_[1]} for 1..$_[0] }
: many 3, {print "hi\n"};
But adding ", sub" will work.
: Any ideas? Does a code ref as an argument have to be first?
sub many($&) { &{$_[1]} for 1..$_[0] }
many 3, sub {print "hi\n"};
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 31 Jul 1999 15:43:17 GMT
From: mwang@mindspring.com (Michael Wang)
Subject: for (1..60) {print ((-M "/etc/passwd")*86400); print "n"; sleep(1);}
Message-Id: <37a31995@news3.us.ibm.net>
What will be printed here by
for (1..60) {print ((-M "/etc/passwd")*86400); print "n"; sleep(1);} ?
I expect increasing numbers, but I get identical numbers. I verified
this is not due to rounding errors. Can someone tell me why? Thanks.
------------------------------
Date: Sat, 31 Jul 1999 16:39:04 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: for (1..60) {print ((-M "/etc/passwd")*86400); print "n"; sleep(1);}
Message-Id: <slrn7q686a.6l0.*@dragons.duesouth.net>
And so it happened, on 31 Jul 1999 15:43:17 GMT, Michael Wang) typed
random characters into perl, and ended up with the following posted to
comp.lang.perl.misc:
: What will be printed here by
:
: for (1..60) {print ((-M "/etc/passwd")*86400); print "n"; sleep(1);} ?
:
: I expect increasing numbers, but I get identical numbers. I verified
: this is not due to rounding errors. Can someone tell me why? Thanks.
man perlfunc:
...
-M Age of file in days when script started.
...
Neither the when, nor the age is changing in your script.
HTH,
--Matthew
------------------------------
Date: Sat, 31 Jul 1999 09:51:46 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: for (1..60) {print ((-M "/etc/passwd")*86400); print "n"; sleep(1);}
Message-Id: <MPG.120cc97244ee0e7f989d85@nntp.hpl.hp.com>
In article <37a31995@news3.us.ibm.net> on 31 Jul 1999 15:43:17 GMT,
Michael Wang <mwang@mindspring.com> says...
> What will be printed here by
>
> for (1..60) {print ((-M "/etc/passwd")*86400); print "n"; sleep(1);} ?
>
> I expect increasing numbers, but I get identical numbers. I verified
> this is not due to rounding errors. Can someone tell me why? Thanks.
One would think that reading the documentation about '-M' might provide
the answer. Surprise, it does! From perlfunc:
-M Age of file in days when script started.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 31 Jul 1999 12:30:20 -0400
From: "Donboy" <webmaster@roleplayinggames.net>
Subject: General question about CHMOD
Message-Id: <dKFo3.10823$Li1.27946446@news-read1.qis.net>
Hey everyone. I don't normally post on this discussion group, but I've got
a question that I can't seem to otherwise find an answer to.
I run a website that has LOTS of message boards and various Perl scripts, so
I have LOTS of pages that are CHMOD to 777. My question is whether or not
777 is a big security risk. Will CHMOD 777 open me up to potential hackers
and whatnot because the security is not good enough??
Followup question: If 777 is too insecure, what other setting could I use
that would give me the same functionality but better security?
Are there any good websites that explain the dangers of CHMOD to 777 (etc)??
------------------------------
Date: Sat, 31 Jul 1999 06:35:46 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Hey, that's pretty neat!
Message-Id: <2ijun7.ge1.ln@magna.metronet.com>
David Cassell (cassell@mail.cor.epa.gov) wrote:
: Is American English the Perl of human languages?
: [50 points. You have 30 minutes to write a discussion
: of up to 4 pages. You may use the front and back of your
: blue-book pages.]
If we get it right, do we get a certification certificate or something?
If so, what does it look like?
Is it fancy with embossing and seals and looks like a diploma
so I can get a PHB to hire me?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 31 Jul 1999 15:06:03 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: is process still running?
Message-Id: <7nv3cr$4ik$1@lublin.zrz.tu-berlin.de>
Abigail <abigail@delanet.com> wrote in comp.lang.perl.misc:
>Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMCLIX September
>MCMXCIII in <URL:news:7nsent$3f1$1@lublin.zrz.tu-berlin.de>:
>{} Tom Christiansen <tchrist@mox.perl.com> wrote in comp.lang.perl.misc:
>{}
>{} [...]
>{}
>{} >or
>{} >
>{} > ${"it's alive and its uid hasn't changed"} = kill(0, $hispid);
>{} >
>{} >Of course, we're assuming that $hispid is positive here.
>{}
>{} We're also assuming that a zombie is alive. Just a side note.
>
>
>Well, zombies aren't dead....
Well, but dialectically speakung, the undead are, sort of, umm, they're
at the same time... It's just that double negation doesn't...
Oh, forget it.
>Abigail
>--
>I know, cause there lives one in my garden.
Do tell.
Anno
------------------------------
Date: 31 Jul 1999 16:54:53 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Newbie alert !!
Message-Id: <7nv9ot$4n0$1@lublin.zrz.tu-berlin.de>
Larry Rosler <lr@hpl.hp.com> wrote in comp.lang.perl.misc:
>In article <37a60505.373788178@newshost.unx.sas.com> on Fri, 30 Jul 1999
>20:06:21 GMT, John Borwick <John.Borwick@sas.com> says...
>...
>> /$_/ is always true, because it's the same as $_ =~ /$_/ .
>> A "tautology," you might say.
>
>Never say 'always'. A 'truism', you might say.
>
>
>#!/usr/local/bin/perl -w
>use strict;
>
>$_ = "";
>'foo' =~ /./; # Then try commenting this line out.
>print "true\n" if /$_/;
Ah, you bring to my attention one of my pet peeves with Perl: the
misfeature that m// is short for the regular expression that last
successfully matched something. Why is this useless?
You only want to use the feature when the pattern can't be specified
literally, otherwise you'd just do that. This means the pattern is
only known at run time, and to initialize m//, you'd have to come
up with a string that is matched by what is basically an arbitrary
pattern. To do this, you'd need an inverse regex engine, as it were,
which is by no means trivial and may indeed be similar in complexity
to the forward engine.
The feature would be much more useful if m// were equivalent to the
last successfully *compiled* regex. I wonder if that could be changed
in some future release of Perl. It is hard to imagine how the feature
could be applied as it is, so the change shouldn't break too many
existing programs. Or am I lacking fantasy?
Anno
------------------------------
Date: 31 Jul 1999 16:18:30 GMT
From: jgd@alpha3.csd.uwm.edu (John G Dobnick)
Subject: Re: NEWSFLASH: Supremes rule anti-advert-ware illegal
Message-Id: <7nv7km$8kg$1@uwm.edu>
[Possibly off topic, and certainly "meta-perl"-ish, but.... :-) ]
From article <37A235CD.C5DA51AC@mail.cor.epa.gov>, by David Cassell <cassell@mail.cor.epa.gov>:
>
> When Ernie Brouwer [a brand-spanking-new poster AFAIK]
> dropped in his Jabberwocky parody, was he chewed up and spit
> out? No.
If we can consider "Perl Poetry" germane to this group, then certainly
"poetry about Perl" is also germane.
Beside, the Jabberwocky parody was _funny_. :-)
My $0.02.
--
John G Dobnick "Knowing how things work is the basis
Information & Media Technologies for appreciation, and is thus a
University of Wisconsin - Milwaukee source of civilized delight."
jgd@csd.uwm.edu ATTnet: (414) 229-5727 -- William Safire
------------------------------
Date: 31 Jul 1999 17:03:43 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: NEWSFLASH: Supremes rule anti-advert-ware illegal
Message-Id: <7nva9f$e3n@dfw-ixnews5.ix.netcom.com>
David Cassell (cassell@mail.cor.epa.gov) wrote:
: I think that there is a certain amount of looseness in
: the interpretation of 'off-topic'. And I think that the
: interpretation differs from discussions to questions. I
: don't think that's bad either. I would hate to be deprived
: of the next Perl parody due to undue ng strictures. I
: would not mind being deprived of the next 'how do I make a
: Back button' question.
You've touched on an important point. The parodies and the rest of the
"off-topic silliness" are all *original*. The questions that can be
answered by the FAQs and the general Web questions are, for the most
part, completely repetitious. They're posted several times a week, or
even several times a day. The parodies, etc. aren't obnoxious because
people haven't seen them hundreds of times already.
------------------------------
Date: Sun, 01 Aug 1999 01:04:09 +1000
From: Pat Heuvel <pheuvel@optusnet.com.au>
Subject: Re: Perl bug?
Message-Id: <37A31069.18FE5017@optusnet.com.au>
Wing wrote:
>
> Hi.
> I think I've tumbled on a bug. Whenever I try to read a file that
> contains the character 0x1a with the following script, it reads the content
> only upto that character.
...
0x1a is the DOS end of text file character. You have opened the file in
text mode and your program has happily reported end-of-file at this
marker.
Try the binmode function right after your open, then your results should
look more like what you expect...
open(INFILE, "test.txt);
binmode INFILE;
while(<INFILE>)
{
etc...
}
Hope this helps,
Pat
--
+---------------------------------------------------------+
+ "Logic clearly dictates, that the strokes of the many +
+ outweigh the strokes of the two..." +
+ (Apologies to Mr Spock) +
+---------------------------------------------------------+
------------------------------
Date: Sat, 31 Jul 1999 17:21:26 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Perl bug?
Message-Id: <Pine.HPP.3.95a.990731170904.6303F-100000@hpplus03.cern.ch>
On Sat, 31 Jul 1999, Larry Rosler wrote:
> In that infamous lineage, files are divided dichotomously: text and
> binary. Within text files, the character "\cZ" (Control-Z, 0x1A)
> indicates end-of-file,
Indeed
> presumably so that multiple subfiles can be
> contained within one file.
Did you really hear of such a thing? I note you said "presumably".
AARI, the reason was that in some situations, files were allocated in
fixed-size blocks. Without a positive indication of where the file
ended, there was no way of stopping the data before the next block
boundary came up.
In that situation, binary files were always a multiple of the block
size. The residue of the last block could have contained whatever the
cat last dragged in, if the software didn't make an effort to zero it.
Some people used to stick hidden messages in there for a laugh. But
I've never heard of it being used for a fresh file of data. I'm open to
ridicule if someone knows better...
> You can treat your file as binary (which it probably is), and use the
> binmode() function immediately after opening it.
absolutely
> If in fact it is a text file, you will have to strip the
> "\r" from the line-endings "\r\n" yourself.
The fact that the questioner thinks there is meaningful data beyond the
ctrl/Z suggests that it isn't a text file. Unless it's been mishandled
at some point in its history, in which case the line endings could be
a right mess by now.
all the best
------------------------------
Date: 31 Jul 1999 12:01:45 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Perl bug?
Message-Id: <x7r9lon6za.fsf@home.sysarch.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> [Posted and a courtesy copy sent to the poster and to TomC.]
LR> In article <rq5nrgfb5p55ta@corp.supernews.com> on Sat, 31 Jul 1999
LR> 07:34:18 -0400, Wing <wingcma@mailexcite.com> says...
>> I think I've tumbled on a bug. Whenever I try to read a file that
>> contains the character 0x1a with the following script, it reads the content
>> only upto that character.
LR> The 'bug' is a design misfeature. We can safely assume that the evil
LR> purveyors of your so-called operating system ripped off this misfeature
LR> from CP/M also, along with so many other idiocies.
LR> In that infamous lineage, files are divided dichotomously: text and
LR> binary. Within text files, the character "\cZ" (Control-Z, 0x1A)
LR> indicates end-of-file, presumably so that multiple subfiles can be
LR> contained within one file. I doubt that anyone actually uses this
LR> capability nowadays.
it goes further back than that, to RT-11 from around 1971-2. it could only
keep the number of 512 byte blocks as the file size in the dir entry. so
the ^Z char was used to mark the actual end of file for text files. i
don't think rt-11 had a binary mode for open, you had to know the
convention yourself but all standard utilities and editors obeyed
it. unix fixed that design flaw with byte resolution in the file size.
cp/m was derived from rt-11 and hence onto redmondware. that's what you
get for stealing bad ideas instead of inventing better ones. uncle bill's
morla legacy lingers on forever. even dec fixed that with vms (text
files are line records), but nt still does it.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: Sat, 31 Jul 1999 12:23:15 -0400
From: "Ken Hirsch" <kenhirsch@myself.com>
Subject: Re: Perl bug?
Message-Id: <7nv84j$9u3$2@birch.prod.itd.earthlink.net>
Wing <wingcma@mailexcite.com> wrote:
> Hi.
> I think I've tumbled on a bug. Whenever I try to read a file that
> contains the character 0x1a with the following script, it reads the
content
> only upto that character.
On MS-DOS and Windows systems, Ctrl-Z is considered an end of file
character.
If you do binmode(FILE) after you open the file, you will be able to read
all characters. Be advised that the lines you read will now be terminated
by '\r\n' instead of '\n', so you may need to change some program logic.
Also note that on MS-DOS the stat -s size will not usually be equal to the
length of all the characters read with <> if you don't use binmode because
CR-LF pairs are translated to a single newline on input.
Ken Hirsch
------------------------------
Date: Sat, 31 Jul 1999 11:52:49 -0400
From: "Ken Hirsch" <kenhirsch@myself.com>
Subject: Re: pipes vs csv
Message-Id: <7nv84i$9u3$1@birch.prod.itd.earthlink.net>
<joeyandsherry@mindspring.com> wrote:>
> Hello,
>
> Is there an advantage or disadvantage of using pipes versus commas as
field
> delimiters in flat text files? I have been successfully using commas, but
> have run into a few problems here and there, and was thinking that pipes
> would eliminate this potential.
The only problem with commas is that they may be valid data, e. g. "Perl,
Inc." or "Wall, Larry"
Pipes are much less likely to be valid and you can edit them out at user
input.
I would not recommend \0 as Faisal did because it confuses many editors and
other text tools even though it is fine with Perl.
There is an ASCII character which is more or less reserved for this purpose,
US, the unit separator, which is decimal 31. This is much less likely to be
valid data than any graphic character. So far I haven't had it confuse any
editors or tools. You can enter it from the keyboard by typing Ctrl+Shift+_
(that's the underscore/minus key with Ctrl and Shift). Or, if you're using
a PC, you can hold down ALT and type 3 1 on the numeric keypad (and then
release Alt).
Ken Hirsch
------------------------------
Date: Sat, 31 Jul 1999 05:59:24 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: print with an inline "
Message-Id: <sdhun7.0b1.ln@magna.metronet.com>
[ quoting reordered from nonsense Jeopardy order into sensible
chronological order.
please put your comments *following* the quoted text that
you are commenting on.
people (the readers of your followup) don't think backwards
in time. they think from past to present, not from present
to past (unless they are at a High School reunion).
]
Makarand Kulkarni (makkulka@cisco.REMOVETHIS.com) wrote:
: Tom Beauchamp wrote:
: >
: > <font face="Arial, Helvetica, sans-serif">Arial</font>
: >
: > I can't figure out how to print the inline quotation marks.
: You have to escape the quotation marks
^^^^^^^
No you don't.
: as follows
: print "<font face=\"Arial, Helvetica, sans-serif\">Arial</font>" ;
print '<font face="Arial, Helvetica, sans-serif">Arial</font>';
print q(<font face="Arial, Helvetica, sans-serif">Arial</font>);
print qq(<font face="Arial, Helvetica, sans-serif">Arial</font>);
No escaping of quotation marks in any of those.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 31 Jul 1999 15:25:44 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Problems with use/require ....
Message-Id: <7nv4ho$4kd$1@lublin.zrz.tu-berlin.de>
Maksym Y. Shevchenko <msh@kar.net> wrote in comp.lang.perl.misc:
>I have 3 files in same directory:
>
>aaa.pl bbb.pm ccc.pl.lib
>
>Here are sources of them:
># -----------------aaa.pl----------------
>#!/usr/local/bin/perl
>use bbb;
>require "ccc.pl.lib";
>print "In main!\n";
>print &ccc,"\n";
>print bbb->b(),"\n";
>#----------------------------------------
>
># -----------------bbb.pm--------------
>package bbb;
>require "ccc.pl.lib";
>sub import {
> return 1;
>}
>sub b {
> return "In bbb::b!".&ccc;
>}
>1;
>#----------------------------------------
>
># -----------------ccc.pl.lib-------------
>sub ccc {
> return "In \&ccc!";
>}
>1;
>#----------------------------------------
>
>Why I got a:
>
>./aaa.pl
>In main!
>Undefined subroutine &main::ccc called at ./aaa.pl line 7.
Why do you expect ccc to be defined in package main? The package
bbb is in effect when you require ccc.pl.lib. The import function
does nothing for you, not only because it's almost a no-op, but also
because you don't provide an export list.
>How I undersand refence to &ccc must be defined from main class and from bbb
>class,
>but defined only from bbb class... Why?
I'm not sure I understand these questions.
Anno
------------------------------
Date: Sat, 31 Jul 1999 06:00:06 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: returning to beginning of a file
Message-Id: <6fhun7.0b1.ln@magna.metronet.com>
skyfaye@my-deja.com wrote:
: I have a file opened for reading. After reaching the end of the file,
: can I return to the beginning without closing and opening it again?
perldoc -f seek
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 31 Jul 1999 06:10:12 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: running programs from inside perl
Message-Id: <42iun7.hd1.ln@magna.metronet.com>
Matt (mattk@cybersurf.net) wrote:
: olumsbaba@my-deja.com wrote:
: >
: > how do I call another program from inside Perl
: three ways
: `java test`; # returns program output
: exec 'java test'; # executes and NEVER returns
: system 'java test'; # returns program return value
If someone is at the level of asking the question asked above,
then mentioning exec() is not appropriate yet.
And you left out a way that _is_ appropriate even for neophytes.
So, take out exec(), and put in "pipe open".
perldoc -f open
open(JAVA, 'java test|') || die "could not fork $!";
while (<JAVA>) {
# do something with line of output from Java program
}
close(JAVA) || die "problem running Java program $!";
See also Perl FAQ, part 8:
"Why doesn't open() return an error when a pipe open fails?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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 V9 Issue 322
*************************************