[26492] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8653 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 10 14:05:34 2005

Date: Thu, 10 Nov 2005 11:05:04 -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           Thu, 10 Nov 2005     Volume: 10 Number: 8653

Today's topics:
    Re: how to interpret string as code? (Anno Siegel)
        leaving mainloop <null@void.0>
    Re: leaving mainloop <null@void.0>
    Re: Need workaround for regex bug in 5.8.6 xhoster@gmail.com
    Re: Need workaround for regex bug in 5.8.6 <jsm@jmarshall.com>
    Re: Need workaround for regex bug in 5.8.6 <jsm@jmarshall.com>
    Re: Shell script <null@void.0>
    Re: Shell script <zawrotny@sb.fsu.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 10 Nov 2005 14:05:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to interpret string as code?
Message-Id: <dkvk47$ff6$1@mamenchi.zrz.TU-Berlin.DE>

Jason Quek  <qjason@starhub.net.sg> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> 
> >Jason Quek  <qjason@starhub.net.sg> wrote in comp.lang.perl.misc:
> >> Hi there
> >> 
> >> As the fields in my data table are not fixed, I need to do this:
> >> 
> >> # ------------------------------------------------------------
> >> $name = 'John Doe';
> >> $fields = '$firstname, $lastname';
> >> ($fields) = split(/\s/, $name);
> >> print "$firstname";		# returns John
> >> print "$lastname";		# returns Doe
> >> # ------------------------------------------------------------
> >> 
> >> where line 3 is interpreted as:
> >> # ------------------------------------------------------------
> >> ($firstname, $lastname) = split(/\s/, $name);
> >> # ------------------------------------------------------------
> >> 
> >> How can this be accomplished? Any help would be appreciated. Thank
> >> you.
> >
> >Are you saying you want to determine the variable names ($firstname and
> >$lastname) at runtime?  So that they could be $vorname and $nachname in
> >another run of the same program?  You don't really want to do that.
> >How would you *use* those elusive variables in the rest of the program
> >if you don't know their names?
> >
> >Instead, use a hash (untested):
> >
> >    my $name = 'John Doe';
> >    my @fields = qw( firstname lastname);
> >    my %person;
> >    @person{ @fields} = split ' ', $name;
> >    print "$person{ firstname}\n";
> >    print "$person{ lastname}\n";
> >
> >If in another run you set @fields = qw( vorname nachname) you can access
> >the parts under $person{ vorname} etc.  But now the variable bits are
> >program data, not parts of the program proper.  That is a much better
> >design.
> >
> >Annp
> 
> Yes you're right, the variable names are only avialable at runtime. I
> understand your method and have several other work arounds, but I was
> wondering if my 'method' were possible. Possibly using 'eval',
> although I wasn't able to get it to work either.

Not with lexicals.  If you try declare them in eval() and use them
outside, that won't work because eval constitutes a lexical block.

For a "solution" with package variables, see the faq "How can I use
a variable as a variable name?" The faq also explains why this is a
bad idea.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Thu, 10 Nov 2005 14:19:04 GMT
From: Shea Martin <null@void.0>
Subject: leaving mainloop
Message-Id: <sFIcf.121925$Ph4.3740544@ursa-nb00s0.nbnet.nb.ca>

I am trying to add an alert pop-up message box to some perl scripts.

sub MsgBox
{
	my $msg = shift;
	if( length($msg) <= 0 )
	{
		$msg = "empty message?";
	}
	my $mw = Tk::MainWindow->new();
	$mw->Label(-text => $msg)->pack;
	$mw->Button(-text => 'ok', -command => sub{exit})->pack;
	&Tk::MainLoop();
}


The problem is, I want to return to my perl script after the the 'ok' 
button has been pressed.  Obviously sub{exit} is the problem, but I 
don't know what else to put?  It won't let me put return or last in 
there.  I am sure that there is a simple way to do this, but I can't see 
the forest for the trees.

~S


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

