[25605] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7849 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 3 09:06:03 2005

Date: Thu, 3 Mar 2005 06:05:33 -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, 3 Mar 2005     Volume: 10 Number: 7849

Today's topics:
        Apache::Status <alexj@floor.ch>
    Re: can someone help? <lie_huo@hotmail.com>
    Re: can someone help? <mark.clements@kcl.ac.uk>
    Re: can someone help? <tadmc@augustmail.com>
    Re: Class::Date <alexj@floor.ch>
        Cloning structures containing weak references <tony@skelding.co.uk>
        minor re, problelm <georgekinley@hotmail.com>
    Re: minor re, problelm <1usa@llenroc.ude.invalid>
    Re: minor re, problelm <1usa@llenroc.ude.invalid>
        mod_perl and db <alexj@floor.ch>
    Re: mod_perl and db <lawrence.tierney@bipcontracts.com>
    Re: mod_perl and db <alexj@floor.ch>
    Re: mod_perl and db <alexj@floor.ch>
    Re: mod_perl and db <lawrence.tierney@bipcontracts.com>
    Re: Need to download 20000 pdf files (aka froggy)
    Re: odd socket behavior with ZoneAlarm <clarke@n_o_s_p_a_m_hyperformix.com>
    Re: Passing in the replace string for a regex via the c <1usa@llenroc.ude.invalid>
    Re: Passing in the replace string for a regex via the c <1usa@llenroc.ude.invalid>
    Re: Passing in the replace string for a regex via the c <tadmc@augustmail.com>
        Passing in the replace string for a regex via the comma <news@ant-roy.co.uk>
    Re: Passing in the replace string for a regex via the c <news@ant-roy.co.uk>
    Re: Passing in the replace string for a regex via the c <shawn.corey@sympatico.ca>
    Re: perl commands (Anno Siegel)
        scripting a curses app <zebee@zip.com.au>
    Re: scripting a curses app (Peter Corlett)
    Re: scripting a curses app <zebee@zip.com.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 03 Mar 2005 12:14:01 +0100
From: Alexandre Jaquet <alexj@floor.ch>
Subject: Apache::Status
Message-Id: <d06rhp$780$1@news.hispeed.ch>

I got another question.

If I would like to add Apache::Status module in my startup.pl script 
does I've to rebuild and reinstall mod_perl ?

http://perl.apache.org/docs/1.0/guide/performance.html#Measuring_the_Memory_Usage_of_Subroutines 


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

Date: Thu, 03 Mar 2005 05:46:22 -0500
From: "Roll" <lie_huo@hotmail.com>
Subject: Re: can someone help?
Message-Id: <e87a3569edcdd1fef1d43055256a1b5a@localhost.talkaboutprogramming.com>

[Thu Mar 03 18:42:11 2005] [error] [client 127.0.0.1] Backslash found where
operator expected at /var/www/html/test.cgi line 5, near "plain\\"
[Thu Mar 03 18:42:11 2005] [error] [client 127.0.0.1] Backslash found
where operator expected at /var/www/html/test.cgi line 5, near "n\\"
[Thu Mar 03 18:42:11 2005] [error] [client 127.0.0.1] syntax error at
/var/www/html/test.cgi line 5, near "Type:"
[Thu Mar 03 18:42:11 2005] [error] [client 127.0.0.1] Execution of
/var/www/html/test.cgi aborted due to compilation errors.
[Thu Mar 03 18:42:11 2005] [error] [client 127.0.0.1] Premature end of
script headers: test.cgi
[Thu Mar 03 18:42:11 2005] [error] [client 127.0.0.1] File does not exist:
/var/www/html/favicon.ico
[Thu Mar 03 18:44:38 2005] [error] [client 127.0.0.1] Can't locate object
method "USE" via package "CGI" (perhaps you forgot to load "CGI"?) at
/var/www/html/test.cgi line 4.
[Thu Mar 03 18:44:38 2005] [error] [client 127.0.0.1] Premature end of
script headers: test.cgi
[tHU mAR 03 18:44:38 2005] [error] [client 127.0.0.1] File does not exist:
/var/www/html/favicon.ico

