Re: subs, eval, and BEGIN

2007-03-19 Thread Chris Wagner
How come u were trying to put it in a begin block?

At 06:28 PM 3/18/2007 -0700, Glenn Linderman wrote:
So I'm trying to make a sub to tr iso-8859-1 to unaccented ASCII 
equivalents.  Maybe one already exists, somewhere, but now that I've 
gotten this far, I'm confused:

#!perl
BEGIN {




--
REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =--
...ne cede malis

0100

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: subs, eval, and BEGIN

2007-03-19 Thread Chris Wagner
It actually does work in the BEGIN block too.  I feel ur pain.  Eval's can
be a total [EMAIL PROTECTED]

At 01:13 AM 3/19/2007 -0700, Glenn Linderman wrote:
Why not?  tr said it compiled the strings at compile time, compile time 
sounded like a begin block, but of course eval is also compile time.  It 
was evolutionary, without quite enough thought at all points in time.  
That wasn't the only bug




--
REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =--
...ne cede malis

0100

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: subs, eval, and BEGIN

2007-03-18 Thread Bill Luebkert
Glenn Linderman wrote:
 So I'm trying to make a sub to tr iso-8859-1 to unaccented ASCII 
 equivalents.  Maybe one already exists, somewhere, but now that I've 
 gotten this far, I'm confused:
 
 #!perl

Where's your use strict and use warnings ?

 BEGIN {
   my ( $tfrom, $tto );
   $tfrom = 'AàÀáÁâÂãÃäÄåÅæÆBCçÇDðÐEèÈéÉêÊëËFGHIìÌíÍîÎïÏJKLM';
   $tto   = 'aaabcccdddefghijklm';
   $tfrom .= 'NñÑOòÒóÓôÔõÕöÖøØPQRSßTþÞUùÙúÚûÛüÜVWXYýÝÿZ';
   $tto   .= 'nnnopqrsstttuvwxz';
   eval END_OF_SUB
 sub tr_iso_8859_1__ASCII
 { my ( \$name ) = @_;
   \$name =~ tr/$tfrom/$tto/;
   print in: \$_[ 0 ] out: \$name\n;
   return ( \$name );
 }
 END_OF_SUB

You need an ';' here.

 }
 
  
 tr_iso_8859_1__ASCII('abcdefABCDEFAàÀáÁâÂãÃäÄåÅæÆBCçÇDðÐEèÈéÉêÊëËFGHIìÌíÍîÎïÏJKLM');
 __END__
 
 produces
 
 Undefined subroutine main::tr_iso_8859_1__ASCII called at 
 d:\my\perl\src\test-tr.pl line 17.
 
 which is the last line of the code.  So what about eval, or what about 
 BEGIN, or what about my syntax, is causing the sub not to be available 
 later... and how do I work around it?
 
 Naturally the BEGIN/eval idea was formulated so that I could use 
 variables to help define the tr parameters, mostly just to avoid long 
 lines, and I already have the sub working using long lines with 
 hard-coded strings.  But why doesn't this one work?

Here's my attempt:

use strict;
use warnings;

my $tfrom = 'AàÀáÁâÂãÃäÄåÅæÆBCçÇDðÐEèÈéÉêÊëËFGHIìÌíÍîÎïÏJKLMNñÑ' .
   'OòÒóÓôÔõÕöÖøØPQRSßTþÞUùÙúÚûÛüÜVWXYýÝÿZ';
my $tto   = 'aaabcccdddefghijklmnnn' .
   'opqrsstttuvwxz';

eval END_OF_SUB
sub tr_iso_8859_1__ASCII {
my \$name = \$_[0];
\$name =~ tr/$tfrom/$tto/;
print in : \$_[0]\nout: \$name\n;
return \$name;
}
END_OF_SUB
;

tr_iso_8859_1__ASCII(
   'abcdefABCDEFAàÀáÁâÂãÃäÄåÅæÆBCçÇDðÐEèÈéÉêÊëËFGHIìÌíÍîÎïÏJKLM');

__END__
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: subs, eval, and BEGIN

2007-03-18 Thread Bill Luebkert
Glenn Linderman wrote:
 
 Well, nice you got rid of the BEGIN block... and it compiles and 
 produces the right output twice oops.  I sure can't see where it 
 does that!  One print statement, in a sub that is called once!

Show your new code.

 The ; can alternately go after END_OF_SUB on the line above... but that 
 doesn't fix the double print.

What double print ?  I got:

in : abcdefABCDEFAàÀáÁâÂãÃäÄåÅæÆBCçÇDðÐEèÈéÉêÊëËFGHIìÌíÍîÎïÏJKLM
out: abcdefabcdefaaabcccdddefghijklm
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs