[23889] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6092 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 7 11:05:44 2004

Date: Sat, 7 Feb 2004 08:05:05 -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           Sat, 7 Feb 2004     Volume: 10 Number: 6092

Today's topics:
        Announce: PerlPointCD 3.00 - a conference CD toolkit <perl@jochen-stenzel.de>
    Re: Clarifications <bik.mido@tiscalinet.it>
        Compiler directives for Perl? (Yash)
    Re: Compiler directives for Perl? <pinyaj@rpi.edu>
    Re: Compiler directives for Perl? <tore@aursand.no>
    Re: Compiler directives for Perl? <gnari@simnet.is>
        converting scalar to an array of elements <charles.h.brashear@boeing.com>
    Re: converting scalar to an array of elements <skweek@no.spam>
    Re: converting scalar to an array of elements <jwillmore@remove.adelphia.net>
    Re: Copy Constructor Craziness (Jay Tilton)
    Re: How to execute a command line in Perlscript <jurgenex@hotmail.com>
    Re: how to find the last "new line" in string <gnari@simnet.is>
    Re: How to use select (select(2)) in Perl? <bernie@fantasyfarm.com>
    Re: Need help passing arrays by reference pls. <1usa@llenroc.ude>
    Re: perl identifier limits (Alex Shinn)
    Re: perl identifier limits (Alex Shinn)
    Re: perl identifier limits <uri@stemsystems.com>
    Re: perl identifier limits <uri@stemsystems.com>
    Re: perl identifier limits <troc@pobox.com>
    Re: trying to create a network script: <invalid-email@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 07 Feb 2004 12:09:25 +0100
From: Jochen Stenzel <perl@jochen-stenzel.de>
Subject: Announce: PerlPointCD 3.00 - a conference CD toolkit
Message-Id: <c02h90$kgr$2@online.de>



PerlPointCD is a tool to compose and maintain conference CDs, as well as 
to build websites presenting conference materials. Initially written and 
used to produce the CDs of the German Perl Workshop 
(www.perlworkshop.de), it now was generalized to be of common use.

To make it easy to start with, to demonstrate how things work, and to 
show how results can look like, the manual is included as a "demo CD" 
with sources, building environment and results.

Version 3.00 can be found at http://sourceforge.net/projects/perlpoint .



Feature list from the README file:

* produces HTML user interfaces to browse,

* one or more template based layouts,

* layouts can provide CSS, Java, JavaScript and/or frames for
        navigation,

* directory based approach makes it easy to organize talks within
        the cd structure,

* automatic conversion between long and (ISO file system and
        web address compliant) short directory names,

* convenient interface: makefile with certain targets,

* ready for teamwork: parts can be prepared by different team
        members (and speakers) and easily integrated,

* easy and transparent integration of speaker materials,

* archive feature to integrate previous conferences,

* related talks (of current year and archives) are linked
        automatically,

* source files can be written in PerlPoint or POD, further formats
        can be added by own source filters in Perl,

* automatic links for CPAN modules,

* module index added automatically,

* author index added automatically,

* index page generated automatically,

* generic texts produced in configurable languages,

* powerful set of predefined PerlPoint macros ready to use,

* integrates validation links into prerelease pages,

* logging check mode for automatic preproductions to find
        errors in integrated materials,

* supports browser navigation bars

* ... and more



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

Date: Sun, 08 Feb 2004 15:35:02 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Clarifications
Message-Id: <t1ic20la029gesf3d9b55bo266btffgnb2@4ax.com>

On Fri, 6 Feb 2004 16:45:45 -0500, "Matt Garrish"
<matthew.garrish@sympatico.ca> wrote:

>> >If you've got an easier way to get a binary from your code than by using
>> >Word I'd like to hear it. Sometimes I wonder what you're smoking...
>>
>> This must be some sort of sarcasm, but I don't get it...
>
>No, sarcasm would be: "Oh gee look, Michele wants to play golf again. That
>*never* gets tiresome!"
>
>The question of whether I'm being serious or just making an example with you
>as the target is more to the heart of the above.