this is the error that i found in error log can anyone explain to me what
is the error?



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

Date: Thu, 03 Mar 2005 11:54:21 +0100
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: can someone help?
Message-Id: <4226ece0@news.kcl.ac.uk>

Roll wrote:
> [Thu Mar 03 18:42:11 2005] [error] [client 127.0.0.1] Backslash found where
> operator expected at /var/www/html/test.cgi line 5, near "plain\\"
> [Thu Mar 03 18:42:11 2005] [error] [client 127.0.0.1] Backslash found
> where operator expected at /var/www/html/test.cgi line 5, near "n\\"
> [Thu Mar 03 18:42:11 2005] [error] [client 127.0.0.1] syntax error at
> /var/www/html/test.cgi line 5, near "Type:"
<snip>
> /var/www/html/favicon.ico
> [Thu Mar 03 18:44:38 2005] [error] [client 127.0.0.1] Can't locate object
> method "USE" via package "CGI" (perhaps you forgot to load "CGI"?) at

You have syntax errors in your script. perl -cw is your friend.

perl -cw test.cgi

will attempt to compile the script and spit out any errors before you 
even try to run it on the server.

for a start you probably want:

use CGI;

*not* USE CGI;

Mark


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

Date: Thu, 3 Mar 2005 07:50:11 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: can someone help?
Message-Id: <slrnd2e5gj.2r8.tadmc@magna.augustmail.com>

Roll <lie_huo@hotmail.com> wrote:

> Subject: Re: can someone help?


You will get more help if potential answerers could tell what
your post was about before reading all of it.

Please put the subject of your article in the Subject of your article.


> [Thu Mar 03 18:42:11 2005] [error] [client 127.0.0.1] Backslash found where
> operator expected at /var/www/html/test.cgi line 5, near "plain\\"

[snip more messages]

> this is the error that i found in error log can anyone explain to me what
> is the error?


What you intended to be a Perl program is not (yet) actually
a Perl program.

You have a syntax error in the code, but since you are the only
one who can see that code it is up to you to fix it.


(did you know that you can nearly always use / as the directory
 separator rather than \ ?
)

-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 03 Mar 2005 09:32:08 +0100
From: Alexandre Jaquet <alexj@floor.ch>
Subject: Re: Class::Date
Message-Id: <d06i27$kfk$1@news.hispeed.ch>

jamie@nospam.com a écrit :
>>i didn't find something usefull with HiRes :(
> 
> Perhaps I am misunderstanding what you are trying to accomplish.  If,
> for example, you needed to time how long something takes...in
> milliseconds...you could:
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Time::HiRes qw(gettimeofday);
> 
> $t0 = gettimeofday();
> #Do something here
> $t1 = gettimeofday();
> $elapsed = $t1 - $t0;
> 
> <disclaimer> Stolen from "The Cookbook"</disclaimer>
> 
> --
> Jamie
> 

Great Jamie it was exactly what I was looking for thx :)


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

Date: 3 Mar 2005 03:15:52 -0800
From: "Mintcake" <tony@skelding.co.uk>
Subject: Cloning structures containing weak references
Message-Id: <1109848552.496818.242290@o13g2000cwo.googlegroups.com>

I've tried various cloning modules to clone a structure containing weak
references.

use Storable 'dclone';
use Scalar::Util qw(weaken isweak);
my $x = 99;
my $y = [ \$x ] ;
weaken $y->[0];
$z = dclone $y;
print "y: ", isweak $y->[0];
print "z: ", isweak $z->[0];

This prints:

y: 1
z:

I've tried it using the Clone module and Clone::PP.  Clone::PP does the
same as Storable.  Clone gives a segmentation fault.

I'm using Perl 5.8.0 on Linux 2.4.20-8



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

