[19398] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1593 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 23 00:05:31 2001

Date: Wed, 22 Aug 2001 21:05:07 -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: <998539507-v10-i1593@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 22 Aug 2001     Volume: 10 Number: 1593

Today's topics:
        bizarre! <e@nospam:[arix.com]>
    Re: Calling severl bat files from perl script <rob_13@excite.com>
    Re: CGI FAQ beta =) (was Re: CGI) (Tim Hammerquist)
    Re: CGI FAQ beta =) (was Re: CGI) (Tim Hammerquist)
    Re: CGI FAQ beta =) (was Re: CGI) (Eric Bohlman)
    Re: DBI:CSV SQL 'order by' problem <jeff@vpservices.com>
        default.ida and your web server <godzilla@stomp.stomp.tokyo>
    Re: Extracting Blocks of text <rob_13@excite.com>
    Re: Help with Calculating fields <jurgenex@hotmail.com>
    Re: Help with Calculating fields <ron@savage.net.au>
    Re: Help with Calculating fields <bwalton@rochester.rr.com>
    Re: i need to count words in perl (Martien Verbruggen)
    Re: Job Control in Perl <bkennedy99@Home.com>
    Re: Perl OO needs the opposite of SUPER:: (John Lin)
    Re: Perl OO needs the opposite of SUPER:: (John Lin)
    Re: Perl OO needs the opposite of SUPER:: <joe+usenet@sunstarsys.com>
    Re: race condition? (David Efflandt)
    Re: redirect stderr for sub-routine <davidhilseenews@yahoo.com>
    Re: redirect stderr for sub-routine <just@usenet.please>
    Re: Strange Problem with Win32::Console <bwalton@rochester.rr.com>
        Using %{$hashref} or %$hashref to dereference?? <miscellaneousemail@yahoo.com>
    Re: Why wont this work!?!?!? (Alan Barclay)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 22 Aug 2001 20:51:42 -0700
From: "ekkis" <e@nospam:[arix.com]>
Subject: bizarre!
Message-Id: <lf%g7.910$rq6.90368@news.pacbell.net>

# perl -v
This is perl, v5.6.0 built for i386-linux

these are ok:

# perl -e '$x{x-this} = 1;'
# perl -e '$x{"no-this"} = 1;'

but this fails:

# perl -e '$x{no-this} = 1;'
syntax error at -e line 1, near "{no"
Execution of -e aborted due to compilation errors.

what gives??

- e




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

Date: Thu, 23 Aug 2001 01:45:27 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: Calling severl bat files from perl script
Message-Id: <Xns9105DD5393A88rock13com@64.8.1.226>

Vic Antillon>

> I need to be able to call a number of '.bat' files from a Perl
> script, one after the other, without waiting for the '.bat'
> files to return (since several of them run indefinitely). The
> 'exec' and 'system' functions don't seem to return unless the
> '.bat' file completes, so typically the first 2 will run, but
> the 2nd never returns so the subsequent 8 '.bat' files are
> never called. 

Can your write one .bat to do your batch of files and execute that 
one from Perl?

-- 
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


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

Date: Thu, 23 Aug 2001 01:12:40 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: CGI FAQ beta =) (was Re: CGI)
Message-Id: <slrn9o8mq1.sk.tim@vegeta.ath.cx>

Me parece que Alan J. Flavell <flavell@mail.cern.ch> dijo:
> On Aug 21, Tim Hammerquist inscribed on the eternal scroll:
> >  The latter was only found on MS-DOS
> >     (the oldest but still most stable software ever to be produces by
> >     Microsoft),
> 
> OK, so I know it's way OT, but I can't help asking: you reckon they
> _produced_ DOS?  I thought they got it from somewhere else, and only
> marketed it.

I didn't say they "wrote" it. I used "produce[d]" in the marketing
sense.  They wrote the data to the 5 1/4 floppies, slapped their MS-DOS
label on it, and sold it. Music producers do little more than this. ;)

-- 
Error: No keyboard detected. Press F1 to continue.
    -- Microsoft Windows


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

Date: Thu, 23 Aug 2001 01:19:31 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: CGI FAQ beta =) (was Re: CGI)
Message-Id: <slrn9o8n6t.sk.tim@vegeta.ath.cx>

Me parece que Richard A. Evans <EvR@compuserve.com> dijo:
[ snippage ]
> 
> Ouch!!!  I remember those days quite well.  Contrary to what a lot of people
> today seem to think, you can do a lot of work without a GUI.

I heartily agree. Back in the MS-DOS 5 days, when Windows 3.11 crashed
once and for all, I was back to either the command line or the Borland
C++ (text mode) IDE.

[ more snippage ]
> And personally, I find you can get a lot of work done using the prompt --
> often easier than using the GUI tools.

Again, agreed.  There are only two apps I have open at _all_ times:
    1. an xterm running bash
    2. xmms
    3. gvim (95% of the time)

[ still more snippage ]
> I believe it was actually a little later than v5.0, but they have certainly
> neglected this, as Win95 was to do away with DOS entirely.  Then Win98 was
> to do so.  Then Win2000.  Perhaps XP?

Honestly, they _are_ moving away from the DOS base (slowly). Win3.x and
Win95 still sat on top of COMMAND.COM, while Win98 was a sort of hybrid.
I'm not sure what WinME does, but I heard it works like NT: Windows at
the base, and a separate command line interface to the Win32 base. Is
this right?

-- 
"supported" is an MS term that means the function exists. The fact
that it always fails means, that it is an exercise for the programmer.
    -- Sarathy, p5p


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

Date: 23 Aug 2001 01:35:16 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: CGI FAQ beta =) (was Re: CGI)
Message-Id: <9m1mkk$6sv$1@bob.news.rcn.net>

Alan J. Flavell <flavell@mail.cern.ch> wrote:
> OK, so I know it's way OT, but I can't help asking: you reckon they
> _produced_ DOS?  I thought they got it from somewhere else, and only
> marketed it.

True for DOS 1.0, but the later versions were developed by Microsoft 
with some help from IBM.



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

Date: Wed, 22 Aug 2001 18:03:37 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: DBI:CSV SQL 'order by' problem
Message-Id: <3B845669.87212389@vpservices.com>

Benjamin Goldberg wrote:
> 
> > Basically, it does a numeric compare if the column value STARTS with
> > a numeric.  Values like '123ABC' or '5.13.2'  would naturally not be
> > handled properly...
> 
> > The main problem now is that I don't want to use a 'local' copy of
> > Statement.pm.  Guess I've got to lobby the SQL maintainers for an
> > update...

That would be me.  I originally sent a patch for this exact problem to
the author of SQL::Statement over two years ago but he's a busy guy.  So
I have taken over maintenance of the module and have released a very
experimental first version of it under the name SQL::Squish.  I should
have a full SQL::Statement out in the next month.  If you want to try
the experimental one, it's at

  http://www.spiritone.com/~jzucker/SQL-Squish-0.02.tar.gz

When it's done it will become the SQL parser for DBD::AnyData (which I
know for sure because it's mine) and possibly also for DBD::CSV and
other modules.

> It'll probably get fixed faster if you give them a patch, rather than
> telling them what's wrong and where and asking them fix it.

True, but I'm also open to advice and suggestions on what needs work. 
Please email those to me as I'm on the road for a while and can't always
check clpm.

-- 
Jeff



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

Date: Wed, 22 Aug 2001 19:34:32 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: default.ida and your web server
Message-Id: <3B846BB8.44FA1EAD@stomp.stomp.tokyo>


One of my favorite projects is hacking IRC attack bots and,
turning them against their owner. This is fun and satiates
my inherent Oklahoma farm girl ornery nature.

