[33011] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4287 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 22 16:09:18 2014

Date: Mon, 22 Sep 2014 13:09:05 -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           Mon, 22 Sep 2014     Volume: 11 Number: 4287

Today's topics:
    Re: accept -vmargs -Xms512m -Xmx1024m using Getopt::Lon <mikaelpetterson@hotmail.com>
    Re: accept -vmargs -Xms512m -Xmx1024m using Getopt::Lon <mikaelpetterson@hotmail.com>
    Re: Modules, how to store private data <whynot@pozharski.name>
    Re: Modules, how to store private data <peter@makholm.net>
    Re: Modules, how to store private data <rweikusat@mobileactivedefense.com>
    Re: Modules, how to store private data <justin.1401@purestblue.com>
    Re: Modules, how to store private data <justin.1401@purestblue.com>
    Re: Modules, how to store private data <justin.1401@purestblue.com>
    Re: Modules, how to store private data <rweikusat@mobileactivedefense.com>
    Re: Modules, how to store private data <whynot@pozharski.name>
    Re: Modules, how to store private data <rweikusat@mobileactivedefense.com>
    Re: Modules, how to store private data <peter@makholm.net>
    Re: perl and math need help with printf or other <lionslair@consolidated.net>
    Re: perl and math need help with printf or other <hjp-usenet3@hjp.at>
    Re: perl and math need help with printf or other <lionslair@consolidated.net>
    Re: perl and math need help with printf or other <rweikusat@mobileactivedefense.com>
    Re: perl and math need help with printf or other <hjp-usenet3@hjp.at>
    Re: somewhat amusing OO pitfall <gravitalsun@hotmail.foo>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 18 Sep 2014 23:14:25 -0700 (PDT)
From: mike <mikaelpetterson@hotmail.com>
Subject: Re: accept -vmargs -Xms512m -Xmx1024m using Getopt::Long
Message-Id: <ea16157a-0cf6-4668-a175-1bb64c13a0c5@googlegroups.com>


> 
> > I am trying:
> 
> >
> 
> >
> 
> > #!/usr/bin/perl 
> 
> >
> 
> > use strict;
> 
> > use warnings;
> 
> > use Getopt::Long; 
> 
> >
> 
> > my @vmargs;
> 
> > my ($man, $help);
> 
> >
> 
> > GetOptions('help|?' => \$help, man => \$man, 'vmargs=s@{,}' => \@vmargs);
> 
> > print "@vmargs\n";
> 
> >
> 
> >
> 
> > ---------------------
> 
> > perl myscript.pl -vmargs -Xms512m -Xmx1024m
> 
> >
> 
> > I get the following output:
> 
> >
> 
> > Unknown option: xmx1024m
> 
> > -Xms512m
> 
> >
> 
> > What am I missing?
> 
> 
> 
> {,} means 'one or more values'. Since -Xms512m is one value, it
> 
> satisfies the condition and the next string is interpreted as option
> 
> because it starts with a dash.
> 
> 
> 
> Why are you passing JVM 'memory control' arguments to Perl, BTW?

I use the script to start eclipse.


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

Date: Fri, 19 Sep 2014 03:20:00 -0700 (PDT)
From: mike <mikaelpetterson@hotmail.com>
Subject: Re: accept -vmargs -Xms512m -Xmx1024m using Getopt::Long
Message-Id: <964c49aa-f751-483a-8eb1-e1b34705bf43@googlegroups.com>

Den torsdagen den 18:e september 2014 kl. 17:06:43 UTC+2 skrev Rainer Weikusat:
> mike <mikaelpetterson@hotmail.com> writes:
> 
> > I am trying:
> 
> >
> 
> >
> 
> > #!/usr/bin/perl 
> 
> >
> 
> > use strict;
> 
> > use warnings;
> 
> > use Getopt::Long; 
> 
> >
> 
> > my @vmargs;
> 
> > my ($man, $help);
> 
> >
> 
> > GetOptions('help|?' => \$help, man => \$man, 'vmargs=s@{,}' => \@vmargs);
> 
> > print "@vmargs\n";
> 
> >
> 
> >
> 
> > ---------------------
> 
> > perl myscript.pl -vmargs -Xms512m -Xmx1024m
> 
> >
> 
> > I get the following output:
> 
> >
> 
> > Unknown option: xmx1024m
> 
> > -Xms512m
> 
> >
> 
> > What am I missing?
> 
> 
> 
> {,} means 'one or more values'. Since -Xms512m is one value, it
> 
> satisfies the condition and the next string is interpreted as option
> 
> because it starts with a dash.
> 
> 
> 
> Why are you passing JVM 'memory control' arguments to Perl, BTW?
I solved it using:

