[30953] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2198 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 10 14:09:50 2009

Date: Tue, 10 Feb 2009 11:09:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 10 Feb 2009     Volume: 11 Number: 2198

Today's topics:
    Re: "make test" fails while installing Math::Calc::Unit <nospam@nospam.invalid>
        A good data structure to store INI files. <perl@marc-s.de>
    Re: A good data structure to store INI files. <tzz@lifelogs.com>
    Re: A good data structure to store INI files. <perl@marc-s.de>
    Re: A good data structure to store INI files. sln@netherlands.com
        ANNOUNCE:  File::Scan::ClamAV-1.91 released <james@lovedthanlost.net>
    Re: automating a perl installation on a cluster (or usi <nospam@nospam.invalid>
    Re: error printing page using LWP::Simple <tadmc@seesig.invalid>
    Re: error printing page using LWP::Simple <baxter.brad@gmail.com>
    Re: error printing page using LWP::Simple <hjp-usenet2@hjp.at>
    Re: File handle to "in memory" file <uri@stemsystems.com>
    Re: how can i convert my perl script to be a perl modul <jurgenex@hotmail.com>
    Re: how can i convert my perl script to be a perl modul <tzz@lifelogs.com>
    Re: indented xml using XML::DOM <mirod@xmltwig.com>
    Re: parse newline <tzz@lifelogs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Feb 2009 17:29:38 +0000 (UTC)
From: Rahul <nospam@nospam.invalid>
Subject: Re: "make test" fails while installing Math::Calc::Units via CPAN
Message-Id: <Xns9BAE74EB297396650A1FC0D7811DDBC81@85.214.105.209>

Ben Morrow <ben@morrow.me.uk> wrote in
news:hm5766-bl2.ln1@osiris.mauzo.dyndns.org: 

> What sort of perl install do you have that doesn't have Test::More?
> It's been core since 5.6.2. Are you using some OS that thinks it's a
> good idea to break the core perl install into a whole lot of separate
> packages? You really want to fix that as soon as possible, or you're
> likely to run into other problems later.
> 
> 

Thanks Ben! I think I got perl as a part of fedora via yum. 

This is what it reports:

Arch   : x86_64
Epoch  : 4
Version: 5.8.8
Release: 30.fc8

Tried to update it as well:

yum update perl
Setting up Update Process
Could not find update match for perl
No Packages marked for Update

Maybe I messed something up along the way! Tried "locate More.pm" with
no results. 


But it all works after I tried 

perl -MCPAN -e 'install Test::More'

and then installed 

perl -MCPAN -e 'install Math::Calc::Units'


Thanks for the pointer! It is strange that yum didn't help.

-- 
Rahul


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

Date: Tue, 10 Feb 2009 18:34:41 +0100
From: Marc Lucksch <perl@marc-s.de>
Subject: A good data structure to store INI files.
Message-Id: <gmsdrc$1e5s$1@ariadne.rz.tu-clausthal.de>

Maybe I'm an idiot here, but I can't figure this one out even if my life 
would depend on it:

I have an file in the quite easy INI format, put I have no idea how to 
store it in a way where it can be easily accessed by other people and 
without any long explanations.

Anyway here is the example file:

 > [Ship]
 > ids_name = 237033
 > ids_info = 66567
 > ids_info1 = 66567
 > ship_class = 1
 > nickname = li_elite
 > LODranges = 0, 75, 150, 1300
 > fuse = intermed_damage_smallship01, 0.000000, 400
 > fuse = intermed_damage_smallship02, 0.000000, 200
 > ;#Well its a lot more in one section, but this proves the point.
 >
 > [Ship]
 > ids_name = 237033
 > ids_info = 66567
 > ship_class = 1
 > nickname = li_elite2
 > LODranges = 0, 175, 150, 1300
 > fuse = intermed_damage_smallship01, 0.000000, 400
 > fuse = intermed_damage_smallship02, 0.000000, 200
 > fuse = intermed_damage_smallship03, 0.000000, 133
 > ;.... (about 250kb of this)

The file is from the Microsoft game Freelancer, but it is unlike any 
normal ini files:

- The section names are doubled, (there are multiple [Ship] entries)
- Some of the keys are doubled as well (0 - 4 fuse entries for example)
- Some of the values are seperated by ",". (That's not a big problem)

The backstory of this whole thing is:

In 1999 Microsoft/Digital Anvil made this game and it came with a lot of 
BINI files, which are just somewhat compressed INI files, looking like 
the one above. After half a year BINI file decompressors and compressors 
were written and I plan to write/wrote one as well for another project 
(plasma.sf.net) in Perl of course. The normal decompressors converted 
the file first and then read it, that's why tools based  on this, like 
FL-Datastorm, take 10 Minutes to scan the game and my implementation 
takes about 2 seconds. (10 seconds when counting models)
But why INI-files, It would seem abitrary to convert them to INI files, 
since it was a binary format before that look like it. However the game 
also accepts gladly uncompressed INI files.

The game itself has many, many mods for it, since you just have to edit 
INI files mostly, and people have found a way to 'break' the BINI files 
in a way that only Freelancer can read them and not any other tools. 
This is a second reason for the parser, since I can't use most tools for 
my own server operator, since it _has_ to read those files. That is also 
the reason I can't just ship it with just a complete set of data files.

Now while I want to put the parser on CPAN, I can't find any way to 
represent this type of data in an easy way... (While a little voice is 
constantly screaming "They are just INI files, ^*&*&%^%^*&$#$")

So I tried the some of the many INI parsers on CPAN. (Since I also have 
to read normal ini files) But I have found none that can even parse that 
file correctly... (See below for examples)

I would love for it to have an easy interface, not for me, but for 
others who might want to use it:

 > my $ini=read...("file.ini")
 > print $ini->{Ship}->{nickname}; #When there is one ship only, also
 > foreach my $ship(%{$ini->{Ship}) {
 >    foreach my $fuse(
 >        print $ship->{nickname}
 >    }
 > }

First idea was TIE, but that won't work with the duality of the thing.
Overload might go, but that opens another can of worms with adding new 
sections and keys that need converting objects and other things.
And overload+TIE is not good at all... (See man overload)
And a pure Object based model is what Python and Java would do, not very 
perlish.

So there I am, no idea, and I need help: First on the datastructure 
issue and second on a nice parser on CPAN that can read that file obove 
right. I don't want to write Yet::Another::INI::Parser::Again for the 
fifth time.

Marc "Maluku" Lucksch

__DATA__ :)

Config::INI::Reader of that file:
 > $VAR1 = {
 >     'Ship' => {
 >           'ship_class' => '1',
 >           'ids_info' => '66567',
 >           'ids_info1' => '66567',
 >           'nickname' => 'li_elite2',
 >           'fuse' => 'intermed_damage_smallship03, 0.000000, 133',
 >           'ids_name' => '237033',
 >           'LODranges' => '0, 175, 150, 1300'
 >     }
 > };

Result: One section missing, 4 fuses missing, fuse and LOD not splitted.

Config::Format::INI

 > $VAR1 = {
 >      'Ship' => {
 >            'ship_class' => ['1'],
 >            'ids_info' => ['66567'],
 >            'nickname' => ['li_elite2'],
 >            'fuse' => [
 >                  'intermed_damage_smallship03',
 >                  '0.000000',
 >                  '133'
 >            ],
 >            'ids_name' => ['237033']
 >      }
 > };

Result: One section missing, 4 fuses missing, LODRanges and ids_info1 
not parsed (why?). The missing LODRanges confuse me a lot here.

 > $VAR1 = {
 >       'Ship' => {
 >             'ship_class' => ['1','1'],
 >             'ids_info' => ['66567','66567'],
 >             'ids_info1' => '66567',
 >             'nickname' => ['li_elite','li_elite2'],
 >             'fuse' => [
 >                   'intermed_damage_smallship01, 0.000000, 400',
 >                   'intermed_damage_smallship02, 0.000000, 200',
 >                   'intermed_damage_smallship03, 0.000000, 133',
 >                   'intermed_damage_smallship01, 0.000000, 400',
 >                   'intermed_damage_smallship02, 0.000000, 200',
 >                   'intermed_damage_smallship03, 0.000000, 133'
 >             ],
 >             'ids_name' => ['237033','237033'],
 >             'LODranges' => [
 >                        '0, 75, 150, 1300',
 >                        '0, 175, 150, 1300'
 >             ]
 >       }
 > };

Result: Well it's all there, but I can't work with it and value are not 
splitted by the comma

And my one FlBini (Games::Freelancer::BINI, when I figure this out)..
$VAR1 = bless( {
 >       'Iter' => 0,
 >       'Data' => [
 >             'Ship',
 >             bless( {
 >                  'Iter' => 0,
 >                  'Data' => [
 >                        'ids_name',
 >                        ['237033'],
 >                        'ids_info',
 >                        ['66567'],
 >                        'ids_info1',
 >                        ['66567'],
 >                        'ship_class',
 >                        ['1'],
 >                        'nickname',
 >                        ['li_elite'],
 >                        'LODranges',
 >                        [
 >                          '0',
 >                          '75',
 >                          '150',
 >                          '1300'
 >                        ],
 >                        'fuse',
 >                        [
 >                          'intermed_damage_smallship01',
 >                          '0.000000',
 >                          '400'
 >                        ],
 >                        'fuse',
 >                        [
 >                          'intermed_damage_smallship02',
 >                          '0.000000',
 >                          '200'
 >                        ],
 >                        'fuse',
 >                        [
 >                          'intermed_damage_smallship03',
 >                          '0.000000',
 >                          '133'
 >                        ]
 >                  ]
 >             }, 'INIArray' ),
 >             'Ship',
 >             bless( {
 >                  'Iter' => 0,
 >                  'Data' => [
 >                        'ids_name',
 >                        ['237033],
 >                        'ids_info',
 >                        ['66567],
 >                        'ship_class',
 >                        ['1'],
 >                        'nickname',
 >                        ['li_elite2],
 >                        'LODranges',
 >                        [
 >                          '0',
 >                          '175',
 >                          '150',
 >                          '1300'
 >                        ],
 >                        'fuse',
 >                        [
 >                          'intermed_damage_smallship01',
 >                          '0.000000',
 >                          '400'
 >                        ],
 >                        'fuse',
 >                        [
 >                          'intermed_damage_smallship02',
 >                          '0.000000',
 >                          '200'
 >                        ],
 >                        'fuse',
 >                        [
 >                          'intermed_damage_smallship03',
 >                          '0.000000',
 >                          '133'
 >                        ]
 >                  ]
 >             }, 'INIArray' )
 >       ]
 > }, 'INIArray' )

Result: cubersome, no direct key access, therefore full scan is needed 
with a good reason. But all data is there.


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

Date: Tue, 10 Feb 2009 12:13:48 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: A good data structure to store INI files.
Message-Id: <86iqnijh2b.fsf@lifelogs.com>

On Tue, 10 Feb 2009 18:34:41 +0100 Marc Lucksch <perl@marc-s.de> wrote: 

ML> Now while I want to put the parser on CPAN, I can't find any way to
ML> represent this type of data in an easy way... (While a little voice is
ML> constantly screaming "They are just INI files, ^*&*&%^%^*&$#$")

At least you're not thinking "oh, I know, I'll use XML" :)

ML> So I tried the some of the many INI parsers on CPAN. (Since I also
ML> have to read normal ini files) But I have found none that can even
ML> parse that file correctly... (See below for examples)

ML> I would love for it to have an easy interface, not for me, but for
ML> others who might want to use it:
 ...
ML> So there I am, no idea, and I need help: First on the datastructure
ML> issue and second on a nice parser on CPAN that can read that file
ML> obove right. I don't want to write Yet::Another::INI::Parser::Again
ML> for the fifth time.

I don't know of any INI parsers that would do this for you, but I wrote
the code below in 10 minutes and it seems to do the right thing.  The
only thing you need to configure is the list that initializes
%comma_keys.

You can write this in a stateful way but it's a waste of time if the
data size is small and you don't expect the string "[Ship]" anywhere
unexpected in the configuration.

Ted

#!/usr/bin/perl

use warnings;
use strict;
use Data::Dumper;

my $parsed = [];
my %comma_keys = map { $_ => 1 } qw/fuse LODranges/;

my $data = join '', grep { $_ !~ m/^;/ } <DATA>;

foreach my $shipline (split '\[Ship\]', $data)
{
 next unless $shipline;
 my $ship = {};
 push @$parsed, $ship;
 foreach my $line (split "\n", $shipline)
 {
  next unless $line;
  my ($key, $val) = split /\s*=\s*/, $line, 2;

  if (exists $comma_keys{$key})
  {
   $val = [ split /\s*,\s*/, $val ];
  }
  
  push @{$ship->{$key}}, $val;
 }

 foreach my $key (keys %$ship)
 {
  next if scalar @{$ship->{$key}} != 1;
  $ship->{$key} = $ship->{$key}->[0];
 }

}

print Dumper $parsed;
__DATA__
[Ship]
ids_name = 237033
ids_info = 66567
ids_info1 = 66567
ship_class = 1
nickname = li_elite
LODranges = 0, 75, 150, 1300
fuse = intermed_damage_smallship01, 0.000000, 400
fuse = intermed_damage_smallship02, 0.000000, 200
;#Well its a lot more in one section, but this proves the point.

[Ship]
ids_name = 237033
ids_info = 66567
ship_class = 1
nickname = li_elite2
LODranges = 0, 175, 150, 1300
fuse = intermed_damage_smallship01, 0.000000, 400
fuse = intermed_damage_smallship02, 0.000000, 200
fuse = intermed_damage_smallship03, 0.000000, 133
;.... (about 250kb of this)


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

Date: Tue, 10 Feb 2009 19:40:31 +0100
From: Marc Lucksch <perl@marc-s.de>
Subject: Re: A good data structure to store INI files.
Message-Id: <gmshmq$1gks$1@ariadne.rz.tu-clausthal.de>

Ted Zlatanov schrieb:
> On Tue, 10 Feb 2009 18:34:41 +0100 Marc Lucksch <perl@marc-s.de> wrote: 
> 
> ML> Now while I want to put the parser on CPAN, I can't find any way to
> ML> represent this type of data in an easy way... (While a little voice is
> ML> constantly screaming "They are just INI files, ^*&*&%^%^*&$#$")
> 
> At least you're not thinking "oh, I know, I'll use XML" :)

I'm quite happy Microsoft didn't use XML for this one when I look at 
 .docx files.

> ML> So I tried the some of the many INI parsers on CPAN. (Since I also
> ML> have to read normal ini files) But I have found none that can even
> ML> parse that file correctly... (See below for examples)

> I don't know of any INI parsers that would do this for you, but I wrote
> the code below in 10 minutes and it seems to do the right thing.

Well first off, thanks for the quick response and the nice script.

Still leaves the problem on how the represent the data, the file is not 
only littered with 277 [Ship] entries, but also [collision group]'s, one 
[Pilot] and lots of [Simple]'s... The file I put was just an example. :(

I want for example access the pilot this way: (Nice and easy for any 
user of this theoretical module)

print $ini->{Pilot}->{nickname}; #Only one pilot.

But the Ships this way:

foreach (@{$ini->{Ships}}) {

}
# But with:
print $ini->{Ships}->{nickname}; #Just print the first nickname of the 
first ship, first value.

I can do that with overload, but how do I handle:

$ini->{Ships}->{nickname}=[qw/li_elite li_fighter/]?:
I should do this:
[Ship]
 ...
nickname=li_elite
nickname=li_fighter
 ...
I can't do that with overload, can I... I need to return a tied thing 
for that. But then I run into the tied/overload bug on
print "$ini->{Ships}->{nickname}" #First entry, now tied, will return a 
tied object, BUT overload comes before tied, so it won't call '""' of 
the tied object, but from $ini->{Ships}, according to the overload manpage.

+ I want to keep the order or otherwise it will confuse diff a lot.


The module should help people write scripts to easily extract and modify 
data in those files, without exporting them to .inis first.
> The
> only thing you need to configure is the list that initializes
> %comma_keys.

That might be a problem, since this is neither thats not the only ini 
file in there.

There are shiparchs (this one), loadouts, equipments, universes, 
systems, bases, markets, asteroids, asteroid_fielf and a lot more files 
of those or similiar formats. (A quick search gave me 1000+ ini files)

And I don't know the keys, lately someone discovered that you can add an 
spin = 0.1, 0, 0 to a planet in a system.ini file and the planet 
rotates. This was never seen before, maybe because they probably removed 
it in the final version. Who knows how many of those are still in there.

But I need to save them all and store them into a database, to run 
queries on it. Well that is working nicely currently as well, but I was 
wondering for a better solution to my problem too.

> You can write this in a stateful way but it's a waste of time if the
> data size is small and you don't expect the string "[Ship]" anywhere
> unexpected in the configuration.

I don't think the parser is the big problem, mine is working nicely. I 
was just wondering if there is another one out there that can do it so I 
don't need to release yet another one.
Since those files are ini files from Microsoft, who if not invented 
them, at least made them popular. (win.ini system.ini)..

I just want to write the decoder/encoder to the binary format of those 
files (I heard they are being used in some other game, too)


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

Date: Tue, 10 Feb 2009 19:08:44 GMT
From: sln@netherlands.com
Subject: Re: A good data structure to store INI files.
Message-Id: <fbj3p4lm1t3qcf538gq5inkc3vcp223nkj@4ax.com>

On Tue, 10 Feb 2009 18:34:41 +0100, Marc Lucksch <perl@marc-s.de> wrote:

>Maybe I'm an idiot here, but I can't figure this one out even if my life 
>would depend on it:
>
>I have an file in the quite easy INI format, put I have no idea how to 
>store it in a way where it can be easily accessed by other people and 
>without any long explanations.
>
>Anyway here is the example file:
>
> > [Ship]
> > ids_name = 237033
> > ids_info = 66567
> > ids_info1 = 66567
> > ship_class = 1
> > nickname = li_elite
> > LODranges = 0, 75, 150, 1300
> > fuse = intermed_damage_smallship01, 0.000000, 400
> > fuse = intermed_damage_smallship02, 0.000000, 200
> > ;#Well its a lot more in one section, but this proves the point.
> >
> > [Ship]
> > ids_name = 237033
> > ids_info = 66567
> > ship_class = 1
> > nickname = li_elite2
> > LODranges = 0, 175, 150, 1300
> > fuse = intermed_damage_smallship01, 0.000000, 400
> > fuse = intermed_damage_smallship02, 0.000000, 200
> > fuse = intermed_damage_smallship03, 0.000000, 133
> > ;.... (about 250kb of this)
>
>The file is from the Microsoft game Freelancer, but it is unlike any 
>normal ini files:
>
>- The section names are doubled, (there are multiple [Ship] entries)
>- Some of the keys are doubled as well (0 - 4 fuse entries for example)
>- Some of the values are seperated by ",". (That's not a big problem)
>
[snip]
>
I don't know that Config::IniFiles will deal with duplicate sections and/or
values correctly. My hunch is it won't. Because to write it out, ie: creating
a new section, returns undef if it already exists.

So, but as a check you could see the results if you parse the file with this:
my @sections = $cfg->Sections();
for my $sect_name (@sections)
{
	my @values = $cfg->Parameters ($sect_name);
	for my $value (@Values)
	{
		...
	}
}

Although I don't think it will parse as you want, you could easily write a regex
parser to read in the file, then write it out using the Config::IniFiles module
with its Group constructs. Might want to check out Groups  and GroupMembers.

Otherwise, I think win32 parses sequential (streaming) sections and values with a
get next kind of thing.

Maybe you should'nt use Perl. You know Perl isin't the be all and end all.

-sln





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

Date: Tue, 10 Feb 2009 13:10:32 GMT
From: James Turnbull <james@lovedthanlost.net>
Subject: ANNOUNCE:  File::Scan::ClamAV-1.91 released
Message-Id: <KEuvy6.15pJ@zorch.sf-bay.org>

File::Scan::ClamAV-1.91

1.91
     - Deprecated rawscan() and replaced with scan() to maintain
       backwards compatibility

     - Tidied module

     - Fix for https://rt.cpan.org/Ticket/Display.html?id=26684

Where To Get It

Version 1.91 is now available at:

http://search.cpan.org/CPAN/authors/id/J/JA/JAMTUR/File-Scan-ClamAV-1.91.tar.gz

Thanks to Colin Faber for kindly allowing me to co-maintain this module
and the CPAN team for sorting out access and permissions.

James Turnbull






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

Date: Tue, 10 Feb 2009 18:29:47 +0000 (UTC)
From: Rahul <nospam@nospam.invalid>
Subject: Re: automating a perl installation on a cluster (or using non-standard nfs paths)
Message-Id: <Xns9BAE7F1E699DB6650A1FC0D7811DDBC81@85.214.105.209>

Ben Morrow <ben@morrow.me.uk> wrote in news:edq166-a0h.ln1
@osiris.mauzo.dyndns.org:

> Specifically, an entry /foo in PERL5LIB will also include
> /foo/VERSION/ARCH, /foo/VERSION and /foo/ARCH where VERSION is something
> like 5.8.8 and ARCH is something like i386-linux. It will also include
> directories for any compatible previous versions that were found at
> Configure time: you can get the list with perl -V:inc_version_list. This
> is exactly the same logic as used by 'use lib'.
> 
> 

I found this quite useful article about automating perl module installs. In 
case it helps anybody else in a similar situation:

http://www.ibm.com/developerworks/opensource/library/l-depperl.html

It does seem that deploying perl across a cluster of machines is quite a 
difficult job!

-- 
Rahul


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

Date: Tue, 10 Feb 2009 06:46:06 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: error printing page using LWP::Simple
Message-Id: <slrngp2toe.8f3.tadmc@tadmc30.sbcglobal.net>

Larry Gates <larry@example.invalid> wrote:
> On Sun, 8 Feb 2009 09:08:29 -0600, Tad J McClellan wrote:
>
>> Have you seen the Posting Guidelines that are posted here frequently?
>
> I read them *all the time.*  


Very good. Thank you.

Sorry for implying that you weren't.


> I'm directed to do so much compulsory reading
> that I don't touch perl unless I've got time to
>
> a) study the newgroup
> b) study the camel doc
> c) study everything someone suggests as far as perldoc goes
> d) have time to work it out with a command line on windows


Most excellent!

You already have most of the items from the 

    "Perl problem resolution checklist"

    http://groups.google.com/group/comp.lang.perl.misc/browse_thread/thread/c255eff3c2a0bf1a?q=#ba1397e88a4c5a57

but I'll point to it here in case it might help in the future.


[ snip other listed things to try ]


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Tue, 10 Feb 2009 10:08:15 -0800 (PST)
From: Brad Baxter <baxter.brad@gmail.com>
Subject: Re: error printing page using LWP::Simple
Message-Id: <9e069804-3ad5-4587-9ad7-e735552c6228@z1g2000yqn.googlegroups.com>

On Feb 6, 6:21=A0am, Peter Makholm <pe...@makholm.net> wrote:
>
> my $t =3D get($url) // "Fail!";
>
> Uhmmm, we don't have a low precedence version of '//'?
>
> //Makholm

I thought it was 'dor', but I don't see it in, e.g.,
http://perldoc.perl.org/perlop.html

--
Brad


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

Date: Tue, 10 Feb 2009 19:59:01 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: error printing page using LWP::Simple
Message-Id: <slrngp3jjl.gn9.hjp-usenet2@hrunkner.hjp.at>

On 2009-02-10 18:08, Brad Baxter <baxter.brad@gmail.com> wrote:
> On Feb 6, 6:21 am, Peter Makholm <pe...@makholm.net> wrote:
>> my $t = get($url) // "Fail!";
>>
>> Uhmmm, we don't have a low precedence version of '//'?
>>
>> //Makholm
>
> I thought it was 'dor', but I don't see it in, e.g.,
> http://perldoc.perl.org/perlop.html

In Perl6 it is (or was, last time I looked at it) "err". 

	hp


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

Date: Tue, 10 Feb 2009 12:55:15 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: File handle to "in memory" file
Message-Id: <x7eiy6dvng.fsf@mail.sysarch.com>

>>>>> "FS" == Frank Seitz <devnull4711@web.de> writes:

  FS> Uri Guttman wrote:
  >>>>>>> "FS" == Frank Seitz <devnull4711@web.de> writes:
  FS> Ideally a class is a piece of code that works properly without
  FS> assumptions about the program it is used in.
  >> and you assume that if your module is used then it will always do
  >> this
  >> stderr thing. make it an option and just do it when enabled. let the top
  >> level code decide whether to enable it or not. checking to see if the
  >> var is used by some other module is silly. what if that module is loaded
  >> after yours and overrides your stuff? you can't predict this so letting
  >> top level code handle the decision and offering this OPTIONAL service is
  >> the best way.

  FS> 1. A class is not a module and vice versa.
  FS> 2. A constructor is not called automatically.

please don't teach me perl! :)

  FS> You missed the point. I can't remember the state by myself, because
  FS> STDERR may change during program execution (under CGI::SpeedyCGI STDERR is
  FS> reopened with every CGI call).
  >> blech. you can always retie it later. and tied is easier to detect.

  FS> Okay, your are right, a tied object is precisely detectable. This is
  FS> what I miss for scalars in the filehandle API. But ties are slow and
  FS> I don't like the code very much.

agreed they are slow. if you are concerned about speedy reopening
stderr, then why don't you close your string and reopen it each time
too? i still don't see the issue.

  >> i think you have painted
  >> yourself into a deep corner. this is definitely an xy problem now. your
  >> bigger problem is solvable without much pain but you have already
  >> chosen a path (and sticking to it) which has much more pain.

  FS> No, it's not an xy problem. I asked a concrete question about
  FS> Perls filehandle API and I know by myself what I have to conclude
  FS> from the (in this case: negative) answer.

well i am sure a better overall solution exists. in fact i know it. but
i can't convince you of that. hence i have to call it an xy problem. not
much more i can do here.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Tue, 10 Feb 2009 08:48:26 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: how can i convert my perl script to be a perl module?
Message-Id: <54b3p4ppn049c4927nlb7366roffluqhbn@4ax.com>

Ted Zlatanov <tzz@lifelogs.com> wrote:
>On Sun, 08 Feb 2009 09:27:48 -0800 Jürgen Exner <jurgenex@hotmail.com> wrote: 
>
>JE> "georg.heiss@gmx.de" <georg.heiss@gmx.de> wrote:
>>> how can i convert my perl script to be a perl module? 
>
>JE> One way: you could follow the suggestions in the FAQ.
>
>JE> perldoc -q module
>
>JE> 	"How do I create a module?"
>
>That doesn't cover the specific case of an existing Perl script.  

You are right, it doesn't.
But it does provide a compact outline (the template) of how to organize
a module and what elements you would typically include. Based on that he
can make the call of which elements are needed in his case. The other
documentation (perldoc perlmod) is rather long and tedious to read.  

>Is
>there something like that in the documentation?  I don't recall it.

The real question is: what does the OP mean by "converting a program
into a module"?

The only thing a program exports is the 'main' function (well, strictly
speaking there is no such thing but you know what I mean). For the
module he will have to evaluate individually which elements he needs to
export for his application, if he needs initialization and cleanup code,
etc, etc.

jue


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

Date: Tue, 10 Feb 2009 12:21:03 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: how can i convert my perl script to be a perl module?
Message-Id: <86eiy6jgq8.fsf@lifelogs.com>

On Tue, 10 Feb 2009 08:48:26 -0800 Jürgen Exner <jurgenex@hotmail.com> wrote: 

JE> Ted Zlatanov <tzz@lifelogs.com> wrote:
>> On Sun, 08 Feb 2009 09:27:48 -0800 Jürgen Exner <jurgenex@hotmail.com> wrote: 
>> 
JE> "georg.heiss@gmx.de" <georg.heiss@gmx.de> wrote:
>>>> how can i convert my perl script to be a perl module? 
>> 
JE> One way: you could follow the suggestions in the FAQ.
>> 
JE> perldoc -q module
>> 
JE> "How do I create a module?"
>> 
>> That doesn't cover the specific case of an existing Perl script.  

JE> You are right, it doesn't.
JE> But it does provide a compact outline (the template) of how to organize
JE> a module and what elements you would typically include. Based on that he
JE> can make the call of which elements are needed in his case. The other
JE> documentation (perldoc perlmod) is rather long and tedious to read.  

>> Is
>> there something like that in the documentation?  I don't recall it.

JE> The real question is: what does the OP mean by "converting a program
JE> into a module"?

JE> The only thing a program exports is the 'main' function (well, strictly
JE> speaking there is no such thing but you know what I mean). For the
JE> module he will have to evaluate individually which elements he needs to
JE> export for his application, if he needs initialization and cleanup code,
JE> etc, etc.

In my experience, the question usually comes down to "I have functions
that should be available to multiple programs, and I realize that do()
is a nasty hack that will bite me sooner or later.  So how do I put
together a library of functions as a module?"

This may be a wrong guess, but it's IMO very common...  Pointing to the
Exporter module (`perldoc Exporter') is probably a good first step, in
addition to the module FAQ you pointed out.

Thanks
Ted


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

Date: Tue, 10 Feb 2009 11:26:07 +0100
From: mirod <mirod@xmltwig.com>
Subject: Re: indented xml using XML::DOM
Message-Id: <4991562c$0$746$5fc30a8@news.tiscali.it>

Parapura Rajkumar wrote:

>   I am using XML::Dom->printToFile to write out an XML::Dom document
> that I created. Is there a way to indent the output.  By default the
> whole xml is written out in just one line.
> 
>   XML::Handler::XMLWriter with newlines option claims to do this but
> doesn't take an XML::Dom object.

XML::DOM doesn't seem to provide any mean of pretty printing the output.
Note that in a purely XML context, there is no need for it, and adding 
whitespace indiscriminately could even lead to the output becoming invalid (wrt 
a DTD).

That said you can always post-process your XML, using xmllint (which comes with 
libxml2) or xml_pp (which comes with XML::Twig) for example.

Finally, I have to add a word of caution about XML::DOM: these days, XML::LibXML 
is the preferred DOM implementation in Perl. It is a lot more powerful than 
XML::DOM, and more actively maintained AFAIK. It is also quite compatible with 
XML::DOM, so it is pretty easy to port the code.

-- 
mirod


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

Date: Tue, 10 Feb 2009 08:39:35 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: parse newline
Message-Id: <86eiy6l5js.fsf@lifelogs.com>

On Mon, 9 Feb 2009 19:16:20 -0600 Tad J McClellan <tadmc@seesig.invalid> wrote: 

TJM> Ted Zlatanov <tzz@lifelogs.com> wrote:
>> Assuming your text is in FILE.TXT:
>> od -t u1 -t a FILE.txt

TJM>     s/txt/TXT/;

SORRY ;)

Ted


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

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:

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

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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.

#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 2198
***************************************


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