[18965] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1160 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 19 18:09:03 2001

Date: Tue, 19 Jun 2001 15:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <992988308-v10-i1160@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 19 Jun 2001     Volume: 10 Number: 1160

Today's topics:
    Re: Are there any Perl - NT oriented message boards? <bart.lateur@skynet.be>
    Re: Are there any Perl - NT oriented message boards? <rsherman@ce.gatech.edu>
        CGI Expect.pm - unknown terminal type <markg454@hotmail.com>
    Re: CGI.pm, cookies and redirect PLS HELP! <mbudash@sonic.net>
    Re: Fetching CGI data as a hash (was DBM in a CGI) <gnarinn@hotmail.com>
        Get all the possibilities <mblanche@uclink.berkeley.edu>
    Re: Get all the possibilities (Greg Bacon)
    Re: Get all the possibilities <rsherman@ce.gatech.edu>
    Re: Get all the possibilities <ren@tivoli.com>
    Re: getsockopt and setsockopt: SO_RCVBUF unsupported? (Michael Fuhr)
    Re: HowTo: Run a command in backticks as root? <bruno.montagnac@renault.com>
    Re: initialising multi-dimensional array <mjcarman@home.com>
        Interfacing to Microsoft Outlook! <daz.thorpe@virgin.net>
    Re: Looking for descriptions of IngPerl Functions and V <gnarinn@hotmail.com>
    Re: matching a list with a regex <aqumsieh@hyperchip.com>
    Re: Memory Issues/File Slurping (Doug McGrath)
        memory-leaks (in mod_perl) <pilsl_@goldfisch.at>
        OLE automation w/ MS Word (G Chew)
        Regexps, using variables to get $1, $2, etc. (googlenews@edge-web.com)
    Re: Regexps, using variables to get $1, $2, etc. <ren@tivoli.com>
    Re: Regexps, using variables to get $1, $2, etc. (Greg Bacon)
    Re: Removing ^M characters <pne-news-20010619@newton.digitalspace.net>
    Re: Setting Return-Path in sendmail from Perl (Igor Mozolevsky)
    Re: Setting Return-Path in sendmail from Perl (Suresh Ramasubramanian)
        Why does this split not work? <nospam@cfl.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 19 Jun 2001 18:11:10 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Are there any Perl - NT oriented message boards?
Message-Id: <mg5vitghahu3clg6g2rrqlvpaq47964b50@4ax.com>

CPERL520335 wrote:

>Can anyone point me in the right direction? (I already know activestate, but
>there's no community boards)

There's a mailing list.

-- 
	Bart.


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

Date: Tue, 19 Jun 2001 16:37:05 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: Are there any Perl - NT oriented message boards?
Message-Id: <3B2F3961.637A8033@ce.gatech.edu>

Bart Lateur wrote:

> CPERL520335 wrote:
>
> >Can anyone point me in the right direction? (I already know activestate, but
> >there's no community boards)
>
> There's a mailing list.
>
> --
>         Bart.

perl-ntadmins@topica.com

http://www.topica.com/lists/perl-ntadmins/



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

Date: Tue, 19 Jun 2001 13:14:12 -0500
From: Mark Gaither <markg454@hotmail.com>
Subject: CGI Expect.pm - unknown terminal type
Message-Id: <3B2F9674.7160268C@hotmail.com>

I have successfully created a script using Expect.pm and Perl 5 which
runs
nicely from the command line (perl ./backup.pl).

I am trying to move this script to a CGI but I have have run into
a problem. I get an 'unknown terminal "unknown"' message and I suspect
that this is related to the fact that a CGI session is not runing as a
known
terminal such as vt100. I know how to set the terminal in Expect but
not using Expect.pm. Any help would be greatly appreciated. I've
included the code at the end of this message.

Regards,

Mark Gaither

-------- Result ---------

Trying 192.168.1.65...

Connected to 192.168.1.65.

Escape character is '^]'.


Red Hat Linux release 6.2 (Zoot)
Kernel 2.2.19pre9 on an i586
login: rock
Password:
Last login: Tue Jun 19 15:51:43 from agassiz
Kickstart-installed Red Hat Linux For Unwired MagicBox Mon Feb 12
16:10:43 CST 2001
unknown terminal "unknown"
[rock@rsn-14 rock]$
----------------------

---------code------------
#!/usr/bin/perl -w

$ENV{'IFS'} = '';
$ENV{'PATH'} = '/bin:/usr/bin:/sbin';

use CGI qw(:standard);
use strict;
use DBI;
use Expect;


$SIG{'INT'}=$SIG{'TERM'}=$SIG{'QUIT'}=eval "sub {exit}";

my $hostname = param('hostname');
my $ip_address = param('ip');
my $debug = 0;

if (!defined($hostname) || !defined($ip_address)) {
    print STDERR "ERROR: missing hostname.\n";
    print STDERR "Usage: rsnsh.pl hostname\n";
    exit;
}

print header();

select (STDOUT);

print <<"HTML";
<html>
<head>
<title>RSN NOC Backup</title>
<link rel="stylesheet" href="/style.css" type="text/css">
</head>
<body>
<h1 align="center">Host: $hostname</h1>
<pre>
HTML

if ($ip_address !~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) {
    print STDERR "Unable to determine IP address. Exiting ...\n";
    exit;
}

if ($debug) {
    print "Hostname: $hostname IP: $ip_address<br>\n";
}

# Create SSH to host machine
$Expect::Log_Stdout=1;
my $stdin=Expect->exp_init(\*STDIN);
my $stdout=Expect->exp_init(\*STDOUT);
my $sh;

$sh=Expect->spawn('telnet','192.168.1.5') or die "spawn failed";

$sh->log_user(1);

$sh->expect(10,
        [
  qr'login: $',
  sub {
    my $fh = shift;
    print $fh "rock\r";
    exp_continue;
  }
        ],
        [
  qr'Password: $',
  sub {
    my $fh = shift;
    print $fh "password123\r";
    exp_continue;
  }
        ],
               [
  timeout =>
  sub {
    die "No login.\n";
  }
        ],
               '-re', qr'[#>:] $', #' wait for shell prompt, then exit
expect
    );

$sh->interact();

$sh->hard_close;

print <<"HTML";
</pre>
</body>
</html>
HTML

exit;
----------------end code------------



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

Date: Tue, 19 Jun 2001 12:24:02 -0700
From: Michael Budash <mbudash@sonic.net>
Subject: Re: CGI.pm, cookies and redirect PLS HELP!
Message-Id: <mbudash-7E8C03.12240219062001@news.pacbell.net>

In article <20010619135922.08314.00000038@ng-cm1.aol.com>, 
cperl520335@aol.com (CPERL520335) wrote:

> I have a script that sets a cookie, then re-directs the browser.
> 
> It's all been working great with the code:-
> 
>   @months =
> ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
>   @days = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
>   ($sec,$min,$hr,$mday,$mon,$yr,$wday,$yday,$isdst) = gmtime(time +
> $cookietime);
>   $timestr = sprintf("%3s, %02d-%3s-%4d %02d:%02d:%02d GMT",
> $days[$wday],$mday,$months[$mon],$yr+1900,$hr,$min,$sec);
>   print "Set-Cookie: AFFILIATE=$userhandle; path=/; expires=$timestr\n";
> 
> 
> followed later by:-
> 
> print "Location: $site1\n\n";
> 
> But now that I'm converting the script to NT the set cookies code isn't
> working.
> 
> I looked at the activestate FAQ, and followed instructions to use 
> CGI.pm's set
> cookie function. So now I have:-
> 
>   $cookietime = "+" . $cookietime . "h";
>   $query = new CGI; 
>   $my_cookie = $query->cookie(-name=>'AFFILIATE', -value=>$userhandle,
> -expires=>$cookietime, -path=>'/');
>   print $query->header(-cookie=>$my_cookie);
> 
> Which works great, but the problem is now that the redirect isn't 
> working. So I
> changed the redirect to the CGI.pm version:-
> 
>   print $query->redirect($site1);
> 
> Which doesn't work either. The "Location: http://......" just get 
> displayed on
> the page.
> 
> So you see my dilema.
> 

drop the 'print $query->header' line and mod your redirect thusly:

print $query->redirect(-location=>$site1,
                       -cookie=>$mycookie);

hth-
-- 
Michael Budash ~~~~~~~~~~ mbudash@sonic.net


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

Date: Tue, 19 Jun 2001 18:19:46 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Fetching CGI data as a hash (was DBM in a CGI)
Message-Id: <992974786.574449774809182.gnarinn@hotmail.com>

In article <Pine.LNX.4.30.0106191655420.19696-100000@s1.uklinux.net>,
Jason Clifford  <jason@uklinux.net> wrote:
>On Tue, 19 Jun 2001, Amittai Aviram wrote:
>
>>
>> %fields = $query->Vars;
>
>This is not supported. You need to do something along the lines of:

upgrade your CGI.pm.

gnari





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

Date: Tue, 19 Jun 2001 12:55:09 -0700
From: Marco UClink <mblanche@uclink.berkeley.edu>
Subject: Get all the possibilities
Message-Id: <B754FC2C.1A59%mblanche@uclink.berkeley.edu>

I am trying to write a small Perl script that display all the possible
strings from 1 character long to x characters long using a 4 letter alphabet
(A,G,C,T). I mean A\n C\n G\n T\n AA\n AC\n AG\n AT\n CA\n etc... I am sure
this is pretty simple but I donšt have the training to resolve the issue.

Any sugestions?



Marco Blanchette, Ph.D.

mblanche@uclink.berkeley.edu

Donald C. Rio's lab
Departement of Molecular and Cell Biology
University of California




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

Date: Tue, 19 Jun 2001 20:41:24 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Get all the possibilities
Message-Id: <tive7kbbn4hf1f@corp.supernews.com>

In article <B754FC2C.1A59%mblanche@uclink.berkeley.edu>,
    Marco UClink  <mblanche@uclink.berkeley.edu> wrote:

: I am trying to write a small Perl script that display all the possible
: strings from 1 character long to x characters long using a 4 letter alphabet
: (A,G,C,T). I mean A\n C\n G\n T\n AA\n AC\n AG\n AT\n CA\n etc... I am sure
: this is pretty simple but I donšt have the training to resolve the issue.
: 
: Any sugestions?

Use recursion:

    #! /usr/local/bin/perl -w

    use strict;

    sub strings {
        my $alpha = shift;
        my $len   = shift;

        return unless $alpha && @$alpha && $len > 0;

        my @result;
        if ($len == 1) {
            @result = map [ $_ ], @$alpha;
        }
        else {
            my @sub = strings($alpha, $len-1);

            foreach my $ltr (@$alpha) {
                foreach my $sub (@sub) {
                    push @result => [ $ltr, @$sub ];
                }
            }
        }

        @result;
    }

    for (1 .. 4) {
        for (strings [ qw/ A G C T / ] => $_) {
            print join('', @$_), "\n";
        }
    }

You could probably speed this up tremendously with the Memoize module
that's available on the CPAN.

Hope this helps,
Greg
-- 
/*
** the usual core dumping code
*/
    -- Juergen Heinzl


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

Date: Tue, 19 Jun 2001 16:40:56 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: Get all the possibilities
Message-Id: <3B2F3A47.693942A8@ce.gatech.edu>

Marco UClink wrote:

> I am trying to write a small Perl script that display all the possible
> strings from 1 character long to x characters long using a 4 letter alphabet
> (A,G,C,T). I mean A\n C\n G\n T\n AA\n AC\n AG\n AT\n CA\n etc... I am sure
> this is pretty simple but I donšt have the training to resolve the issue.
>
> Any sugestions?
>
> Marco Blanchette, Ph.D.
>
> mblanche@uclink.berkeley.edu
>
> Donald C. Rio's lab
> Departement of Molecular and Cell Biology
> University of California

perldoc -q permute

might get you started.



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

Date: 19 Jun 2001 15:19:52 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Get all the possibilities
Message-Id: <m3ithsdxxz.fsf@dhcp9-173.support.tivoli.com>

On Tue, 19 Jun 2001, mblanche@uclink.berkeley.edu wrote:

> I am trying to write a small Perl script that display all the
> possible strings from 1 character long to x characters long using a
> 4 letter alphabet (A,G,C,T). I mean A\n C\n G\n T\n AA\n AC\n AG\n
> AT\n CA\n etc... I am sure this is pretty simple but I donšt have
> the training to resolve the issue.

I believe a similar question has been asked recently on this group.  A
groups.google.com search for "permutations" might reveal it.

Here's one solution that I just threw together (meaning I think it
works OK, but it isn't thoroughly tested):

#!/usr/bin/perl
use strict;
use warnings;
my @parts = qw/A G C T/;
sub permute {  # poor name as this includes sub-permutations
  my ($first, @rest) = @_;
  return [ $first ] unless @rest;  # end of recursion; last element
  my @result;
  for my $perm (permute(@rest)) {
    push @result,
      map { [@$perm[0..$_-1], $first, @$perm[$_..$#{$perm}]] } 0..@$perm;
    push @result, [ @$perm ];  # sub-permutations included here
  }
  push @result, [ $first ];    # first element included here
  @result;
}
print @$_,"\n" for permute @parts;
__END__

-- 
Ren Maddox
ren@tivoli.com


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

Date: 19 Jun 2001 14:01:41 -0600
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: getsockopt and setsockopt: SO_RCVBUF unsupported?
Message-Id: <9gob35$l14@flatland.dimensional.com>

esteban0@excite.com (Stephen Scheck) writes:

> I'm trying, with no success, to get getsockopt() and setsockopt()
> to show or set a socket's SOL_SOCKET SO_RCVBUF option. Here's
> what I'm doing:
>
> $value = getsockopt($socket, &SOL_SOCKET, &SO_RCVBUF);
> print "$value\n" if ( defined($value) );

You'll need to unpack the value returned by getsockopt().  On my
system, most socket options are integers, so the following would
work:

$rcvbuf = unpack("i", $value);

The perlipc manual page has a couple of examples packing longs
instead of integers in calls to setsockopt(), so you may wish to
check your system's documentation.  Longs and integers are the same
on some systems so it may not matter, but I prefer to use the type
that's documented.

> $result = setsockopt($socket, &SOL_SOCKET, &SO_RCVBUF, 64 * 1024);
> die("uh oh!") if ( ! defined($result) );

Try packing the value, like this:

$result = setsockopt($socket, &SOL_SOCKET, &SO_RCVBUF, pack("i", 64 * 1024));

Hope this helps.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


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

Date: Tue, 19 Jun 2001 20:19:38 +0200
From: Bruno Montagnac <bruno.montagnac@renault.com>
Subject: Re: HowTo: Run a command in backticks as root?
Message-Id: <3B2F97B8.60BFE964@renault.com>

hi,

it's typically an UNIX pb, not a Perl one...
if u want to run a process with root rights, u'll have to "give" the
binary to root (chown) & to activate the suid bit (chmod)
then, u can run the nmap binary from Perl under the apache user (the
process will still be owned by root)
remember to set acces rights on for the apache user (others +rx or with
ACLs may be)

take care to nmap safety... or only give read/exec rights to apache user
(playing with a subdirectory set) to avoid everyone launch it...

Simon Devlin wrote:

> [---snip---]
> I have a utility (a portscanner) that needs to be run as root in order
> to function fully.
> [---snip---]
> $command="nmap -sS -O -oX - 10.1.1.1-255 |";
> [---snip---]
> Basically, it's fine, but some of the features, require that NMAP be
> run as root, and I'm not sure how to make perl do this.
> [---snip---]
> Note, that in this instance, the perl program is running under the
> apache user as the result of a webfronted report generator.
> [---snip---]

--
 //\  Bruno Montagnac
// \\ DTSI/DSO/Service:18741
\\ // XX XXX XX XXX [API:SQY-OVA-613]
 \//  Technocentre RENAULT (Place Ovale)





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

Date: Thu, 14 Jun 2001 10:48:15 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: initialising multi-dimensional array
Message-Id: <3B28DCBF.2C01CD63@home.com>

Mark Grimshaw wrote:
> 
> Anno Siegel wrote:
>>
>> You should acquaint yourself with the way Perl treats an undefined
>> value in numeric context, and its interaction with warnings.  You 
>> will probably find you don't have to initialize the array after all.
> 
> It's not exactly a numeric context.  I simply print the element 
> value back to a browser.  If it's undef it prints nothing.  I want
> it to print 0.

So use || to default the print():

print $x[4][7] || 0;

> I was wondering if there was a special variable to do this for me
> [...]
> Perhaps I shouldn't have used the words 'initialise everything' but
> the words 'override the default undef setting for empty array slots'.

No, there is no special setting to default unitialized variables to 
something other than undef. Until you define something, it's undefined.

If you could determine how large your array is going to be before you
start populating it, then you could initialize everything up front. But
if it grows during the execution of your program, you don't really have
an option other than traversing it, looking at each element, and 
defaulting it to zero if it's undefined. Or, as I said, you could just
modify the print() to handle undefined values.

-mjc


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

Date: Tue, 19 Jun 2001 19:19:11 +0100
From: "Darren Thorpe" <daz.thorpe@virgin.net>
Subject: Interfacing to Microsoft Outlook!
Message-Id: <RvMX6.3459$Kj.413827@news2-win.server.ntlworld.com>

Hi,

I don't know if anybody can help, but....

I want to create an Accept/Decline response to a Microsoft Outlook meeting
request. Here's the process:

1. Invite attendees to a meeting. Include a link to a web page that allows
the invitee to accept or decline the invitation.

2. Invitee reviews meeting request and uses the hyper link to open a web
page that generates the appropiate accept decline response back to the
senders Outlook.

I don't want to bore anyone with the reasons for doing this (although if
you're interested...), but I've been struggling on this for some time now.
Any pointers would be great.

Cheers, Darren.




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

Date: Tue, 19 Jun 2001 18:21:38 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Looking for descriptions of IngPerl Functions and Variables in Perl v5
Message-Id: <992974898.0943080922588706.gnarinn@hotmail.com>

In article <GF6psE.uLr@alfalfa.utcs.utoronto.ca>,
Daniel Czajko <czajko@ocas.on.ca> wrote:
>Anybody knows where I can find those descriptions?
>

perldoc perlfunc
perldoc perlvar

Is this what you mean?

gnari


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

Date: 19 Jun 2001 14:28:21 -0400
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: matching a list with a regex
Message-Id: <7aae34b9yy.fsf@merlin.rene.hyperchip.com>


Bart Lateur <bart.lateur@skynet.be> writes:

> This is a working solution:
> 
> 	/\((?:(?:\d+|"[^"]*")(?:,(?:\d+|"[^"]*"))*)?\)/
> 
> but the repetition of the term pattern is ugly, especially since my real
> pattern will be more complex than this. Ideally, I'd want something that
> is only half as big as this one...

I can't think of anything better except for using qr// (which is not
really what you're asking for, but I think it makes it more manageable):

PS. UNTESTED:

	my $re = qr{(?:\d+|"[^"]*")};

	/\((?:$re(?:,$re)*)?\)/

--Ala


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

Date: 19 Jun 2001 12:18:06 -0700
From: doug.mcgrath@us.telegyr.com (Doug McGrath)
Subject: Re: Memory Issues/File Slurping
Message-Id: <a4e10296.0106191118.6121f86c@posting.google.com>

> It's a typo.  Another is that the line:
> 	my $string = qr[ \@((:[^\@]|\@\@)*))\@ ];
> should either be:
> 	my $string = qr[ \@((?:[^\@]|\@\@)*))\@ ]x;
> or
> 	my $string = qr[\@((?:[^\@]|\@\@)*))\@];
> since the spaces aren't meant to be part of the string.  I'm not
> entirely sure, but the following change might [or might not] improve it:
> 	my $string = qr[ \@((?:[^\@]+|\@\@)*))\@ ]x;

I wondered if it might be just a typo, but I didn't want to appear
overly foolish...

With the various changes, my script is now able to run through the
entire repository without dying from lack of memory or thrashing so
badly that it drags nearly to a halt -- thank you!

One of things that's been bugging me in the original work that I had
was the following:

    $line =~ m/\Gstrict;/;

In this instance, $line contained the entire contents of a 25 MB
repository file, and the previous matches had set pos($line) to one
character (which was a space) before "strict;" occured in the string.

According to "ps agxv" before and after the line, the memory usage of
my script jumped 16 MB for this pattern match, and I'm at a loss to
explain why.

I could understand if there were wild cards and the regex engine had
to build a huge tree of possible matches, but in this case, there's
only one possible match with the anchor, and it seems like it should
either succeed or fail immediately with only a few bytes built up into
the match.

It's clear to me that writing efficient regex's on files of this size
require that I understand the process that the regex engine is going
through, but it's also clear to me that I currently don't because I
have absolutely NO explanation for the above behavior.

Thanks,
Doug McGrath


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

Date: Tue, 19 Jun 2001 22:40:40 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: memory-leaks (in mod_perl)
Message-Id: <3b2fb8c9$1@e-post.inode.at>


I've a strange memleak (like all memleaks are) and want to know if there is 
a way to tell how many references (and which) point to a certain construct 
(anymous hashes and arrays in my case) ?

Second I'd like to know, if there is way to manually delete a anonymous 
construct or 'free' the mem allocated by it ?

My problem in detail:

I've a script that is running for long time (module in mod_perl) and 
obviously has a memory leak. The main-data-structure in my program is a 
anonymous hash whose entries are mostly anonmous hashes, subs, lists etc. 
again.
I can extend the leaking-effect by just adding an anoymous 20MB-Array to 
the hash in the init-sub, so my system get in big trouble after 5,6 calls 
 ...

My problem: Can a script be mem-leaking without having any global variable 
? The calling script calls the init-sub of the module that delivers the 
described hashpointer, which is passed as argument to any further sub.
I cant imagine of any way there can be memleaking when doing it this way.
At least when the last sub is closed, all reference-counters should be zero 
again ...

However there is another strange thing: when I manually delete the hash_ptr 
to the bigarray the leaking is reduced by its big size. Shouldnt it be 
deleted anyway when leaving the script ?
Or : If any other reference points to bigarray, deleting the hash-entry 
shouldnt free the allocated mem at all ?

I'm doomed ....
thnx for help,
peter


Scheme (cant post the whole project, that has actually more than 5000 lines 
of code)
----module---------
package my pack
use strict;

sub init
{
  my $ptr={};
  $ptr->{big}=[]; $#{$ptr->{big}}=20_000_000;
  $ptr->{other}=somehing;
  return $ptr;
}

lot of subs like
sub example
{
  my $ptr=shift;
  my $a=other_sub($ptr)+1;
  $ptr->{val1}+=$a;
  return $a; 
}

----calling script-------
use module qw (init example)

main();


sub main
{
   my $ptr=module::init();
   my $x=sub1($ptr);
   my $y=sub2($ptr,x);

   # uncommenting the next line will reduce leaking by amount of bigarray !
   # delete($ptr->{bigarray});
  
}

sub1
{ 
  my $ptr=shift;
  $ptr->{val2}=example($ptr);
}
sub2
{ 
  my $ptr=shift;
  print $ptr->{val1},"\n";
}



-- 
pilsl_@goldfisch.at
http://www.goldfisch.at


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

Date: Tue, 19 Jun 2001 18:51:33 GMT
From: treblig@NOSPAM.ix.netcom.com (G Chew)
Subject: OLE automation w/ MS Word
Message-Id: <3b2f9da2.14238638@nntp.ix.netcom.com>

Hello,

I'm trying to implement a script that reads a text file and writes it
out in MS Word format.  I decided to use the Win32 OLE module to start
up an instance of MS Word and have it do the heavy lifting.  Here's a
code snippet where I fire up Word:


	my ($FullFolderPath, @Names) = @_;
	my ($Name,$FileName,$FileNamePath);
	use strict;
	use Win32::OLE;
	use Win32::OLE::Const 'Microsoft Word';

	my $Word = Win32::OLE->new('Word.Application',
sub{$_[0]->Quit;}) || die "Oops, cannot start
Word:".Win32::OLE->LastError();


The script as a whole does what I want it to do when I tested it out
on my desktop PC (Win 98, Office 2000).  However, when I copied it to
a web server (Win NT, Office 2000 installed), I get the following
message:


Oops, cannot start Word:Win32::OLE(0.1501) error 0x8001010a: "The
message filter indicated that the application is busy" at
F:\inetpub\www\scripts\FatMat.pl line 842.


There doesn't appear to be any other instance of Winword running on
the server.  Frankly, I'm stumped.  Why would the script work
correctly on my desktop and not the server?  Why is the application
busy?  Does anyone have any suggestions?

Thanks,

Gilbert




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

Date: Tue, 19 Jun 2001 19:36:52 -0000
From: Egghead (googlenews@edge-web.com)
Subject: Regexps, using variables to get $1, $2, etc.
Message-Id: <tivaek8bf22n77@corp.supernews.com>

I'd like to take a string, match and store patterns within the string using
a regexp defined in a variable ($match) which stores values in $1, $2, $`, etc.
Then I'd like to get the data contained in the read-only variables and
manipulate it with another variable ($replace).

Sorry, can't describe it better than that. Here's the script:

$string = 'this.20010420162000.txt';
$match = '^th(.*?)\.(\d{14})\.txt$';
$replace = '$1.during.$2';

if($string =~ /$match/) {
  # what to do now? $replace should be 'is.during.20010420162000'
  # I've tried:
  # $new = $replace;
  # $new = eval($replace);
  # some other variants of the same
  # none work
}

If this is documented anywhere I'd love to see it, maybe I need to use map or
something like that, I just can't figure it out. Appreciate your input.

thanks!


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

Date: 19 Jun 2001 14:59:19 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Regexps, using variables to get $1, $2, etc.
Message-Id: <m3ofrkdyw8.fsf@dhcp9-173.support.tivoli.com>

On Tue, 19 Jun 2001, Egghead wrote:

> I'd like to take a string, match and store patterns within the
> string using a regexp defined in a variable ($match) which stores
> values in $1, $2, $`, etc.  Then I'd like to get the data contained
> in the read-only variables and manipulate it with another variable
> ($replace).
> 
> Sorry, can't describe it better than that. Here's the script:
> 
> $string = 'this.20010420162000.txt';
> $match = '^th(.*?)\.(\d{14})\.txt$';
> $replace = '$1.during.$2';
> 
> if($string =~ /$match/) {
>   # what to do now? $replace should be 'is.during.20010420162000'
>   # I've tried:
>   # $new = $replace;
>   # $new = eval($replace);
>   # some other variants of the same
>   # none work

      $new = eval qq/"$replace"/;

> }
> 
> If this is documented anywhere I'd love to see it, maybe I need to
> use map or something like that, I just can't figure it
> out. Appreciate your input.

I don't like the eval in this solution, but I think it is actually
safe as long as the value of $replace is controlled.  That is, the
value of $string cannot be manipulated to lead to execution of
arbitrary code.  (The value of $replace certainly can.)

Better would be to rework the methodology a bit.  If nothing else,
something like:

if(my @matches = $string =~ /$match/) {
  ($new = $replace) =~ s/\$(\d+)/$matches[$1-1]/g;
}

is a big improvement.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Tue, 19 Jun 2001 20:21:55 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Regexps, using variables to get $1, $2, etc.
Message-Id: <tivd33mffdlbd4@corp.supernews.com>

In article <tivaek8bf22n77@corp.supernews.com>,
    googlenews@edge-web.com <Egghead> wrote:

: I'd like to take a string, match and store patterns within the string
: using a regexp defined in a variable ($match) which stores values in
: $1, $2, $`, etc. Then I'd like to get the data contained in the
: read-only variables and manipulate it with another variable
: ($replace).
: 
: [snip]
: 
: If this is documented anywhere I'd love to see it, maybe I need to use
: map or something like that, I just can't figure it out. Appreciate
: your input.

Using the technique from "How do I expand variables in text strings?"
in Section 4 of the Perl FAQ, I used the following:

    % cat try
    #! /usr/local/bin/perl -w

    use strict;

    my $string  = 'this.20010420162000.txt';
    my $match   = '^th(.*?)\.(\d{14})\.txt$';
    my $replace = '$1.during.$2';
    my $result;

    if (my @saved = $string =~ /$match/) {
        my $i = 1;
        my %match = map +($i++ => $_), @saved;

        ($result = $replace) =~ s/\$(\w+)/$match{$1}/g;
        print "result = '$result'\n";
    }
    else {
        print "No match.\n";
    }
    % ./try
    result = 'is.during.20010420162000'

I had to use the map because the s/// would change the values of
$1, $2, and friends.

If you want to add $`, $&, and $', then you need to make some changes:

    #! /usr/local/bin/perl -w

    use strict;

    my $string  = 'this.20010420162000.txt';
    my $match   = '^th(.*?)\.(\d{14})\.txt$';
    my $replace = '$1.during.$2.$&';
    my $result;

    if (my @matches = $string =~ /$match/) {
        my %match;
        for (1 .. @matches, qw/ ` & ' /) {
            no strict 'refs';
            $match{$_} = ${$_};
        }

        ($result = $replace) =~ s/\$([\w`&']+)/$match{$1}/g;
        print "result = '$result'\n";
    }
    else {
        print "No match.\n";
    }

Hope this helps,
Greg
-- 
Government seems to operate on the principle that if even one individual
is incapable of using his freedom competently, no one can be allowed to
be free.
    -- Harry Browne


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

Date: Tue, 19 Jun 2001 20:56:16 +0200
From: Philip Newton <pne-news-20010619@newton.digitalspace.net>
Subject: Re: Removing ^M characters
Message-Id: <1i6vito507i958844ee8saacesm06vpeer@4ax.com>

[modules & tk removed]

On Sun, 17 Jun 2001 15:37:37 -0400, "Mr. Ozette Brown"
<ozette@ozette.net> wrote:

> Under Windows:
> perl -pi.bak -e 's/\cM$//' filename.txt

Bzzt, wrong. At least running under command.com.

Firstly, Perl there will read the file in text mode (since you didn't
binmode() anywhere) and will never see a "\cM", since the C I/O library
will have turned CRLF into a plain LF, and secondly, you'd need to use
double quotes instead of single quotes.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Tue, 19 Jun 2001 18:04:14 GMT
From: igor@hybrid-lab.net.nospam (Igor Mozolevsky)
Subject: Re: Setting Return-Path in sendmail from Perl
Message-Id: <Xns90C5C177F65A0IDIMOZ.NEUTRON.1@62.253.162.107>

"Steven Stalzer" <steve@newmediacreations.com> wrote in
news:dbMX6.46110$Ua3.3684466@typhoon2.ba-dsg.net: 

> I am hoping to do something like this: 
>     open(MAIL,"|$mailprog -t");
>     print MAIL "To: $email\n";
>     print MAIL "From: $steve\n";
>     print MAIL "Return-Path: $bounce_alias\n";
>     print MAIL "Subject: $subject\n\n" ;
> 

You can't just add a return-path as sendmail adds another one at the point 
of delivery, just use a valid from.

IM :-)


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

Date: 19 Jun 2001 18:54:41 GMT
From: mallet.I_Kill_Spammers@cluestick.org (Suresh Ramasubramanian)
Subject: Re: Setting Return-Path in sendmail from Perl
Message-Id: <slrn9iv8eq.5g.mallet.I_Kill_Spammers@blackehlo.cluestick.org>

Igor Mozolevsky proclaimed on comp.mail.sendmail that:
>  "Steven Stalzer" <steve@newmediacreations.com> wrote in
>  news:dbMX6.46110$Ua3.3684466@typhoon2.ba-dsg.net: 
>  
> > I am hoping to do something like this: 
> >     open(MAIL,"|$mailprog -t");
> >     print MAIL "To: $email\n";
> >     print MAIL "From: $steve\n";
> >     print MAIL "Return-Path: $bounce_alias\n";
> >     print MAIL "Subject: $subject\n\n" ;
> > 
>  
>  You can't just add a return-path as sendmail adds another one at the point 
>  of delivery, just use a valid from.
 
 And call sendmail with -f to set the envelope sender.

 	--suresh

-- 
Suresh Ramasubramanian + Wallopus Malletus Indigenensis
mallet @ cluestick.org + Lumber Cartel of India, tinlcI
EMail Sturmbannfuhrer, Lower Middle Class Unix Sysadmin  


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

Date: Tue, 19 Jun 2001 21:07:46 GMT
From: tuxy <nospam@cfl.rr.com>
Subject: Why does this split not work?
Message-Id: <3B2F8801.3473B055@cfl.rr.com>

I'm trying to split a pretty large buffer (>1000 lines) into sections
based on a line that looks like

	NAME Jane Doe

The file is a series of name-values like

	NAME Jane Doe
	AGE 21
	ADDRESS Anytown USA
	!
	NAME John Smith
           . 
           .



so I'm using something like

   my @people=split /^\s*NAME\s+/m,$buf;

and I'm getting very odd results. It consistently fails with this
message:

   Use of uninitialized value in split at datax.pm line 447, <IN> line
21 (#1)

which I cannot comprehend. I checked perldoc perlfunc for split and
didn't see anything that looked like this problem discussed.  How could
something be "uninitialized"? $buf is definitely initialized since I
guess from the message it managed to get through 10 lines of it before
it failed. What could be "uninitialized" at line 10? Even empty lines
parse OK with /m.

Another oddity- tweaking the code above this line (for unrelated tasks)
CHANGES the line this fails at- sometimes it says <IN> line 2, line 10,
21, etc for the exact same input file. I looked at the file and see
nothing unusual on any of those lines. I also turned on diagnostics and
it didn't offer any further insight.

By the way, the resultant array is one element which contains the entire
buffer, even though there are many lines that meet the regex criteria.

Strangeness!

Thank-You....


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

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.  

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


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