Then I don't understand your example. Yes, word .doc format is binary.
Yes, I think there are a ton of easier ways to create a binary from
one's code than using Word:

  # cat >test
  some
  f*@#ing
  text
  # perl -p0777i.bak -e '$_^="x" x length $_' test
  # perl -le 'print $_, ":\t", (-T)?"text":"binary" for @ARGV' test*
  test:   binary
  test.bak:       text
  # echo -e "\n" | cat -A test -
  ^K^W^U^]r^^R8[^Q^V^_r^L^]^@^Lr$
  $

And the other way round:

  # perl -p0777i.bak -e '$_^="x" x length $_' test
  # perl -le 'print $_, ":\t", (-T)?"text":"binary" for @ARGV' test*
  test:   text
  test.bak:       binary
  # cat test
  some
  f*@#ing
  text


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: 7 Feb 2004 05:37:26 -0800
From: yashgt@yahoo.com (Yash)
Subject: Compiler directives for Perl?
Message-Id: <5a373b1d.0402070537.2ba38112@posting.google.com>

I have a Perl program that processes millions of records, and hence
has to be efficient. However, during development and testing, we do a
lot of logging to a file for debugging.
The code has a lot of statements such as:
diagnostic("Input line is");
diagnostic($inputLine);

The function is defeined as:
sub diagnostic
{
    if ( $DIAGNOSTICS == 1 )
    {
        printf LOGFILE $_[0];    	
    }
}

When this same program is shipped and executed on the client's system,
even if the $DIAGNOSTICS value is set to 0, the condition checks are
still done, just that no message is logged.
I would ideally like to instruct Perl not to compile any code related
to the diagnostic statements. Is there a way to specify compiler
directives to Perl as is done in C++ compilers?
In c++ I would compile using
cc .... -DDIAG. The code would have 
#ifdef DIAG
	diagnostic code
#endef

I know Perl is interpreted, but it still does compilation before
running. Is there some way I can pass an argument so that I make it
compile without diagnostic messages?


Thanks


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

Date: Sat, 7 Feb 2004 09:39:11 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Yash <yashgt@yahoo.com>
Subject: Re: Compiler directives for Perl?
Message-Id: <Pine.SGI.3.96.1040207092916.176239A-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On 7 Feb 2004, Yash wrote:

>I have a Perl program that processes millions of records, and hence
>has to be efficient. However, during development and testing, we do a
>lot of logging to a file for debugging.
>The code has a lot of statements such as:
>diagnostic("Input line is");
>diagnostic($inputLine);

>sub diagnostic
>{
>    if ( $DIAGNOSTICS == 1 )
>    {
>        printf LOGFILE $_[0];    	
>    }
>}
>
>In c++ I would compile using
>cc .... -DDIAG. The code would have 
>#ifdef DIAG
>	diagnostic code
>#endef

Well, you could use a constant and then define diagnostic() depending on
the constant.

  use constant DIAGNOSTICS => 1;

  ...

  *diagnostic = DIAGNOSTICS ?
    sub { print LOGFILE $_[0] } :  # why printf()?
    sub { };

Or, you could use DIAGNOSTICS on each line that calls diagnostic():

  diagnostic($x) if DIAGNOSTICS;

  ...

  sub diagnostic { print LOGFILE $_[0] }

Or, you could go CRAZY and use 'perl -P yourfile.pl', which allows you to
do things like '#ifdef' and '#endif' (it passes your code through the C
preprocessor).

  perldoc perlrun

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Sat, 07 Feb 2004 15:59:53 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Compiler directives for Perl?
Message-Id: <pan.2004.02.07.14.57.05.948242@aursand.no>

On Sat, 07 Feb 2004 05:37:26 -0800, Yash wrote:
> I have a Perl program that processes millions of records, and hence has
> to be efficient. However, during development and testing, we do a lot of
> logging to a file for debugging. The code has a lot of statements such
> as: diagnostic("Input line is");
> diagnostic($inputLine);
> 
> The function is defeined as:
> sub diagnostic
> {
>     if ( $DIAGNOSTICS == 1 )
>     {
>         printf LOGFILE $_[0];
>     }
> }
> 
> When this same program is shipped and executed on the client's system,
> even if the $DIAGNOSTICS value is set to 0, the condition checks are
> still done, just that no message is logged. I would ideally like to
> instruct Perl not to compile any code related to the diagnostic
> statements. Is there a way to specify compiler directives to Perl as is
> done in C++ compilers?

By using constants you should probably be able to accomplish this, as
constants used in an expression will be optimized away (if the constant is
false, of course);

  use constant DEBUG => 0;

  if ( DEBUG ) {
      # This will be optimized away
  }

Please take a look at 'perldoc constant' for more information.


-- 
Tore Aursand <tore@aursand.no>
"Nothing is certain but death and taxes. Of the two, taxes happen
 annually." -- Joel Fox


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

Date: Sat, 7 Feb 2004 14:17:25 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Compiler directives for Perl?
Message-Id: <c02rvs$6t3$1@news.simnet.is>

"Yash" <yashgt@yahoo.com> wrote in message
news:5a373b1d.0402070537.2ba38112@posting.google.com...
> I have a Perl program that processes millions of records, and hence
> has to be efficient. However, during development and testing, we do a
> lot of logging to a file for debugging.
> The code has a lot of statements such as:
> diagnostic("Input line is");
> diagnostic($inputLine);
> ...

if all your debug are in the above format, then just pass your sources
through a perl -ni.bak -e'print unless /^diagnostic\(/' source.pl >
production.pl

this would be simple to set up in a Makefile
  make debug
  make production


> ... Is there a way to specify compiler
> directives to Perl as is done in C++ compilers?
> In c++ I would compile using
> cc .... -DDIAG. The code would have
> #ifdef DIAG
> diagnostic code
> #endef

you might want to look at the Filter modules.
Filter::pp comes to mind.

gnari






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

Date: Sat, 7 Feb 2004 13:17:33 GMT
From: "Chuckb" <charles.h.brashear@boeing.com>
Subject: converting scalar to an array of elements
Message-Id: <Hspu98.MIH@news.boeing.com>

I should know this but, what is the quickest way to convert a scalar value
into an array?
Ex: $name="Fred";
    so that
$arrayname[0]="F";
$arrayname[1]="r";
$arrayname[2]="e";
$arrayname[3]="d";

Thanks!




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

Date: Sat, 07 Feb 2004 14:55:19 +0100
From: AlV <skweek@no.spam>
Subject: Re: converting scalar to an array of elements
Message-Id: <c02qo7$1q4$1@news-reader5.wanadoo.fr>

Chuckb wrote:
> I should know this but, what is the quickest way to convert a scalar value
> into an array?
> Ex: $name="Fred";
>     so that
> $arrayname[0]="F";
> $arrayname[1]="r";
> $arrayname[2]="e";
> $arrayname[3]="d";

perldoc -f split


use warnings;
use strict;

my $name="Fred";
my @arrayname = split //, $name;
foreach (@arrayname)
{
   print $_, "\n";
}


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

Date: Sat, 07 Feb 2004 09:02:16 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: converting scalar to an array of elements
Message-Id: <pan.2004.02.07.14.02.14.840332@remove.adelphia.net>

On Sat, 07 Feb 2004 13:17:33 +0000, Chuckb wrote:

> I should know this but, what is the quickest way to convert a scalar value
> into an array?
> Ex: $name="Fred";
>     so that
> $arrayname[0]="F";
> $arrayname[1]="r";
> $arrayname[2]="e";
> $arrayname[3]="d";

Use 'split' :-)

This is a simple one liner to produce what you wanted ...

prompt> perl -e '$name="Fred";@chars=split //, $name;print join("\n",
@chars),"\n";' 
F
r
e
d
prompt>

Salt to taste :-)

HTH


-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Monday, n.:  In Christian countries, the day after the baseball
game.   -- Ambrose Bierce, "The Devil's Dictionary" 



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

Date: Sat, 07 Feb 2004 09:33:39 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Copy Constructor Craziness
Message-Id: <4024a8f9.9404503@news.erols.com>

use63net@yahoo.com (Unknown Poster) wrote:

: # the code for the Rational class is too long to include in a post

You could still trim it down to only the parts necessary to demonstrate
what you describe.  Like, say,

    package Rational;
    use overload
        '""' => sub { "$_[0][0]/$_[0][1]" },
        '+'  =>
            sub {
                my $obj = shift;
                my( $num, $dem ) = @$obj;
                $num += $_[0] * $dem;
                ref($obj)->new( $num, $dem );
            },
    ;
    sub new { my $c = shift; bless [@_], $c }

: # an object represents a fractional number, so its two data members 
: # are scalars - the fraction's numerator and denominator
: 
: use Rational;
: use warnings;
: use strict;
: 
: my $f = Rational->new(1, 7) ;
: my $g = $f;
: print "\$g = $g, ";
: ++$g;
: print "after ++, \$g = $g, \$f = $f\n";
: 
: ------------------------------------------
: 
: output is:
: $g = 1/7, after ++, $g = 8/7, $f = 1/7
: 
: I'm not arguing that this result is "wrong", just that it appears
: to be inconsistent with what Programming Perl states about
: copy constructors.  Again, I do not overload "=" for the
: Rational class.  Copy constructors are supposedly autogenerated
: only when "the object is a plain scalar".  I'm not sure what that 
: means, but don't see how a class with two scalars qualifies for 
: autogeneration.

Back up a couple pages to see:

    The ++$a operation can be autogenerated using $a+=1 or $a=$a+1, ....
                                                           ^^^^^^^
That second part is a tricky read.  Is the '=' in there supposed to be a
copy constructor, or does it represent an ordinary, non-overloaded
assignment?

There's a conspicuous change in the 5.8 docs:

    The ++$a operation can be expressed in terms of $a+=1 or $a+1, ....

As I read it, that means that the class will use an available copy
constructor to do ++$a, but it can finesse its way around a copy
constructor's absence without having to autogenerate one.



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

Date: Sat, 07 Feb 2004 14:14:58 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How to execute a command line in Perlscript
Message-Id: <Cp6Vb.23497$EH5.5377@nwrddc01.gnilink.net>

[TOFU snipped]

Eric SALGON wrote:
> Unfortunatly, I have implemented "shell" and "puts" functions in my
> ASP code but `$_` return no result in @output array with a simple
> 'dir' command.
>
> I'm afraid it's a problem of right on my IIS server.

But PerlScript is executed client side.
The web server (be it IIS or Apache or whatever) has nothing to do with it.

jue





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

Date: Sat, 7 Feb 2004 10:27:25 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: how to find the last "new line" in string
Message-Id: <c02egr$5d2$1@news.simnet.is>

"Walter Roberson" <roberson@ibd.nrc-cnrc.gc.ca> wrote in message
news:c02026$j7v$1@canopus.cc.umanitoba.ca...

[replacing last newline in string to space]

>
> This should work, though (I think):
>
>   $string =~ s/\n([^\n]*)\z/ \1/;

why the [^\n] ?
whats wrong with:

$string =~ s/\n(.*)\z/ \1/;

gnari






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

Date: Sat, 07 Feb 2004 09:18:42 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: How to use select (select(2)) in Perl?
Message-Id: <jrs9205i2iavnggodtslah4qnlfss9c5mr@library.airnews.net>

gazelle@yin.interaccess.com (Kenny McCormack) wrote:

} In article <vhhc101fugrdumi4mv312mt7usbt0v7sba@library.airnews.net>,
} Bernie Cosell  <bernie@fantasyfarm.com> wrote:

} >I notice that you skipped over the comment about your patronizing Lucy
} >science lecture: ...
} 
} But, anyway, the only reason I am taking time to post this is to ask what
} you mean by "Lucy science".  It sounds so intriguing.  Does it have
} anything to do with 7th Heaven?

Nope -- it is from the "Peanuts" comic strip.  Someone would ask Lucy a
question, and she'd relate some authoritative-sounding, but wrong,
explanation for whatever-it-is.

  /B\

-- 
Bernie Cosell                     Fantasy Farm Fibers
bernie@fantasyfarm.com            Pearisburg, VA
    -->  Too many people, too few sheep  <--          


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