Date: Thu, 03 Mar 2005 13:32:00 GMT
From: "George" <georgekinley@hotmail.com>
Subject: minor re, problelm
Message-Id: <xn0dzbfs1csxctm002@news.europe.nokia.com>

I have 
($pI,$vI)=($input=~/(\d+),(\d+)/) || ($input=~/(.*),(.*)/);
print "($pI,$vI)";
which work fine if $input="24,qwerr" but returns (1,) if $input="38,29"
why is that
why this "or" is not working, and how can I use ?: in this case


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

Date: Thu, 03 Mar 2005 13:47:24 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: minor re, problelm
Message-Id: <Xns960E596B2733Aasu1cornelledu@127.0.0.1>

"George" <georgekinley@hotmail.com> wrote in news:xn0dzbfs1csxctm002
@news.europe.nokia.com:

Putting some effort into writing your question will usually help you 
find the answer in the process.

Please do read the posting guidelines posted here regularly.

> I have 
> ($pI,$vI)=($input=~/(\d+),(\d+)/) || ($input=~/(.*),(.*)/);
> print "($pI,$vI)";
> which work fine if $input="24,qwerr" but returns (1,) if 
$input="38,29"

Please define what "work fine" means?

> why is that
> why this "or" is not working, 

I do not see any "or" in the code you posted.

As always, the Perl documentation is your friend. From perldoc perlop:

   In particular, this means that you shouldn't use this for selecting
   between two aggregates for assignment:

       @a = @b || @c;              # this is wrong
       @a = scalar(@b) || @c;      # really meant this
       @a = @b ? @b : @c;          # this works fine, though


Which leads us to:

#! /usr/bin/perl

use strict;
use warnings;

print "@{[ print_matches('24,qwerr') ]}\n";
print "@{[ print_matches('38,29') ]}\n";

sub print_matches {
    my ($input) = @_;
    my @ret = ($input =~ /(\d+),(\d+)/) 
              ? ($1, $2) 
              : ($input =~ /(.*),(.*)/);
}

__END__

D:\Home\asu1\UseNet\clpmisc> v
24 qwerr
38 29

Sinan


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

Date: Thu, 03 Mar 2005 13:54:43 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: minor re, problelm
Message-Id: <Xns960E5AA8CC6F2asu1cornelledu@127.0.0.1>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in 
news:Xns960E596B2733Aasu1cornelledu@127.0.0.1:

> sub print_matches {
>     my ($input) = @_;
>     my @ret = ($input =~ /(\d+),(\d+)/) 
>               ? ($1, $2) 
>               : ($input =~ /(.*),(.*)/);
> }
> 
> __END__

Of course, it would be better to call this sub something other than 
print_matches because one thing it does not do is print.

Sinan.


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

Date: Thu, 03 Mar 2005 10:47:03 +0100
From: Alexandre Jaquet <alexj@floor.ch>
Subject: mod_perl and db
Message-Id: <d06mem$s5a$1@news.hispeed.ch>

I'm looking for a way to minimize sql queries. I'm been using mysql, 
mod_perl and unix server. Does anything exist to trick with it like 
DataSet and RecordSet in dot net ?

Any web ressource about this subject ?

thx in advance


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

Date: Thu, 03 Mar 2005 10:44:29 GMT
From: "Lord0" <lawrence.tierney@bipcontracts.com>
Subject: Re: mod_perl and db
Message-Id: <hUBVd.357$d75.186@newsfe4-gui.ntli.net>

> I'm looking for a way to minimize sql queries. I'm been using mysql, 
> mod_perl and unix server. Does anything exist to trick with it like 
> DataSet and RecordSet in dot net ?
>
> Any web ressource about this subject ?
>
> thx in advance

You can have a look at Apache::DBI - this will provide you will a persistent 
pool of DB connections, saving you the overhead of having to create them *on 
the fly*. With mod perl you could cache the results of common queries and 
store them for future use.....what is the dot net DataSet/RecordSet trick? 




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

