[32397] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3664 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 12 14:09:23 2012

Date: Thu, 12 Apr 2012 11:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 12 Apr 2012     Volume: 11 Number: 3664

Today's topics:
    Re: f python? <timr@probo.com>
        Help with a hash <herbert.burnswell@gmail.com>
    Re: Help with a hash <rweikusat@mssgmbh.com>
    Re: Help with a hash <jimsgibson@gmail.com>
    Re: Help with a hash <rweikusat@mssgmbh.com>
    Re: Help with a hash <ben@morrow.me.uk>
    Re: Help with pattern matching <ben@morrow.me.uk>
    Re: Help with pattern matching <gogala.mladen@gmail.com>
    Re: Help with pattern matching <ben@morrow.me.uk>
    Re: Help with pattern matching <gogala.mladen@gmail.com>
    Re: Help with pattern matching <ben@morrow.me.uk>
    Re: Help with pattern matching <glex_no-spam@qwest-spam-no.invalid>
    Re: Help with pattern matching <artmerar@yahoo.com>
    Re: Help with pattern matching (Tim McDaniel)
    Re: Help with perl special variable riccardo.marini@gmail.com
    Re: Help with perl special variable <ben@morrow.me.uk>
    Re: Help with perl special variable (Tim McDaniel)
        looking for some kind of IDL for Perl types only <tzz@lifelogs.com>
    Re: looking for some kind of IDL for Perl types only <bjoern@hoehrmann.de>
    Re: looking for some kind of IDL for Perl types only <tzz@lifelogs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Apr 2012 22:16:59 -0700
From: Tim Roberts <timr@probo.com>
Subject: Re: f python?
Message-Id: <b7pco754sqd7bcpotqr7iori33s5lsr7i0@4ax.com>

"WJ" <w_a_x_man@yahoo.com> wrote:
>
>Slashes can work under windows, up to a point:

ALL Windows APIs accept forward slashes.  The only place they are not
accepted is command line commands that take options which can begin with
forward slash.

>Also, most languages I use under windows allow you to use
>slashes in paths:

All of them should do so.  They're just string being passed to CreateFile,
and CreateFile accepts forward slashes just fine.
-- 
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.


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

Date: Wed, 11 Apr 2012 14:27:58 -0700 (PDT)
From: HB <herbert.burnswell@gmail.com>
Subject: Help with a hash
Message-Id: <88de9512-597b-47af-b335-fee0ba3f180b@w17g2000yqe.googlegroups.com>

Hi All,

I'm looking to create a pretty simple script that will create the
system V run level links for custom chkconfig scripts on Linux.  I was
thinking it will work with 4 arguments as:

 ./script <run levels on> <start order #> <kill order #> </etc/init.d/
scriptname>

If I'm thinking correctly, the best way to do this is put ARGV[0] into
a hash as: 0=off, 1=off, 2=off, 3=on, etc.  I would use only the run
levels to be on in the argument such as:

 ./script 345 x x x

My question is on the checking of ARGV[0] and how to drop the info
into a hash.  I.E. in the example above:

- make sure there are only numbers 0-6 used and max of 7
- if a number is not present it equals 'off'
- if a number is present it equals 'on'
- getting data into hash

I should be fine once I get this part squared away.  Is this the best
way to go about setting this up and if so can someone help me out with
this hash?

Thank you very much in advance.

Best regards,

Herb


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

Date: Wed, 11 Apr 2012 23:12:34 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Help with a hash
Message-Id: <87ty0pudd9.fsf@sapphire.mobileactivedefense.com>

HB <herbert.burnswell@gmail.com> writes:

[...]

> ./script 345 x x x
>
> My question is on the checking of ARGV[0] and how to drop the info
> into a hash.  I.E. in the example above:
>
> - make sure there are only numbers 0-6 used and max of 7
> - if a number is not present it equals 'off'
> - if a number is present it equals 'on'
> - getting data into hash
>
> I should be fine once I get this part squared away.  Is this the best
> way to go about setting this up

