[9213] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2808 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 7 21:07:34 1998

Date: Sun, 7 Jun 98 18:00:20 -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, 7 Jun 1998     Volume: 8 Number: 2808

Today's topics:
    Re: Am I looking at an anonymous array <tchrist@mox.perl.com>
    Re: delete slice in list <due@murray.fordham.edu>
    Re: Downloading Perl <net4u@arese.com>
    Re: END{} to dump object data. (Larry Rosler)
    Re: END{} to dump object data. <ckilburn@nbnet.nb.ca>
    Re: END{} to dump object data. <lr@hpl.hp.com>
    Re: File processor and conditional output <cowanb@mindspring.com>
    Re: Force garbage collection <tchrist@mox.perl.com>
    Re: Force garbage collection (Bbirthisel)
    Re: HTTP Header Info rpearce@my-dejanews.com
    Re: I'm having problems: <tchrist@mox.perl.com>
    Re: lines of text, inserting spaces (Larry Rosler)
        Matrix: WWW-DB Access Options elizabethsugar@my-dejanews.com
    Re: perl-frage <joat@series2000.com>
    Re: question <tchrist@mox.perl.com>
        Searchable Perl FAQ up (temporary) (Mike Heins)
    Re: The Very Basics! ptimmins@netserv.unmc.edu
    Re: The Very Basics! <tchrist@mox.perl.com>
    Re: what's a cross-platform \n please? <tchrist@mox.perl.com>
    Re: what's a cross-platform \n please? <tchrist@mox.perl.com>
    Re: what's a cross-platform \n please? (Larry Rosler)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 7 Jun 1998 23:02:50 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Am I looking at an anonymous array