Date: 7 Feb 2004 12:52:52 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: Need help passing arrays by reference pls.
Message-Id: <Xns9488502BC927Basu1cornelledu@132.236.56.8>

g_klinedinst@hotmail.com (G Klinedinst) wrote in 
news:168f035a.0402061349.79d8b12b@posting.google.com:

> Unfortunately the arrays hold an index to another array, which
> basically tells which input fields were filled out, so some of the
> arrays are going to be empty(due to the user not entering any data at
> that position).

In that case, maybe parallel arrays are not the right data structure for 
the problem. How about using a hash?
 
>> # You should avoid the unnecessary concatenations you had in 
>> # your code.
>> 
>> print "\n\n" ;
>> 
>> test(\@arr1, \@arr2);
>> 
>> sub test {
>>     my ($subArr1, $subArr2) = @_;
>> 
>>     print $subArr1->[0], ':', scalar @{$subArr1}, "\n" ;
>>     print $subArr2->[0], ':', scalar @{$subArr2}, "\n" ;
>> }
> 
> Why is that? Are the commas implemented faster, or just for
> readability? 

Well, at least in my mind, the above is an improvement in readability and 
maintainability.

> Just curious. It's a habit I picked up from Java so now
> even my Perl code looks like that.

I know and hate the constant String additions in Java :) 

> I hope things are starting to warm up there in Ithaca for you.

Just a little.

Sinan.

-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


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

Date: 7 Feb 2004 01:39:19 -0800
From: google-maps@synthcode.com (Alex Shinn)
Subject: Re: perl identifier limits
Message-Id: <dc6cff67.0402070139.3381a3cd@posting.google.com>

Rocco Caputo <troc@pobox.com> wrote in message news:<slrnc27h3p.eu.troc@eyrie.homenet>...
>
> But it's a very rare problem to run into.  As such, it's not a pressing
> issue for [wild guess] 99% of the people who use Perl.  As you feel
> strongly about it, you may want to address the problem yourself and
> submit a patch.

I will probably end up doing so.  The md5sum is an interesting idea,
but I don't like even insignificant probabilities of clashes, and at times
I need to debug the generated code so readable names are a plus.

> Or you can do the damsel in distress routine ("OH! HELP! SOMEONE PLEASE
> HELP ME!") until some shining knight patches it for you.  For your sake,
> I hope you're cute.  :)

How about I just say I'm cute and hide behind my gender-neutral
first name and race-neutral last name? :)  Any brave knights out there?

> While you're holding your breath, consider rolling your own symbol
> table:  A hash of long identifiers mapped to computed short ones.  As
> your program writes Perl source, it can translate the too-long symbols
> into the short ones.

The more I think about this the uglier it gets.  When you generate code like

  $var1 = expr1;
  $var2 = expr2;

  sub func1 { <some-expr-of-var1> }
  sub func2 { func1(<some-expr-of-var2>) }

replacing all of those with nested hash-tables gets really convoluted:

  $hash = $globalhash{$modulename};

  $hash{var1} = expr1;
  $hash{var2} = expr2;

  $hash{func1} = sub { <some-expr-of-$hash{var1}> }
  $hash{func2} = sub { &{$hash{func1}}(<some-expr-of-$hash{var2}>) }

Maybe the above example doesn't look *too* horrible, but the more
variable references and subroutines you have the more cryptic it is.
And I do have to debug the generated code sometimes.  That plus
all the places where I have to rewrite the code generators makes
patching Perl the easiest solution.

Thanks for your help,
Alex


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

Date: 7 Feb 2004 01:48:34 -0800
From: google-maps@synthcode.com (Alex Shinn)
Subject: Re: perl identifier limits
Message-Id: <dc6cff67.0402070148.3b8b6526@posting.google.com>

Uri Guttman <uri@stemsystems.com> wrote in message news:<x73c9ot6c9.fsf@mail.sysarch.com>...
> >>>>> "AS" == Alex Shinn <foof@synthcode.com> writes:
> 
>   AS> You obviously don't write Perl with a Lisp mindset.  If you
> 
> hell, i wouldn't do anything with a lisp mindset. i would rather toggle
> in code by binary switches (done it) than have a lisp mindset.

