[29009] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 253 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 22 14:10:12 2007

Date: Thu, 22 Mar 2007 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, 22 Mar 2007     Volume: 11 Number: 253

Today's topics:
        is mod_perl better for CGI application? <john1949@yahoo.com>
    Re: is mod_perl better for CGI application? xhoster@gmail.com
    Re: is mod_perl better for CGI application? (Jamie)
    Re: non-greedy match breaks '?' match? <paduille.4060.mumia.w+nospam@earthlink.net>
    Re: non-greedy match breaks '?' match? <abigail@abigail.be>
    Re: non-greedy match breaks '?' match? <mritty@gmail.com>
    Re: non-greedy match breaks '?' match? xhoster@gmail.com
    Re: non-greedy match breaks '?' match? <glennj@ncf.ca>
    Re: On Java's Interface (the meaning of interface in co <jimburton1@gmail.com>
    Re: On Java's Interface (the meaning of interface in co <slarti@beeblebrox.net>
    Re: On Java's Interface (the meaning of interface in co <nmw@ion.le.ac.uk>
        Perl Equivelent of C++ program <john.wilkinson@philips.com>
    Re: Perl Equivelent of C++ program <scobloke2@infotop.co.uk>
    Re: Perl Equivelent of C++ program anno4000@radom.zrz.tu-berlin.de
    Re: problem using timelocal, localtime to discern d-o-w <mritty@gmail.com>
    Re: problem using timelocal, localtime to discern d-o-w <glennj@ncf.ca>
    Re: problem using timelocal, localtime to discern d-o-w <jfcampbell@aol.com>
        Problem with indirect variables <mdudley@king-cart.com>
        Simple Expect problem <bpatton@ti.com>
    Re: Simple Expect problem <paduille.4060.mumia.w+nospam@earthlink.net>
    Re: variable evaluation and printing <chadw3@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 22 Mar 2007 15:41:47 -0000
From: "John" <john1949@yahoo.com>
Subject: is mod_perl better for CGI application?
Message-Id: <puednXe5_5AnPp_bnZ2dnUVZ8q2dnZ2d@eclipse.net.uk>

This is more of a hosting question, I know.

We use Perl primarily to write our website.  The site uses CGI.pm
extensively.  So, every page begins my $x=param('x') etc and depending
on whether it is 'undef' will jump to some routine or other.  Lots of forms.

Now, would we better off hosting on 'mod_perl' server, and what are the
key advantages?

Regards
John




--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 89020 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!




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

Date: 22 Mar 2007 16:13:46 GMT
From: xhoster@gmail.com
Subject: Re: is mod_perl better for CGI application?
Message-Id: <20070322121348.234$qc@newsreader.com>

"John" <john1949@yahoo.com> wrote:
> This is more of a hosting question, I know.
>
> We use Perl primarily to write our website.  The site uses CGI.pm
> extensively.  So, every page begins my $x=param('x') etc and depending
> on whether it is 'undef' will jump to some routine or other.  Lots of
> forms.
>
> Now, would we better off hosting on 'mod_perl' server, and what are the
> key advantages?

The key advantage is the over-head speed and ability to cache database
handles and such.  The disadvantage is that it is more finicky and easier
to screw up.

Are you having performance problems with your server keeping up with
requests, are these problems due to the start-up overhead of the CGI
scripts and the overhead of creating the database handles?

Xho

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


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

Date: Thu, 22 Mar 2007 17:14:57 GMT
From: nospam@geniegate.com (Jamie)
Subject: Re: is mod_perl better for CGI application?
Message-Id: <Lc1174562480123070x8d07960@pong.podro.com>

In <puednXe5_5AnPp_bnZ2dnUVZ8q2dnZ2d@eclipse.net.uk>,
"John" <john1949@yahoo.com> mentions:
>This is more of a hosting question, I know.
>
>We use Perl primarily to write our website.  The site uses CGI.pm
>extensively.  So, every page begins my $x=param('x') etc and depending
>on whether it is 'undef' will jump to some routine or other.  Lots of forms.
>
>Now, would we better off hosting on 'mod_perl' server, and what are the
>key advantages?

mod_perl is really good if you need access to the internals of apache, you
can do amazing stuff with filters and configurations and so-forth.

It does however, add bloat to apache. It's also pretty easy to screw
up, a bit harder to develop for (for example, unless you tweak the settings,
you'll have to restart apache each time you change a file, since they are
loaded in memory.)

mod_perl is fast.

I stumbled across this (again) awhile ago:

