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 4.49 How do I process/modify each element of an array?         


Author: PerlFAQ Server
Date: Mar 2, 2008 18: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.49: How do I process/modify each element of an array?

Use "for"/"foreach":

for (@lines) {
s/foo/bar/; # change that word
tr/XZ/ZX/; # swap those letters
}

Here's another; let's compute spherical volumes:

for (@volumes = @radii) { # @volumes has changed parts
$_ **= 3;
$_ *= (4/3) * 3.14159; # this will be constant folded
}

which can also be done with "map()" which is made to transform one list
into another:
Show full article (2.18Kb)
no comments
  Best way to distribute program with modules         


Author: January Weiner
Date: Mar 2, 2008 16:10

Hi,

I have written quite a complex (at least for me) program of >10k lines of
code, packed in a main file and a dozen modules. While I am writing up the
publication (yep, it's a scientific program), I am wondering, what would be
the best way to package it.

Specifically, I would like to make the installation for the user as
painless as possible. Right now I write something along the lines "move
the Xxx directory into /usr/local/lib/site_perl or any other apropriate
directory with Perl modules", but this is hardly satisfactory.

I really have no experience with that, and regretfully, I will not have
time to devote a lot of attention to proper packaging, because other issues
around the publication are more pressing. Is there anything simple I could
do? I know I could use the PAR module (actually, I use pp to create
binaries), but I would much prefer to have a simple "clever" installer script.

Best regards,

January
1 Comment
  Crypt::CBC vs individual cipher module differs?         


Author: Waylen Gumbal
Date: Mar 2, 2008 16:01

I noticed that if I use a "CBC compatible" crypt module directly, I get
a normal expected result. But if I use CBC with the same cipher type on
the same key and plaintext I get a completely different result.

I've been up and down the perldoc for Crypt::CBC and just can't figure
out why the results differ so much. Because they differ so much you
can't use one method to decrypt the other.

For example:

use Crypt::CBC;
use Crypt::OpenSSL::AES;

$key = 'secretpassphrase';
$text = 'Crypt Test #0001';

my $en1 = new Crypt::OpenSSL::AES($key)->encrypt($text);

my $en2 = new Crypt::CBC(
-key => $key, -cipher => 'Crypt::OpenSSL::AES'
)->encrypt($text);

my $en1h = unpack('H*', $en1);
my $en2h = unpack('H*', $en2);

print "OpenSSL AES\n[$en1h]\n\n";
print "AES via CBC\n[$en2h]\n\n";
Show full article (1.04Kb)
5 Comments
  FAQ 4.58 How can I know how many entries are in a hash?         


Author: PerlFAQ Server
Date: Mar 2, 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.58: How can I know how many entries are in a hash?

If you mean how many keys, then all you have to do is use the keys()
function in a scalar context:

$num_keys = keys %%hash;

The keys() function also resets the iterator, which means that you may
see strange results if you use this between uses of other hash operators
such as each().

--------------------------------------------------------------------
Show full article (1.34Kb)
no comments
  Re: php vs perl for RDBMS backend work         


Author: Jerry Stuckle
Date: Mar 2, 2008 11:59

dcruncher4@aim.com wrote:
> Hi,
>
> I would like to get an opinion on using php vs perl for backend
> database related work. This is basically a script for nightly batch jobs
> which reads from different databases and write to databases.
> So far I have used perl/DBI for this.
>
> I am looking into the possibility of using php for the same, if it
> provides any significant benefit in code maintenance etc.
>
> TIA.
>
>

Both are just languages. Neither one has any particular advantage in
maintenance, etc. It much more depends on the programmers who write the
code, how well the code is written and commented, the skills of the
people maintaining the code, and a bunch of other things.
Show full article (0.98Kb)
3 Comments
  package_name->new(); a basic language queston         


Author: werwer
Date: Mar 2, 2008 08:12

This isn't about PerlSAX, but a package construct I found there in an
example using the module. I have no idea what's going on here so I'm
guessing. This appears in the code

my $handler = SaxHandler->new();

But there is no SaxHandler anywhere in the documentation ..... but
wait! Later in the code the author defines a package as in

package SaxHandler;

and in this package are subroutines with names of the callbacks, the
SAX event handling routines, that SAX will call for each different XML
event (starting ending new final ....)

I had no idea a package name could be used in such a fashion. I
appreciate some short discussion of what's going on. Thanks.
3 Comments
  FAQ 4.59 How do I sort a hash (optionally by value instead of key)?         


Author: PerlFAQ Server
Date: Mar 2, 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.59: How do I sort a hash (optionally by value instead of key)?

(contributed by brian d foy)

To sort a hash, start with the keys. In this example, we give the list
of keys to the sort function which then compares them ASCIIbetically
(which might be affected by your locale settings). The output list has
the keys in ASCIIbetical order. Once we have the keys, we can go through
them to create a report which lists the keys in ASCIIbetical order.

my @keys = sort { $a cmp $b } keys %%hash;

foreach my $key ( @keys )
{
printf "%%-20s %%6d\n", $key, $hash{$key};
}
Show full article (2.85Kb)
no comments
  killing the children         


Author: lekonna
Date: Mar 2, 2008 05:27

Hi guys,

i'm having a bit of a problem here with the exec functionality. I seem
to be unable to kill the children of my process. Hope you can help me
with this one.

I'm doing a client-server setup where the server requests the clients
to start instances of a certain application and now the bugger doesn't
seem to die properly. The code in nutshell is here, i'll eliminate my
crappy message handling and just quote the handler funcs:


$pid = fork;
if ( $pid == 0 )
{
exec( $my_command,$my_args) or die "can't do it Jim!";
} else {
$jobs{$pid} = $my_args;
}
Show full article (1.09Kb)
5 Comments
  unsetenv in the shell         


Author: Si
Date: Mar 2, 2008 01:00

hi, i have a perl program that calls another application. this second
application uses the value of certain environment variables during its
operation. i'm having trouble with unsetting those variables during
the course of the perl script.

my (wrong) pseudo code:

$var1 = $ENV{'VAR1};
$var2 = $ENV{'VAR2'};
$var3 = $ENV{'VAR3'};

system( "unsetenv VAR1");
system( "unsetenv VAR2");
system( "unsetenv VAR3");

run_the_external_app;

system( "setenv VAR1 $var1");
system( "setenv VAR2 $var2");
system( "setenv VAR3 $var3");

can someone tell me what the correct syntax should be for this?
10 Comments
  FAQ 4.51 How do I permute N elements of a list?         


Author: PerlFAQ Server
Date: Mar 2, 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.51: How do I permute N elements of a list?

Use the "List::Permutor" module on CPAN. If the list is actually an
array, try the "Algorithm::Permute" module (also on CPAN). It's written
in XS code and is very efficient:

use Algorithm::Permute;

my @array = 'a'..'d';
my $p_iterator = Algorithm::Permute->new ( \@array );

while (my @perm = $p_iterator->next) {
print "next permutation: (@perm)\n";
}

For even faster execution, you could do:

use Algorithm::Permute;

my @array = 'a'..'d';
Show full article (3.36Kb)
no comments