I wasn't suggesting you do, nor was I suggesting there is anything
superior about Lisp.  It just encourages another style of programming
called meta-programming.  And the nice thing about Perl is TMTOWDI -
you can meta-program and write code generators if you want.

> the symbol table is not meant to be a general purpose hash structure. so
> using it as such (via symrefs) is very dumb.

I'm not using it as a hash table, I'm actually writing Perl *code* and so
the natural solution is to use identifiers.  Using hash-tables is a clumsy
workaround.  Regardless, I don't understand your animosity and don't
appreciate being called dumb.  I can only assume you feel threatened by
something you don't understand and feel the need to put it down.

-- 
Alex


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

Date: Sat, 07 Feb 2004 09:58:38 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perl identifier limits
Message-Id: <x7oesbp5wx.fsf@mail.sysarch.com>

>>>>> "AS" == Alex Shinn <google-maps@synthcode.com> writes:

  AS> The more I think about this the uglier it gets.  When you generate
  AS> code like

  AS>   $var1 = expr1;
  AS>   $var2 = expr2;

  AS>   sub func1 { <some-expr-of-var1> }
  AS>   sub func2 { func1(<some-expr-of-var2>) }

  AS> replacing all of those with nested hash-tables gets really convoluted:

  AS>   $hash = $globalhash{$modulename};

  AS>   $hash{var1} = expr1;
  AS>   $hash{var2} = expr2;

  AS>   $hash{func1} = sub { <some-expr-of-$hash{var1}> }
  AS>   $hash{func2} = sub { &{$hash{func1}}(<some-expr-of-$hash{var2}>) }

this is cleaner code to generate IMO

  $hash{func1} = sub { <some-expr-of-$hash{var1}> }
  $hash{func2} = sub { $hash{func1}->(<some-expr-of-$hash{var2}>) }

  AS> Maybe the above example doesn't look *too* horrible, but the more
  AS> variable references and subroutines you have the more cryptic it
  AS> is.  And I do have to debug the generated code sometimes.  That
  AS> plus all the places where I have to rewrite the code generators
  AS> makes patching Perl the easiest solution.

