[16835] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4247 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 7 11:05:32 2000

Date: Thu, 7 Sep 2000 08:05:12 -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: <968339112-v9-i4247@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 7 Sep 2000     Volume: 9 Number: 4247

Today's topics:
    Re: Bit fields in perl <sb@muccpu1.muc.sdm.de>
        Calling a C program haytog@my-deja.com
        Calling a C program haytog@my-deja.com
    Re: Calling a C program <foo@bar.va>
        CGI/perl    "open" (Ivan Lee)
    Re: CGI/perl    "open" <care227@attglobal.net>
        Font Color in CGI w/OOP <kliquori@my-deja.com>
        ftp and chmod program tobiwan@my-deja.com
    Re: ftp and chmod program <Peter.Dintelmann@dresdner-bank.com>
    Re: ftp and chmod program (Rafael Garcia-Suarez)
    Re: ftp and chmod program tobiwan@my-deja.com
    Re: ftp and chmod program (Mark-Jason Dominus)
    Re: Getting a range of rows with DBI <nospam@jsoft.xs4all.nl>
    Re: Help needed - regexp (Smylers)
    Re: Help needed - regexp (Mark-Jason Dominus)
    Re: help with net::ftp->login <peckert@epicrealm.com>
    Re: how is everyone? <bart.lateur@skynet.be>
    Re: how to  encrypt source code? <dsa@dassda.com>
    Re: How to create a simple backup program? <bart.lateur@skynet.be>
    Re: HTML::parse bug <bart.lateur@skynet.be>
    Re: HTML::parse bug <T.Cockle@staffs.ac.uk>
        memory leak with subroutine references <oliver.ebenhoeh@rz.hu-berlin.de>
        my()inside if{...}, how to make vars visible <samara_biz@hotmail.com>
    Re: my()inside if{...}, how to make vars visible <aqumsieh@hyperchip.com>
    Re: newbie: redirect problem <bart.lateur@skynet.be>
    Re: newbie: redirect problem <bart.lateur@skynet.be>
    Re: newbie: redirect problem <bart.lateur@skynet.be>
    Re: newbie: redirect problem <christopher_j@uswest.net>
    Re: perl & htaccess <godoy@conectiva.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 7 Sep 2000 11:53:15 GMT
From: Steffen Beyer <sb@muccpu1.muc.sdm.de>
Subject: Re: Bit fields in perl
Message-Id: <8p7vjb$rq6$1@solti3.sdm.de>

In article <13AD5852E1762059.56CCBEB6EA96D246.128621E87CFADD3F@lp.airnews.net>, David E. Vandewalle <vandewal@skyblue.com> wrote:

> I need to do something in perl invloving packed binary data that is a little
> different
> than anything else I have ever done in perl.  Although I have figured out a way
> to do it,
> it seems like a kludge, and I'm looking for a cleaner method.  

> Here's the deal:

> I've got a text file full of hex data in 16 bit words.
> (it's a dump of a MIL-STD-1553 message buffer ... if anyone cares)

> looks kinda like this:
> 1234 ABCD 1234 ABCD 1234 ABCD 1234 ABCD
> 1234 ABCD 1234 ABCD 1234 ABCD 1234 ABCD
> 1234 ABCD 1234 ABCD 1234 ABCD 1234 ABCD
> 1234 ABCD 1234 ABCD 1234 ABCD 1234

> Now, if all of the data were in chunks that were multiples of one word,
> I would be ready to rock, but that would be _far_ too easy.

> What I've got is multiple fields of various lengths packed into each word. 
> Luckily fields
> are not allowed to span between words.  Fields can be (and are) any length from 
> 1 bit to 16 bits.

> I have another text file that describes the word number and bit locations of
> each
> field. (it's actually an ada source module ... if anyone cares)

> After reading up on pack/unpack my initial thought at how to attack this was to
> read each word as a scalar, unpack into a binary string of 16 ones/zeros, hack
> off 
> the leading/trailing places I don't need, and then convert back to scalar. Or
> something
> along those lines.

> Is there a simpler, faster, or more elegant way to do this than what I'm
> describing?

> any and all input is greatly appreciated, and thanks for the time.
> /dev

This kind of problem is exactly what the Bit::Vector module has been
written for! (See especially the function "Chunk_Read()".)

See http://www.engelschall.com/u/sb/download/pkg/Bit-Vector-5.8.tar.gz
 or http://www.perl.com/CPAN/modules/by-module/Bit/Bit-Vector-5.8.tar.gz

Hope this helps!
-- 
    Steffen Beyer <sb@engelschall.com>
    http://www.engelschall.com/u/sb/whoami/ (Who am I)
    http://www.engelschall.com/u/sb/gallery/ (Fotos Brasil, USA, ...)
    http://www.engelschall.com/u/sb/download/ (Free Perl and C Software)


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

Date: Thu, 07 Sep 2000 14:00:32 GMT
From: haytog@my-deja.com
Subject: Calling a C program
Message-Id: <8p871i$j6n$1@nnrp1.deja.com>

Hi,

I need to call a C program from a Perl script, I am pretty new to Perl.

I have seen an example to call the C program

open (PROG , "/usr/local/smsnd"|);
while (<PROG>)
{
print;
}
close (PROG);

I need to get the returned value from the C program which will be in the
form of an integer.  I don't require any output from the C program at
all.

Is there a simpler way of doing this and reading the returned value from
the C program in the perl script ?


Thanks


Chris


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 07 Sep 2000 14:00:20 GMT
From: haytog@my-deja.com
Subject: Calling a C program
Message-Id: <8p8717$j6i$1@nnrp1.deja.com>

Hi,

I need to call a C program from a Perl script, I am pretty new to Perl.

I have seen an example to call the C program

open (PROG , "/usr/local/smsnd"|);
while (<PROG>)
{
print;
}
close (PROG);

I need to get the returned value from the C program which will be in the
form of an integer.  I don't require any output from the C program at
all.

Is there a simpler way of doing this and reading the returned value from
the C program in the perl script ?


Thanks

Chris


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 07 Sep 2000 16:46:52 +0200
From: Marco Natoni <foo@bar.va>
Subject: Re: Calling a C program
Message-Id: <39B7AA5C.C280887E@bar.va>

Chris,

haytog@my-deja.com wrote:
> I need to call a C program from a Perl script, I am pretty new 
> to Perl.

  If the program is already compiled in an executable and if it is
structured as the ISO standard recite and if if it returns something and
if your operating system handles correctly the return values of its
programs, you can obtain what you are searching for with the Perl sub
/system/.

	$ret_val=system $path_of_the_exe;

> I have seen an example to call the C program> 
> open (PROG , "/usr/local/smsnd"|);
> while (<PROG>)
> {
> print;
> }
> close (PROG);

  This is an uncorrect way to open a pipe with a program.  Using a pipe
you can obtain the data stream coming from the program standard output,
not its return value.  If that is what you want, you can easily reach it
via the following statement:

	$prg_out=`$path_of_the_exe`;

if you want the output as a single string or

	@prg_out=`$path_of_the_exe`;

if you want the output as an array of lines.

  More info at:

	$ perldoc -f system
	$ perldoc perlop


	Best regards,
		Marco


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

Date: Thu, 07 Sep 2000 15:27:10 GMT
From: ginola@mailcity.com (Ivan Lee)
Subject: CGI/perl    "open"
Message-Id: <39b7b3bc.8138192@news.alphalink.com.au>

Hi,
I have a line like below
open(GUESTBOOK_IN, "../view.html");
because the server of cgi is automatic link to the server only for
cgi, so is that possible to  do the
"http://hostname/~username/view.html"
instead of ../view.html

Thanks

**************************************
¯u ¸ô ®³ Ivan Lee
http://www.geocities.com/ginola79/
http://www.geocities.com/ivanlee79/


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

Date: 07 Sep 2000 15:01:59 GMT
From: Drew Simonis <care227@attglobal.net>
Subject: Re: CGI/perl    "open"
Message-Id: <39B7AB68.3967A21@attglobal.net>

Ivan Lee wrote:
> 
> Hi,
> I have a line like below
> open(GUESTBOOK_IN, "../view.html");
> because the server of cgi is automatic link to the server only for
> cgi, so is that possible to  do the
> "http://hostname/~username/view.html"
> instead of ../view.html

Don't be so lazy.  This one is so easy to try, you should be ashamed
of yourself for not making that small effort.  

see:

$ perldoc -f open

for documentation of the open function.  And do try, you'll learn
far more, far faster, if you experiment a bit on your own.


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

Date: Thu, 07 Sep 2000 13:21:34 GMT
From: kliquori <kliquori@my-deja.com>
Subject: Font Color in CGI w/OOP
Message-Id: <8p84oa$gbr$1@nnrp1.deja.com>

I am trying to set the font color in a CGI script. Currently I'm using:

print "<font color=\"#ff0000\">MY TEXT</font>";

But I would like to use objects. For example, for a new line I'm using:

print $q->br;

Is there a way to do this with objects? I couldn't find the answer in
O'Reilly's _CGI Programming with Perl_.

TIA
 ...Kevin


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 07 Sep 2000 10:46:29 GMT
From: tobiwan@my-deja.com
Subject: ftp and chmod program
Message-Id: <8p7rm1$6fs$1@nnrp1.deja.com>

 I'd like to write a perl program (not a cgi script) that will
automatically ftp some files to a remote machine, and change the
permissions on them _on the remote machine_.

I know how to ftp a file, and I know how to use chmod on a file on my
local machine - but not how to change permissions via ftp.

Any help appreciated.

--

Cheers,
Toby


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 7 Sep 2000 13:19:19 +0200
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: ftp and chmod program
Message-Id: <8p7tk0$h1@intranews.bank.dresdner.net>

    Hi,

tobiwan@my-deja.com schrieb in Nachricht
<8p7rm1$6fs$1@nnrp1.deja.com>...

    [snip]

>I know how to ftp a file, and I know how to use chmod on a file on my
>local machine - but not how to change permissions via ftp.

    so you are really facing a FTP problem and not a
    Perl problem since you do not know how to achieve
    your chmod at a FTP prompt.
    My FTP does not list any commands to do a chmod
    on the remote side.

    Regards,

        Peter Dintelmann






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

Date: Thu, 07 Sep 2000 11:58:18 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: ftp and chmod program
Message-Id: <slrn8rf12c.3p0.rgarciasuarez@rafael.kazibao.net>

tobiwan@my-deja.com wrote in comp.lang.perl.misc:
> I'd like to write a perl program (not a cgi script) that will
>automatically ftp some files to a remote machine, and change the
>permissions on them _on the remote machine_.
>
>I know how to ftp a file, and I know how to use chmod on a file on my
>local machine - but not how to change permissions via ftp.

The question is : does the ftp server support the chmod command? (type
'help' at the ftp command-line prompt to know).

If it does, you can subclass Net::FTP to add this command.

-- 
Rafael Garcia-Suarez | http://rgarciasuarez.free.fr/


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

Date: Thu, 07 Sep 2000 12:45:09 GMT
From: tobiwan@my-deja.com
Subject: Re: ftp and chmod program
Message-Id: <8p82kg$dul$1@nnrp1.deja.com>

In article <slrn8rf12c.3p0.rgarciasuarez@rafael.kazibao.net>,
  rgarciasuarez@free.fr (Rafael Garcia-Suarez) wrote:
> tobiwan@my-deja.com wrote in comp.lang.perl.misc:
> > I'd like to write a perl program (not a cgi script) that will
> >automatically ftp some files to a remote machine, and change the
> >permissions on them _on the remote machine_.
> >
> >I know how to ftp a file, and I know how to use chmod on a file on my
> >local machine - but not how to change permissions via ftp.
>
> The question is : does the ftp server support the chmod command? (type
> 'help' at the ftp command-line prompt to know).
>
> If it does, you can subclass Net::FTP to add this command.
>
> --
> Rafael Garcia-Suarez | http://rgarciasuarez.free.fr/
>

I was hoping it would already be supported by someone :-)

The server supports the command - I tested it through a linux box and
it worked fine. Its just my cr@##y ftp client program (MS-DOS on my NT
workstation) that doesn't seem to.