Since your keys are the number 0, 1, 2, 3, 4, 5 and 6, I'd prefer to
use an array for that. I would also simply use 'undef' as
'off'. Example how this could be done:

------------
my @levels;

while ($ARGV[0] =~ /(.)/g) {
    $levels[$1] = 1;
    $1 =~ /[0-6]/ or die("invalid run-level $1");
}

printf("%d\t%s\n", $_, $levels[$_] ? 'on' : 'off') for (0 .. 6);
------------

NB: This doesn't check if ARGV[0] is empty or not available at all.

NB^2: Settting $levels[$1] and the check for invalid values have to be
done in this order to avoid clobbering $1.


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

Date: Wed, 11 Apr 2012 15:14:08 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Help with a hash
Message-Id: <110420121514082998%jimsgibson@gmail.com>

In article
<88de9512-597b-47af-b335-fee0ba3f180b@w17g2000yqe.googlegroups.com>, HB
<herbert.burnswell@gmail.com> wrote:

> Hi All,
> 
> I'm looking to create a pretty simple script that will create the
> system V run level links for custom chkconfig scripts on Linux.  I was
> thinking it will work with 4 arguments as:
> 
> ./script <run levels on> <start order #> <kill order #> </etc/init.d/
> scriptname>
> 
> If I'm thinking correctly, the best way to do this is put ARGV[0] into
> a hash as: 0=off, 1=off, 2=off, 3=on, etc.  I would use only the run
> levels to be on in the argument such as:
> 
> ./script 345 x x x
> 
> My question is on the checking of ARGV[0] and how to drop the info
> into a hash.  I.E. in the example above:
> 
> - make sure there are only numbers 0-6 used and max of 7

my $levels = $ARGV[0];
if( $levels !~ /^[0-6]{1,7}$/ ) {
  die("Invalid first argument: \"$levels\"\n");
}

> - if a number is not present it equals 'off'
> - if a number is present it equals 'on'
> - getting data into hash

my @levels;
$levels[$_] = 'off' for 0..6;
$levels[$_] = 'on' for split(//,$levels);

All untested.

-- 
Jim Gibson


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

Date: Wed, 11 Apr 2012 23:14:56 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Help with a hash
Message-Id: <87pqbdud9b.fsf@sapphire.mobileactivedefense.com>

HB <herbert.burnswell@gmail.com> writes:

[...]

> - make sure there are only numbers 0-6 used and max of 7

I would also omit the 'at most seven' check. That buys nothing except
'being anal about syntax' and 343536 can just be treated as 3456
instead.


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

Date: Thu, 12 Apr 2012 00:23:58 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Help with a hash
Message-Id: <edgh59-jq51.ln1@anubis.morrow.me.uk>


Quoth Rainer Weikusat <rweikusat@mssgmbh.com>:
> 
> my @levels;
> 
> while ($ARGV[0] =~ /(.)/g) {
>     $levels[$1] = 1;
>     $1 =~ /[0-6]/ or die("invalid run-level $1");
> }
> 
> printf("%d\t%s\n", $_, $levels[$_] ? 'on' : 'off') for (0 .. 6);
> ------------
> 
> NB: This doesn't check if ARGV[0] is empty or not available at all.
> 
> NB^2: Settting $levels[$1] and the check for invalid values have to be
> done in this order to avoid clobbering $1.

So use an ordinary variable instead:

    while (my ($l) = $ARGV[0] =~ /./g) {
        $l =~ /[0-6]/ or die ...;
        $levels[$l] = 1;
    }

I avoid $N where possible, both for this reason and because it becomes
very easy to forget what the various $N are supposed to represent as you
get further away from the pattern match.

I would do it like this:

    @ARGV == 4 or die "Usage: ...\n";
    my ($levels, $start, $kill, $script) = @ARGV;

    # here's an example of where it's hard to avoid $1
    $levels =~ /([^0-6])/ and die "bad runlevel $1\n";

    my @levels;
    for (split //, $levels) {
        $levels[$_] and die "duplicate runlevel $_\n";
        $levels[$_] = 1;
    }

or perhaps

    my @levels = map $levels =~ s/$_//, 0..6;
    length $levels and die "bad runlevels '$levels'";

Ben



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

Date: Wed, 11 Apr 2012 20:00:01 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Help with pattern matching
Message-Id: <hu0h59-ct11.ln1@anubis.morrow.me.uk>


Quoth Rainer Weikusat <rweikusat@mssgmbh.com>:
> 
> Yes. And as 'experienced Perl persons' both of you should know that I
> know that the Perl regular expression (sub-)language is not identical
> to the regular expression language used by sed (or anything else) and
> that this is besides the point since the topic of conversations was
> 'delimiter characters for regular expressions': Somebody who use
> anything except Perl has to deal with the // convention, anyway,
> consequently, keeping it for Perl doesn't make things worse than they
> already are.

Anyone who has to deal with regexes[0] in any language other than Perl
or JavaScript has my condolences :).