and you could do a global replace on all sub defs and sub calls to use
the hashes. in fact you could do this as a pass AFTER you generate all
the code. it would almost be as easy as:

	s/sub\s*(\w+)/\$hash{$1} = sub/g ;
	s/(\w+)\(/\$hash{$1}->(/g ;

the second one will probably need a tighter way to find your sub names
and not find perl funcs. but i leave that as an exercise to you. (hint:
use a /e and call a sub. in there check for the existance of the
generated sub name and only replace if found). (another hint: if all
your sub names are very long then just look for a minimum size to match)

see, simple. i will send you a bill. :)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sat, 07 Feb 2004 10:04:22 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perl identifier limits
Message-Id: <x7k72zp5ne.fsf@mail.sysarch.com>

>>>>> "AS" == Alex Shinn <google-maps@synthcode.com> writes:

  AS> Uri Guttman <uri@stemsystems.com> wrote in message news:<x73c9ot6c9.fsf@mail.sysarch.com>...

  AS> You obviously don't write Perl with a Lisp mindset.  If you
  >> 
  >> hell, i wouldn't do anything with a lisp mindset. i would rather toggle
  >> in code by binary switches (done it) than have a lisp mindset.

  AS> I wasn't suggesting you do, nor was I suggesting there is anything
  AS> superior about Lisp.  It just encourages another style of programming
  AS> called meta-programming.  And the nice thing about Perl is TMTOWDI -
  AS> you can meta-program and write code generators if you want.

well, you brought up lisp mindset. them's fighting words! :)

and i have generated code in several projects so i understand the
issues.

  >> the symbol table is not meant to be a general purpose hash structure. so
  >> using it as such (via symrefs) is very dumb.

  AS> I'm not using it as a hash table, I'm actually writing Perl *code*
  AS> and so the natural solution is to use identifiers.  Using
  AS> hash-tables is a clumsy workaround.  Regardless, I don't
  AS> understand your animosity and don't appreciate being called dumb.
  AS> I can only assume you feel threatened by something you don't
  AS> understand and feel the need to put it down.

but you are using it as a hash table in that you are creating names in
it. true they are simple (if long identifiers) but they are just
entries. the symtable has this max id restriction so you have to convert
to a regular hash table. my point was that assuming the symtable is a
normal hash with infinite length keys was wrong. and i have railed
against symrefs (which you aren't using) plenty of times so it carried
over here.

but see my other post just now for a solution that should work and be
very easy to do.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sat, 07 Feb 2004 12:40:23 GMT
From: Rocco Caputo <troc@pobox.com>
Subject: Re: perl identifier limits
Message-Id: <slrnc29n95.eu.troc@eyrie.homenet>

On 7 Feb 2004 01:39:19 -0800, Alex Shinn wrote:
> Rocco Caputo <troc@pobox.com> wrote in message news:<slrnc27h3p.eu.troc@eyrie.homenet>...
>> While you're holding your breath, consider rolling your own symbol
>> table:  A hash of long identifiers mapped to computed short ones.  As
>> your program writes Perl source, it can translate the too-long symbols
>> into the short ones.
>
> The more I think about this the uglier it gets.  When you generate code like
>
>   $var1 = expr1;
>   $var2 = expr2;
>
>   sub func1 { <some-expr-of-var1> }
>   sub func2 { func1(<some-expr-of-var2>) }
>
> replacing all of those with nested hash-tables gets really convoluted:
>
>   $hash = $globalhash{$modulename};
>
>   $hash{var1} = expr1;
>   $hash{var2} = expr2;
>
>   $hash{func1} = sub { <some-expr-of-$hash{var1}> }
>   $hash{func2} = sub { &{$hash{func1}}(<some-expr-of-$hash{var2}>) }

This is not what I intended.  The %symbol_table hash would be kept in
your code generator.  You would translate your long names to shorter
ones at output time.

  #!/usr/bin/perl
  # This is the CODE GENERATOR, not the generated code!

  my %symbol_table;
  my $symbol = "symAAAAAA";

  ... la la la ...;

  $symbol_table{$long_version} = $symbol++;

  ... la la la ...;

  print "$symbol_table{$long_version} = $expression\n";

  ... la la la ...;

  print "sub $symbol_table{$long_version} { $body }\n";

  ... la la la ...;

So the generated source is full of symAAAAAA, symAAAAAB, or something
you like better.  It's not as meaningful as your intepretation, but it's
less ugly and certainly faster at runtime.

> Maybe the above example doesn't look *too* horrible, but the more
> variable references and subroutines you have the more cryptic it is.
> And I do have to debug the generated code sometimes.  That plus
> all the places where I have to rewrite the code generators makes
> patching Perl the easiest solution.

Debugging generated code sucks.  At least generate well commented code
if you can't avoid it.

It says something bad about your program if patching Perl is easier than
maintaining it.

-- 
Rocco Caputo - rcaputo@pobox.com - http://poe.perl.org/


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

Date: Sat, 07 Feb 2004 14:52:26 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: trying to create a network script:
Message-Id: <4024FAC7.8090400@rochester.rr.com>

Nex6 wrote:

 ...
> open fh, '+<\\\\$file\\c$\\reset.reg' or die "can't open $file: $!";

-----------^------^^^^^---------------^
$file won't get interpolated in a '-quoted string.  So you will attempt 
to open the literal \\$file\c$\reset.reg, which probably doesn't exist. 
  I assume you have admin authority on the computers you are accessing; 
otherwise you will get a permission denied error when going the c$ route.

Better is probably something like:

open FH,"+<//$file/c\$/reset.reg" or die "Can't open $file: $!";

(FH uppercase by convention, so it will never conflict with possible 
future reserved keywords in future versions of Perl).  Also, Perl 
permits you to use / instead of \ as path separators on Windoze, which 
makes it a bit easier since you don't have to quote the /'s.  And note 
that you need to quote the $ in this case.

Also, your code was conspicuously missing the following:

use strict;
use warnings;

Let Perl help you -- use those two.


 ...


> -Nex6

HTH.
-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

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 V10 Issue 6092
***************************************


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