Date: Thu, 03 Mar 2005 11:51:40 +0100
From: Alexandre Jaquet <alexj@floor.ch>
Subject: Re: mod_perl and db
Message-Id: <d06q7r$4g7$1@news.hispeed.ch>

Lord0 a écrit :
>>I'm looking for a way to minimize sql queries. I'm been using mysql, 
>>mod_perl and unix server. Does anything exist to trick with it like 
>>DataSet and RecordSet in dot net ?
>>
>>Any web ressource about this subject ?
>>
>>thx in advance
> 
> 
> You can have a look at Apache::DBI - this will provide you will a persistent 
> pool of DB connections, saving you the overhead of having to create them *on 
> the fly*. With mod perl you could cache the results of common queries and 
> store them for future use.....what is the dot net DataSet/RecordSet trick? 
> 
> 
thx lawrence recordset and dataset does this kind of optimisation


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

Date: Thu, 03 Mar 2005 11:53:20 +0100
From: Alexandre Jaquet <alexj@floor.ch>
Subject: Re: mod_perl and db
Message-Id: <d06qav$4g7$2@news.hispeed.ch>

Alexandre Jaquet a écrit :
> Lord0 a écrit :
> 
>>> I'm looking for a way to minimize sql queries. I'm been using mysql, 
>>> mod_perl and unix server. Does anything exist to trick with it like 
>>> DataSet and RecordSet in dot net ?
>>>
>>> Any web ressource about this subject ?
>>>
>>> thx in advance
>>
>>
>>
>> You can have a look at Apache::DBI - this will provide you will a 
>> persistent pool of DB connections, saving you the overhead of having 
>> to create them *on the fly*. With mod perl you could cache the results 
>> of common queries and store them for future use.....what is the dot 
>> net DataSet/RecordSet trick?
>>
> thx lawrence recordset and dataset does this kind of optimisation

I currently read documentation about SQL_CACHE (mysql) is that another 
optimisation than mod_perl one ? 
http://dev.mysql.com/doc/mysql/en/query-cache-how.html


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

Date: Thu, 03 Mar 2005 13:34:38 GMT
From: "Lord0" <lawrence.tierney@bipcontracts.com>
Subject: Re: mod_perl and db
Message-Id: <OnEVd.29$077.17@newsfe4-gui.ntli.net>


> I currently read documentation about SQL_CACHE (mysql) is that another
> optimisation than mod_perl one ? 
> http://dev.mysql.com/doc/mysql/en/query-cache-how.html

Yes this is unrelated to mod_perl. 




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

Date: Thu, 03 Mar 2005 21:06:38 +1300
From: "Shane (aka froggy)" <spamspamuber.l33t.god@spamgmail.com>
Subject: Re: Need to download 20000 pdf files
Message-Id: <pan.2005.03.03.08.06.38.616854@spamgmail.com>

On Wed, 02 Mar 2005 12:22:56 -0800, Hemant wrote:

> I am working on a project that requires me to have access to more than
> 20000 pdf files. Any suggestions on how to go about searching over the
> internet and be able to download the files?

er.. from all the other posts it seems an easy task
but I dont get it.. are you asking how to just download the pdf
documents.. or search them out over the net.. or search out random pdf
documents for downloading?
-- 

Hardware, n.: The parts of a computer system that can be kicked



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

Date: Thu, 3 Mar 2005 07:46:51 -0600
From: "AC" <clarke@n_o_s_p_a_m_hyperformix.com>
Subject: Re: odd socket behavior with ZoneAlarm
Message-Id: <422714f7$0$92313$39cecf19@news.twtelecom.net>

I apologize to those who feel (with some justification) that this is 
off-topic...

Using read() fails and using recv() or sysread() succeeds. I do have a 
simple client and server that fail. By the way, I think that the free 
version of ZA is ok, its the ZA Security Suite that is bad.