More recently, I have turned my attention to Code Redworm.
It may be of interest to you to learn how to capture inquiries
generated in association with this Code Redworm. This is
a technique, a modification of a technique, I use to hack
Script Kiddies and wreak havoc upon their sociopathic fun.

If you have a decent web server mounted upon your machine,
configure it to listen to port 80, which it probably does
by default. Write a simple Perl script which captures
incoming requests via a typical Apache custom error
message keyed to invalid requests; page not found.


http://httpd.apache.org/docs/custom-error.html


Within your Perl script, if you are an imaginative programmer,
if you are a rogue Perl programmer like myself, you may include
capture of lots of information well beyond what your server log
will capture. Incidently, most incoming Code Redworm requests
are missed by a standard web server log, not all, but most.

Easy enough procedure. Logon to our internet, start your
personal webserver and your imaginative Perl script will
take care of business, quietly in the background.

You will be amazed, simply amazed.

I would not suggest you do this on machines vulnerable to Code Redworm.
If you need to ask why, turn off your computer, go outside and play
under the sunshine for the next ten years.


Here are some random samples from thousands of requests I have
captured, much like I capture information on Script Kiddies.
Much of the actual information has been snipped out to protect
the guilty and, perhaps a few innocents.


Godzilla!  Queen Of Perl Heretics.
--

10:36:40 08/06/2001 - RESTRICTED FILE REDIRECT:
   - DNS:  - IPA: 207.179.69.202
   - System: 
   - Redirect URL: /default.ida


17:40:14 08/09/2001 - RESTRICTED FILE REDIRECT:
   - DNS:  - IPA: 207.168.100.182
   - System: 
   - Redirect URL: /default.ida

15:19:37 08/10/2001 - RESTRICTED FILE REDIRECT:
   - DNS: host-65-162-107-242.api-digital.com - IPA: 65.162.107.242
   - System: 
   - Redirect URL: /default.ida



This one is exceptionally lame:


13:56:56 08/12/2001 - RESTRICTED FILE REDIRECT:
   - DNS:  - IPA: 216.3.21.36
   - System: 
   - Redirect URL: /scripts/..Áœ../winnt/system32/cmd.exe


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

Date: Thu, 23 Aug 2001 01:42:21 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: Extracting Blocks of text
Message-Id: <Xns9105DCCD45E79rock13com@64.8.1.226>

flii>

> Put simply, a trying to write a short script to extract simple
> blocks of text from a ASCII file. The beginning of the text
> block starts with a particular string and is terminated with
> another string or character (I'm actually extracting blocks of
> SQL from PL/SQL scripts). Therefore, the blocks of text are of
> a variable size, and may be quite large.

Maybe:
#!/usr/bin/perl

while(<FH>) {
    if(/begin string/ ... /end string/) {
        # this should be the lines you want
    }
}

'begin string' and 'end string' are the bits that define your 
block.

-- 
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


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

Date: Wed, 22 Aug 2001 18:12:55 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Help with Calculating fields
Message-Id: <3b845898@news.microsoft.com>

"James Salt" <james.salt@virgin.net> wrote in message
news:3B8431A6.94310E1F@virgin.net...
> I must say before I ask my question I am new to CGI scripts. However I
> do know some C++ and I have made various alterations to the formmail
> script that I am using.
>
> What I want to do in the cgi script is to multiply a form field
> (Quantitiy) by a number that I want to hard code into the script
> (amount).
>
> I can multiply two numbers together in the script but when I try to
> multiply a variable name by a number this does not work. I think where I
> am going wrong is the script might think the form field that I am trying
> to multiply is text, how do I specify that the text field I am wanting
> to use is a number field and not a text field?
>
> This is a little piece of the script I am using, any help to put me on
> the right track would be gratefully appreciated:
>
> $amount=20*Quantity;

When I try to run this snippet I get a
    Operator or semicolon missing before *Quantity [...]
    Ambiguous use of * resolved as operator * [...]
    Bareword "Quantity" not allowed while "strict subs" in use