I didn't think of subclassing Net::FTP - I've not done that sort of
thing before. I'll have a go - after a quick look I reckon I can do it,
although it might take me a while to work out.

Cheers,
Toby


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 07 Sep 2000 15:01:11 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: ftp and chmod program
Message-Id: <39b7adb7.3a33$1a7@news.op.net>

In article <slrn8rf12c.3p0.rgarciasuarez@rafael.kazibao.net>,
Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
>The question is : does the ftp server support the chmod command? (type
>'help' at the ftp command-line prompt to know).
>
>If it does, you can subclass Net::FTP to add this command.

Subclassing Net::FTP might be more work than is necessary.
Net::FTP already provides a ->quot() method that will send any command
you want it to.



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

Date: Thu, 7 Sep 2000 16:01:49 +0200
From: "Willem Joosten" <nospam@jsoft.xs4all.nl>
Subject: Re: Getting a range of rows with DBI
Message-Id: <8p87ar$2ui$1@news.tudelft.nl>


"jason" <elephant@squirrelgroup.com> wrote in message
news:MPG.141d8c323bf454ac989750@localhost...
> Willem Joosten <nospam@jsoft.xs4all.nl> wrote ..
> >for a web database app I have to make a search result like output. So I
need
> >to show rows 1-10 on the first page, 11-20 second etc etc. The problem is
> >the records in the database are not continuous so I can't just get the
> >correct rows with a select.
> >
> >Any clues on how to tackle this problem?
>
> a) do the same 'select' each time - but limit the output to the
> requested row range