I am half suspicious that ZA and possibly other firewalls are mucking with 
the text sent across, like changing the newline (this would explain the 
hanging).

Here is a client and server that break. I grabbed them off this newsgroup 
and they work on my developement machine, but fail on my test machine (by 
having the client hang)...

======================
sockettest_srv.pl

#!/usr/bin/perl -w
use strict;

BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }

use Socket;
use Carp;

use IO::Socket; # for autoflush

my $EOL = "\015\012";

sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }

my $port = shift || 2345;
my $proto = getprotobyname('tcp');

($port) = $port =~ /^(\d+)$/                        or die "invalid port";
socket(Server, PF_INET, SOCK_STREAM, $proto)        || die "socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR,
                                        pack("l", 1))   || die "setsockopt: 
$!";
bind(Server, sockaddr_in($port, INADDR_ANY))        || die "bind: $!";
listen(Server,SOMAXCONN)                            || die "listen: $!";
logmsg "server started on port $port";
my $paddr;
$SIG{CHLD} = \&REAPER;

for ( ; $paddr = accept(Client,Server); close Client)
{
    autoflush Client 1;

    my($port,$iaddr) = sockaddr_in($paddr);
    my $name = gethostbyaddr($iaddr,AF_INET);

    logmsg "connection from $name [",
                inet_ntoa($iaddr), "]
                at port $port";
    print Client "From the server, hello there, $name, it's now ",
                        scalar localtime, $EOL;
}

======================
sockettest_cl.pl

#!/usr/bin/perl -w

use strict;
use Socket;

my ($remote,$port, $iaddr, $paddr, $proto, $line);

$remote  = shift || 'localhost';

$port    = shift || 2345;  # random port
if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }

die "No port" unless $port;

$iaddr   = inet_aton($remote)               || die "no host: $remote";
$paddr   = sockaddr_in($port, $iaddr);
$proto   = getprotobyname('tcp');

my $sockhand;
print "Socket open...\n";
socket($sockhand, PF_INET, SOCK_STREAM, $proto)  || die "socket: $!";

print "Socket connect...\n";
connect($sockhand, $paddr)    || die "connect: $!";

if (0)
{
    print "recv(Socket) read lines...\n";

    my $data = "";

    while (defined (recv($sockhand, $data, 1024, 0)) && length($data) > 0)
    {
 print $data;
    }
}
else
{
    print "<Socket> read lines...\n";

    while (defined($line = <$sockhand>))
    {
 print $line;
    }
}

print "Socket close\n";
close ($sockhand)            || die "close: $!";




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

Date: Thu, 03 Mar 2005 13:28:16 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Passing in the replace string for a regex via the command line - HOW?
Message-Id: <Xns960E562C2340Basu1cornelledu@127.0.0.1>

Anthony Roy <news@ant-roy.co.uk> wrote in news:d06tgr$osb$1
@south.jnrs.ja.net:

> I am trying to pass in the find and replace values for a regex 
> substitution via the command lin, but I am not getting the expexted 
> result at all.
> 
> The perl program (attached) is:
> 
> ------------------------------------
> $in = shift;
> $out = shift;
> $string = shift;
> 
> $string =~ s/$in/$out/;
> print $string;
> ------------------------------------
> 
> The command line used to call the script is:
> 
> perl rename.pl (\w+).old $1 abcd.old

What happens to $1 will depend very much on the shell you are using. You 
might have to quote the arguments to get consistent behavior.

> I had expected the output to be: abcd
> 
> instead it gives: $1

From perldoc perlop:

    bracketing quotes, e.g., "s(foo)(bar)" or "s<foo>/bar/". A "/e"
    will cause the replacement portion to be treated as a
    full-fledged Perl expression and evaluated right then and there.
    It is, however, syntax checked at compile-time. A second "e"
    modifier will cause the replacement portion to be "eval"ed
    before being run as a Perl expression.

Giving us:

#! /usr/bin/perl -T

use strict;
use warnings;

my ($in, $out, $string) = @ARGV;

