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
  insert codes dynamically         


Author: Rose
Date: Mar 5, 2008 19:37

I have to add objects dynamically in a code and therefore the number of
objects are not known beforehand. How to achieve this effectly in a simple
way? e.g.

#fixed codes

$panel = Panel->new(
-length => 1000,
-width => 10,
);

#dynamic codes

my $obj1 = Object::Generic->new(
-start => 10,
-end => 10,
-display_name => 'C'
);

my $obj2 = Object::Generic->new(
-start => 88,
-end => 89,
-display_name => 'T'
);
Show full article (0.90Kb)
10 Comments
  FAQ 5.3 How do I count the number of lines in a file?         


Author: PerlFAQ Server
Date: Mar 5, 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.3: How do I count the number of lines in a file?

One fairly efficient way is to count newlines in the file. The following
program uses a feature of tr///, as documented in perlop. If your text
file doesn't end with a newline, then it's not really a proper text
file, so this may report one fewer line than you expect.

$lines = 0;
open(FILE, $filename) or die "Can't open `$filename': $!";
while (sysread FILE, $buffer, 4096) {
$lines += ($buffer =~ tr/\n//);
}
close FILE;

This assumes no funny games with newline translations.

--------------------------------------------------------------------
Show full article (1.62Kb)
7 Comments
  module needs to know its own path         


Author: Marten Lehmann
Date: Mar 5, 2008 16:08

Hello,

within a perl module, I need to access content included with this
module, but stored in separate files (WSDL definitions in my case).

If my module lies in /usr/lib/perl5/xxx/MyModule.pm, the WDSL files
could be stored in /usr/lib/perl5/xxx/MyModule/WSDLs/*.wsdl or similar.

But how can the perl module find out where it has been loaded from? The
files I have to access would always be relative to the perl module. But
that doesn't help much, as the working directory within the perl module
for a perl script in /test/script.pl would always be /test and not the
path to the script. So reading from ./WSDLs/*.wsdl would fail.

Any ideas?

Regards
Marten
10 Comments
  Gtk2 IRC Client Sluggish and not Responsive         


Author: deadpickle
Date: Mar 5, 2008 14:23

I am writing a Gtk2 IRC client (and have been for months now) and have
been having problems with it. The problems keep occuring as I try to
figure out a good way to handle incoming messages as well as out
going. One module Parse::IRC has done wonders in organizing the server
outputs. Right now the program starts a Glib::Timeout on connection
then IO::Selects the socket and listens to see if the socket can be
read. This is causing the Gtk2 part of the program to be sluggish and
non-responsive but the terminal window receives inputs just fine. What
I'm looking for is a way to make this program work smoother (and
please dont suggest using Net::IRC it has the same problems).

#!/usr/local/bin/perl -w
use strict;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/;
use Parse::IRC;
use IO::Select;
Show full article (6.75Kb)
no comments
  Parsing blocks of text in Perl         


Author: mxyzplk
Date: Mar 5, 2008 12:35

OK, so every way I've thought of doing this is really ugly. I'm using
Perl 5.8.4 and only have access to the stock libraries, mostly.

What I need to do is parse through a text file and perform some
transformations on embedded link structures for a wiki content
conversion. A "link" is defined as anything wrapped in double
brackets - [[]], which can appear anywhere in a line of text
and multiple links can appear in a line of text.

1) If the link has a colon (":") in it, I need to strip out all
special characters and spaces (everything except [a-zA_Z0-9]) from the
portion before the colon but leave the part after the colon intact.
Examples:
[[Operation Intranet 2.0!:EvalHome|Eval Home]] -->
[[OperationIntranet20:EvalHome|Eval Home]]
[[UP Platform:Home|UP Platform]] --> [[UPPlatform:Home|UP Platform]]
Show full article (1.67Kb)
7 Comments
  FAQ 4.62 Why don't my tied hashes make the defined/exists distinction?         


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

This is an excerpt from the latest version perlfaq4.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 .

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

4.62: Why don't my tied hashes make the defined/exists distinction?

This depends on the tied hash's implementation of EXISTS(). For example,
there isn't the concept of undef with hashes that are tied to DBM*
files. It also means that exists() and defined() do the same thing with
a DBM* file, and what they end up doing is not what they do with
ordinary hashes.

--------------------------------------------------------------------
Show full article (1.35Kb)
no comments
  FAQ 4.65 How can I store a multidimensional array in a DBM file?         


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

This is an excerpt from the latest version perlfaq4.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 .

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

4.65: How can I store a multidimensional array in a DBM file?

Either stringify the structure yourself (no fun), or else get the MLDBM
(which uses Data::Dumper) module from CPAN and layer it on top of either
DB_File or GDBM_File.

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

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
Show full article (1.21Kb)
no comments
  FAQ 4.69 How can I use a reference as a hash key?         


Author: PerlFAQ Server
Date: Mar 5, 2008 00:03

This is an excerpt from the latest version perlfaq4.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 .

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

4.69: How can I use a reference as a hash key?

(contributed by brian d foy)

Hash keys are strings, so you can't really use a reference as the key.
When you try to do that, perl turns the reference into its stringified
form (for instance, "HASH(0xDEADBEEF)"). From there you can't get back
the reference from the stringified form, at least without doing some
extra work on your own. Also remember that hash keys must be unique, but
two different variables can store the same reference (and those
variables can change later).

The "Tie::RefHash" module, which is distributed with perl, might be what
you want. It handles that extra work.

--------------------------------------------------------------------
Show full article (1.65Kb)
no comments