The limit is the problem since the number sometimes jump from 100 to 200 so
I can't limit them on the select. LIMIT isn't implemented either :(

> b) create a more complex system whereby a single 'select' is done on the
> initial running of the script .. and at that point a temporary table is
> created with all the results .. or with the primary keys of all the
> results .. which means that on subsequent calls the lookups are very
> quick

The primary keys tip is great. I've implemented a sub which creates the
primary keys only and those are sliced in results pages.

Thanks!





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

Date: Thu, 7 Sep 2000 11:49:00 +0100 (BST)
From: Smylers-usenet@stripey.com (Smylers)
Subject: Re: Help needed - regexp
Message-Id: <2000Sep7.104900.3246@leeds.ac.uk>

Martien Verbruggen <mgjv@tradingpost.com.au> uttered something along the
lines of:

> On Thu, 07 Sep 2000 03:00:42 GMT,
> 	Mark-Jason Dominus <mjd@plover.com> wrote:
> 
> > For example:
> > 
> >         "foo>bar>" =~ /^(.*?)>$/;
> > 
> > is not at all the same as 
> > 
> >         "foo>bar>" =~ /^([^>]*)>$/;
> > 
> > The first one matches and the second does not.
> 
> Am I misunderstanding what you are saying here? As far as I can tell,
> they both match, and they both should.

The second one shouldn't match because the character class excludes
matching a ">", and the regexp is tied to the start and end of the
string.

> # perl -w
> "foo>bar>" =~ /^(.*?)>$/;
> print "$1 from $&\n";
> "foo>bar>" =~ /^([^>]*)>$/;
> print "$1 from $&\n";
> __END__
> foo>bar from foo>bar>
> foo>bar from foo>bar>

That doesn't prove anything with regard to the second one -- perlvar
states that $& is "[t]he string matched by the last successful pattern
match", so it is carried over from the first one and completely
unaffected by the non-matching second regexp.

Smylers



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

Date: Thu, 07 Sep 2000 14:49:45 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Help needed - regexp
Message-Id: <39b7ab08.39bc$183@news.op.net>

In article <39B71530.40D601DA@home.com>,
Rick Delaney  <rick.delaney@home.com> wrote:
>Actually, it already makes a small attempt at reading your mind by
>looking ahead to the next regexp node.  If the next thing to match is a
>fixed string (">" in this case), then .*? can quickly jump ahead to it.

Oh, I forgot about that.  Thanks!



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

Date: Thu, 07 Sep 2000 13:00:46 GMT
From: Paul Eckert <peckert@epicrealm.com>
Subject: Re: help with net::ftp->login
Message-Id: <39B791AD.BCCD0AB8@epicrealm.com>


"Simon Chrétien" wrote:
> 
> If it could help here's what I do:
> $ftp = Net::FTP->new($ip, Port, $port, Timeout, 200, Debug, 1);
>  eval { $status = $ftp->login($login, $password) }; warn $@ if $@;