$string =~ s/$in/$out/ee;

print "$string\n";

__END__

Note that this script will not run as it stands because of the -T switch 
in the shebang line. You will need to decide what acceptable patterns 
can be used as the replacement string and untaint them, following the 
instructions in perldoc perlsec.

Or, you can remove the -T switch, but don't do that before you have read 
perlsec and said out loud "I accept the possibility that this script can 
be used to wipe away my life" :)

Sinan.


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

Date: Thu, 03 Mar 2005 13:47:51 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Passing in the replace string for a regex via the command line - HOW?
Message-Id: <Xns960E597E7FB6Easu1cornelledu@127.0.0.1>

Anthony Roy <news@ant-roy.co.uk> wrote in news:d074h6$qv3$1
@south.jnrs.ja.net:

> A. Sinan Unur wrote:
> ...
> 
>> $string =~ s/$in/$out/ee;
> 
> Excellent - I knew there would be a simple solution. Thanks.

Ignore -T at your own peril.

Sinan.


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

Date: Thu, 3 Mar 2005 07:58:52 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Passing in the replace string for a regex via the command line - HOW?
Message-Id: <slrnd2e60s.2r8.tadmc@magna.augustmail.com>

Anthony Roy <news@ant-roy.co.uk> wrote:

> I am trying to pass in the find and replace values for a regex 
> substitution via the command lin,

> $string =~ s/$in/$out/;

> perl rename.pl (\w+).old $1 abcd.old
> 
> I had expected the output to be: abcd
> 
> instead it gives: $1


> Any idea how to get this to work as it should?


   $string =~ s/$in/$out/ee;


See also:

   perldoc -q strings

       How can I expand variables in text strings?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 03 Mar 2005 11:47:38 +0000
From: Anthony Roy <news@ant-roy.co.uk>
Subject: Passing in the replace string for a regex via the command line - HOW?
Message-Id: <d06tgr$osb$1@south.jnrs.ja.net>

Hi all,

I have just come accross this little problem:

I am trying to pass in the find and replace values for a regex 
substitution via the command lin, but I am not getting the expexted 
result at all.

The perl program (attached) is:

------------------------------------
$in = shift;
$out = shift;
$string = shift;

$string =~ s/$in/$out/;
print $string;
------------------------------------

The command line used to call the script is:

perl rename.pl (\w+).old $1 abcd.old

I had expected the output to be: abcd

instead it gives: $1

Replacing the line "$string =~ s/$in/$out/;" with "$string =~ 
s/$in/$1/;" works as expected.

I presume that the $out is being expanded to $1, but the $1 is not then 
being expanded itself.

Any idea how to get this to work as it should?

Thanks.

-- 
Anthony Roy.


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

Date: Thu, 03 Mar 2005 13:47:18 +0000
From: Anthony Roy <news@ant-roy.co.uk>
Subject: Re: Passing in the replace string for a regex via the command line - HOW?
Message-Id: <d074h6$qv3$1@south.jnrs.ja.net>

A. Sinan Unur wrote:
 ...

> $string =~ s/$in/$out/ee;

Excellent - I knew there would be a simple solution. Thanks.

-- 
Anthony Roy.


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

Date: Thu, 03 Mar 2005 08:33:23 -0500
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: Passing in the replace string for a regex via the command line - HOW?
Message-Id: <umEVd.35773$kz6.698750@news20.bellglobal.com>

Anthony Roy wrote:
> Hi all,
> 
> I have just come accross this little problem:
> 
> I am trying to pass in the find and replace values for a regex 
> substitution via the command lin, but I am not getting the expexted 
> result at all.
> 
> The perl program (attached) is:
> 
> ------------------------------------
> $in = shift;
> $out = shift;
> $string = shift;
> 
> $string =~ s/$in/$out/;
> print $string;
> ------------------------------------
> 
> The command line used to call the script is:
> 
> perl rename.pl (\w+).old $1 abcd.old
> 
> I had expected the output to be: abcd
> 
> instead it gives: $1
> 
> Replacing the line "$string =~ s/$in/$out/;" with "$string =~ 
> s/$in/$1/;" works as expected.
> 
> I presume that the $out is being expanded to $1, but the $1 is not then 
> being expanded itself.
> 
> Any idea how to get this to work as it should?
> 
> Thanks.
> 