What do you get?
Hint: you missed the "$" in front of the variable "$Quantity" (and use
strict and -w would have told you)

jue




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

Date: Thu, 23 Aug 2001 11:17:56 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: Help with Calculating fields
Message-Id: <XTYg7.1298$vI2.71779@ozemail.com.au>

James

See below.

--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
James Salt <james.salt@virgin.net> wrote in message news:3B8431A6.94310E1F@virgin.net...
> I must say before I ask my question I am new to CGI scripts. However I

Ah.

> do know some C++ and I have made various alterations to the formmail
> script that I am using.

Oh.

> What I want to do in the cgi script is to multiply a form field
> (Quantitiy) by a number that I want to hard code into the script
> (amount).

This tested code will get you going:

-----><8-----
#!/usr/bin/perl -T

use integer;
use strict;
use warnings;

use CGI;

# ----------------------------------------------------------------

my($q)   = CGI -> new();
my($quantity) = $q -> param('Quantity');

if ($quantity =~ /^(\d+)$/)
{
 $quantity = $1;
}
else
{
 $quantity = 0;
}

my($amount) = 20 * $quantity;

print $q -> header(),
  $q -> start_html(),
  $q -> start_form({action => $q -> url(), name => 'form_name'}),
  "Quantity: $quantity. Amount: $amount",
  $q -> br(),
  'Please enter a quantity: ',
  $q -> textfield({force => 1, name => 'Quantity', size => 10, value => $quantity}),
  $q -> submit(),
  $q -> end_form(),
  $q -> end_html();
-----><8-----





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

Date: Thu, 23 Aug 2001 01:29:19 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Help with Calculating fields
Message-Id: <3B845C81.78F33EFA@rochester.rr.com>

James Salt wrote:
> 
> I must say before I ask my question I am new to CGI scripts. However I
> do know some C++ and I have made various alterations to the formmail
> script that I am using.
> 
> What I want to do in the cgi script is to multiply a form field
> (Quantitiy) by a number that I want to hard code into the script
> (amount).
> 
> I can multiply two numbers together in the script but when I try to
> multiply a variable name by a number this does not work. I think where I
> am going wrong is the script might think the form field that I am trying
> to multiply is text, how do I specify that the text field I am wanting
> to use is a number field and not a text field?
> 
> This is a little piece of the script I am using, any help to put me on
> the right track would be gratefully appreciated:
> 
> $amount=20*Quantity;
> 
> print MAIL "This is the $amount you need to pay to\n\n ";
 ...
> James

The fundamental problem is that "Quantity" above is a bareword, and not
a variable.  You want $Quantity.  

The conversion between strings and numbers (and visa-versa) is
transparent in Perl -- if a string is used in a numeric context, as much
of the string as possible is converted to a number and the rest is
ignored. So, for example:

10*'20xxx' is 200
'10y2'*'2.0e01' is 200

Also, when you describe your problem, you state "this does not work". 
That description is most unhelpful to the people who are trying to help
you.  Please state exactly what it is you think is not working, what the
error messages (if any) say *exactly*, what you think the results should
be, *exactly* what the results were, and *please* include a complete
executable example snippet of code (as short as possible) that
illustrates your problem and can be cut, pasted and executed to show the
problem.  That will maximize your responses in this newsgroup.
-- 
Bob Walton


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

Date: Thu, 23 Aug 2001 02:22:53 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: i need to count words in perl
Message-Id: <slrn9o8q7u.5fl.mgjv@verbruggen.comdyn.com.au>

On Wed, 22 Aug 2001 16:58:23 -0100,
	Rainer Klier <Rainer.Klier@erl.sbs.de> wrote:
> Larry S wrote:
>> 
>> ok, i have a variable, $text, which contains a certain amount of words.
>> i want to display the first 30 words of $text, nothing more. 
                                                  ^^^^^^^^^^^^
>> any simple solutions?
> 
> print join " ",((split " ",$text)[0..29]);
             ^^^