'vmargs=s@' => \@vmargs

And adding jvm arguments like:

-vmargs -Xmx1024m -vmargs -Xms512m

//mike


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

Date: Fri, 19 Sep 2014 09:41:33 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: Modules, how to store private data
Message-Id: <slrnm1nk0t.im1.whynot@orphan.zombinet>

with <87oaudyuul.fsf@vps1.hacking.dk> Peter Makholm wrote:

*SKIP*
> So what can be used for identifying the object? Well, as long as the
> object lives, the address used by the reference is unique and if you use
> the object itself as hash key it will actually us a representation of
> the address. So:
>
>       $private_data{$self}{something} = shift;
>
> would work as long as objects stays live. This means you need to clean
> up when an object is destroyed. This can be done by adding a destructor
> for your object:
>
> sub DESTROY {
>     my $self = shift;
>
>     delete $private_data{$self};
> }

Does this technology cope with Scalar::Util::weaken() and/or
Storable::dclone() (or whatnot)?

*CUT*

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom


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

Date: Fri, 19 Sep 2014 13:55:48 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: Modules, how to store private data
Message-Id: <878ulfzuwr.fsf@vps1.hacking.dk>

Eric Pozharski <whynot@pozharski.name> writes:

About Inside-Out objects:

> Does this technology cope with Scalar::Util::weaken() and/or
> Storable::dclone() (or whatnot)?

I can't imagine uses cases of Scalar::Util::weaken where it would have
any problems with Inside-Out objects.

But modules that requires introspection of objects will not work out of
the box with Inside-Out objects. Given that one of the main reasons for
Inside-Out objects is to strengthen the encapsulation this makes
perfectly sense.

Storable implement hooks that allows Inside-Out object to interact with
storable. This is done by implementing two methods (STORABLE_freeze and
STORABLE_thaw) in your own class. See the Storable documentation for
details.

//Makholm


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

Date: Fri, 19 Sep 2014 13:28:17 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Modules, how to store private data
Message-Id: <87lhpfkd5q.fsf@sable.mobileactivedefense.com>

Peter Makholm <peter@makholm.net> writes:
> Eric Pozharski <whynot@pozharski.name> writes:
>
> About Inside-Out objects:
>
>> Does this technology cope with Scalar::Util::weaken() and/or
>> Storable::dclone() (or whatnot)?
>
> I can't imagine uses cases of Scalar::Util::weaken where it would have
> any problems with Inside-Out objects.

People with a sufficiently lively phantasy can presumably imagine some
bizarre effect happening in case a weak reference was used as a hash key
 ... except that references can't be used as hash keys and their string
representation is used instead. 

> But modules that requires introspection of objects will not work out of
> the box with Inside-Out objects.

There is no such thing as 'introspection of objects' in Perl because
objects don't have a specific implementation (which is otherwise
inaccessible from the language itself except insofar a certain API
offers peephole views into it). But that's really besides the point
because there's nothing which stops someone from writing a Java class
whose methods store some information in a static hash map. In case
someone else now 'serializes' an instance of the class without knowing
what he is working with, that someone is possibly up to a nasty
surprise. But breaking stuff apart based on a prima facie conviction
that one will be able to put it back together again (or that destruction
is an worthy end) in itself is bound to end with a heap of rubble every
once in a while and maybe, that's just what was intended (I surely
assume that Mr Eric mainly intended to communicate the he could break
this (!!1), something every idiot with a hammer can, do but 'defending
against idiots attacking with hammers' is usually not a purpose of
software). 

> Given that one of the main reasons for Inside-Out objects is to
> strengthen the encapsulation this makes perfectly sense.

Given that enforced encapsulation is nothing but an attempt to "defend
against idiots attacking with hammers" "strenghtening it" doesn't "make
perfect sense", especially in a language which knows nothing of it.

A Perl object is 'some kind of reference' and 'other data' can be
attached to such a reference in various way, depending on what is most
useful or convenient in a given situation. Often, the reference will
refer to some container object and some scheme for storing data items in
the container object will be employed. But this may not be appropriate,
say, because object instances are being serialized but some transient
data also belonging to them shouldn't or mustn't. So why not store it
elsewhere?


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