Date: Thu, 10 Nov 2005 14:40:04 GMT
From: Shea Martin <null@void.0>
Subject: Re: leaving mainloop
Message-Id: <8ZIcf.121932$Ph4.3740790@ursa-nb00s0.nbnet.nb.ca>

Shea Martin wrote:
> I am trying to add an alert pop-up message box to some perl scripts.
> 
> sub MsgBox
> {
>     my $msg = shift;
>     if( length($msg) <= 0 )
>     {
>         $msg = "empty message?";
>     }
>     my $mw = Tk::MainWindow->new();
>     $mw->Label(-text => $msg)->pack;
>     $mw->Button(-text => 'ok', -command => sub{exit})->pack;
>     &Tk::MainLoop();
> }
> 
> 
> The problem is, I want to return to my perl script after the the 'ok' 
> button has been pressed.  Obviously sub{exit} is the problem, but I 
> don't know what else to put?  It won't let me put return or last in 
> there.  I am sure that there is a simple way to do this, but I can't see 
> the forest for the trees.
> 
> ~S

FOund my answer:

$mw->Button(-text => 'ok', -command => [$mw => 'destroy'])->pack;

~S


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

Date: 10 Nov 2005 15:23:03 GMT
From: xhoster@gmail.com
Subject: Re: Need workaround for regex bug in 5.8.6
Message-Id: <20051110102303.893$cK@newsreader.com>

james@jmarshall.com wrote:
> I found a weird bug in Perl 5.8.6:  If a variable in a CGI script (only)
> is long enough, the script dies when it matches the variable against the
> pattern /(.|ab)*/

Why match against that in the first place?  Is there any case in which that
pattern match will fail?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 10 Nov 2005 08:08:56 -0800
From: James Marshall <jsm@jmarshall.com>
Subject: Re: Need workaround for regex bug in 5.8.6
Message-Id: <20051110080625.G22930@jmarshall.com>

On Thu, 10 Nov 2005 xhoster@gmail.com wrote:

> james@jmarshall.com wrote:
>> I found a weird bug in Perl 5.8.6:  If a variable in a CGI script (only)
>> is long enough, the script dies when it matches the variable against the
>> pattern /(.|ab)*/
>
> Why match against that in the first place?  Is there any case in which that
> pattern match will fail?

The actual pattern I'm using is much longer and more complex.  The pattern 
above was the result of reducing it to a simple test case.


James


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

Date: Thu, 10 Nov 2005 08:21:23 -0800
From: James Marshall <jsm@jmarshall.com>
Subject: Re: Need workaround for regex bug in 5.8.6
Message-Id: <20051110080949.Q22930@jmarshall.com>

OK, thanks very much for the explanation.  Unfortunately, none of the 
alternatives are possible in this situation, except maybe the third-- I'll 
have to think about it some more.  Thanks for fixing part of it five years 
ago; if I knew more about Perl internals I'd finish it myself.

Thanks also to Rob for his experimentation and feedback under Windows.

Cheers,
James
 ............................................................................
  James Marshall      james@jmarshall.com       Berkeley, CA      @}-'-,--
                        "Teach people what you know."
 ............................................................................


On Thu, 10 Nov 2005, Ilya Zakharevich wrote:

IZ> [A complimentary Cc of this posting was sent to
IZ> James Marshall 
IZ> <james@jmarshall.com>], who wrote in article <20051109142502.Y33644@jmarshall.com>:
IZ> > I found a weird bug in Perl 5.8.6:  If a variable in a CGI script (only) 
IZ> > is long enough, the script dies when it matches the variable against the 
IZ> > pattern /(.|ab)*/ .
IZ> 
IZ> This is a very old limitation of the Perl REx engine: it uses C stack
IZ> for backtracking-data storage; since C stack is a very scarse
IZ> resource, and running out of stack is a catastrophic process (as
IZ> opposed to running out of heap), this makes things very restrictive.
IZ> 
IZ> Actually, about 5 years ago I added the necessary infrastructure to
IZ> the REx engine to keep these data on Perl stacks (as opposed to C
IZ> stacks, Perl stacks can grow, and running out of stack can be caught -
IZ> at least in some situations); moreover, I converted one part of the
IZ> REx engine (out of 4 or 5 different parts) to use this infrastructure.
IZ> 
IZ> At this moment I had no time to convert the remaining constructs.  I
IZ> hoped that "everybody" will be able to continue and "copy" the
IZ> provided modification to the other constructs.  Apparently, nobody
IZ> volunteered.
IZ> 
IZ> =======================================================
IZ> 
IZ> Meanwhile, you have several alternatives:
IZ> 
IZ>   a) Make sure that your Perl is compiled with "stack checking code",
IZ>      so that running out of stack is not catastrophic (will not help
IZ>      with data processing :-(, but will help with bookkeeping ;-);
IZ> 
IZ>   b) Increase amount of stack so that your data can be processed (not
IZ>      always feasible);
IZ> 
IZ>   c) Do not use ()* on complicated constructs (likewise).
IZ> 
IZ> Sorry to be a bearer of a sad news,
IZ> Ilya
IZ> 


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

Date: Thu, 10 Nov 2005 14:36:26 GMT
From: Shea Martin <null@void.0>
Subject: Re: Shell script
Message-Id: <KVIcf.121930$Ph4.3740692@ursa-nb00s0.nbnet.nb.ca>

Shabam wrote:
> Up to now I've been doing this manually via the command shell.  However I'm
> sure I can automate this using a script with better results.  Can someone
> show me how I can do this?
> 
> cp -pr /site/template/user /site/j/jason
> cp -p /site/data/j/jason.dat /site/data/j/jason.dat; pico -w
> /site/data/j/jason.dat
> 
> In pico I'm basically changing the first 3 lines, replacing the first line
> with user "jason"s email, second with his name, and third with his zip code.
> 
> I'm trying to come up with a script that will take the username, email,
> name, and zip code as arguments.  Once done it will perform the above steps
> and be done.  Can someone perhaps help me with this?  I've dabbled in some
> Perl, but mostly by editting what's already been made.  Thanks.
> 
> 

You could learn a minimal amount of perl/ruby/bash/python, then write a 
short script to do all this for you.  Actually, you could do it will 
just the sed command if you are on unix. Thats what I would do.

~S


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

Date: 10 Nov 2005 16:21:22 GMT
From: Michael Zawrotny <zawrotny@sb.fsu.edu>
Subject: Re: Shell script
Message-Id: <slrndn6ss2.jun.zawrotny@localhost.localdomain>

[ follow-ups trimmed to clpm ]

On Thu, 10 Nov 2005 14:36:26 GMT, Shea Martin <null@void.0> wrote:
>  Shabam wrote:
> > 
> > In pico I'm basically changing the first 3 lines, replacing the first line
> > with user "jason"s email, second with his name, and third with his zip code.
> > 
> > I'm trying to come up with a script that will take the username, email,
> > name, and zip code as arguments.  Once done it will perform the above steps
> > and be done.  Can someone perhaps help me with this?  I've dabbled in some
> > Perl, but mostly by editting what's already been made.  Thanks.
> 
>  You could learn a minimal amount of perl/ruby/bash/python, then write a 
>  short script to do all this for you.  Actually, you could do it will 
>  just the sed command if you are on unix. Thats what I would do.

I would use the Template Toolkit for this.  You can setup the template
file and use the tpage program to generate the final version.  There
are online tutorials (e.g. 
www.devshed.com/c/a/Perl/Getting-Started-with-the-Perl-Template-Toolkit/),
and the sample chapter of "Perl Template Toolkit" that O'Reilly has
graciously posted on the web
(http://www.oreilly.com/catalog/perltt/chapter/ch02.pdf) is probably
enough to get you through the job at hand.

One benefit to you is that you shouldn't need to write any code to use
TT.


Mike

-- 
Michael Zawrotny
Institute of Molecular Biophysics
Florida State University                | email:  zawrotny@sb.fsu.edu
Tallahassee, FL 32306-4380              | phone:  (850) 644-0069


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

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


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