That displays unwanted whitespace ;)

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In a world without fences, who needs
Commercial Dynamics Pty. Ltd.   | Gates?
NSW, Australia                  | 


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

Date: Thu, 23 Aug 2001 02:41:56 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: Job Control in Perl
Message-Id: <U3_g7.126554$EP6.35072154@news1.rdc2.pa.home.com>


"Chris Knowlton" <christopher.knowlton@usa.xerox.com> wrote in message
news:9m0k6d$i7a$1@news.wrc.xerox.com...

>     $pid = $pid * -1;
>
>     kill 9, $pid;
>     waitpid $pid, 0;
>
> This code does not kill anything and the parent hangs waiting for waitpid
to
> unblock.

I have had signal propagation issues as well - I would definitely suggest
putting in a few signal handlers to understand exactly how the signals are
sending, e.g.

$SIG{HUP} = sub { print "$$: got a HUP\n"; die };

You may also want to try a less harsh signal than KILL, I don't know how
that affects propagation.  Another thing that worked for me was to set the
parent as a process group leader (use POSIX; POSIX::setsid()) - this allowed
me to kill -process_id, which sent the signal to the whole group.  Hoep this
helps --

--Ben Kennedy




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

Date: 22 Aug 2001 18:12:15 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Re: Perl OO needs the opposite of SUPER::
Message-Id: <a73bcad1.0108221712.5b636401@posting.google.com>

Ren Maddox wrote
> On 21 Aug 2001, John Lin wrote:
> It seems that you could solve the problem by separating the down-class
> call into a base method that does nothing else.
> 
> sub call_report {
>     $self->report;
> }
> 
> Then, you simply override call_report in the intermediate class.  Of
> course, this doesn't automatically extend to multiple levels of
> intermediate classes.

Yes.  This is the "renaming" solution, which does not solve the problem.

> I'm still not clear on how the VIRTUAL version would solve it.

Well, Joe Schaefer has solved it by current Perl OO.  Please have a look.
And... let's not discuss VIRTUAL any more.  It's not needed.  :p

> I'd still like to see this implemented in some language that does
> support the construct.  I think it would help our understanding.

No other languages support this.  Only Perl can do it.  Long life Perl!!!

Thank you very much.  I really appreciate!
John Lin


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

Date: 22 Aug 2001 18:15:58 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Re: Perl OO needs the opposite of SUPER::
Message-Id: <a73bcad1.0108221715.239a688a@posting.google.com>

Joe Schaefer wrote
> If I haven't misunderstood your problem, there are a lot of ways to 
> solve it in Perl without rewriting the Report, EvenReport, and 
> OddReport packages.  Here's one approach:
> 
> #!/usr/bin/perl -w
> use strict;
> package Report;
> sub report { die "override me" }
> 
> package EvenReport;
> use base 'Report';
> sub report { "even" }
> 
> package ExtendedReport;                 # an abstract "interface"
> sub report {
>     local *report;
>     "extended " . shift() -> report;    # similar to SUPER::report
> }
> 
> # ... sample usage >>>
> 
> package MyReport;
> use base qw/ExtendedReport EvenReport/; # "implements" ExtendedReport
> my $foo = bless {};
> print $foo->report;
> 
> __END__
> 
> ~> extended even

Wow!!! great!!!  It works!!!  It is really what I want!!!
Thank you very much.  I need to improve my ability of asking questions.

Also thanks to anyone who offers your help and opinions.  I learned a lot here.
Thank you all.
John Lin


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

Date: 22 Aug 2001 22:15:43 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Perl OO needs the opposite of SUPER::
Message-Id: <m3k7zvcyi8.fsf@mumonkan.sunstarsys.com>

johnlin@chttl.com.tw (John Lin) writes:

[code snipped]

> Wow!!! great!!!  It works!!!  It is really what I want!!!

