comp.lang.perl.misc
  Home FAQ Contact Sign in
comp.lang.perl.misc only
 
Advanced search
March 2008
motuwethfrsasuw
     12 9
3456789 10
10111213141516 11
17181920212223 12
24252627282930 13
31       14
2008
 Jan   Feb   Mar   Apr 
 May   Jun   Jul   Aug 
 Sep   Oct   Nov   Dec 
2008 2007 2006  
total
comp.lang.perl.misc Profile…
RELATED GROUPS

POPULAR GROUPS

more...

 Up
  FAQ 5.33 How do I dup() a filehandle in Perl?         


Author: PerlFAQ Server
Date: Mar 14, 2008 18:03

This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

5.33: How do I dup() a filehandle in Perl?

If you check "open" in perlfunc, you'll see that several of the ways to
call open() should do the trick. For example:

open(LOG, ">>/foo/logfile");
open(STDERR, ">&LOG");

Or even with a literal numeric descriptor:

$fd = $ENV{MHCONTEXTFD};
open(MHCONTEXT, "<&=$fd"); # like fdopen(3S)

Note that "<&STDIN" makes a copy, but "<&=STDIN" make an alias. That
means if you close an aliased handle, all aliases become inaccessible.
This is not true with a copied one.

Error checking, as always, has been left as an exercise for the reader.

--------------------------------------------------------------------
Show full article (1.63Kb)
no comments
  handle tab-delimited file         


Author: Ela
Date: Mar 14, 2008 17:57

\t matches BOTH tab and space.

How can I split the following line into 2 words instead of 5?

1234\tI am a boy\n
3 Comments
  FAQ 5.38 How do I select a random line from a file?         


Author: PerlFAQ Server
Date: Mar 14, 2008 12:03

This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

5.38: How do I select a random line from a file?

Here's an algorithm from the Camel Book:

srand;
rand($.) < 1 && ($line = $_) while <>;

This has a significant advantage in space over reading the whole file
in. You can find a proof of this method in *The Art of Computer
Programming*, Volume 2, Section 3.4.2, by Donald E. Knuth.

You can use the File::Random module which provides a function for that
algorithm:

use File::Random qw/random_line/;
my $line = random_line($filename);

Another way is to use the Tie::File module, which treats the entire file
as an array. Simply access a random array element.
Show full article (1.67Kb)
no comments
  XML::Parser::Style::Subs         


Author: xhoster
Date: Mar 14, 2008 10:12

The code in XML::Parser::Style::Subs seems to be quite slow in some
situations, and also it silently eats any errors that might occur in
the call backs.

sub Start {
no strict 'refs';
my $expat = shift;
my $tag = shift;
my $sub = $expat->{Pkg} . "::$tag";
eval { &$sub($expat, $tag, @_) };
}

I've replaced it for my purposes with:

sub Start {
no strict 'refs';
my $sub = $_[0]->{Pkg} . "::$_[1]";
return unless defined &$sub;
&$sub(@_);
}

The sub End was also modified analogously.)
Show full article (1.13Kb)
1 Comment
  Perl's installed module isn't recognized         


Author: L. D. James
Date: Mar 14, 2008 07:59

Can someone tell me what's going wrong with my perl operation? I
recently started over my Linux, Apache, Mysql, and Perl on a new hard
drive when I had a drive failure. Everything on the system is freshly
installed. At present everything works except for my scripts that
uses DBD::mysql. I used cpan to install DBD::mysql. It appears to be
installed okay, but still fail to work.

Please look at the information itemized below.

Thanks in advance for any suggestions or comments.

Simplest code to reproduce the error:

commandline: perl -MDBD::mysql -e 1
Can't load '/usr/local/lib/perl5/site_perl/5.10.0/i686-linux/auto/DBD/
mysql/mysql.so' for module DBD::mysql: libmysqlclient.so.14: cannot
open shared object file: No such file or directory at /usr/local/lib/
perl5/5.10.0/i686-linux/DynaLoader.pm line 203.
at -e line 0
Compilation failed in require.
BEGIN failed--compilation aborted.

