[28765] in Perl-Users-Digest
Perl-Users Digest, Issue: 9 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 10 00:06:00 2007
Date: Tue, 9 Jan 2007 21:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 9 Jan 2007 Volume: 11 Number: 9
Today's topics:
How do i change STDOUT back to the screen <loz.brown@gmail.com>
Re: How do i change STDOUT back to the screen <tbmoore9@verizon.net>
Re: How do i change STDOUT back to the screen <spamtrap@dot-app.org>
Re: Indirect function call via Name <mark.clementsREMOVETHIS@wanadoo.fr>
Re: Iterator special variable $_ <carno.spam@verizon.net>
Re: OSCON 2006 - Perl programming vs. scripting <sigzero@gmail.com>
Re: OSCON 2006 - Perl programming vs. scripting <brian.d.foy@gmail.com>
Re: Perl free e-books <john@castleamber.com>
Re: PERL5LIB variable does not work as expected <brian.d.foy@gmail.com>
Re: PERL5LIB variable does not work as expected <stahl.karl@gmail.com>
posting https forms <xx@wp.pl>
Re: posting https forms <glex_no-spam@qwest-spam-no.invalid>
Re: posting https forms <john@castleamber.com>
problems DB_File <john.swilting@wanadoo.fr>
Re: problems DB_File <glex_no-spam@qwest-spam-no.invalid>
Taint and $0 <utoddl@email.unc.edu>
Re: Xah's Edu Corner: Introduction to 3D Graphics Progr <hg@nospam.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 9 Jan 2007 10:49:03 -0800
From: "lozbrown" <loz.brown@gmail.com>
Subject: How do i change STDOUT back to the screen
Message-Id: <1168368543.892457.8570@k58g2000hse.googlegroups.com>
Ok this is a very novice question but please help,
I have a subroutine that uses STDOUT:
---------------------------------code--------------------------------------------------
sub savefile {
my $content = get($_[0]);
print "saving file $_[0]";
#download the file
die "Couldn't get $_[0]" unless defined $content;
#Open same file for writing, reusing STDOUT
open (STDOUT, ">$_[1]") or die "Can't open $_[1]: $!\n";
binmode(STDOUT);
print "$content";
#Finish up
close STDOUT;
}
------------------------------End
code-----------------------------------------
but how do I send stdout back to the screen so i can use the print
command an it will appear on the screen.
currently after the subroutine has been called i get this error message
print() on closed filehandle STDOUT at C:\Docum...
------------------------------
Date: Tue, 09 Jan 2007 19:29:09 GMT
From: boyd <tbmoore9@verizon.net>
Subject: Re: How do i change STDOUT back to the screen
Message-Id: <tbmoore9-0BF17D.14290909012007@news.verizon.net>
In article <1168368543.892457.8570@k58g2000hse.googlegroups.com>,
"lozbrown" <loz.brown@gmail.com> wrote:
> Ok this is a very novice question but please help,
>
> I have a subroutine that uses STDOUT:
>
> ---------------------------------code-----------------------------------------
> ---------
> sub savefile {
> my $content = get($_[0]);
> print "saving file $_[0]";
> #download the file
>
> die "Couldn't get $_[0]" unless defined $content;
>
>
> #Open same file for writing, reusing STDOUT
> open (STDOUT, ">$_[1]") or die "Can't open $_[1]: $!\n";
> binmode(STDOUT);
> print "$content";
>
> #Finish up
> close STDOUT;
> }
> ------------------------------End
> code-----------------------------------------
>
> but how do I send stdout back to the screen so i can use the print
> command an it will appear on the screen.
>
> currently after the subroutine has been called i get this error message
>
> print() on closed filehandle STDOUT at C:\Docum...
Most folks use another file handle than STDOUT to do the file writing,
leaving STDOUT to write to the screen. Others might use STDERR to do
screen output, since it is usually attached to the terminal screen.
To print to a file handle, just put the filehandle after the print
statement, as in:
print STDERR "saving file $_[0]\n";
The way to open a filehandle is
open OUT, ">$_[1]";
binmode(OUT);
in your above script, and use
print OUT "$content";
...
close OUT;
Boyd
------------------------------
Date: Tue, 09 Jan 2007 14:43:54 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How do i change STDOUT back to the screen
Message-Id: <m21wm4f0jp.fsf@Sherm-Pendleys-Computer.local>
boyd <tbmoore9@verizon.net> writes:
> The way to open a filehandle is
> open OUT, ">$_[1]";
Always, yes always, check the result of open(). Also, the three-argument
form of open() is preferred, as is lexical file handles.
Putting all that together:
open my $out_file, '>', $_[1] or die "Could not open $_[1]: $!";
> binmode(OUT);
binmode($out_file);
> in your above script, and use
> print OUT "$content";
Useless use of quotes.
print $out_file $content;
See:
perldoc -q quoting.
> close OUT;
Not strictly needed with lexical file handles; they're automagically closed
when the variable referring to them goes out of scope. But if you *do* call
close() explicitly, you should check the result:
close $out_file or die "Could not close $_[1]: $!";
Suggested reading:
perldoc perlopentut
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Tue, 09 Jan 2007 18:39:48 +0100
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Indirect function call via Name
Message-Id: <45a3d368$0$25926$ba4acef3@news.orange.fr>
Ronald Fischer wrote:
> What would be the best (most elegant) way to solve the following:
>
> Suppose I have the name of a function (i.e. not a coderef) as a
> string, and I would like to call this function, passing to it
> all the parameters of the current function (i.e. @_). For example:
>
> our $func="bar";
>
> sub foo
> {
> # Of course the following would not work
> &$func(@_);
> }
>
> foo('x',5); # This is supposed to call &bar('x',5)
>
> The above would work if $func were a code ref, but it is a string.
> I came to the following solution which works, but is ugly:
>
> use Data::Dumper;
> sub foo
> {
> local $Data::Dumper::Terse=1; # No varnames
> local $Data::Dumper::Indent=0; # No newlines
> eval("$func(".join(',',Dumper(@_)).')');
> }
>
> Could someone suggest a better alternative?
I'd use a dispatch table.
F:\Documents and Settings\Mark3>cat testdispatch.pl
use strict;
use warnings;
my %dispatch = (
thisone => \&func1,
thatone => \&func2,
);
printmessage("thisone");
printmessage("thatone");
sub printmessage {
my $funcname = shift;
print $dispatch{$funcname}->()."\n";
}
sub func1 {
return "message from func1";
}
sub func2 {
return "message from func2";
}
F:\Documents and Settings\Mark3>perl testdispatch.pl
message from func1
message from func2
------------------------------
Date: Wed, 10 Jan 2007 00:53:22 GMT
From: "Verizon" <carno.spam@verizon.net>
Subject: Re: Iterator special variable $_
Message-Id: <6OWoh.3440$AM4.3155@trnddc07>
"Mark Hobley" <markhobley@hotpop.deletethisbit.com> wrote in message
news:506874-jua.ln1@neptune.markhobley.yi.org...
> Would you expect nested loops using the iterator variable to work?
>
> use strict;
> use warnings;
> for ($_=0; $_<=3; $_++) {
> print "Loop $_\n";
> for ($_=0; $_<=6; $_++) {
> print "Value $_\n";
> }
> }
What you seem to want here is something like:
for(0..3)
{
print "Loop 0: $_\n" ;
for(0..6) # Perl automatically localizes $_, but now you can't see
the count for the outer loop
{
print "Loop 1: $_\n" ;
}
}
Perl will localize the scope of $_ for you and the $_ of the outer loop will
be maintained. $_ should not be thought of as an iterator, although it can
contain the value associated with one.
If you assign things to $_ all bets are off. You should avoid assigning to
the default variable ($_) - think of it as a global read-mostly even though
it isn't necessarily global and there are many cases where you will want to
modify it, such as in substitutions. "Never" is probably more appropriate
than "should", but "never" has its limitations too and Perl lets you do all
sorts of things that you shouldn't - that is why we love it so much!
If you need to be able to use the iterator from the outer loop within the
inner loop, you're better off assigning it to a local variable. In this
case you can do it the usual Perl way or use your iterator expression:
foreach my $outer (0..3) # or: for (my $outer = 0 ; $outer < 4 ;
$outer++)
{
print "Loop 0: $outer\n" ;
foreach my $inner (0..6) # etc.
{
print "Loop 1: $outer/$inner\n" ;
}
}
Craig Arnold
------------------------------
Date: 9 Jan 2007 06:59:42 -0800
From: "Robert Hicks" <sigzero@gmail.com>
Subject: Re: OSCON 2006 - Perl programming vs. scripting
Message-Id: <1168354782.589687.122730@11g2000cwr.googlegroups.com>
John Bokma wrote:
> brian d foy <brian.d.foy@gmail.com> wrote:
<snip>
>
> BTW, what kind of book. And if you need a reviewer... :-p
>
I think it is the next in the Perl "learning" series. I could be wrong.
brian is doing so many things it is hard to keep up. : )
Robert
------------------------------
Date: Tue, 09 Jan 2007 13:44:03 -0600
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: OSCON 2006 - Perl programming vs. scripting
Message-Id: <090120071344030269%brian.d.foy@gmail.com>
In article <1168354782.589687.122730@11g2000cwr.googlegroups.com>,
Robert Hicks <sigzero@gmail.com> wrote:
> John Bokma wrote:
> > brian d foy <brian.d.foy@gmail.com> wrote:
> <snip>
> >
> > BTW, what kind of book. And if you need a reviewer... :-p
> >
>
> I think it is the next in the Perl "learning" series. I could be wrong.
> brian is doing so many things it is hard to keep up. : )
Oh, I think I was talking about Mastering Perl:
http://www.pair.com/comdog/mastering_perl/
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: 10 Jan 2007 03:25:05 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Perl free e-books
Message-Id: <Xns98B3D9DFE2CC5castleamber@130.133.1.4>
"Shuo Shi" <moya0901@126.com> wrote:
> Dear all,
>
> I am very glad to join this news group of Perl subject. So would you
> please share some info on URL address to download the free e-books (
> pdf format is perfect ) about Perl? At best, the book can cover the
> content from beginning to super programmer of Perl? I would appreciate
> it very much!
Don't post in HTML, Usenet is plain text.
As for free e-books: what's wrong with the documentation that comes with
your Perl installation? Have you already checked out
perldoc perldoc
(on the command line).
If you use Active(State) Perl and have installed it in the default
location, check out:
file:///C:/Perl/html/index.html
I recommend to bookmark that location in your browser, or if you use
Firefox to even drag that location onto the bookmarks toolbar.
Notice the "Getting Started" in the left column.
If you scroll a bit down in that column, there is a Perl Core
Documentation.
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: Tue, 09 Jan 2007 13:43:15 -0600
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: PERL5LIB variable does not work as expected
Message-Id: <090120071343157342%brian.d.foy@gmail.com>
In article <080120071209502814%jgibson@mail.arc.nasa.gov>, Jim Gibson
<jgibson@mail.arc.nasa.gov> wrote:
> In article <1168284875.141010.297540@42g2000cwt.googlegroups.com>, DJ
> Stunks <DJStunks@gmail.com> wrote:
>
>
> >
> > Others have addressed your actual problem, but my question is why use
> > PERL5LIB in your environment rather than the lib pragma in your script
> > (er, program? :P)
> >
> > perldoc lib
>
> Because it is better to define a value in one place rather than in
> every source file that needs it?
Well, PERL5LIB doesn't work under taint checking, for instance, but
lib always does.
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: 9 Jan 2007 19:35:41 -0800
From: "Ishmael" <stahl.karl@gmail.com>
Subject: Re: PERL5LIB variable does not work as expected
Message-Id: <1168400140.910456.200110@p59g2000hsd.googlegroups.com>
> Wrong direction...
>
> The error is "libgmp.so.3: open failed" which is the external library
> dependency
> for Math::GMP. It's installed separately -- this aspect of the problem
> has nothing to do with @INC.
>
> Normally, Perl looks at the libpth setting for external libraries.
> Check
> perl -V:libpth. Is libgmp.so.3 in one of those directories....? Is the
> full
> path to that library readable...? Where did you build and install
> libgmp...?
>
> --
> Charles DeRykus
Ah! This is promising. I did as you said, and sure enough, the
library path came up as follows:
libpth='/usr/local/lib/db3 /usr/local/lib /apps/supported/lib/sol2.sun4
/usr/lib
/usr/ccs/lib';
Now the question is, how do I change the libpth? It doesn't appear to
be an environment variable.
------------------------------
Date: Tue, 09 Jan 2007 16:36:21 +0100
From: avlee <xx@wp.pl>
Subject: posting https forms
Message-Id: <op.tlv8avpx1sq83a@saturn>
Hello
I'm looking for library which could allow me posting (POST method) forms=
on https pages.
I found LWP - which allows for that but only for http:
my $path =3D "http://mypage.com/";
my $ua =3D new LWP::UserAgent;
my %form =3D (
'username' =3D> 'user',
'password' =3D> 'pass',
);
my $response =3D $ua->post($path, \%form);
but when i change it to https it does not work.
How can i get page using ssl and post method forms ?
Thanx
------------------------------
Date: Tue, 09 Jan 2007 09:48:12 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: posting https forms
Message-Id: <45a3b881$0$10297$815e3792@news.qwest.net>
avlee wrote:
> Hello
>
> I'm looking for library which could allow me posting (POST method) forms
> on https pages.
> I found LWP - which allows for that but only for http:
>
> my $path = "http://mypage.com/";
> my $ua = new LWP::UserAgent;
my $ua = LWP::UserAgent->new;
> my %form = (
> 'username' => 'user',
> 'password' => 'pass',
> );
No need to quote username and password.
> my $response = $ua->post($path, \%form);
>
> but when i change it to https it does not work.
Next time, post the error you get. Saying "does not work"
doesn't help anyone.
> How can i get page using ssl and post method forms ?
Searching the Internet on LWP and https should have
shown that it is supported.
perldoc lwpcook
" URLs with https scheme are accessed in exactly the same way as with
http scheme, provided that an SSL interface module for LWP has been
properly installed (see the README.SSL file found in the libwww-perl
distribution for more details). "
------------------------------
Date: 9 Jan 2007 16:51:40 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: posting https forms
Message-Id: <Xns98B36E7B42234castleamber@130.133.1.4>
avlee <xx@wp.pl> wrote:
> Hello
>
> I'm looking for library which could allow me posting (POST method) forms
> on https pages.
> I found LWP - which allows for that but only for http:
http://www.google.com/search?q=perl%20https
If you can't read documentation (LWP comes with documentation) or/and
can't use Google learn those two valuable skills first before you start to
program.
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: Tue, 09 Jan 2007 21:13:09 +0100
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: problems DB_File
Message-Id: <45a3f750$0$5075$ba4acef3@news.orange.fr>
i resumed the example of the book cgi perl
I try to make him(it) walk
I do not understand why that walks(works) not
I throw(launch) it since the line of command(order)
The base of donnees does not exist
help help help
i am french
help help help
> #!/usr/bin/perl -w
> use CGI qw/:standard escapeHTML/;
> use strict;
> use Fcntl qw( :DEFAULT :flock );
> use DB_File;
> my $query = new CGI;
> use constant COUNT_FILE => "/usr/local/apache/data/counter/count.dbm";
> my %count;
> my $url = $ENV{DOCUMENT_URI};
> local *DBM;
>
> if ( my $db = tie %count, "DB_File", COUNT_FILE, O_RDWR | O_CREAT ) {
> my $fd = $db->fd;
> open DBM, "+<&=$fd" or die "Could not dup DBM for lock: $!";
> flock DBM, LOCK_EX;
> undef $db;
> $count{$url} = 0 unless exists $count{$url};
> my $num_hits = ++$count{$url};
> untie %count;
> close DBM;
> print p("visiteurs",tt(escapeHTML($num_hits)));
> close DBM;
> } else {
> print p("[Error processing counter data]");
> }
------------------------------
Date: Tue, 09 Jan 2007 14:44:39 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: problems DB_File
Message-Id: <45a3fdfd$0$63458$815e3792@news.qwest.net>
john.swilting wrote:
> i resumed the example of the book cgi perl
> I try to make him(it) walk
> I do not understand why that walks(works) not
> I throw(launch) it since the line of command(order)
> The base of donnees does not exist
>
> help help help
> i am french
> help help help
Can't help with that.
>
>> #!/usr/bin/perl -w
>> use CGI qw/:standard escapeHTML/;
>> use strict;
>> use Fcntl qw( :DEFAULT :flock );
>> use DB_File;
>> my $query = new CGI;
>> use constant COUNT_FILE => "/usr/local/apache/data/counter/count.dbm";
Likely that the UID running the Web server process can't
write that file. Try something in /tmp.
>> my %count;
>> my $url = $ENV{DOCUMENT_URI};
>> local *DBM;
>>
>> if ( my $db = tie %count, "DB_File", COUNT_FILE, O_RDWR | O_CREAT ) {
>> my $fd = $db->fd;
>> open DBM, "+<&=$fd" or die "Could not dup DBM for lock: $!";
>> flock DBM, LOCK_EX;
>> undef $db;
perldoc DB_File
"See "Locking: The Trouble with fd" for an explanation for why you
should not use "fd" to lock your database."
>> $count{$url} = 0 unless exists $count{$url};
>> my $num_hits = ++$count{$url};
>> untie %count;
>> close DBM;
>> print p("visiteurs",tt(escapeHTML($num_hits)));
>> close DBM;
Ahhh.. it's already closed.
>> } else {
>> print p("[Error processing counter data]");
The error message should be in $!.
print p("[Error processing counter data: $!]");
>> }
------------------------------
Date: Tue, 09 Jan 2007 16:37:39 -0500
From: "Todd M. Lewis" <utoddl@email.unc.edu>
Subject: Taint and $0
Message-Id: <45a40b22$1_2@news.unc.edu>
I'm running perl v5.8.8 under Solaris. When I'm not running tainted, $0
contains a normal "/path/to/my/pgm.pl". However, when I run the same
program tainted, $0 contains "/dev/fd/4".
How can I get the path to my perl program when tainted? The reason I
care is I have a set of test and production programs in the same
directory, and they have names like
prga.test.pl
prga.pl
prgb.test.pl
prgb.pl
etc. If the program is a ".test" version, it can tell that from $0 and
log debugging information. The production copies are identical, but they
run more quietly. This has worked very well until now, where for IPC
reasons I need to run one of these things sgid, and that turns on
tainting, and that breaks $0.
Any suggestions?
------------------------------
Date: Tue, 09 Jan 2007 10:24:16 +0100
From: hg <hg@nospam.org>
Subject: Re: Xah's Edu Corner: Introduction to 3D Graphics Programing
Message-Id: <DkPoh.21303$kn7.16808@newsfe23.lga>
Xah Lee wrote:
> I don't know OpenGL, but i think it is a low-level crap, and have done
> the industry huge irreparable damage the same way unix has.
So you _are_ psychic ! is the end of the world be in 2007 ?
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 9
************************************