http://www.fastcgi.com/

Basically, it'll turn your script(s) into daemons. Apache forwards
the connection to a daemon, the daemon handles the request. 

Works with perl, it's fast and it'll let you do stuff like cache database
handles. Also enables you to do a fair amount of your work in plain CGI
and then "move over" to FastCGI as the time comes. I was blown away by
how fast it was (and how it simplified development model) You still
have the "restart problem" but you can do 99% of your work in CGI mode
and then flip over to FastCGI when the time comes. 

At first, one would think that moving the process out of apache would slow
things down. Doesn't appear to be the case and it'll let you trim apache down
some-what, for serving static content. 

I'd recommend checking into it.

For stuff that doesn't get used very often (control panel admin page, etc..)
plain CGI makes a lot of sense. Remember with mod_perl or FastCGI or servlets
or any of that stuff, the web application stays in memory, even when no one is
using it. By moving seldom used programs over to boring, flat CGI mode you can
free up more resources for the web applications that /DO/ get used a lot. (and
put those applications on FastCGI / mod_perl) 

You'll get better overall response times this way.


Jamie
-- 
http://www.geniegate.com                    Custom web programming
Perl * Java * UNIX                        User Management Solutions


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

Date: Thu, 22 Mar 2007 13:39:51 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <HGvMh.15199$tD2.6612@newsread1.news.pas.earthlink.net>

On 03/22/2007 04:45 AM, Alexis Huxley wrote:
> The following code:
> 
> 	$x = "abc"; 
> 	$x =~ /^(a)(b)(c?)/;
> 	print "\$1=$1, \$2=$2, \$3=$3\n";
> 
> outputs this:
> 
> 	$1=a, $2=b, $3=c
> 
> which is just what I expect.
> 
> But with only the second line changed to:
> 
> 	$x =~ /^(a)(.*?)(c?)/;
> 
> Now the output changes to:
> 
> 	$1=a, $2=, $3=
> 
> Can some kind soul please explain to me why the 'c' is
> no longer eaten by 'c?'. The only explanation I can
> find is that the non-greediness of one part of the RE
> (the '.*?') has a higher priority than the greediness of 
> another part of the RE (the 'c?' is no longer greedy).
> 

c? is never greedy.

> What I'm tring to say is "extract 'a' and, if it is there,
> then also extract 'c'". 
> 

my $x = 'abc';
$x =~ /(a).(c?)/;


> I realise I can to this in a couple of steps ("try to
> match one 'c', and if that fails then try to match
> zero 'c's"), but there must be a more elegant way to
> do that.
> 
> Many thanks!
> 
> Alexis

The problem is that it's perfectly acceptable for both .*? and c? to 
match zero characters. Try this one-liner:

perl -Mwarnings -le 'print "Match $1" if (q{nncn} =~ /n(c?)/)'

==> Match

A match took place, but $1 is empty because c? means to match zero or 
one c's, so it matched one "n" and zero c's. Zero c's--when 
captured--become an empty string (not undef).


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

Date: 22 Mar 2007 13:44:02 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <slrnf05205.o4.abigail@alexandra.abigail.be>

Mumia W. (paduille.4060.mumia.w+nospam@earthlink.net) wrote on MMMMCMLI
September MCMXCIII in <URL:news:HGvMh.15199$tD2.6612@newsread1.news.pas.earthlink.net>:
__  
__  c? is never greedy.


But it is:

    $ perl -wle '"c" =~ /c?/ and print $&'
    c


Abigail
-- 
#!/opt/perl/bin/perl   --    # No trailing newline after the last line!    
BEGIN{$|=$SIG{__WARN__}=sub{$_=$_[0];y-_- -;print/(.)"$/;seek _,-open(_ 
,"+<$0"),2;truncate _,tell _;close _;exec$0}}//rekcaH_lreP_rehtona_tsuJ


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

Date: 22 Mar 2007 08:09:46 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <1174576186.362353.131400@d57g2000hsg.googlegroups.com>

On Mar 22, 9:39 am, "Mumia W."

> c? is never greedy.

Of course it is.  ? is a quantifier.  All quantifiers are greedy.  All
quantifiers can be made non-greeding by putting a ? after them,
including the ? quantifier.

$ perl -le'"abc" =~ /(a)(b)(c?)/; print "$1-$2-$3"'
a-b-c
$ perl -le'"abc" =~ /(a)(b)(c??)/; print "$1-$2-$3"'
a-b-

Paul Lalli



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