Date: Fri, 19 Sep 2014 13:08:37 +0100
From: Justin C <justin.1401@purestblue.com>
Subject: Re: Modules, how to store private data
Message-Id: <5viteb-3o2.ln1@zem.masonsmusic.co.uk>

On 2014-09-18, Henry Law <news@lawshouse.org> wrote:
> On 18/09/14 12:50, Justin C wrote:
>> What this
>> allows, though, is, AIUI, the person using the module to directly
>> access the data without using my methods.
>
> Indeed; that's often the case.  Just warn people loudly not to do that, 
> and change the internal structure (so their direct-access code breaks) 
> every time you release a new version; they'll soon learn.


I like this suggestion. I don't think it's the best solution, but I
can see how it would make me feel better when "they" are pissing 
me off.

I'll keep this idea to hand, just in case.

   Justin.

-- 
Justin C, by the sea.


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

Date: Fri, 19 Sep 2014 13:22:38 +0100
From: Justin C <justin.1401@purestblue.com>
Subject: Re: Modules, how to store private data
Message-Id: <epjteb-3o2.ln1@zem.masonsmusic.co.uk>

On 2014-09-18, Martijn Lievaart <m@rtij.nl.invlalid> wrote:
> On Thu, 18 Sep 2014 12:50:05 +0100, Justin C wrote:
>
>> Are there any reasons I shouldn't adopt this method for my future module
>> development? Have I been doing it wrong up until now or, as always with
>> perl it's just that TIMTOWTDI?
>
> You are doing it wrong now, as your new approach will share the data over 
> all objects.
>
> But yes, TIMTOWTDI, and what you are trying to do is already done by 
> others. The best known implementation is Moose.

One of these days I'll get round to reading the docs for Moose (and/or)
similar modules. Maybe I should stop trying to do this stuff by hand.

Thank you for letting me know I'm re-inventing the wheel!


   Justin.

-- 
Justin C, by the sea.


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

Date: Fri, 19 Sep 2014 13:43:18 +0100
From: Justin C <justin.1401@purestblue.com>
Subject: Re: Modules, how to store private data
Message-Id: <60lteb-r4n.ln1@zem.masonsmusic.co.uk>

On 2014-09-18, Peter Makholm <peter@makholm.net> wrote:
> Justin C <justin.1401@purestblue.com> writes:
>
>> my %private_data;
>
> [...]
>
>> sub something {
>>     my $self = shift;
>>     if (@_) {
>>         $private_data{something} = shift;
>>     }
>>     return $private_data{something};
>> }
>
> This makes $private_data{something} shared between all instances of your
> class. Instead you need to use an identifier unique for your object:

Ah, I see. For where I've used it so far there have, fortunately, 
been only one instance.


> sub something {
>     my $self = shift;
>     if (@_) {
>          $private_data{...}{something} = shift;
>     }
>     return $private_data{...}{something};
> }
>
> So what can be used for identifying the object? Well, as long as the
> object lives, the address used by the reference is unique and if you use
> the object itself as hash key it will actually us a representation of
> the address. So:
>
>       $private_data{$self}{something} = shift;

That looks straight-forward enough. 


> would work as long as objects stays live. This means you need to clean
> up when an object is destroyed. This can be done by adding a destructor
> for your object:
>
> sub DESTROY {
>     my $self = shift;
>
>     delete $private_data{$self};
> }

OK.


> This is basically how Inside-Out objects works. You can see more
> documentation for this idea in the perlobj manual page and by any of the
> modules implementing Inside-Out objects, for example Object::InsideOut.
>
> But note that even though you can't see the data by naïve introspection
> of the object it self (i.e. using Data::Dumper) data is still available
> to an insisting user by way of the PadWalker module.

I'm not looking to totally hide the data, I just want the casual
observer to use the code as intended.


>> Are there any reasons I shouldn't adopt this method for my future
>> module development? Have I been doing it wrong up until now or,
>> as always with perl it's just that TIMTOWTDI? 
>
> Inside-Out objects was very much hyped a few years ago. These days I
> don't see as many caring about the features provided by this technology
> and then it is simpler to just use ordinary old style perl objects.

My main concern is someone casually looking at the data, making 
assumptions about certain parts of it, and thinking "It'd be easier
if I just..." [time passes] ... and then I get an email.


> My solution is just to beat users that knowlingly breaks the
> encapsulation with a used tea bag. That works too.