Then here's another one.  The previous solution was IMO more
elegant than this one, but it required your application scripts 
to be changed in a nontrivial way.  If you're in a situation where 
everything has already been written and is ready to go, but your
boss/customer/id demands that you retrofit the ExtendedReport 
functionality in the laziest possible way, this is probably
how I'd do it.

Yes, it's the "renaming" solution, just automated a bit. Like 
modifying a foreign package's @ISA, it's simultaneously appalling 
and wonderful- and hence more Perlish than the previous answer.


#!/usr/bin/perl -wl
use strict;
package Report;
sub report { die "override me" }

package EvenReport;
use base 'Report';
sub report { "even" }

package ExtendedReport;
sub import {
    my $pkg = $_[1];
    no strict;
    eval "*$pkg" . "::_aux_report = \\&$pkg"   .    '::report;' .
         "*$pkg" . '::report      =   *ExtendedReport::report';
    die if $@;

}

sub report {
    "extended " . shift() -> _aux_report
}


#... application script follows- only change is:
# use ExtendedReport 'EvenReport'; # see BEGIN below

package main;
BEGIN { ExtendedReport -> import(qw/EvenReport/) } # use ExtendedReport
my $foo = bless {}, 'EvenReport';                  # new EvenReport
print $foo->report;


__END__
~> extended even

Also have a look at Conway's OOP, in particular his treatment of
multimethods in chapter 13.  AFAICT it don't directly apply here,
but if you can grok what he's doing there, problems like these are 
fairly easy to handle.

Best.

-- 
Joe Schaefer                  "Whatever you are, be a good one."
                                               -- Abraham Lincoln



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

Date: Thu, 23 Aug 2001 02:05:19 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: race condition?
Message-Id: <slrn9o8p6v.ind.see-sig@typhoon.xnet.com>

On Wed, 22 Aug 2001, Jonah Klimack <jonah@nospam.adtrackz.com> wrote:
> I have a website in which members can
> modify their information in a database.
> (flat file text database)
> 
> Last night, my database got corrupted somehow.
> It's been running just fine for 8 months, with over 8500 members.
> I'm blaming it on this bit of code.
> All the other scripts that interact with the database do read
> only, or print on to the end of it. I always make sure to
> lock exclusive when printing, and shared when reading.
> 
> I think I should be keeping a lock on the file during
> this whole procedure of modifying a user's entry in the
> database because if multiple instances of
> this code are running into the same time, I'm sure I can run into problems.

Yes, open the file for read/write (+<), flock it exclusively, write or
copy modified data to it, then close it.  Otherwise it can get stepped on
by another instance anytime it is not exclusively flocked.

-- 
David Efflandt  (Reply-To is valid)  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Thu, 23 Aug 2001 02:34:53 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: redirect stderr for sub-routine
Message-Id: <hZZg7.7347$hT4.1690196@news1.rdc1.md.home.com>


"Um... Oh" <just@usenet.please> wrote in message
news:3b8418cb_1@binarykiller.newsgroups.com...
> "Tassilo von Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in
> message news:3B8429E1.1040501@post.rwth-aachen.de...
> > Um... Oh wrote:
> >
> > What is <$fh> exactly?
>
> It's supposed to be reading from a file handle.
>
> > Anyway, I don't really have an idea what you
> > want.
>
> I'm trying to capture the output of a sub-
> routine which I haven't written.
>
> For example:
>
> do_the_magic_redirecting_thing;
> call_ftp_routine_i_didn't_write;
> if (there was an error) {
>    print_what_the_ftp_routine_wrote_to_stderr;
> }
> print STDERR "Other things I need STDERR for\n";
>
> This part works for me:
>
> > open STDERR, ">err.log"
> > or die "Error: Could not redirect stderr: $!";
>
> But after:
>
> > close STDERR;
>
> I can't write to STDERR anymore.
>
> I want to restore STDERR so I can use it elsewhere. How do I do that?
>
> Thanks.
>

The idea is covered in perldoc, if you can find it (perldoc -q local worked
for me):
"How can I make a filehandle local to a subroutine?"

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