Date: 22 Mar 2007 16:37:37 GMT
From: xhoster@gmail.com
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <20070322123738.652$10@newsreader.com>

Alexis Huxley <ahuxley@gmx.net> wrote:
> The following code:
>
>         $x = "abc";
>         $x =~ /^(a)(b)(c?)/;
>         print "\$1=$1, \$2=$2, \$3=$3\n";
>
> outputs this:
>
>         $1=a, $2=b, $3=c
>
> which is just what I expect.
>
> But with only the second line changed to:
>
>         $x =~ /^(a)(.*?)(c?)/;
>
> Now the output changes to:
>
>         $1=a, $2=, $3=
>
> Can some kind soul please explain to me why the 'c' is
> no longer eaten by 'c?'.

because b doesn't match c.  The second chunk takes as few characters as
possible, which is zero.  That leaves the next chunk to try to match a "b"
against /c?/, which succeeds only due to the ? letting it succeed with
empty.  Therefore, the whole thing succeeds, and you are done.


> The only explanation I can
> find is that the non-greediness of one part of the RE
> (the '.*?') has a higher priority than the greediness of
> another part of the RE (the 'c?' is no longer greedy).

Unfortunately, "greedy" has two different meanings.  The more technical
one is that one part of the match makes a locally "optimal" choice (as long
as the match succeeds) without checking to see if a less locally optimal
one would improve the global optimality.  In this sense, Perl's regex are
always greedy--they never backtrack to improve the optimality of match
lengths, they only backtrack when the match would otherwise fail
altogether.


The other sense of the word is what is considered to be "locally optimal"
in the first place.  Without the ?, taking as many characters as possible
is considered optimal, i.e. the other sense of the word "greedy".  With the
?, it changes to thinking that taking as few characters as possible is
locally optimal, i.e. "nongreedy".  But this non-greediness is still
applied in a greedy way.

>
> What I'm tring to say is "extract 'a' and, if it is there,
> then also extract 'c'".

It seems unlikely that this is what you really want to do.  With this
type of problem, a solution that works on a simplified example is unlikely
to transfer to the real problem at hand.

Xho

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


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

Date: 22 Mar 2007 17:03:32 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: non-greedy match breaks '?' match?
Message-Id: <slrnf05dn5.s5p.glennj@smeagol.ncf.ca>

At 2007-03-22 11:09AM, "Paul Lalli" wrote:
>  On Mar 22, 9:39 am, "Mumia W."
>  
> > c? is never greedy.
>  
>  Of course it is.  ? is a quantifier.  All quantifiers are greedy.  All
>  quantifiers can be made non-greeding by putting a ? after them,
>  including the ? quantifier.
>  
>  $ perl -le'"abc" =~ /(a)(b)(c?)/; print "$1-$2-$3"'
>  a-b-c
>  $ perl -le'"abc" =~ /(a)(b)(c??)/; print "$1-$2-$3"'
>  a-b-

Thanks, Paul.  Very illuminating post.

-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry


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

Date: 22 Mar 2007 07:58:04 -0700
From: "jim burton" <jimburton1@gmail.com>
Subject: Re: On Java's Interface (the meaning of interface in computer programing)
Message-Id: <1174575484.699736.260130@n59g2000hsh.googlegroups.com>

On 22 Mar, 12:45, Lew <l...@nospam.lewscanon.com> wrote:
> Jim Burton wrote:
> > Or you could stop feeding the trolls.
>
> People need to stop saying that. The original post was a detailed if incorrect
> exposition of Java information. How in the world do you rate that trollish?
>
> I have absolutely no reason to rate the OP as a troll or their post as trollish.
>
> -- Lew

Oh, in that case welcome to usenet. Take a while to settle in. There's
this guy here called Xah and he is a troll.



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

Date: Thu, 22 Mar 2007 10:40:38 -0500
From: "Slartibartfast" <slarti@beeblebrox.net>
Subject: Re: On Java's Interface (the meaning of interface in computer programing)
Message-Id: <ArxMh.10950$Ng1.3575@newsfe19.lga>


"jim burton" <jimburton1@gmail.com> wrote in message 
news:1174575484.699736.260130@n59g2000hsh.googlegroups.com...
> On 22 Mar, 12:45, Lew <l...@nospam.lewscanon.com> wrote:
>> Jim Burton wrote:
>> > Or you could stop feeding the trolls.
>>
>> People need to stop saying that. The original post was a detailed if 
>> incorrect
>> exposition of Java information. How in the world do you rate that 
>> trollish?
>>
>> I have absolutely no reason to rate the OP as a troll or their post as 
>> trollish.
>>
>> -- Lew
>
> Oh, in that case welcome to usenet. Take a while to settle in. There's
> this guy here called Xah and he is a troll.
>