Simon:
   Net::FTP returns undef as the value of $ftp for bogus $ip/$port combinations.
   Obviously, you can't then blindly eval() it in the next statement.
   Try error-checking the $ftp return value before going on to further code.

-- 
Paul Eckert
Sr. Software Engineer
Epicrealm Inc.
1651 N. Glenville Dr., Suite 212
Richardson, TX 75081
(972) 479-0135 x300
peckert@epicrealm.com


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

Date: Thu, 07 Sep 2000 13:53:59 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how is everyone?
Message-Id: <hf7frs80r4nm0mu2us9mkffeuckgd4qvg0@4ax.com>

toy wrote:

>long time no see all.  How is everyone?

Apparently, in a bad mood.


   ;-)

-- 
	Bart.


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

Date: Thu, 7 Sep 2000 22:53:16 +0800
From: DT <dsa@dassda.com>
Subject: Re: how to  encrypt source code?
Message-Id: <MPG.14222cb98a60f9a8989686@news.cyberway.com.sg>

Thank for your ideas and suggestions. You people are nice!


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

Date: Thu, 07 Sep 2000 13:41:22 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How to create a simple backup program?
Message-Id: <oe6frs4idd899ih8ukv4ktipghgnn88coq@4ax.com>

monkfunk@my-deja.com wrote:

>I really am forcing the perl thing I know.  I'm trying to learn it.  I
>like it's string manipulation strengths.  I'm going to wrap the script
>up with perl2exe.

Do you need it to be in Perl? Otherwise, if on Unix, I'd try doing it
with just tar. This program has interesting features, like backing up
only files that have been changed since a certain date.

Oops, that's right, "perl2exe" means that it's in Windows. So tar is
out. Well, there's always Archive::Tar, that works on Windows too (it's
even standard in the distribution on Windows). The disadvantage is that
the whole decompressed archive needs to fit in memory all at once. But
combining this module with File::Find, and you can pretty much do it.
And, last but not least, this module, just like the tar program, has
built-in gzip support.

-- 
	Bart.


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

Date: Thu, 07 Sep 2000 14:26:24 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: HTML::parse bug
Message-Id: <uk8frssfiptn6pt96pj2clgh2juaekg9tb@4ax.com>

Randal L. Schwartz wrote:

>And further down in this thread, you post code that shows something in
>a SIG handler other than $SIG{WHATEVER} = 'IGNORE'.
>
>You *will* experience crashes then.  Get used to it.  Signals
>are not reliable, and this is the unreliablity. :)
>
>The bug is not in HTML::Parse.  Nothing to see here.  Move along. :)

Randal is right. You need to find another approach, one that doesn't
require the signals. If all else fails, double forking is what I would
try. The parent launches a child, which in turn launches a grandchild,
and exits. That doesn't take long, so the parent can just wait for it.
And now everybody (parent and grandchild) can each safely go their own
way.

In some versions of perlfunc (not in my 5.6 distribution) the entry for
fork() even contains a coding example:

    <http://www.perl.com/pub/doc/manual/html/pod/perlfunc/fork.html>


Here's what perlipc says:

    On most Unix platforms, the `CHLD' (sometimes also known as `CLD')
    signal has special behavior with respect to a value of `'IGNORE''.
    Setting `$SIG{CHLD}' to `'IGNORE'' on such a platform has the effect
    of not creating zombie processes when the parent process fails to
    `wait()' on its child processes (i.e. child processes are
    automatically reaped).
    Calling `wait()' with `$SIG{CHLD}' set to `'IGNORE'' usually returns
    `-1' on such platforms.

So, if you're lucky, you needn't even bother.

-- 
	Bart.


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

Date: Thu, 07 Sep 2000 15:18:09 +0100
From: Tim Cockle <T.Cockle@staffs.ac.uk>
Subject: Re: HTML::parse bug
Message-Id: <39B7A3A1.DCABAE07@staffs.ac.uk>

As you suggested in your e-mail I removed the Signal lines.

The crashing still occurs so it's not that!

Cheers,

Tim

"Randal L. Schwartz" wrote:

> >>>>> "Tim" == Tim Cockle <T.Cockle@staffs.ac.uk> writes:
>
> Tim> I have found a bug somwwhere in HTML::parse. I have written a simple
> Tim> server wich works fine. However if I convert it into a forking server it
> Tim> crashes out.
>
> And further down in this thread, you post code that shows something in
> a SIG handler other than $SIG{WHATEVER} = 'IGNORE'.
>
> You *will* experience crashes then.  Get used to it.  Signals
> are not reliable, and this is the unreliablity. :)
>
> The bug is not in HTML::Parse.  Nothing to see here.  Move along. :)
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mr. T. P. Cockle M.Sc. B.Sc. (hons) Pg.D.                 Ph.D. Representative

Research (Distributed Computer Systems)
School of Computing,
Staffordshire University,
Stafford ST18 0DG.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




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

Date: Thu, 07 Sep 2000 16:11:21 +0200
From: Oliver =?iso-8859-1?Q?Ebenh=F6h?= <oliver.ebenhoeh@rz.hu-berlin.de>
Subject: memory leak with subroutine references
Message-Id: <39B7A209.296A49C0@rz.hu-berlin.de>

Hi,
I wrote a perl subroutine that converts an object (details not so
important) into a subroutine and returns a reference to it:

sub to_sub {
  my $func = shift;

  my $code = ...; # Here the PERL-code of the subroutine is generated
from $func

  my $rs;
  eval "\$rs = sub \{ ".$code."\}";
  print $@ if $@;

  return $rs;
}


This works fine but somehow dereferencing does not seem to work.
When I enter something like (in my little shell):

for($i=0;$i<1000;$i++){$f = $foo->to_sub}

the memory used by the program increases by 4MB!
With "normal" variables (scalars, arrays & hashes) this does not happen
in a corresponding piece of code.

Does someone know how to avoid this memory leak?

Oliver


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

Date: Thu, 07 Sep 2000 09:32:47 -0400
From: "Alex T." <samara_biz@hotmail.com>
Subject: my()inside if{...}, how to make vars visible
Message-Id: <39B798FF.87D626DD@hotmail.com>

Hi,

I'm using Win32::OLE to create an excel spreadsheet based on the results
of a text file processing. I also create a corresponding text file. The
problem I ran into is:

I want to be able to "turn off" the excel files feature, meaning that my
program would only write into text files. In order to do that, I set a
special variable $mkexl to 0.
Then I have the following code:

if( $mkexl ){
#create an Excel object
my $xl_app = CreateObject OLE 'Excel.Application' || die "$!";

#set visibility
$xl_app->{Visible} = 0;
} #if
 ...
 if( $mkexl ){
 #open a new workbook
 my $workbook = $xl_app->Workbooks->Add;
 } #if
 ...
etc.

So the problem is that after I did that, my program doesn't work with
"use strict" anymore. As I understand, that's because my() inside the if
statement braces desclares that the variable's scope is only the if
statement, so later when I try to access the "same" variable in my later
parts of the code, it says that I should have declared an explicit
package name for that variable.

So how do I work around that problem? Do I have to declare all the
variables that I might use at the beginning of my program, e.g. outside
the if statements? How is it usually done?

Thanks a lot!

Alex



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

Date: Thu, 07 Sep 2000 14:10:10 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: my()inside if{...}, how to make vars visible
Message-Id: <7avgw85m4c.fsf@merlin.hyperchip.com>


"Alex T." <samara_biz@hotmail.com> writes:

> So the problem is that after I did that, my program doesn't work with
> "use strict" anymore. As I understand, that's because my() inside the if
> statement braces desclares that the variable's scope is only the if
> statement, so later when I try to access the "same" variable in my later
> parts of the code, it says that I should have declared an explicit
> package name for that variable.

That's correct.

> So how do I work around that problem? Do I have to declare all the
> variables that I might use at the beginning of my program, e.g. outside
> the if statements? How is it usually done?

Well, if you want a variable to be global, then you have to declare it
as such. For other variables, that have a more temporary use, you should
localize them to their appropriate scope.

--Ala


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

Date: Thu, 07 Sep 2000 13:59:18 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: newbie: redirect problem
Message-Id: <co7frsgb84q8qee2uf8micpe5evs213jd5@4ax.com>