Ben

[0] I prefer not to call them 'regular expressions', since they aren't.
Even grep has backreferences, which can't be implemented with a DFA.



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

Date: Wed, 11 Apr 2012 21:10:45 +0000 (UTC)
From: Mladen Gogala <gogala.mladen@gmail.com>
Subject: Re: Help with pattern matching
Message-Id: <jm4s0k$sso$1@solani.org>

On Wed, 11 Apr 2012 11:21:28 +0200, Wolf Behrenhoff wrote:

> Prefer using the open with three arguments (as done for access_log).
> Also, the FILE handle is global -> better use a "normal" variable here

That really messes up working with formats. Formats are a very useful 
piece of Perl and I use them a lot.



-- 
http://mgogala.byethost5.com


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

Date: Wed, 11 Apr 2012 22:38:20 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Help with pattern matching
Message-Id: <c7ah59-3441.ln1@anubis.morrow.me.uk>


Quoth Mladen Gogala <gogala.mladen@gmail.com>:
> On Wed, 11 Apr 2012 11:21:28 +0200, Wolf Behrenhoff wrote:
> 
> > Prefer using the open with three arguments (as done for access_log).
> > Also, the FILE handle is global -> better use a "normal" variable here
> 
> That really messes up working with formats. Formats are a very useful 
> piece of Perl and I use them a lot.

Consider switching to Perl6::Form instead. It's a great deal saner.

(Don't be put off by the 'Perl6' prefix. It's a perfectly ordinary Perl
5 module, that just happens to have been written as a demonstration of
the Perl 6 way of doing formats.)

You may also be interested in the $~ and $^ variables, and their
equivalent IO::Handle methods ->format_name and ->format_top_name. Even
if you want to use Perl 5 formats, you don't need to use global bareword
filehandles.

Ben



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

Date: Thu, 12 Apr 2012 02:38:44 +0000 (UTC)
From: Mladen Gogala <gogala.mladen@gmail.com>
Subject: Re: Help with pattern matching
Message-Id: <pan.2012.04.12.02.38.44@gmail.com>

On Wed, 11 Apr 2012 22:38:20 +0100, Ben Morrow wrote:


> Consider switching to Perl6::Form instead. It's a great deal saner.
> 
> (Don't be put off by the 'Perl6' prefix. It's a perfectly ordinary Perl
> 5 module, that just happens to have been written as a demonstration of
> the Perl 6 way of doing formats.)