Message-Id: <6lf66q$655$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, kpreid@ibm.net (Kevin Reid) writes:
:sub isanon ($$) {

my $var = "you can't find me";

--tom
-- 
"A momentary lapse of stupidity" -- Dean Roehrich


------------------------------

Date: 7 Jun 1998 22:52:41 GMT
From: "Allan M. Due" <due@murray.fordham.edu>
Subject: Re: delete slice in list
Message-Id: <6lf5jp$9lf$0@206.165.146.137>


Daniel Grisinger wrote in message <6leul0$od$1@perrin.dimensional.com>...
>>
>Will this suffice?
>
>$a = 'split and splice with just one semicolon for a guy on clpm';
>@result = map { @$_[0 .. $#$_-5] } [split / /, $a];
>print join ' ', @result;


This is quite sufficient with the tiny caveat that the original poster
wanted the last three elements removed and the sting in the same line too
so:
@new = map { @$_[0 .. $#$_-3];} [split / /, 'Dvorak keyboard is wonderful.
Eh eh eh?'];
works like a charm.

Now if, it not too much to ask, could I request a wee bit more edification?
I have never seen @$_ before.  I can see how it works after playing with the
code but I would never have guessed it would work if I had not seen it here
first.  Any suggested readings or sources of explanation?

Allan M. Due
Due@discovernet.net
Admin@WhiteCrow.net

The beginning of wisdom is the definitions of terms.
- Socrates


>
>>Any additional edification would be appreciated.
>>
>Hope this helps :-).
>
>Regards,
>Daniel
>--
>Daniel Grisinger       dgris@perrin.dimensional.com
>"No kings, no presidents, just a rough consensus and
>running code."
>                        Dave Clark




------------------------------

Date: Sat, 06 Jun 1998 14:38:18 +0200
From: Marcello Veggiotti <net4u@arese.com>
To: Rainer Pielmann <pira0011@rz03.FH-Karlsruhe.DE>
Subject: Re: Downloading Perl
Message-Id: <3579383A.82CCC52D@arese.com>

You can download it from http://www.activestate.com/pw32/

Have a nice day

Rainer Pielmann wrote:

> Hello,
>
> I am new to Perl. Can anyone tell me where I can download a full
> operational Perl version for a Windows 95 system?
>
> Thx
>
> Rainer





------------------------------

Date: Sun, 7 Jun 1998 14:56:19 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: END{} to dump object data.
Message-Id: <MPG.fe4ac5beb88311a9896a2@nntp.hpl.hp.com>

In article <357B02C5.910EA00F@nbnet.nb.ca>, ckilburn@nbnet.nb.ca says...
> I would like to have the END{} subroutine dump the object data.
> Since END{} is not a callable method, I don't see how I can access
> the object data.
> 
> I am confused about the scope of END{}.
> All of the examples I have seen only print messages for illustration.
> 
> The script I am writing calls other scripts of which any could fail.
> I store the status of the process, what failed what succeeded,
> within the object's data so that I can rerun the process without
> redoing what succeeded.
> 
> Maybe I should put an explicit call within the END{}.
> 
> END {
>   Class->cleanup();
> }
> 
> Before I try this, I would like so experienced input.

Actually, you should try it first *before* asking in the newsgroup.  You 
would have discovered immediately that END{} (like BEGIN{}) has the same 
scope as any other subroutine in the package it is in.  The only 
difference is that it is executed automatically, without arguments, on 
exit from the program.

-- 
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


------------------------------

Date: Sun, 07 Jun 1998 20:57:31 -0300
From: Colin Kilburn <ckilburn@nbnet.nb.ca>
Subject: Re: END{} to dump object data.
Message-Id: <357B28EA.754B086F@nbnet.nb.ca>

Ok, so I tried it. The only way I could access the object data in the
END{} subroutine was to make the the hash global. (%custInfo)

Is there a way to make the hash anonymous and local to the new{}
constructor
while still being able to access it in the END{} subroutine?

Thanks,
Colin

Code included for reference :

use     strict;
package C::Customer;
my      %custInfo;                     # customer configuration info
hash

sub new
{
  my $proto = shift;                   # shift implicit for object
dereference
  my $class = ref($proto) || $proto;   # ref returns base class if
inheritance
  my $self  = {%custInfo};             # object data
  bless ($self, $class);               # ordain

  $custInfo{test} = "vital data";

  return ($self); # return object reference
}

END
{
  print "in END\n";
  my ($key, $value);
  ($key, $value) = each (%custInfo) ;
  print " $key => $value\n";
}

1;

Larry Rosler wrote:

> In article <357B02C5.910EA00F@nbnet.nb.ca>, ckilburn@nbnet.nb.ca
> says...
> > I would like to have the END{} subroutine dump the object data.
> > Since END{} is not a callable method, I don't see how I can access
> > the object data.
> >
> > I am confused about the scope of END{}.
> > All of the examples I have seen only print messages for
> illustration.
> >
> > The script I am writing calls other scripts of which any could fail.
>
> > I store the status of the process, what failed what succeeded,
> > within the object's data so that I can rerun the process without
> > redoing what succeeded.
> >
> > Maybe I should put an explicit call within the END{}.
> >
> > END {
> >   Class->cleanup();
> > }
> >
> > Before I try this, I would like so experienced input.
>
> Actually, you should try it first *before* asking in the newsgroup.
> You
> would have discovered immediately that END{} (like BEGIN{}) has the
> same
> scope as any other subroutine in the package it is in.  The only
> difference is that it is executed automatically, without arguments, on
>
> exit from the program.
>
> --
> Larry Rosler
> Hewlett-Packard Laboratories
> lr@hpl.hp.com





------------------------------

Date: Sun, 07 Jun 1998 17:43:09 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: END{} to dump object data.
Message-Id: <357B339D.A932F3A8@hpl.hp.com>

In article <357B28EA.754B086F@nbnet.nb.ca>, ckilburn@nbnet.nb.ca says...
> Ok, so I tried it. The only way I could access the object data in the
> END{} subroutine was to make the the hash global. (%custInfo)
> 
> Is there a way to make the hash anonymous and local to the new{}
constructor
> while still being able to access it in the END{} subroutine?
> 
> Thanks,
> Colin
> 
> Code included for reference :
> 
> use     strict;
> package C::Customer;

{

> my      %custInfo;                     # customer configuration info
> hash
> 
> sub new
> {
>   my $proto = shift;                   # shift implicit for object
> dereference
>   my $class = ref($proto) || $proto;   # ref returns base class if
> inheritance
>   my $self  = {%custInfo};             # object data
>   bless ($self, $class);               # ordain
> 
>   $custInfo{test} = "vital data";
> 
>   return ($self); # return object reference
> }
> 
> END
> {
>   print "in END\n";
>   my ($key, $value);
>   ($key, $value) = each (%custInfo) ;
>   print " $key => $value\n";
> }

}

-- 
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


------------------------------

Date: Sun, 07 Jun 1998 18:30:22 -0400
From: Bill Cowan <cowanb@mindspring.com>
To: Erik Huelsmann <ErikH@Bitsmart.com>
Subject: Re: File processor and conditional output
Message-Id: <357B147E.DECDC955@mindspring.com>

Erik Huelsmann wrote:
> 
> I am looking for a textfile processor like a C preprocessor, to allow
> for conditional output. Since I am absolutely new to perl... Can it be
> done easily in perl (or maybe: has it been done already)?
> 

See CPAN for text processing modules (mainly Text::xxxx group):

	http://www.perl.com/CPAN/modules/by-module/Text/

I did similar research two months ago. I think you will find useful well
documented modules, which mainly follow a template/boilerplate approach
with embedded preprocessor commands.

-- Bill
------------------------------------------------------------------------
Metagenix, Inc:  Leading the Way in Data Migration.
Web:  http://www.metagenix.com/ for more datails.
Bill Cowan, cowanb@mindspring.com, Voice: 919-210-4910 Fax: 919-489-2621
Applying Perl-based toolkit and methodology to data migration process.


------------------------------

Date: 7 Jun 1998 23:13:03 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Force garbage collection
Message-Id: <6lf6pv$655$5@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    "Preferred Customer" <plmiller@postoffice.worldnet.att.net> writes:

What a lame name.

:I am running a perl program to process a large file ( 15,000,000 records of
:1000 bytes each).  I simply read a single record, process it, and write it
:out to a file.  What is happening is that I get an out of memory failure. 
:It appears that the arrays and hashes I am using are not being reused but
:new memory is assigned for each record. Using top Isee that my address
:space is approaching 2 gig when I get the out of memory message.  Is there
:a way I could force garbage collection every 100,000 records?

I believe you've found a bug in your program, not Perl.
If you say

    push(@a, 1) while 1;

You'll run out of memory, too.  If your data has no circular references,
it should be fine.  

You probably just seen to say

    my @a;

or

    @a = ();

At the opportune point.

--tom
-- 
Sometimes when you fill a vacuum, it still sucks.   --Rob Pike


------------------------------

Date: 07 Jun 1998 23:42:33 GMT
From: bbirthisel@aol.com (Bbirthisel)
Subject: Re: Force garbage collection
Message-Id: <1998060723423300.TAA25340@ladder01.news.aol.com>

Hi Paul:

>I am running a perl program to process a large file ( 15,000,000 records of
>1000 bytes each).  I simply read a single record, process it, and write it
>out to a file.  What is happening is that I get an out of memory failure. 
>It appears that the arrays and hashes I am using are not being reused but
>new memory is assigned for each record. Using top Isee that my address
>space is approaching 2 gig when I get the out of memory message.  Is there
>a way I could force garbage collection every 100,000 records?

You would have to modify the script. There is no switch to tell perl "cleanup
after every ??? operations".

The details of how to modify the script are algorithm dependent. You would
have to "undef" some of the temporary storage at a time that it wasn't actually
in use. But I won't try to guess from the description when that would be.

-bill
Making computers work in Manufacturing for over 25 years (inquiries welcome)


------------------------------

Date: Sun, 07 Jun 1998 22:42:52 GMT
From: rpearce@my-dejanews.com
Subject: Re: HTTP Header Info
Message-Id: <6lf51c$7st$1@nnrp1.dejanews.com>

Have you tried routing it thru an shtml file and use exec cgi to call the
actuall perl script?  Not sure if the variables would get passed thru both,
but it would just show the .shtml file in the Location: bar.

Just a thought.


In article <6leqta$sek$1@nnrp1.dejanews.com>,
  bobbybooby@my-dejanews.com wrote:
>
> I think I may have been unclear.  I think I have the correct group.
>
> Here's the story.  The site I'm working on is  driven using a perl script
> calling the content from a flat database file (so I can use a layout
> template).  Each link in the site is pointing to the script with a filename
> delimiter (i.e., <A HREF="cgi-bin/script.pl?filename">name</A> (an implied
> GET, thus the reason for the URL Address Window showing
> "http://www.servername.com/cgi-bin/script.pl?filename").  If I called using
> an implied POST (i.e., <A
> HREF="cgi-bin/script.pl?filename=filename">name</A>, I'd eliminate the
> "?filename" information caused by the GET, but would still get the
> "http://www.servername.com/cgi-bin/script.pl" part.  I do not want the
> browser clients to show full URL in the Address window, I want the URL parsed
> and have the browser only show the main URL info (i.e.,
> http://www.servername.com).  I realize that I can turn off showing the
> address in my browser - duh!  The question is, can I control what address is
> shown in the browser address window from within the perl script potentially
> by declaring the HTTP headers to override the actual?  Thus the reason for
> the posting here.
>
> In article <357a81e7.7719049@news.btinternet.com>,
>   Gellyfish@btinternet.com (Jonathan Stowe) wrote:
> >
> > On Sun, 07 Jun 1998 05:59:20 GMT, bobbybooby@my-dejanews.com wrote :
> >
> > >Does anyone know how to do the following?
> > >
> > >I'd like to control the address that appears in the browser address bar.  I
> > >have a site that draws the info from a flat files using perl and forms and
> > >the resulting URL that appears in the Browser Address bar looks like
> > >"http://www.servername.com/cgi-bin/script.pl?filename"
> > >
> >  Eh,oh
> > Yes thats what happens when the HTTP request method is GET and this
> > will happen whatever language the CGI is written in. If you dont like
> > it you could always check in the documentation for your browser how to
> > hide the URL box.
> >
> > >Is there a way to set the HTTP header information in the script to fool the
> > >browser so it doesn't show all the garbage after the
> > >"http://www.servername.com"?  Kind of like
> > >
> >
> > Ask in an appropriate newsgroup about how to use the POST method and
> > this isnt an appropriate newsgroup.
> >
> > >print FILEHANDLE Location:http://www.servername.com";
> > >
> >
> > What do you think that will achieve ?
> >
> It was an example.  This particular line does nothing.
> > /J\
> > Jonathan Stowe
> > Some of your questions answered:
> > <URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
> >
> >
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/   Now offering spam-free web-based newsreading
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


------------------------------

Date: 7 Jun 1998 23:05:42 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: I'm having problems:
Message-Id: <6lf6c6$655$2@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    kpreid@ibm.net (Kevin Reid) writes:
:I think the name File::Find is misleading. It ought to be called
:File::DirRecurse or something like that.

Misleading?  Hello?  It's entirely obvious, since it's an emulation of
the standard find program, as used by find2perl.

--tom
-- 
Whenever people agree with me I always feel I must be wrong.
                --Oscar Wilde


------------------------------

Date: Sun, 7 Jun 1998 14:48:13 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: lines of text, inserting spaces
Message-Id: <MPG.fe4aa7b3b41aaf19896a0@nntp.hpl.hp.com>

In article <6levaj$4m8@news-central.tiac.net>, mike@stok.co.uk says...
> You might consider using unpack if you're dealing with formatted records.
> The debugger example below carves up the line into fields containing 4, 4,
> 5, 6 characters and the rest of the line, and then the print takes
> advantage of spaces being inserted between array elements inside double
> quotes:
> 
>   DB<1> $str = "112121821745647263562393434941947\n"
> 
>   DB<2> @fields = unpack 'a4 a4 a5 a6 a6 a*', $str
> 
>   DB<3> print "@fields"
> 1121 2182 17456 472635 623934 34941947

Many times no!!!

The spaces in the format string of pack/unpack are irrelevant, and may be 
used to enhance readability.  The spaces in the output of your print 
statement are the contents of the $" variable, ' '  by default.  Try 
setting it to something else and you will see.

-- 
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


------------------------------

Date: Sun, 07 Jun 1998 23:44:02 GMT
From: elizabethsugar@my-dejanews.com
To: liz@rawl.co.nz
Subject: Matrix: WWW-DB Access Options
Message-Id: <6lf8k2$bd1$1@nnrp1.dejanews.com>

  Hi!

I'm trying to figure out what the best option is for the following scenerio by
producing a matrix first as a general best practice idea, and secondly as
anything specific to a UNIX SunOS 5.5.1 Ingres 6.4 situation.
Also if you've developed any of these and have any comments good/bad, please
let me know!  Thanks in advance for your help.

Database:  Ingres 6.4 OS:  SunOS 5.5.1 Site:  highly complex client
interaction site i.e. if you select an item in a list, need to populate
another list and/or tabl e via the Database so lots of constant processing by
one client. Situation is similar to an application for sales people, needing
information about various products and options available to come up with the
best options for a given customer. Expecting up to 5,000 nodes accessing the
site (if this must be limited, please let me know that too) Matrix consists
of the Issues, the options, and what i've got so far:

MATRIX

  ISSUES:
----------
  Simplicity (development,

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


------------------------------

Date: Sun, 07 Jun 1998 20:28:41 -0400
From: Tim Kramer <joat@series2000.com>
Subject: Re: perl-frage
Message-Id: <357B3038.8FBD5092@series2000.com>

Jonathan Stowe wrote:

> English please.  Or use a de.* newsgroup.

He did write it in English.  Twice.  And once in German,
just to be sure.  I was able to understand all three posts.

The answer to wolfram.oehms question is "maybe".
The username might be parsed out of the visitors
variables but only if the user has bothered to fill in
a valid return address (and many people don't).



------------------------------

Date: 7 Jun 1998 23:07:57 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: question
Message-Id: <6lf6gd$655$3@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    "wolfram.oehms" <wolfram.oehms@metronet.de> writes:
:Is there a way to send an email out to everyone who comes to our website
:automatically without them filling out a form,etc... ?

Not without a small thermonuclear holocaust, as all such 
evil acts merit.

--tom
-- 
    "Lisp has all the visual appeal of oatmeal with fingernail clippings mixed in."
    	--Larry Wall


------------------------------

Date: 7 Jun 1998 19:51:17 -0500
From: mikeh@minivend.com (Mike Heins)
Subject: Searchable Perl FAQ up (temporary)
Message-Id: <357b2775.0@news.one.net>

Dear All,

I have put an experimental Perl FAQ up at:

    Frames
	http://www.minivend.com/cgi-bin/perlfaq/frames

    No frames
	http://www.minivend.com/cgi-bin/perlfaq

It is searchable, and is relatively navigable. It won't be
up long, for this server can't stand the additional strain, but
if it turns out to be something that people want I am sure
I will be able to find a permanent home.

I will try to keep it up for 3 days, hoping for helpful comments.
If it disappears then you will be redirected to an appropriate place.

Please send comments to:

	perlfaq@minivend.com

-- 
Mike Heins                          http://www.minivend.com/  ___ 
                                    Internet Robotics        |_ _|____
Fast, reliable, cheap.              131 Willow Lane, Floor 2  | ||  _ \
Pick two and we'll talk.            Oxford, OH  45056         | || |_) |
 -- unknown                         <mikeh@minivend.com>     |___|  _ <
                                    513.523.7621 FAX 7501        |_| \_\


------------------------------

Date: Sun, 07 Jun 1998 22:52:45 GMT
From: ptimmins@netserv.unmc.edu
Subject: Re: The Very Basics!
Message-Id: <6lf5jt$8f2$1@nnrp1.dejanews.com>

In article <357AE833.E60EF469@cin.net>,
  Tim & Kim <peach@cin.net> wrote:
>
> Ok,  Lamer question.  Do I have to find a particular CGI directory on my
> web page server?  Can I just put a CGI with Perl program up, where my
> current page is, and have it run?  Very confused about this as the book
> I bought assumes previous genius status.

1. probably
2. probably not

>    Please e-mail if willing to help!
>          Thanks!

No. Go look at comp.infosystems.www.authoring.cgi.

Best of luck to you in all your endeavors. I hope you obtain all that your
efforts warrant.

Patrick Timmins
U. Nebraska Medical Center

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


------------------------------

Date: 7 Jun 1998 23:09:53 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: The Very Basics!
Message-Id: <6lf6k1$655$4@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, Tim & Kim <peach@cin.net> writes:
:Ok,  Lamer question.  Do I have to find a particular CGI directory on my
:web page server?  

There must surely be some Perl content in your question, but
I for one was unable to find it.  Apparently you've confused
this for some web-related newsgroup.  

It's not.

--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 


------------------------------

Date: 7 Jun 1998 23:14:44 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: what's a cross-platform \n please?
Message-Id: <6lf6t4$655$6@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, lr@hpl.hp.com (Larry Rosler) writes:
:It makes all the difference whether the file is open for binary or text!

Only on primitive systems. 

--tom
-- 
    "New versions happen." --Larry Wall


------------------------------

Date: 7 Jun 1998 23:23:50 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: what's a cross-platform \n please?
Message-Id: <6lf7e6$655$7@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to various parties via mail]

In comp.lang.perl.misc, lr@hpl.hp.com (Larry Rosler) writes:
:It makes all the difference whether the file is open for binary or text!

Let's try it another way.  The "text" versus "binary" distinction
is a symptom of bad design.  When a file is a file is a file,

Here's another excerpt from the Perl Cookbook:

    ``The most brilliant decision in all of Unix was the choice of a
      *single* character for the newline sequence.''

		--Mike O'Dell, only half jokingly


    Before the Unix Revolution, every kind of data source and destination
    was inherently different.  Merely getting two programs to understand
    each other required not only heavy wizardry but also the occasional
    sacrifice of a virgin stack of punch cards to an itinerant mainframe
    repairman.  This computational Tower of Babel made programmers
    dream of quitting computers to take up some less painful hobby,
    like autoflagellation.

    Today, those days of cruel and unusual programming are largely
    behind us.  Modern operating systems work hard to provide the illusion
    that I/O devices, network connections, process control information,
    other programs, the system console, and even users' terminals are
    all abstract streams of bytes called ``files''.  This lets you easily
    write programs that don't care where their input came from nor where
    their output goes.

    Because programs read and write via byte streams of simple text, every
    program can communicate with every other program--even programs that
    haven't been written yet!  It is difficult to overstate the power
    and elegance of this approach.  No longer dependent upon troglodyte
    gnomes with secret tomes of JCL or COM incantations, ordinary users
    can now create custom tools out of smaller components by using simple
    command-line I/O redirection, pipelines, and backticks.

 ....

    Not everyone agrees what a line in a text file is, because one
    person's textual character set is another's binary gibberish. Even
    when all parties involved are using ASCII instead of EBCDIC, Rad50,
    or Unicode, discrepancies arise.

    There is no such thing as a newline character. It is purely virtual,
    a figment of the operating system, standard libraries, device drivers,
    and Perl, who all conspire to make your life easy.

[Or as easy it can get when supporting CP/M. --tchrist]

    Under Unix or Plan9, a "\n" represents the physical sequence "\cJ"--
    a linefeed. However, on a terminal that's not in raw mode, an <ENTER>
    key generates an incoming "\cM" (a carriage return), which turns
    into "\cJ", while an outgoing "\cJ" magically turns into
    "\cM\cJ". This strangeness doesn't happen with normal files,
    just terminal devices, and is handled strictly by the device driver.

    On a Mac, a "\n" is usually represented by "\cM"; just to make life
    interesting (and because it's required by the standard than \n and
    \r represent different characters), a "\r" represents a "\cJ". You
    will note that this is exactly the opposite of the way that Unix,
    Plan9, VMS, CP/M, or nearly anyone else does it. This means that
    Mac programmers writing files for other systems, or talking over
    a network, have to be more careful than the rest of us. If they
    just send out "\n", they'll deliver a "\cM" and no "\cJ" will ever
    be seen. Most network services prefer to receive and send "\cM\cJ"
    as a line terminator, but most are also content to receive merely a
    "\cJ". The old adage ``be liberal in what you accept, and conservative
    in what you send'' is still true today.

    Under VMS, DOS, or derivatives thereof, a "\n" represents "\cJ",
    in a similar fashion to Unix and Plan9. From the perspective of a
    tty, Unix and DOS behave identically: a user who hits `<ENTER>'
    generates a "\cM", but this arrives at the program as a "\n",
    which is "\cJ". And a "\n" (that's a "\cJ", remember) sent to
    a terminal shows up as a "\cM\cJ".

    But these strange conversions happen to Windows files as well. A
    ``text file'' in DOS actually contains two characters at the end of
    every line, "\cM\cJ".  And the last block in the file has a "\cZ"
    in it to indicate where the text stops. When you write a line like
    "bad news\n" on those systems, the file ends up containing "bad
    news\cM\cJ", just as if it were a terminal.

    When you read a line on such systems, it's even stranger. The file
    itself contains "bad news\cM\cJ", a ten-byte string. When you read
    it in, your program gets nothing but "bad news\n", where that "\n"
    is the virtual newline character, that is, a linefeed ("\cJ"). That
    means to get rid of it, a single `chop' or `chomp' will do it. But
    your poor program has been tricked into thinking it's only read nine
    bytes from the file. If you were to read ten such lines, you would
    appear to have read 90 just bytes into the file, but in fact would
    be at position 100. That's why the `tell' function must always be
    used to figure out where you are. You can't infer your position just
    by counting what you've read.

    This legacy of the old CP/M file system, in which their equivalent
    of an inode stored only block counts and not file sizes, has been a
    source of frustration and despair to programmers for decades now. And
    there's no end in sight.  Because DOS is compatible with CP/M file
    formats, Windows with DOS, and NT with Windows, the transgressions
    of the fathers have truly been visited unto the children of the
    fourth generation.

--tom
-- 
    "That is not dead which can eternal lie
    And with strange aeons, even death may die."
	    --H.P. Lovecraft


------------------------------

Date: Sun, 7 Jun 1998 16:59:15 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: what's a cross-platform \n please?
Message-Id: <MPG.fe4c92a4b72c19b9896a3@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <6lf6t4$655$6@csnews.cs.colorado.edu>, tchrist@mox.perl.com 
says...
>  [courtesy cc of this posting sent to cited author via email]
> 
> In comp.lang.perl.misc, lr@hpl.hp.com (Larry Rosler) writes:
> :It makes all the difference whether the file is open for binary or text!
> 
> Only on primitive systems. 

Indeed.  'Primitive' in the sense of 'retrograde' (reverting to an 
earlier or inferior condition) -- record-oriented files, JCL, DD cards 
(yes, cards!), ...  The real tragedy of DOS etc. (evilness, in fact) is 
not primitiveness; it is backwardness.

But some of us have to deal with this backwardness (is that why they got 
the slashes backward too :-???) in the real world.  Perl does it rather 
neatly.  Three cheers for Perl!

-- 
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


------------------------------

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 2808
**************************************

home help back first fref pref prev next nref lref last post