sub print_to_stderr
{
    print STDERR "ERROR: just kidding\n";
}

sub redirect_print
{
    local ( *STDERR );
    open ( STDERR, ">>log" ) or die "Error opening log file: $!\n";
    print_to_stderr();
    close STDERR;
}

print_to_stderr();
redirect_print();
print_to_stderr();


David Hilsee




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

Date: Wed, 22 Aug 2001 20:09:42 -0700
From: "Um... Oh" <just@usenet.please>
Subject: Re: redirect stderr for sub-routine
Message-Id: <3b8457cb$1_2@binarykiller.newsgroups.com>


"David Hilsee" <davidhilseenews@yahoo.com> wrote in message
news:hZZg7.7347$hT4.1690196@news1.rdc1.md.home.com...
> sub redirect_print
> {
>     local ( *STDERR );
>     open ( STDERR, ">>log" ) or die "Error opening log file: $!\n";
>     print_to_stderr();
>     close STDERR;
> }

Thanks!




-----=  Posted via Newsfeeds.Com, Uncensored Usenet News  =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
 Check out our new Unlimited Server. No Download or Time Limits!
-----==  Over 80,000 Newsgroups - 19 Different Servers!  ==-----


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

Date: Thu, 23 Aug 2001 02:11:51 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Strange Problem with Win32::Console
Message-Id: <3B846674.2C4F9351@rochester.rr.com>

Lyle Goldman wrote:
> 
> -
>         Hello. I have been using the Win32::Console package to turn off echoing
> while a user enters a password. It works well. However, after the password is
> entered and the console echo is turned back on, the Perl program will no longer
> accept standard input! Why is this happening and what can I do to fix it?
> 
>         Here is the code, stripped of error checking.
> 
> use Win32::Console;
> 
> sub getpass
> {
>         my ($password, $term);
>         $term = new Win32::Console STD_INPUT_HANDLE;
>         my $echo = ENABLE_ECHO_INPUT;
>         $term->Mode($term->Mode & ~$echo);
>         $password = <STDIN>;
>         print "\n";
>         $term->Mode($term->Mode | $echo);
>         return $password;
> }
 ...
>                                                 - Lyle Goldman

You are deleting the variable that holds your console ($term in sub
getpass -- when it goes out of scope).  Try making it a global by
removing it from the my(...), and it will work.  You might consider
opening the console elsewhere in case you want to call getpass more than
once, as things aren't real nice when you clobber your console either.
-- 
Bob Walton


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

Date: Thu, 23 Aug 2001 02:53:18 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Using %{$hashref} or %$hashref to dereference??
Message-Id: <MPG.15ee1ddd9261e20598978d@news.edmonton.telusplanet.net>

Hi everyone,

I have noticed that in the posts in CLPM a lot of statements using 
references are of the form....

%$hashref 

or some such.  While in perlreftut most if not all the references in it's 
code examples are of the form....

%{$hashref}

Please bear with me if my question seems silly or picky but I am 
wondering if there is a reason as to why the "{}" seems to be left out in 
a lot of real world programming whereas they are included in 
documentation code examples?  

I am trying to develop a consistent coding style and am inclined to use 
the "{}" for clarity as to what I am doing exactly but then perhaps I 
should just skip them.  As long as I am consistent.  

Any thoughts on this? 

---
Carlos 
www.internetsuccess.ca
*NOTE*: Internet Success is NOT yet fully operational so please don't 
subscribe.  Thanks.


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

Date: 23 Aug 2001 02:35:19 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Why wont this work!?!?!?
Message-Id: <998534076.656860@elaine.furryape.com>

In article <3B840FE7.57C10D1F@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>This is untrue. Your message is:
>
>  " (offline mode: enter name=value pairs on standard input) "

Depends what version of CGI.pm you are using. Current CGI.pm only
prints that message if loaded with qw(-debug);


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

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


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