I don't drink tea, could I use broken beer bottles instead? 

Thank you for your reply. Clear and concise, much appreciated.


   Justin.

-- 
Justin C, by the sea.


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

Date: Fri, 19 Sep 2014 16:39:31 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Modules, how to store private data
Message-Id: <87oaubbowc.fsf@sable.mobileactivedefense.com>

Justin C <justin.1401@purestblue.com> writes:
> On 2014-09-18, Martijn Lievaart <m@rtij.nl.invlalid> wrote:
>> On Thu, 18 Sep 2014 12:50:05 +0100, Justin C wrote:
>>
>>> Are there any reasons I shouldn't adopt this method for my future module
>>> development? Have I been doing it wrong up until now or, as always with
>>> perl it's just that TIMTOWTDI?
>>
>> You are doing it wrong now, as your new approach will share the data over 
>> all objects.
>>
>> But yes, TIMTOWTDI, and what you are trying to do is already done by 
>> others. The best known implementation is Moose.
>
> One of these days I'll get round to reading the docs for Moose (and/or)
> similar modules. Maybe I should stop trying to do this stuff by hand.
>
> Thank you for letting me know I'm re-inventing the wheel!

JFTR: Wheels look like this:

https://www.google.co.uk/search?q=wheel&biw=1106&bih=873&tbm=isch&imgil=FivgBkwVc23IVM%253A%253BLOI4IsVT35IPAM%253Bhttp%25253A%25252F%25252Feofdreams.com%25252Fwheel.html&source=iu&pf=m&fir=FivgBkwVc23IVM%253A%252CLOI4IsVT35IPAM%252C_&usg=__U8ME88DghuHUNpKc-5I2whwyu_4%3D&ved=0CEgQyjc&ei=0UwcVEPBijiusoH4CA#facrc=_&imgdii=_&imgrc=eVCeSi8fpAdtAM%253A%3Bvc-J1_P7298dPM%3Bhttp%253A%252F%252Fwww.northerntool.com%252Fimages%252Fproduct%252F2000x2000%252F207%252F20715_2000x2000.jpg%3Bhttp%253A%252F%252Fwww.northerntool.com%252Fshop%252Ftools%252Fcategory_tires-wheels%252Bspoked-wheels%252Bflat-free-spoked-wheels%3B2000%3B2000

and are widely employed as parts of all kinds of machines (and have been
for a few thousand years) because they're useful.

OTOH, a 'moose' is something like this

http://en.wikipedia.org/wiki/Moose#mediaviewer/File:Chukotka_Moose.jpg

ie, a large, quadruped mammal whose main occupation is 'roam around in
the woods and eat stuff'.


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

Date: Sat, 20 Sep 2014 13:25:38 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: Modules, how to store private data
Message-Id: <slrnm1qlh2.a93.whynot@orphan.zombinet>

with <878ulfzuwr.fsf@vps1.hacking.dk> Peter Makholm wrote:
> Eric Pozharski <whynot@pozharski.name> writes:

> About Inside-Out objects:
>> Does this technology cope with Scalar::Util::weaken() and/or
>> Storable::dclone() (or whatnot)?
> I can't imagine uses cases of Scalar::Util::weaken where it would have
> any problems with Inside-Out objects.

What about something like this:

	$weak = $obj = Class->new; # creates underground record
	weaken $weak;              # still fine two objects, one record
	...
	undef $obj;                # implicit DESTROY purges record
	...
	$weak->whatever;           # one object, no record

Besides, if address is used as an identifier, then how $weak would find
the underground record?  Unless a custom Class::weaken() is provided and
required to be invoked instead of S::U::weaken().

I'm not arguing, I'm just thinking here (e.g. aggregation).  I'm not
convinced.

*SKIP*
> Storable implement hooks that allows Inside-Out object to interact with
> storable. This is done by implementing two methods (STORABLE_freeze and
> STORABLE_thaw) in your own class. See the Storable documentation for
> details.

AAMOF, I'm surprised.  Really.

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom


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

Date: Sun, 21 Sep 2014 15:10:32 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Modules, how to store private data
Message-Id: <8738bljc87.fsf@sable.mobileactivedefense.com>