#!/usr/bin/perl

use strict;
use warnings;

my $in = shift;
my $out = shift;
my $string = shift;

eval "\$string =~ s/$in/$out/;";
print $string, "\n";

__END__

You have to eval the string '$1' to code. See perldoc -f eval

    --- Shawn


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

Date: 3 Mar 2005 09:51:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl commands
Message-Id: <d06mm5$iut$1@mamenchi.zrz.TU-Berlin.DE>

Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> Chris Mattern <matternc@comcast.net> wrote:
> 
> > Whoever did this isn't very good.
> 
> 
> That sums it up quite well.
> 
> It clearly was written my an amateur.

Hey!  Don't give amateurs a bad name!

Anno


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

Date: Thu, 03 Mar 2005 09:52:18 GMT
From: Zebee Johnstone <zebee@zip.com.au>
Subject: scripting a curses app
Message-Id: <slrnd2dnc6.76t.zebee@zeus.zipworld.com.au>

we have some hardware boxes that are configured via telnet into a curses
based app.

Is there a perl module that can script input to curses applications?

All the stuff in CPAN that comes up when searching for curses is how to
write apps using it, not how to speak to apps using it.

Will Expect handle this?

Zebee


-- 
Zebee Johnstone (zebee@zip.com.au), proud holder of
aus.motorcycles Poser Permit #1.
"Motorcycles are like peanuts... who can stop at just one?"


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

Date: 03 Mar 2005 10:04:16 GMT
From: abuse@dopiaza.cabal.org.uk (Peter Corlett)
Subject: Re: scripting a curses app
Message-Id: <4226e120$0$38044$5a6aecb4@news.aaisp.net.uk>

Zebee Johnstone <zebee@zip.com.au> wrote:
> we have some hardware boxes that are configured via telnet into a
> curses based app. Is there a perl module that can script input to
> curses applications?

google:screen+scrape+cpan.org suggests not. It's all geared to
screen-scraping websites these days.

[...]
> Will Expect handle this?

I have used Expect to script a specific curses-based application, but
that had a fairly crude display update mechanism, and wasn't
mission-critical enough that I got away with it screwing up all the
time. However, Expect is unlikely to work too well for the general
case of all curses apps.

You may find that the device doesn't actually use curses and is
sufficiently inefficient in its screen updates that there are enough
tokens for you to expect.

I have a very old C program I wrote at
http://www.cabal.org.uk/freeware/misc/snoopio.html which you may be
able to tee into the connection to log what's actually going over the
wire in an interactive session to see if unleashing Expect on it is
likely to be fruitful.

If you find you have to do it the hard way by rendering to a virtual
frame buffer and plucking data from that, Term::VT102 looks like a
very good start, and I suspect its author had pretty much the same
problem as you.

-- 
Though intelligence is powerless to modify character, it is a dab hand at
finding euphemisms for its weaknesses.
								- Quentin Crisp


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

Date: Thu, 03 Mar 2005 10:37:59 GMT
From: Zebee Johnstone <zebee@zip.com.au>
Subject: Re: scripting a curses app
Message-Id: <slrnd2dq1r.8nn.zebee@zeus.zipworld.com.au>

In comp.lang.perl.misc on 03 Mar 2005 10:04:16 GMT
Peter Corlett <abuse@dopiaza.cabal.org.uk> wrote:
> 
> You may find that the device doesn't actually use curses and is
> sufficiently inefficient in its screen updates that there are enough
> tokens for you to expect.

Hmm.. could be.  I'll borrow your prog and see what I can find.

Zebee


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

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


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