Why oh why does anyone even bother to respond to Xah Lee? See the true Xah 
at:

http://node60091.multiply.com/photos/album/1

WARNING: Nudity!!! Not family- or work-friendly!!!




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

Date: Thu, 22 Mar 2007 17:11:10 +0000
From: Nigel Wade <nmw@ion.le.ac.uk>
Subject: Re: On Java's Interface (the meaning of interface in computer programing)
Message-Id: <etudbe$gbf$1@south.jnrs.ja.net>

Lew wrote:

> Jim Burton wrote:
>> Or you could stop feeding the trolls.
> 
> People need to stop saying that. The original post was a detailed if incorrect 
> exposition of Java information. How in the world do you rate that trollish?

a) Xah's posting history.
b) the cross-posting
c) the advocacy of the contents

> 
> I have absolutely no reason to rate the OP as a troll or their post as
trollish.
> 

In time you will learn...

It wasn't even a good troll. To be a good troll the message actually needs to be
interesting enough to get people to read it. 


-- 
Nigel Wade, System Administrator, Space Plasma Physics Group,
            University of Leicester, Leicester, LE1 7RH, UK 
E-mail :    nmw@ion.le.ac.uk 
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555


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

Date: Thu, 22 Mar 2007 15:08:57 +0000
From: John Wilkinson <john.wilkinson@philips.com>
Subject: Perl Equivelent of C++ program
Message-Id: <p3s5wsbvor7f.cbkanophxyv3.dlg@40tude.net>

Hi,
I have a simple C++ program example, I would dearly love to swap to perl.
It uses pipes, which I do not understand, and I was wondering if anyone 
could convert this bit of code for me:
#include <stdio>
#include <string>
#include <sys/types>
#include <unistd>