Eric Pozharski <whynot@pozharski.name> writes:
> with <878ulfzuwr.fsf@vps1.hacking.dk> Peter Makholm wrote:
>> Eric Pozharski <whynot@pozharski.name> writes:
>
>> About Inside-Out objects:
>>> Does this technology cope with Scalar::Util::weaken() and/or
>>> Storable::dclone() (or whatnot)?
>> I can't imagine uses cases of Scalar::Util::weaken where it would have
>> any problems with Inside-Out objects.
>
> What about something like this:
>
> 	$weak = $obj = Class->new; # creates underground record
> 	weaken $weak;              # still fine two objects, one record

These are two references to one object, one of them having been weakened
(more precisely, two RVs [or comparable scalars] pointing the the same
object). 

> 	...
> 	undef $obj;                # implicit DESTROY purges record
> 	...
> 	$weak->whatever;           # one object, no record

And this is a fatal runtime error because $weak will be undef here.

> Besides, if address is used as an identifier, then how $weak would find
> the underground record?

Perl OO 101 sample program:

----------------
package Datum;

my %data;

sub new
{
    return bless([], $_[0]);
}

sub set
{
    $data{$_[0]} = $_[1];
}

sub get
{
    return $data{$_[0]};
}

sub DESTROY
{
    delete($data{$_[0]});
}

package main;

my ($o, $w);

$o = Datum->new();
$w = $o;

print("$w, $o\n");

$w->set(8);
print($o->get(), "\n");
--------------

> Unless a custom Class::weaken() is provided and
> required to be invoked instead of S::U::weaken().
>
> I'm not arguing, I'm just thinking here

Ignorance usually makes a bad starting point for theorizing.


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

Date: Mon, 22 Sep 2014 10:07:52 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: Modules, how to store private data
Message-Id: <8738bkyt5z.fsf@vps1.hacking.dk>

Eric Pozharski <whynot@pozharski.name> writes:

>> I can't imagine uses cases of Scalar::Util::weaken where it would have
>> any problems with Inside-Out objects.
>
> What about something like this:
>
> 	$weak = $obj = Class->new; # creates underground record
> 	weaken $weak;              # still fine two objects, one record
> 	...
> 	undef $obj;                # implicit DESTROY purges record
> 	...
> 	$weak->whatever;           # one object, no record

I fail to see the valid use-case of weaken illustrated by this
code snippet. You are actively telling the runtime system that your
object should be deallocated if $weak is the only reference to the
object. So don't act surprised wehn the object gets deallocated leaving
$weak as a dangling reference.

My testing of the case also fails to show any difference between
ordinary objects and InsideOut objects with the above code. In both
cases $weak will be undef in the last line.

In this case I think weaken works consistently between the object models
in question. But I wouldn't be surprised if a wrongly used weaken could
act differently with different ways to represent objects.

//Makholm


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

Date: Sat, 20 Sep 2014 22:51:34 -0500
From: Martin Eastburn <lionslair@consolidated.net>
Subject: Re: perl and math need help with printf or other
Message-Id: <oXrTv.258686$412.127012@fx30.iad>

On 5/17/2014 6:00 PM, Bill Cunningham wrote:
>      I am looking at several languages for math work. Algebraic work mainly
> linear equations and expanding and factoring equations. All this can be done
> by hand of course and C has a good library. What can perl do with math?
>
> Bill
>
>
After 10 years away from Perl, I'm trying to learn the language again. 
I started with the Pink version manual - and downloaded from JPL.

Anyway - today I generated pi to 10,000 places and thought that was 
good.  I then did a factorial to 10,000 numbers - that is 10000!  for most.

Math is powerful in many extents.  Maybe several programs make it best.

The hangup I'm working on is taking my output file generated thus :

perl -Mbignum=bpi -le "print bpi(10000)">filename

and the file is a long array of digits.   I want to format the file and
output it again to a file - with 70 characters with an offset of 10 chars.

I just can't seem to locate the readin length output input line with \n 
and loop back until EOF.

I'm looking in my books, but one never knows.

Seems to me it is a standard text file or data file mod that makes a 
file easy to read or print.

Martin


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

Date: Sun, 21 Sep 2014 11:05:37 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: perl and math need help with printf or other
Message-Id: <slrnm1t571.bj8.hjp-usenet3@hrunkner.hjp.at>