Attempt to install/verify module via CPAN:
Show full article (2.63Kb)
3 Comments
  P~(ptilde) 0.9 released, new scripting language with novel regex         


Author: ptilderegex
Date: Mar 14, 2008 07:27

P~ (pronounced "ptilde") is a new Java friendly scripting language.
The principle reason for creating it was to offer a new and more
powerful approach to creating regular expressions. Unlike all other
regex engines, P~ does not use the Perl-compatible metacharacter
syntax, instead using algebraic syntax for regex composition. This
decision opens the door to more powerful side-effects than even
possible in Perl, but preserving the readability and maintainability
of P~ regexes. In other regex engines, your regular expressions become
hard to read as the difficulty of the problem increases. Not so in P~.

While P~ makes it easy to grapple with matching and transformation
problems that are hard for even Perl programmers, its basic grammar is
Java-like, more so than even Groovy. This means that Java programmers
can quickly learn the basic grammar forms.

P~ is also Java friendly because you can import Java classes within
your scripts, and use their public apis just like in your Java code.
All you have to do is make sure that when you launch the Ptilde
scripting application, you include the appropriate Java libraries (jar
files) in the classpath.
Show full article (1.85Kb)
7 Comments
  FAQ 5.37 Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl?         


Author: PerlFAQ Server
Date: Mar 14, 2008 06:03

This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

5.37: Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl?

This is elaborately and painstakingly described in the file-dir-perms
article in the "Far More Than You Ever Wanted To Know" collection in
http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz .

The executive summary: learn how your filesystem works. The permissions
on a file say what can happen to the data in that file. The permissions
on a directory say what can happen to the list of files in that
directory. If you delete a file, you're removing its name from the
directory (so the operation depends on the permissions of the directory,
not of the file). If you try to write to the file, the permissions of
the file govern whether you're allowed to.

--------------------------------------------------------------------
Show full article (1.77Kb)
no comments
  POE and SOAP         


Author: Mpapec
Date: Mar 14, 2008 05:56

I want to build small soap server which should provide persistent DBI
statement handles. POE::Component::Server::SOAP handles one client at
the time, so there is a lot of waiting for other clients.

I've tried to change perldoc example so the server wouldn't block, but
now server doesn't respond at all. :)
http://search.cpan.org/~apocal/POE-Component-Server-SOAP-1.11/lib/POE/Component/Server/SOAP...

server
++++++
use strict;
use warnings;

use Data::Dumper;
use POE;
use POE::Component::Server::SOAP;

POE::Component::Server::SOAP->new(
'ALIAS' => 'MySOAP',
'ADDRESS' => 'localhost',
'PORT' => 32080,
'HOSTNAME' => 'MyHost.com',
);
Show full article (3.25Kb)
no comments
  assigning array to a scalar variable         


Author: venkatesh.naughty
Date: Mar 14, 2008 01:39

Hi all,
How to assign array variable to a scalar retaining the content of the
array in the scalar variable not number of elements ;
eg:
@array={"hi","venkatesh"};
$x=@array;
I dont want $x to store 2
instead to store hi venkatesh
7 Comments
  Posting Guidelines for comp.lang.perl.misc ($Revision: 1.8 $)         


Author: tadmc
Date: Mar 14, 2008 00:18

Outline
Before posting to comp.lang.perl.misc
Must
- Check the Perl Frequently Asked Questions (FAQ)
- Check the other standard Perl docs (*.pod)
Really Really Should
- Lurk for a while before posting
- Search a Usenet archive
If You Like
- Check Other Resources
Posting to comp.lang.perl.misc
Is there a better place to ask your question?
- Question should be about Perl, not about the application area
How to participate (post) in the clpmisc community
- Carefully choose the contents of your Subject header
- Use an effective followup style
- Speak Perl rather than English, when possible
- Ask perl to help you
- Do not re-type Perl code
- Provide enough information ...
Show full article (16.63Kb)
no comments
 
1 2