int main (int argc, char* argv{}){

   int n;
   char line[1024];

   while((n = read(STDIN_FILENO, line, 1024)) > 0) {
      line[n]= '\0';
      if (strcmp(line,"firstcommand" == 0) {
             strcpy(line, "answer,= 1234 -2345 155 test");
     }
     else {
            strcpy(line, "unknown command");
     }
     n = strlen(line);
     if (write(STDOUT_FILENO, line, n) != n) {
        fprintf(stderr,"Server can't write to stdout\n");
     }
   }
}

This is supposed to be a simple example server, started by another process, 
and using pipes to communicate to this server.

Many regards,
John 


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

Date: Thu, 22 Mar 2007 15:43:06 +0000
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: Perl Equivelent of C++ program
Message-Id: <4602a40b$0$27120$db0fefd9@news.zen.co.uk>

John Wilkinson wrote:
> Hi,
> I have a simple C++ program example, I would dearly love to swap to perl.
> It uses pipes, which I do not understand, and I was wondering if anyone 
> could convert this bit of code for me:
> #include <stdio>
> #include <string>
> #include <sys/types>
> #include <unistd>
> 
> int main (int argc, char* argv{}){
> 
>    int n;
>    char line[1024];
> 
>    while((n = read(STDIN_FILENO, line, 1024)) > 0) {
>       line[n]= '\0';
>       if (strcmp(line,"firstcommand" == 0) {
>              strcpy(line, "answer,= 1234 -2345 155 test");
>      }
>      else {
>             strcpy(line, "unknown command");
>      }
>      n = strlen(line);
>      if (write(STDOUT_FILENO, line, n) != n) {
>         fprintf(stderr,"Server can't write to stdout\n");
>      }
>    }
> }
> 
> This is supposed to be a simple example server, started by another process, 
> and using pipes to communicate to this server.
> 

Since I'm not a C programmer I suspect it is equivalent to something not 
entirely unlike this (untested):

    #!perl
    use strict;
    use warnings;
    my $reply = "Oops";
    while(<>) {
      if (/^firstcommand/) { $reply = "answer,= 1234 -2345 155 test"; }
      else                 { $reply = "unknown command"; }
      print $reply or warn "Server can't write to stdout because $!\n";
    }

But I think you will be much better off abandoning your C examples and 
starting by looking for Perl examples instead.


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

Date: 22 Mar 2007 16:36:30 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Perl Equivelent of C++ program
Message-Id: <56fpkeF28jlqbU1@mid.dfncis.de>

John Wilkinson  <john.wilkinson@philips.com> wrote in comp.lang.perl.misc:
> Hi,
> I have a simple C++ program example, I would dearly love to swap to perl.

It's a C program.

> It uses pipes, which I do not understand, and I was wondering if anyone 

It doesn't use pipes as such.  It reads from standard input and writes
to standard output.  If these happen to be pipes that makes no
difference to your program.

> could convert this bit of code for me:

[has been done, code snipped]

Anno


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

Date: 22 Mar 2007 06:27:35 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: problem using timelocal, localtime to discern d-o-w.
Message-Id: <1174570055.014943.172600@b75g2000hsg.googlegroups.com>

On Mar 22, 8:49 am, "John" <jfcampb...@aol.com> wrote:
> Given a date passed in from a spreadsheet, I'm trying to come up with
> the day of the week.
>
> Trying to use timelocal (http://search.cpan.org/~drolsky/Time-
> Local-1.17/lib/Time/Local.pm) to turn the date into a scalar, then
> localtime to return the full slate of results, including the day of
> the week.
>
> I seem to be getting back at least what I put in -- that is the month,
> day and year are inverted, reverted and returned as I first called
> timelocal. But the day of week is not matching my paper calendar.
>
> #!/usr/bin/perl -w
> use strict;
> use Time::Local;
>
> my $gdate;
> my @wkdayname = ('Sunday', 'Monday', 'Tuesday', 'Wednesday',
> 'Thursday',
>         'Friday', 'Saturday', 'Sunday');
>
> {
>         $gdate = "4/18/2007";
>         my ($gmonth, $gmday, $gyear);
>         ($gmonth, $gmday, $gyear) = split(/\//,$gdate);
>
>         {
>         print "\ngmonth = $gmonth, ";
>         print "gmday = $gmday, ";
>         print "gyear = $gyear\n ";
>         }
>
>         my $gday;
>         my @timeScr;
>         my $scrTime=timelocal(0, 0, 11, $gmday, $gmonth, $gyear-1900);

You should, perhaps, read the documentation you linked to above. :-)

     It is worth drawing particular attention to the expected
     ranges for the values provided.  The value for the day of
     the month is the actual day (ie 1..31), while the month is
     the number of months since January (0..11).  This is
     consistent with the values returned from localtime() and
     gmtime().

So in other words, you passed it *May* 18, 2007, which is indeed a
Friday.

>         @timeScr = localtime($scrTime);
>         print "timescr= @timeScr \n";
>
>         $gday = $timeScr[6];
>         print "using timescr6 gday = $gday\n";
>         $gday = $wkdayname[$gday];
>         print "gday = $gday\n";
>
> }
>
> Results:
>
> gmonth = 4, gmday = 18, gyear = 2007
>  timescr= 0 0 11 18 4 107 5 137 1
> using timescr6 gday = 5
> gday = Friday
>
> But it says here that April 18, 2007 is a Wednesday.


By the way, there's no need for localtime/timelocal here.  Just pass
your values to POSIX::strftime and ask it what the day of week is:

#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw/strftime/;
my $gdate = "4/18/2007";
my ($gmonth, $gmday, $gyear) = split(/\//,$gdate);
print "\ngmonth = $gmonth, ";
print "gmday = $gmday, ";
print "gyear = $gyear\n";
print strftime("%A\n", 0, 0, 0, $gmday, $gmonth - 1, $gyear - 1900);
__END__

Hope this helps,
Paul Lalli





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

Date: 22 Mar 2007 13:37:17 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: problem using timelocal, localtime to discern d-o-w.
Message-Id: <slrnf051kd.s5p.glennj@smeagol.ncf.ca>

At 2007-03-22 08:49AM, "John" wrote:
>  	my $scrTime=timelocal(0, 0, 11, $gmday, $gmonth, $gyear-1900);

print scalar localtime $scrTime;
    # => Fri May 18 11:00:00 2007
-------------^^^

You forgot to subtract 1 from $gmonth.

-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry


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

Date: 22 Mar 2007 07:12:36 -0700
From: "John" <jfcampbell@aol.com>
Subject: Re: problem using timelocal, localtime to discern d-o-w.
Message-Id: <1174572756.159830.321420@n76g2000hsh.googlegroups.com>

On Mar 22, 9:27 am, "Paul Lalli" <mri...@gmail.com> wrote:
>
>      ... the month is
>      the number of months since January (0..11).  This is
>      consistent with the values returned from localtime() and
>      gmtime().
>
> By the way, there's no need for localtime/timelocal here.  Just pass
> your values to POSIX::strftime

> Hope this helps,


It does help. strftime works like a charm. Thanks also to Glenn.




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

Date: Thu, 22 Mar 2007 17:08:15 GMT
From: Marshall Dudley <mdudley@king-cart.com>
Subject: Problem with indirect variables
Message-Id: <3KyMh.16217$G23.13312@newsreading01.news.tds.net>

Why can I not get the second variable to print it's value in the 
following code?

$test = "Test String";
$form_data{'test'} = "form data variable";
foreach $string (test,"form_data{'test'}") {
        print "$string = $$string\n";
}

perl test.pl
test = Test String
form_data{'test'} =

Thanks,

Marshall


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

Date: 22 Mar 2007 06:58:11 -0700
From: "bpatton" <bpatton@ti.com>
Subject: Simple Expect problem
Message-Id: <1174571891.803464.3820@o5g2000hsb.googlegroups.com>

I'm trying to write a wrapper(X) that calls another wrapper(Y).
Y prompts the user for information using STDOUT.

My job is for regression testing, so I must wiggle all the prompts for
all values.

Here is a very simple example of what I want to do.   y.pl
#!/usr/local/bin/perl
use strict;
use warnings;
$| = 1;
print "Begin command line IO now.\n";
NUMBER:
print "Enter number : ";
my $number = <>;
print("Letters entered!\n") , goto(NUMBER) if $number =~ /[a-zA-Z]/;
print "Number entered : $number\n";
LETTERS:
print "Enter alpha characters : ";
my $name = <>;
print("Numbers entered!\n") , goto(LETTERS) if $name =~ /[0-9]/;
print "Letters entered : $name\n";
print "Are you ready to quit? <y/n> ";
my $q = <>;
goto NUMBER if $q =~ /n/;
exit 1571234; # make sure it gets strange error code

#################################################################################
Here is what I'm trying to do with Expect x.pl :
#!/usr/local/bin/perl
use strict;
use warnings;
use FileHandle;
use Expect;
$| = 1;

my $exp = new Expect;
$exp->raw_pty(1);
$exp->spawn("y.pl");
while (1) {
  my $get = $exp->expect(1,
                         ['Begin command line IO now.',
                          sub {exp_continue;}
                         ],
                         ['Enter number.*',
                          sub {my $fh = shift;
                                $fh->send('1');
                                exp_continue;
                              }
                          ],
                         ['Numbers entered!.*',
                          sub { exp_continue;}
                          ],
                         ['Enter alpha characters : ',
                          sub {my $fh = shift;
                                $fh->send('a');
                                exp_continue;
                              }
                          ],
                         ['Letters entered.*',
                          sub {exp_continue;}
                          ],
                         ['Are you ready to quit <y/n> ',
                          sub {my $fh = shift;
                                $fh->send('y');
                                exp_continue;
                              }
                          ],
                          );

- Hide quoted text -
- Show quoted text -



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

Date: Thu, 22 Mar 2007 15:21:32 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: Simple Expect problem
Message-Id: <0axMh.130087$_73.1949@newsread2.news.pas.earthlink.net>

On 03/22/2007 08:58 AM, bpatton wrote:
> I'm trying to write a wrapper(X) that calls another wrapper(Y).
> Y prompts the user for information using STDOUT.
> 
> My job is for regression testing, so I must wiggle all the prompts for
> all values.
> 
> Here is a very simple example of what I want to do.   y.pl
> [ snipped scripts without any explanation of what is wrong with them ]

Posting Guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html




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

Date: 22 Mar 2007 09:56:12 -0700
From: "manunderstress" <chadw3@gmail.com>
Subject: Re: variable evaluation and printing
Message-Id: <1174582572.129785.131850@l75g2000hse.googlegroups.com>

>
> You are trying to use symbolic references, and have demonstrated one
> reason they are not recommended (they only work on global variables and
> your variables are lexical).
>
> See 'perldoc -q variable
>
>      How can I use a variable as a variable name?
>
> for other reasons why not to do this. Use a hash, instead.
>

Fair enough, but now I'm at a loss how else to do what I want to do,
that is, without using scalar variables I have previously created in
the script as keys for the hash (%post_checks)- and their evaluation
as the value for the hash.

I have a bunch of scalar variables that will be dynamically generated
(hostid, ifconfig, whatever) and I want to add each key->value pair  -
if it exists- to a hash (what I thought I was doing...by adding key-
>values to %post_checks).




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

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


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