Thanks a lot! Looks much simpler than associating formats through handles 
using fdopen(fileno(...). As a matter of fact, it looks very, very 
interesting. I will try it over the weekend. That will probably remove 
some of the complaints by perlcritic. That is a really useful nagging 
piece of software.
BTW, I am a DBA, not a programmer. I find Perl ideal for writing quick 
and pretty reports that have to be run from crontab. Don't judge me too 
harshly.



-- 
http://mgogala.byethost5.com


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

Date: Thu, 12 Apr 2012 12:34:12 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Help with pattern matching
Message-Id: <k6ri59-17j1.ln1@anubis.morrow.me.uk>


Quoth Mladen Gogala <gogala.mladen@gmail.com>:
>
> BTW, I am a DBA, not a programmer. I find Perl ideal for writing quick 
> and pretty reports that have to be run from crontab. Don't judge me too 
> harshly.

Oh, I don't :). There's nothing wrong with writing quick-and-dirty Perl,
as long as you're willing to learn when there are better ways of doing
things.

Ben



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

Date: Thu, 12 Apr 2012 12:18:32 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Help with pattern matching
Message-Id: <4f870e68$0$9075$815e3792@news.qwest.net>

On 04/11/12 09:38, ExecMan wrote:
[...]
>
> I'm just worried about a 4 million line file going into an array.  As
> long as it does not take up too many resources.  If the file is say,
> 300MB, that is a lot to put into an array......
>
>

There are many ways to do what you are asking, however think about
what is it -exactly- that you're trying to count?  Is the 'url' to match
against the referrer?  Is it hits to certain pages?  Something else?

If what you're after doesn't occur in most of the lines, you might
be able to greatly reduce the number of lines you want to look at
by narrowing down your universe to only lines that might contain what
you're after.

e.g.
open( FILE, '/bin/egrep 'abc123|thispage|zzzyyyxxx' 
/home/httpdlogs/apache2/access_log |' );

or..

/bin/egrep 'abc123|thispage|zzzyyyxxx' 
/home/httpdlogs/apache2/access_log | myprogram.pl

where myprogram.pl reads from STDIN.

That approach can be used to not include lines too. e.g.  those
with '.gif' or '.jpg', or any other string, using '-v'.

If you're after referrer, or certain strings in the URL part of the
line, then possibly parse every line and store the specific field
you're after, into a hash, with the count as the value,. Once
they are all gathered, go through that hash looking for those that
contain your 'urls'. That way you parse the file once, gathering only
the relevant data, then go through that as many times as you need.
You'll avoid having to run multiple regular expressions on every
single line in the log.

Possibly you could use Apache::ParseLog to do all of
the work and then simply grep/filter the output as needed.

See also:
perldoc -q 'How do I efficiently match many regular expressions at once'




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

Date: Thu, 12 Apr 2012 10:37:08 -0700 (PDT)
From: ExecMan <artmerar@yahoo.com>
Subject: Re: Help with pattern matching
Message-Id: <a0a27bc6-a397-4a06-844f-c854dc114c80@f17g2000yqj.googlegroups.com>

On Apr 12, 12:18=A0pm, "J. Gleixner" <glex_no-s...@qwest-spam-
no.invalid> wrote:
> On 04/11/12 09:38, ExecMan wrote:
> [...]
>
>
>
> > I'm just worried about a 4 million line file going into an array. =A0As
> > long as it does not take up too many resources. =A0If the file is say,
> > 300MB, that is a lot to put into an array......
>
> There are many ways to do what you are asking, however think about
> what is it -exactly- that you're trying to count? =A0Is the 'url' to matc=
h
> against the referrer? =A0Is it hits to certain pages? =A0Something else?
>
> If what you're after doesn't occur in most of the lines, you might
> be able to greatly reduce the number of lines you want to look at
> by narrowing down your universe to only lines that might contain what
> you're after.
>
> e.g.
> open( FILE, '/bin/egrep 'abc123|thispage|zzzyyyxxx'
> /home/httpdlogs/apache2/access_log |' );
>
> or..
>
> /bin/egrep 'abc123|thispage|zzzyyyxxx'
> /home/httpdlogs/apache2/access_log | myprogram.pl
>
> where myprogram.pl reads from STDIN.
>
> That approach can be used to not include lines too. e.g. =A0those
> with '.gif' or '.jpg', or any other string, using '-v'.
>
> If you're after referrer, or certain strings in the URL part of the
> line, then possibly parse every line and store the specific field
> you're after, into a hash, with the count as the value,. Once
> they are all gathered, go through that hash looking for those that
> contain your 'urls'. That way you parse the file once, gathering only
> the relevant data, then go through that as many times as you need.
> You'll avoid having to run multiple regular expressions on every
> single line in the log.
>
> Possibly you could use Apache::ParseLog to do all of
> the work and then simply grep/filter the output as needed.
>
> See also:
> perldoc -q 'How do I efficiently match many regular expressions at once'

I love this.  From a simple programming question I am accumulating all
this wisdom in Perl.

Another thing I was wondering about is why to use the 'strict'
method?  Advantages?  Disadvantages?


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

Date: Thu, 12 Apr 2012 17:58:55 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Help with pattern matching
Message-Id: <jm754v$rlb$2@reader1.panix.com>

In article <a0a27bc6-a397-4a06-844f-c854dc114c80@f17g2000yqj.googlegroups.com>,
ExecMan  <artmerar@yahoo.com> wrote:
>Another thing I was wondering about is why to use the 'strict'
>method?  Advantages?  Disadvantages?

You mean

    use strict;

?  The technical term is "Perl pragma".  The purpose is described at
the top of the man page as "strict - Perl pragma to restrict unsafe
constructs".

Since it restricts unsafe constructs, it is deemed a very very good
idea indeed.  If it flags an error, it's much more likely than not
(though not guaranteed) that you're doing something wrong than that
you're doing something reasonable and need to turn off "use strict".

The usual idiom is

    use strict;
    use warnings;

(or vice versa).  My ork-place codes so that they often add
    no warnings 'uninitialized';
but I prefer to just not code that way, and I suspect that that's the
most common warning to turn off (though I could easily be wrong).

-- 
Tim McDaniel, tmcd@panix.com


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

Date: Thu, 12 Apr 2012 02:19:19 -0700 (PDT)
From: riccardo.marini@gmail.com
Subject: Re: Help with perl special variable
Message-Id: <24881700.650.1334222359841.JavaMail.geo-discussion-forums@vbue17>

Il giorno mercoled=EC 11 aprile 2012 18:37:43 UTC+2, Ben Morrow ha scritto:
> Quoth riccardo.marini@gmail.com:
> >=20
> > I saw the light..
> > ..
> > my $test=3Deval "\"$destination[$i]\"";
> > print "$test\n";=20
> > ..
> >=20
> > finally shows:
> > /somedir/somepath/OIAC-ciao=20
> >=20
> > I really can't understand why it needs that kind of quoting ..
> > Without it, doesn't works..
> > Can someone explain??=20
>=20
> I can try... :).
>=20
> The first thing that happens is this
>=20
>     "\"$destination[$i]\""
>=20
> string is evaluated. Since it's double-quoted, it interprets backslashes
> specially and interpolates variables, so the result is the string
>=20
>     '"/somedir/somepath/$2"'
>=20
> I've single-quoted that string to show that it won't be expanded again
> (at least, not until you ask for it).
>=20
> The next thing that happens is that string is passed to eval. This looks
> at the string and interprets it as a Perl expression, in this case the
> expression
>=20
>     "/somedir/somepath/$2"
>=20
> . Notice I've removed the single quotes, since this is no longer a
> string *containing* a Perl expression, it's an actual Perl expression.
> (This distinction is a little confusing, but is at the heart of what
> eval does.)
>=20
> This expression is another double-quoted string, so again variables are
> expanded and the result is
>=20
>     '/somedir/somepath/OIAC-ciao'
>=20
> (I've single-quoted it for the same reason as before), which string is
> then assigned to $test.

Thanks m8. Your explainetion is great.

> eval is much too powerful a tool for the job you are doing. Even if you
> aren't worried about the security implications, the multiple layers of
> quoting required get very confusing. Assuming you only want to support
> numbered variables in your substitutions, I would use something like
> this:
>=20
>     if ( my @capture =3D /$regex[$i]/ ) {
>         my $result =3D $destination[$i];
>         $result =3D~ s/\$([0-9]+)/$capture[$1]/eg;
>         print "$result\n";
>     }
>=20
> This expands the variables in the result explicitly, rather than trying
> to get perl to do it for you with eval.
>=20
> Ben

I m now using following code:=20
 ..
        if ( my @capture =3D /$regex[$i]/ ) {
            my $result =3D $destination[$i];
            print "CAPTURE: @capture\n";
            print "BEFORE s//: $result\n";
            $result =3D~ s/\$([0-9]+)/$capture[$1-1]/eg;
            print "AFTER s//: $result\n";
        }
 ..

And works fine.
I only added "$1-1' cause "$1" will be out of index in @capture.
This should be safer, and should work against any or multiple $[0-9] in my =
configuration line.

Can you confirm?

Thanks again Ben
perlnoob.


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

Date: Thu, 12 Apr 2012 12:36:31 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Help with perl special variable
Message-Id: <vari59-17j1.ln1@anubis.morrow.me.uk>


Quoth riccardo.marini@gmail.com:
> Il giorno mercoledì 11 aprile 2012 18:37:43 UTC+2, Ben Morrow ha scritto:
> 
> > eval is much too powerful a tool for the job you are doing. Even if you
> > aren't worried about the security implications, the multiple layers of
> > quoting required get very confusing. Assuming you only want to support
> > numbered variables in your substitutions, I would use something like
> > this:
> > 
> >     if ( my @capture = /$regex[$i]/ ) {
> >         my $result = $destination[$i];
> >         $result =~ s/\$([0-9]+)/$capture[$1]/eg;
> >         print "$result\n";
> >     }
> 
> I m now using following code: 
> ..
>         if ( my @capture = /$regex[$i]/ ) {
>             my $result = $destination[$i];
>             print "CAPTURE: @capture\n";
>             print "BEFORE s//: $result\n";
>             $result =~ s/\$([0-9]+)/$capture[$1-1]/eg;
>             print "AFTER s//: $result\n";
>         }
> ..
> 
> And works fine.
> I only added "$1-1' cause "$1" will be out of index in @capture.

Oh yes, so it is. Sorry about that :).

> This should be safer, and should work against any or multiple $[0-9] in
> my configuration line.
> 
> Can you confirm?

It should do, yes.

Ben



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

Date: Thu, 12 Apr 2012 16:01:13 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Help with perl special variable
Message-Id: <jm6u89$rne$1@reader1.panix.com>

In article <24881700.650.1334222359841.JavaMail.geo-discussion-forums@vbue17>,
 <riccardo.marini@gmail.com> wrote:
>I m now using following code: 
>..
>        if ( my @capture = /$regex[$i]/ ) {
>            my $result = $destination[$i];
>            print "CAPTURE: @capture\n";
>            print "BEFORE s//: $result\n";
>            $result =~ s/\$([0-9]+)/$capture[$1-1]/eg;
>            print "AFTER s//: $result\n";
>        }
>..
>
>And works fine.
>I only added "$1-1' cause "$1" will be out of index in @capture.
>This should be safer, and should work against any or multiple $[0-9]
>in my configuration line.

I think it would be a little better if you sure that a reference is
valid before referring to it.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#! /usr/bin/perl
use strict;
use warnings;

my $regexp = '^(.)(.)';  # boobies!
$_ = 'ABC';
if (my @capture = /$regexp/) {
    my $result = 'left $1 right $2 invalid $3';
    print "CAPTURE: '", join("' '", @capture), "'\n";
    print "BEFORE s//: '$result'\n";
    my $bad = 0;
    foreach my $ref ($result =~ /\$([0-9]+)/g) {
        if (! exists $capture[$ref-1]) {
            warn "result '$result' refers to \$$ref, which is not captured in the regexp.\n";
            $bad = 1;
        }
    }
    if ($bad) {
        die "Dying due to bad element reference.\n";
    }
    $result =~ s/\$([0-9]+)/$capture[$1-1]/eg;
    print "AFTER s//: '$result'\n";
}
exit 0;


-- 
Tim McDaniel, tmcd@panix.com


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

Date: Wed, 11 Apr 2012 15:57:01 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: looking for some kind of IDL for Perl types only
Message-Id: <8762d6f3ea.fsf@lifelogs.com>

I'm trying to describe a function's data interface through a simple JSON
language (a sort of DSL).  Yes, this is a lot like an IDL.  For instance
this interface takes a boolean "activated" parameter and a "users" hash
with mandatory and optional keys as shown.

    {
        "activated": { "type": "boolean" },

        "users": 
        {
# "stringmap" has only string keys
            "type": "stringmap",
            "keys": 
            { 
                "gecos" : "string", 
                "uid"   : "integer", 
                "home"  : "string",
                "shell" : "string"
            },
            "optional_keys":
            {
                "passwdhash"     : "string", 
                "groupname"      : "string", 
                "_allow_dup_gid" : "boolean",
                "_enforce"       : "boolean",
                "_nocreate_home" : "boolean",
                "_noseed"        : "boolean"
            }
        }
    }

I am not attached to the JSON-based DSL, it's just my first prototype.

Parsing and validating the DSL strikes me as boring and surely something
that has been done before, but I'm not crazy about using existing IDLs
like Protocol Buffers, Thrift IDL, WSDL, or the Avro IDL
(http://avro.apache.org/docs/current/idl.html) because they are all too
complex.  SWIG is too C-oriented, and so on.

I'd rather have something very simple and easy to parse, which only
supports the basic pure data types in Perl (strings, integers, floating
point, booleans) and lists and hashes that use those data types.  I
don't want custom data types.  Does such a beast exist in CPAN or
Perl-land?  Ideally I should be able to pass it an interface definition
and the actual data, and it should tell me if there's a problem and
where.

Thanks
Ted


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

Date: Wed, 11 Apr 2012 22:51:40 +0200
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: looking for some kind of IDL for Perl types only
Message-Id: <2jrbo71nb3anrlllhmkmmtmev2aiql2ii5@hive.bjoern.hoehrmann.de>

* Ted Zlatanov wrote in comp.lang.perl.misc:
>I'm trying to describe a function's data interface through a simple JSON
>language (a sort of DSL).  Yes, this is a lot like an IDL.  For instance
>this interface takes a boolean "activated" parameter and a "users" hash
>with mandatory and optional keys as shown.

You might be looking for <http://en.wikipedia.org/wiki/JSON#Schema>.

>I'd rather have something very simple and easy to parse, which only
>supports the basic pure data types in Perl (strings, integers, floating
>point, booleans) and lists and hashes that use those data types.  I
>don't want custom data types.  Does such a beast exist in CPAN or
>Perl-land?  Ideally I should be able to pass it an interface definition
>and the actual data, and it should tell me if there's a problem and
>where.

(I do not know how mature the JSON Schema implementations in Perl are.)
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 


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

Date: Wed, 11 Apr 2012 17:23:01 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: looking for some kind of IDL for Perl types only
Message-Id: <871unuezey.fsf@lifelogs.com>

On Wed, 11 Apr 2012 22:51:40 +0200 Bjoern Hoehrmann <bjoern@hoehrmann.de> wrote: 

BH> * Ted Zlatanov wrote in comp.lang.perl.misc:
>> I'm trying to describe a function's data interface through a simple JSON
>> language (a sort of DSL).  Yes, this is a lot like an IDL.  For instance
>> this interface takes a boolean "activated" parameter and a "users" hash
>> with mandatory and optional keys as shown.

BH> You might be looking for <http://en.wikipedia.org/wiki/JSON#Schema>.

Ah, very nice.  A little bit overkill for my needs, but it's not verbose
and does not need special compilers.
http://davidwalsh.name/json-validation has a nice summary.

BH> (I do not know how mature the JSON Schema implementations in Perl are.)

JSON::Schema on CPAN is fairly new but it's a start.

Thank you very much!
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:

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


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