On 2014-09-21 03:51, Martin Eastburn <lionslair@consolidated.net> wrote:
> After 10 years away from Perl, I'm trying to learn the language again. 
> I started with the Pink version manual - and downloaded from JPL.
>
> Anyway - today I generated pi to 10,000 places and thought that was 
> good.  I then did a factorial to 10,000 numbers - that is 10000!  for most.
>
> Math is powerful in many extents.  Maybe several programs make it best.
>
> The hangup I'm working on is taking my output file generated thus :
>
> perl -Mbignum=bpi -le "print bpi(10000)">filename
>
> and the file is a long array of digits.   I want to format the file and
> output it again to a file - with 70 characters with an offset of 10 chars.
>
> I just can't seem to locate the readin length output input line with \n 
> and loop back until EOF.

What is the "readin length output input line"? Please try to state your
problem clearly. Are you looking for:

 * a function/operator to read a line from a file? (<>)
 * a function to determine the length of string? (length)
 * a function to split a long string into fixed size chunks?
   (I'd use substr in a loop here)

or do you have trouble writing a loop which does what you want? Then
show us what you've tried and we will help to fix it.

        hp


-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


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

Date: Sun, 21 Sep 2014 23:06:13 -0500
From: Martin Eastburn <lionslair@consolidated.net>
Subject: Re: perl and math need help with printf or other
Message-Id: <9fNTv.279905$y33.272232@fx28.iad>

On 9/21/2014 4:05 AM, Peter J. Holzer wrote: <snip>
> On 2014-09-21 03:51, Martin Eastburn <lionslair@consolidated.net> wrote:
>> After 10 years away from Perl, I'm trying to learn the language again.
>> I started with the Pink version manual - and downloaded from JPL.
Unix box is long gone, so now a nice high speed PC is the replacement.
Notice the " in place of the ' in the various lines. and the C:\ gives 
it away a bit and users\martin.....
One does get tired at night - that was 35 years more or less.  I bought 
the pink manual - only one at that time in San Jose at the one and only 
Engineering book store.  IEEE bought them and I've lost track. - but now 
I have 4 blue with a third party one from Amazon.

Well I solved it.  Not graceful or pretty but not bad.  Here is the 
header of the output text :

command line to generate the output file from the input file.
C:\Users\Martin\Desktop\perl>perl Perl_test.pl <pi_10000.txt >yy.txt


C:\Users\Martin\Desktop\perl>more yy.txt
           The input line has : 10002 characters

 
3.14159265358979323846264338327950288419716939937510582097494459230781
 
6406286208998628034825342117067982148086513282306647093844609550582231
 
7253594081284811174502841027019385211055596446229489549303819644288109
The blank lines are generated in this tool - I have a 80 column limit.
So the wrap fakes us out. The last line :
            5524988727584610126483699989225695968815920560010165525637568
Notice the last line tabbed over the 10 spaces - and did not complete
the full line.  The last digits are the same as the input file - Phew!

There is 10 spaces before each line and they are packed line after line.
Here is the Perl script:  Any Long line will be split up.

C:\Users\Martin\Desktop\perl>more Perl_test.pl
#!perl
#
$line = <STDIN>;
my $char_length = 0;
#
if ($line eq "\n") {
     print "That was just a blank line!\n";# and bail out
   }    else {
     my $char_length = length($line);
#
print "          The input line has : $char_length characters\n\n";
chomp($line);
#
# $line contains 10000+2 characters.  starting with 3.14159.....;
# The three and decimal point comprise the added two.  10k decimal values.;
#
$offset = 0;
$length = 70;
$str_length = 1+($char_length/70);
#
for ($i = 0; $i<($str_length); $i++){
#
my $part = substr($line,$offset,$length);

print "          $part";
$offset = $offset+$length;
print "\n";
};
print "\n";
   };

C:\Users\Martin\Desktop\perl>

Please let me know where I did good and bad.  I tried to have
the $str_length defined as ($char_length/$length) but the compiler 
didn't like what it saw.  So I hard coded it for now.
70 chars are what are printed with a 10 space leading edge. (hole punch).

Martin


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

Date: Mon, 22 Sep 2014 11:14:30 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: perl and math need help with printf or other
Message-Id: <87ppeoezcp.fsf@sable.mobileactivedefense.com>

Martin Eastburn <lionslair@consolidated.net> writes:

[break a long line down into sequences of at most 70 chars]

> $line = <STDIN>;
> my $char_length = 0;
> #
> if ($line eq "\n") {
>     print "That was just a blank line!\n";# and bail out
>   }    else {
>     my $char_length = length($line);
> #
> print "          The input line has : $char_length characters\n\n";
> chomp($line);
> #
> # $line contains 10000+2 characters.  starting with 3.14159.....;
> # The three and decimal point comprise the added two.  10k decimal values.;
> #
> $offset = 0;
> $length = 70;
> $str_length = 1+($char_length/70);
> #
> for ($i = 0; $i<($str_length); $i++){
> #
> my $part = substr($line,$offset,$length);
>
> print "          $part";
> $offset = $offset+$length;
> print "\n";
> };
> print "\n";
>   };

Hmm ... looks complicated for what it does. Conventional alternative:

-----------
my ($in, $ofs);

$in = <STDIN>;
chomp($in);

do {
    print(' ' x 10, substr($in, $ofs, 70), "\n");
} while ($ofs += 70) < length($in);
------------

Minus possibly inappropriate quoting for teletype-style systems (with
returning carriages):

perl -lne 'print(" " x 10, $_) for /.{1,70}/g'

The

/.{1,70}/g

is a regex matching at least one and at most 70 characters, the trailing
g means 'global'. In list context (as above), this returns a list of
strings from the input line (in $_) which sucessively matched the
pattern. These matches are greedy which means they'll only match less
than 70 characters if less than 70 remain unprocessed. Each of this is
in turn aliased to $_ by the for and then printed with 10 (" " times 10)
spaces in front of it.




	   





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

Date: Mon, 22 Sep 2014 21:48:39 +0200
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: perl and math need help with printf or other
Message-Id: <slrnm20v8o.mdp.hjp-usenet3@hrunkner.hjp.at>

On 2014-09-22 04:06, Martin Eastburn <lionslair@consolidated.net> wrote:
> On 9/21/2014 4:05 AM, Peter J. Holzer wrote: <snip>
>> On 2014-09-21 03:51, Martin Eastburn <lionslair@consolidated.net> wrote:
>>> After 10 years away from Perl, I'm trying to learn the language again.
[...]
> Well I solved it.  Not graceful or pretty but not bad.  Here is the 
> header of the output text :
>
[...]
> #!perl
> #
> $line = <STDIN>;
> my $char_length = 0;
> #
> if ($line eq "\n") {
>      print "That was just a blank line!\n";# and bail out
>    }    else {
>      my $char_length = length($line);
> #
> print "          The input line has : $char_length characters\n\n";
> chomp($line);
> #
> # $line contains 10000+2 characters.  starting with 3.14159.....;
> # The three and decimal point comprise the added two.  10k decimal values.;
> #
> $offset = 0;
> $length = 70;
> $str_length = 1+($char_length/70);
> #
> for ($i = 0; $i<($str_length); $i++){
> #
> my $part = substr($line,$offset,$length);
>
> print "          $part";
> $offset = $offset+$length;
> print "\n";
> };
> print "\n";
>    };
>
> C:\Users\Martin\Desktop\perl>
>
> Please let me know where I did good and bad.

Well, the first thing which immediately catches the eye is the
atrocious (sorry) indentation. It is completely impossible to see the
structure of the program. So let's fix this first.

    #!perl
    #
    $line = <STDIN>;
    my $char_length = 0;
    #
    if ($line eq "\n") {
        print "That was just a blank line!\n";# and bail out
    } else {
        my $char_length = length($line);
        #
        print "          The input line has : $char_length characters\n\n";
        chomp($line);
        #
        # $line contains 10000+2 characters.  starting with 3.14159.....;
        # The three and decimal point comprise the added two.  10k decimal values.;
        #
        $offset = 0;
        $length = 70;
        $str_length = 1+($char_length/70);
        #
        for ($i = 0; $i<($str_length); $i++){
            #
            my $part = substr($line,$offset,$length);

            print "          $part";
            $offset = $offset+$length;
            print "\n";
        };
        print "\n";
    };

Ok, that's better. Now we see that the almost everything the script does
in normal operation is tucked away in an else branch. We don't want
that, and at the same time let's get rid of these empty comments. Empty
lines look less cluttered:

    #!perl

    $line = <STDIN>;
    my $char_length = 0;

    if ($line eq "\n") {
        print "That was just a blank line!\n";# and bail out
        exit 1;
    }

    my $char_length = length($line);

    print "          The input line has : $char_length characters\n\n";
    chomp($line);

    # $line contains 10000+2 characters.  starting with 3.14159.....;
    # The three and decimal point comprise the added two.  10k decimal values.;

    $offset = 0;
    $length = 70;
    $str_length = 1+($char_length/70);

    for ($i = 0; $i<($str_length); $i++){

        my $part = substr($line,$offset,$length);

        print "          $part";
        $offset = $offset+$length;
        print "\n";
    };
    print "\n";

The naming of the variables is strange. What does $char_length and
$str_length mean? The names imply the length of a character (or maybe
a length in characters) and the length of a string. But $str_length is
the number of lines you will print and $char_length is the length of the
input line $line. So let's change that:

    #!perl

    $line = <STDIN>;
    my $char_length = 0;

    if ($line eq "\n") {
        print "That was just a blank line!\n";# and bail out
        exit 1;
    }

    my $line_length = length($line);

    print "          The input line has : $line_length characters\n\n";
    chomp($line);

    # $line contains 10000+2 characters.  starting with 3.14159.....;
    # The three and decimal point comprise the added two.  10k decimal values.;

    $offset = 0;
    $length = 70;
    $lines_number = 1+($line_length/70);

    for ($i = 0; $i<($lines_number); $i++){

        my $part = substr($line,$offset,$length);

        print "          $part";
        $offset = $offset+$length;
        print "\n";
    };
    print "\n";

And while I'm looking at the variables, I see that you have declared
some of them with "my" and some are undeclared global variables. That
doesn't look intentional, so let the compiler complain about undeclared
variables (and some other things):

    #!perl
    use warnings;
    use strict;

    my $line = <STDIN>;
    my $char_length = 0;

    if ($line eq "\n") {
        print "That was just a blank line!\n";# and bail out
        exit 1;
    }

    my $line_length = length($line);

    print "          The input line has : $line_length characters\n\n";
    chomp($line);

    # $line contains 10000+2 characters.  starting with 3.14159.....;
    # The three and decimal point comprise the added two.  10k decimal values.;

    my $offset = 0;
    my $length = 70;
    my $lines_number = 1+($line_length/70);

    for ($i = 0; $i<($lines_number); $i++){

        my $part = substr($line,$offset,$length);

        print "          $part";
        $offset = $offset+$length;
        print "\n";
    };
    print "\n";



The computation of $lines_number is off. It jumps from 1 to 2 when the
input line 69 characters + 1 newline. But that should only happen when
you have 71 characters + 1 newline (70 characters still fit on one
line). I would use the ceil function to compute the number of lines:

    use POSIX 'ceil';
    $lines_number = ceil($line_length/70);

but it turns out we don't need to compute that at all. Why use a loop
counter which is incremented by 1 and an extra offset which is
incremented by $length, when we can just use the offset?

    #!perl
    use warnings;
    use strict;

    my $line = <STDIN>;

    if ($line eq "\n") {
        print "That was just a blank line!\n";# and bail out
        exit 1;
    }

    chomp($line);

    my $line_length = length($line);
    print "          The input line has : $line_length characters\n\n";

    # $line contains 10000+2 characters.  starting with 3.14159.....;
    # The three and decimal point comprise the added two.  10k decimal values.;

    my $length = 70;

    for (my $offset = 0; $offset < $line_length; $offset += $length) {

        my $part = substr($line,$offset,$length);

        print "          $part";
        print "\n";
    };
    print "\n";

I'd also reduce the for loop a bit:

    for (my $offset = 0; $offset < $line_length; $offset += $length) {
        print " " x 10, substr($line, $offset, $length), "\n";
    };

And personally I'd ditch the check for an empty input line and print
only the number without any extraneous information (the number of
characters, extra newlines, ...), but that changes what the program
does, so I'll leave that to you.

> I tried to have
> the $str_length defined as ($char_length/$length) but the compiler 
> didn't like what it saw.  So I hard coded it for now.

Strange. I don't see how that could happen. There was probably some
other error in the script.

        hp

-- 
   _  | Peter J. Holzer    | Fluch der elektronischen Textverarbeitung:
|_|_) |                    | Man feilt solange an seinen Text um, bis
| |   | hjp@hjp.at         | die Satzbestandteile des Satzes nicht mehr
__/   | http://www.hjp.at/ | zusammenpaßt. -- Ralph Babel


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

Date: Sat, 20 Sep 2014 11:35:12 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: somewhat amusing OO pitfall
Message-Id: <lvje8i$121h$1@news.ntua.gr>

you should change the do_print like this

sub do_print
{
print_it  __PACKAGE__ eq ref $_[0] ? @_[1_..$#_] : @_
}



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 4287
***************************************


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