macdo wrote:

>No - I'm afraid all this does is display in my browser the string
>"Location: http://www.somewhere.com\n\n"

You must have printed a content-type header first, such as "text/html".
Don't. The location header (plus an empty line) is all you need.

-- 
	Bart.


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

Date: Thu, 07 Sep 2000 14:01:28 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: newbie: redirect problem
Message-Id: <hr7frs8e0bagahnt885kscr0vkfg3hs6sr@4ax.com>

Alan J. Flavell wrote:

>> print "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\; 
>> URL=http://www.somewhere.com\">";
>
>You could also "try" putting your head in a bucket?
>
>> Cheating a bit 
>
>Why "cheat" when a properly-engineered solution is available?

It's amazing how many offical websites, probably designed by
"professionals", behave in this way. Often, there's an intermediate page
that is quickly skipped, but that surely messes with your ability go
back by pressing the "back" button (duh!).

-- 
	Bart.


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

Date: Thu, 07 Sep 2000 14:03:09 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: newbie: redirect problem
Message-Id: <av7frsorrj4pck3d8lpqk0irv8uttk3dc7@4ax.com>

Alan J. Flavell wrote:

>> >print "Location: http://www.newlocation.com\n\n";
>
>> Or even better:
>> 
>> print "Location: http://www.newlocation.com/\n\n";
>
>Why do you suppose so?  

Because otherwise there is one more runaround to be made. You make the
slashless request, the server replies, "no, you need to go to this
address" (with a slash), and then the browser goes there.

-- 
	Bart.


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

Date: Thu, 7 Sep 2000 07:17:19 -0700
From: "Christopher M. Jones" <christopher_j@uswest.net>
Subject: Re: newbie: redirect problem
Message-Id: <HrNt5.37$M06.51558@news.uswest.net>


"Bart Lateur" <bart.lateur@skynet.be> wrote:
> Alan J. Flavell wrote:
>
> >> print "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0\;
> >> URL=http://www.somewhere.com\">";
> >
> >You could also "try" putting your head in a bucket?
> >
> >> Cheating a bit
> >
> >Why "cheat" when a properly-engineered solution is available?
>
> It's amazing how many offical websites, probably designed by
> "professionals", behave in this way. Often, there's an intermediate page
> that is quickly skipped, but that surely messes with your ability go
> back by pressing the "back" button (duh!).


Actually, the meta 0 second refresh works fabulously.  It is
excellent for providng simpler urls to other locations.  And
it doesn't break your back button either, it functions the
same as a regular HTTP redirect but it's just a plain old
html file so it can do somethings easier.  Some websites use
other wacky redirections schemes (the most common "bad" ones
involve javascript).  And yes, it is amazing how many of these
there are that screw up your ability to go back and are yet
"professional" web sites for big companies or organizations.
It is all the more surprising considering all the different
ways there are to do it right.




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

Date: 07 Sep 2000 09:35:02 -0300
From: Jorge Godoy <godoy@conectiva.com>
Subject: Re: perl & htaccess
Message-Id: <kp7l8ov0qx.fsf@dagon.casa>

>>>>> MC  writes:

    > 1) can a perl script determine what login was
    > used to enter an htaccess protected site?

I used this snippet of code in my last CGI:

,----
| use strict;
| use CGI qw(:standard);
| 
| use vars qw(%ENV);
| 
| (...)
| 
|     if (defined($ENV{REMOTE_USER})) {
|         $user = $ENV{REMOTE_USER};
|     } else {
|         bail("Couldn't find who you are");
|     }
| 
| (...)
`----

If somebody has a better approach, please send me! ;-)

    > 2) can a perl script add a user/pwd to an htaccess file ?

I think it's just a matter of opening the file and adding the new
user. Please, remember about checking if there's already a user with
the desired username in the password file. 

The only problem you might get here is with file permissions (and
locking). Remember that the web server usually runs as nobody and,
unless you're using a suid script, your script runs as the same user.


Be seeing you,
-- 
Godoy. <godoy@conectiva@com>

Departamento de Publicações       Conectiva S.A.
Publishing Department             Conectiva Inc.


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4247
**************************************


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