Re: Can't locate CPAN.pm in @INC

2008-02-01 Thread Adriano Ferreira
On Feb 1, 2008 10:47 AM, Pradeep Mishra <[EMAIL PROTECTED]> wrote:
> hi all
>
> I have been trying to install spamassin using ...perl -MCPAN -e shell
> which throws an error
>
> Can't locate CPAN.pm in @INC (@INC contains:
> /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
> /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi
> /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi
> /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
> /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7
> /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5
> /usr/lib/perl5/site_perl
> /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
> /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi
> /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi
> /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
> /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7
> /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5
> /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi
> /usr/lib/perl5/5.8.8 .).
> BEGIN failed--compilation aborted.
> [EMAIL PROTECTED] ~]#
>
>
> Tried to search for CPAN.pm but is not found.
>
> perl version is
> [EMAIL PROTECTED] ~]# perl -v
>
> This is perl, v5.8.8 built for i386-linux-thread-multi
>
>
> packages installed
> [EMAIL PROTECTED] ~]# rpm -qa | grep perl
> perl-devel-5.8.8-32.fc8
> perl-libs-5.8.8-32.fc8
> perl-String-CRC32-1.4-3.fc8
> perl-5.8.8-32.fc8
> perl-ExtUtils-MakeMaker-6.30-32.fc8
> groff-perl-1.18.1.4-10.fc8
> perl-DBI-1.58-2.fc8
> perl-Test-Harness-2.56-32.fc8
> perl-DBD-MySQL-4.005-2.fc8.1
> perl-ExtUtils-Embed-1.26-32.fc8
> [EMAIL PROTECTED] ~]#
>
>
>
> Would appreciate if some one can help me solve this issue.

It looks like you need to install a rpm package which should probably
be named perl-CPAN or something like that. Your current system does
not have CPAN installed or have used some weird path perl is not
looking at.

>
> Thanks in advance.
>
> Regards
>
>
>
>
> --
> Good Judgement comes from Experience and Experience comes from bad
> Judgement!!
> The more I know, the more I realize I don't know!?
> The easiest way to find out is to try it!!!
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Shell qw(mysqldump) and localtime.

2007-09-03 Thread Adriano Ferreira
On 9/3/07, Shams Fantar <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I want to give a date (the year, the day, the hour and the minute) to a
> file. So, I use localtime function. But I don't understand how to use
> localtime (after reading the documentation on this function). Can you
> help me with this function?
>
> Next, I want to use a shell command, so I use the Shell function[2], and
> I must use the 'mysqldump' command :
>
> mysqldump -u root -p *** --all-databases > $FILE

The Shell module may be used to make this system call to the utility
'mysqldump' transparent to the code. Like this:

  use Shell qw( mysqldump );
  my $content = mysqldump( qw( -u root -p *** --all-databases ) );

The mysqldump() function gets all the output produced by the utility
'mysqldump'. But there's very much to be gained by using Shell. And
unless your script is very small, it's not such a good idea to use it
(the Shell core module).

>
> How could I use this command with the Shell function ?
>
> [1] : http://perldoc.perl.org/functions/localtime.html
> [2] : http://perldoc.perl.org/Shell.html
>
> I'm a beginner with perl... :-)
>
> Thanks !

Welcome to Perl.

Best regards,
Adriano Ferreira

> --
> Shams Fantar (http://snurf.info)
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Logging STDERR and other output

2007-08-30 Thread Adriano Ferreira
On 8/30/07, Beginner <[EMAIL PROTECTED]> wrote:
> On 30 Aug 2007 at 6:32, Peter Scott wrote:
>
> > On Thu, 30 Aug 2007 10:32:01 +0100, Beginner wrote:
> > > I want all the output plus any error messages to got to a log file. I
> > > used the BEGIN block to direct STDERR into the file:
> > >
> > > BEGIN {
> > >   open(STDERR, ">>/usr/local/myreports/report.log") || die "Can't
> > > write to file: $!\n";
> > > }
> > >
> > > use strict;
> > > use warnings;
> > > ...
> > > ### Start some logging ###
> > > my $log;
> > > my $logfile = "$dist_dir/report.log";
> > > open($log,">>$logfile") || die "Can't write to $logfile: $!\n";
> > > print $log "$0 called at ", &tm," with pid $$\n";
> >
> > Why are you using a BEGIN block?  Why not just make it the first
> > executable statement?  Do you have any other 'use' statements in the
> > program?
>
> Yes I do. Several standard modules plus one or 2 of my own. The BEGIN
> block adds the path to my modules as well so it really looks like
> this at the moment (I have tested Mumia's INIT yet):
>
> BEGIN { unshift @INC, '/etc/perl';

This is better done with

use lib qw(/etc/perl);

which doesn't need the surrounding "BEGIN" block.

> $| = 1;
> open(STDERR, ">>/usr/local/myreports/report.log") || die
> "Can't write to file: $!\n";
> }
>
> use MY::MakePDF;
> use MY::SendEmail;
> use MY::Number;
> use MY::PDF_Handler;
> use File::Basename;
> use strict;
> use warnings;
>
> I want the STDERR from those modules to go to the log file also.

Just perfect ;-)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Logging STDERR and other output

2007-08-30 Thread Adriano Ferreira
On 8/30/07, Peter Scott <[EMAIL PROTECTED]> wrote:
> On Thu, 30 Aug 2007 10:32:01 +0100, Beginner wrote:
> > I want all the output plus any error messages to got to a log file. I
> > used the BEGIN block to direct STDERR into the file:
> >
> > BEGIN {
> >   open(STDERR, ">>/usr/local/myreports/report.log") || die "Can't
> > write to file: $!\n";
> > }
> >
> > use strict;
> > use warnings;
> > ...
> > ### Start some logging ###
> > my $log;
> > my $logfile = "$dist_dir/report.log";
> > open($log,">>$logfile") || die "Can't write to $logfile: $!\n";
> > print $log "$0 called at ", &tm," with pid $$\n";
>
> Why are you using a BEGIN block?  Why not just make it the first
> executable statement?  Do you have any other 'use' statements in the
> program?

Because otherwise it would be too late to catch the output of other
compile-time statements like "use" or other "BEGIN" blocks.

> --
> Peter Scott
> http://www.perlmedic.com/
> http://www.perldebugged.com/
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: [OT] How do you use Perl?

2007-08-09 Thread Adriano Ferreira
On 8/9/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hello list,
>
> Just be curious to see how do you guys use Perl for work.Would you be
> pleased to give a vote below?
>
> [a] CGI/Web Development
> [b] System Administration
> [c] mod_perl -- write Apache handler
> [d] write commercial products
> [e] Biological analysis
> [f] others

There are more people that wish to know that kind of things. For
example, the 2007 Perl Survey is online to get the answers to some of
these questions. The results will be published by the start of
October.

http://perlsurvey.org/

Read the usage terms. Take the survey.

Cheers,
Adriano.

> For me I primarily used it for a and b.
> Thanks!
> 
> Check Out the new free AIM(R) Mail -- 2 GB of storage and
> industry-leading spam and email virus protection.
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Getting sub routine name as string

2007-08-02 Thread Adriano Ferreira
On 8/2/07, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote:
> Brown, Rodrick wrote:
> > How can I get the subroutine calling name as a string?
> >
> > Ie. Sub foo { } I would like to get foo back as a string.
>
> See `perldoc -f caller`

Shawn is absolutely right. The builtin "caller" is what you need to
get the subroutine name you're in and the callers all the way up.

Sub::Identify is when you want to go from a coderef to the subroutine name.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Getting sub routine name as string

2007-08-02 Thread Adriano Ferreira
On 8/2/07, Brown, Rodrick <[EMAIL PROTECTED]> wrote:
>
> How can I get the subroutine calling name as a string?
>
> Ie. Sub foo { } I would like to get foo back as a string.

Sub::Identify may be useful.
http://search.cpan.org/dist/Sub-Identify

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: **Installing CGI.pm

2007-07-31 Thread Adriano Ferreira
On 7/31/07, Johnson, Reginald (GTI) <[EMAIL PROTECTED]> wrote:
> On Jul 31, 1:31 pm, [EMAIL PROTECTED] (Jackson Samson) wrote:
> > I have downloaded the CGI.pm to my Windows machine.  Do I need a C
> > compiler to build this or can I use ppm install CGI.pm?
>
> Neither.  CGI is a core Perl module.  Nothing external needs to be
> installed.  You had no reason to download CGI.pm.  Just use it:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use CGI;
> # . . .
>
> Paul Lalli
>
> How would one find out what the other core perl modules are?

Module::CoreList is the answer. This will be a core module in 5.10,
but by now if you use 5.8 or older install the module via CPAN. When
it installs, a script called "corelist" comes together. With it you
can query about core modules. (Read the docs at
http://search.cpan.org/perldoc?Module::CoreList)

$ corelist CGI

CGI was first released with perl 5.004

$ corelist Class::Accessor

Class::Accessor was not in CORE (or so I think)

$ corelist /^File::/

File::Basename was first released with perl 5

File::CheckTree was first released with perl 5

File::Compare was first released with perl 5.004

File::Copy was first released with perl 5.002

File::DosGlob was first released with perl 5.00405

File::Fetch was first released with perl 5.009005

File::Find was first released with perl 5

File::Glob was first released with perl 5.006

File::GlobMapper was first released with perl 5.009004

File::Path was first released with perl 5.001

File::Spec was first released with perl 5.00405

File::Spec::Cygwin was first released with perl 5.006002

File::Spec::Epoc was first released with perl 5.006001

File::Spec::Functions was first released with perl 5.00504

File::Spec::Mac was first released with perl 5.00405

File::Spec::OS2 was first released with perl 5.00405

File::Spec::Unix was first released with perl 5.00405

File::Spec::VMS was first released with perl 5.00405

File::Spec::Win32 was first released with perl 5.00405

File::Temp was first released with perl 5.006001

File::stat was first released with perl 5.004

> 
>
> This message w/attachments (message) may be privileged, confidential or 
> proprietary, and if you are not an intended recipient, please notify the 
> sender, do not use or share it and delete it. Unless specifically indicated, 
> this message is not an offer to sell or a solicitation of any investment 
> products or other financial product or service, an official confirmation of 
> any transaction, or an official statement of Merrill Lynch. Subject to 
> applicable law, Merrill Lynch may monitor, review and retain e-communications 
> (EC) traveling through its networks/systems. The laws of the country of each 
> sender/recipient may impact the handling of EC, and EC may be archived, 
> supervised and produced in countries other than the country in which you are 
> located. This message cannot be guaranteed to be secure or error-free. This 
> message is subject to terms available at the following link: 
> http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch 
> you consent to the foregoing.
> 
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: how do I Append to Perl's @INC array using a variable

2007-07-23 Thread Adriano Ferreira

On 7/23/07, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote:

Chris Pax wrote:
> I know that if i use: use lib "/path/to/dir" works. but when I try to
> use a variable it does not work.
> here is my code:
> @dirs = split /\// , $0;
> delete $dirs[-1];
> my $runningDir = join "/",@dirs;
> $runningDir.="/";
> use lib $runningDir;

use File::Basename;
use lib dirname( $0 );


Pay attention to the fact that the solution by Shawn does not work
also if you try to do something like this:

use File::Basename;
my $dir = dirname( $0 );
use lib $dir;

because "use lib" happens at compile-time and "$dir = dirname( $0 )"
happens at runtime. That means the expression used as argument to "use
lib" should be computed at a BEGIN block, or the variables will
probably be undef when you use them.

use File::Basename;
my $dir;
BEGIN { $dir = dirname( $0 ); }
use lib $dir;

will work. (But that's compile time also. The difference is that you
promoted some of your computation to earlier evaluation.)

If you really want to change the library path in runtime, you will need to use:

require lib; # somewhere

lib->import( $dir );# or

push @INC, $dir;# which is just what "lib" does but with some extras


--
Just my 0.0002 million dollars worth,
   Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: how to launch perl

2007-07-20 Thread Adriano Ferreira

On 7/20/07, Chas Owens <[EMAIL PROTECTED]> wrote:

On 7/20/07, Adriano Ferreira <[EMAIL PROTECTED]> wrote:
snip
> Just adding to what John already said, it hangs because, when used
> without arguments like script file names or "  -e 'print qq{Hello,
> world\n}'   ", it expects the script is coming from the standard
> input.
>
> So you can do
>
> $ perl -wT
>
> print "Hello, world!\n";
>
> for (1..10) {
> print STDOUT ('one','two','three')[$_ % 3];
> }
>
> Hello, world!
>
> ^D (or something that tells your system the stream is over)
>
> twothreeonetwothreeonetwothreeonetwo
snip

There are also some Perl REPLs* out there that allow you to use a Perl
interpreter interactively.

zoidberg, a Perl shell:
http://search.cpan.org/~pardus/Zoidberg-0.95/lib/Zoidberg.pm


zoidberg is intented to be a shell (like bash, zsh) only that the
command language is Perl. Not exactly a simple REPL.


psh, another Perl shell: http://sourceforge.net/projects/psh/
Devel::REPL, a modern Perl REPL:
http://search.cpan.org/~mstrout/Devel-REPL-1.001000/lib/Devel/REPL.pm


The modernity of Devel::REPL is at using state-of-art Perl OO like
Moose and being extendable. Beyond that, this modernity means today
some 5 seconds to start the interactive interpreter ;-)

$ re.pl
(5 seconds later, your prompt:)
$



There are probably others out there.


I am one of the contenders here, having written Shell::Perl

http://search.cpan.org/dist/Shell-Perl/

which needs severely more work to be a really decent REPL. But for
now, it works (if you accept its limitations)


* REPL stands for Read, Eval, Print, Loop.



Cheers,
Adriano Ferreira

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: how to launch perl

2007-07-20 Thread Adriano Ferreira

On 7/20/07, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:

Hey Guys,
I am working on linux (redhat) 1999 version without the xwindows.
I have configured my dns server on this linux box and it works fine for my test 
lab network at home. Apache and sendmail are also working fine without any 
problem.
I have this huge book called the camel about perl which i have read
over ten times before even touching the program perl itself to get the theory 
of the whole thing. now when i went to the shell as root
trying to launch perl from #!/usr/bin/perl -wT
nothing seems tobe working, it hangs and doesn't go any further on the next 
line for ever till i kill the process and then it tells me stopped perl. what 
is it that i am ding wrong , i need somebody to help me understand how to 
launch this program perl. i know it is installed because the program tells me 
everything is o.k when i rpm -q perl.


Just adding to what John already said, it hangs because, when used
without arguments like script file names or "  -e 'print qq{Hello,
world\n}'   ", it expects the script is coming from the standard
input.

So you can do

$ perl -wT

print "Hello, world!\n";

for (1..10) {
   print STDOUT ('one','two','three')[$_ % 3];
}

Hello, world!

^D (or something that tells your system the stream is over)

twothreeonetwothreeonetwothreeonetwo


i even typed in all the example perl cgi scripts that i learned
still nothing, i like working upwards that is why i am using
a lower version of linux and then try to move on to the latest
kernels.
please let me know what to do .
thanks in advance
john conteh
africanuniversityonline.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: interpolation of function reference in a here doc

2007-07-02 Thread Adriano Ferreira

On 7/2/07, Gabriel Striewe <[EMAIL PROTECTED]> wrote:

Dear List,

I wanted to interpolate a function reference in a here doc.
The following works fine:

my $hello = sub {
 return "hello world!";
};

printf "hello $s\n", &$hello();

But when I use a heredoc instead, it doesn't work:

print <

You will encounter the problem if instead of

   printf "hello %s\n", &$hello();

you would have tried:

   print "hello &$hello()\n";

That's an issue with the rules of string interpolation. (Read "perldoc
perlop", section on quote-like operators.) Simplistically, I think the
right thing you are expecting for (calling the code ref in $hello) is
not done because the only sigils that matter in interpolation are $
and @. That's why

  $ perl -e '$h = sub {1}; print "hello &$h()" '
  hello &CODE(0x10240d64)()

(where the only thing interpolated was the stringification of the code
ref in $h).

The weird/scary way to make it work is

$ perl -e '$h = sub {1}; print "hello @{[ &$h() ]}" '
hello 1



Thanks for your advice.

Gabriel

--
http://www.gabriel-striewe.de



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Leading zeros kept or not kept while increment or decrement

2007-06-12 Thread Adriano Ferreira

On 6/12/07, Angerstein <[EMAIL PROTECTED]> wrote:


Perl does
$x="0001";
$x++;
print $x;

Output:
0002

BUT

$x="0002";
$x--;
print $x;

Output:
1

Why and how can I avoid that.

(yes, i know about printf)


So use it ;-) Read the section "Auto-increment and Auto-decrement" in
" perldoc perlop " which ends with the phrase

 The auto-decrement operator is not magical.

Unlike ++, which keeps the string-ish nature of the variable contents,
the -- operator turns the string into a number and simply does a
numerical decrement with it. So if you need this four digit format and
a decrement, you'll have to use printf (or sprintf).

Cheers,
Adriano Ferreira.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: new vs ->new

2007-06-11 Thread Adriano Ferreira

On 6/11/07, Robert Hicks <[EMAIL PROTECTED]> wrote:

Dr.Ruud wrote:
> "Adriano Ferreira" schreef:
>
>> Definitely go with
>>  my $test = Some::Module->new;
>
> or even with:
>my $test = Some::Module::->new();
>
While I am sure that will work...I have never seen it with parens after
the new.


As the docs say, there is nothing special about C< new >. It is only a
convention that it is the usual named used for a constructor. As any
other methods without arguments, it can be invoked as

 Some::Module->new

or

Some::Module->new()

But on the hand, it the constructor has parameters, you will
forcefully need the parameters

Some::Module->new($arg1, $arg2)

because

Some::Module->new $arg1, $arg2

(or something like that) is illegal. This is different from
subroutines invoked without parentheses around their arguments (which
are legal if the sub definition was seen before so that the
interpreter knows it refers to code). But that has to do with
requirements of Perl syntax.

Cheers,
Adriano Ferreira.


Robert

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Run a block of sql commands using 'here document'

2007-06-08 Thread Adriano Ferreira

On 6/8/07, Martin Barth <[EMAIL PROTECTED]> wrote:

Hi,

> I know that using 'Here Documents', we can output multiple lines. But is it
> possible to run a couple of commands?
>
> $s = qx [sqlplus user/[EMAIL PROTECTED] < select 2 from DUAL;
> exit
> ENDOFSQL];

what do you think about that:

open(DBI, "| sqlplus user/[EMAIL PROTECTED]");
then print DBI with a Here Document?

that should work, shouldn't it?


Martin's idea seems the way to go. You can abstract it via

sub sqlplus {
  my $param = shift;
  my $script_text = shift;
  open my $script, "| sqlplus $param" or die $!;
  print $script $script_text;
  close $script or die $!;
}

sqlplus("user/[EMAIL PROTECTED]", <

Re: new vs ->new

2007-06-08 Thread Adriano Ferreira

On 6/8/07, Robert Hicks <[EMAIL PROTECTED]> wrote:

I see some modules that call "new" like:

my $test = new Some::Module;

and some like:

my $test = Some::Module->new;

Is there a difference and what is the "recommended" way?


Definitely go with

my $test = Some::Module->new;

The indirect object notation is ambiguous and many Perl developers
discourage its use. IIRC, this also made its way to Perl documentation
as well: all the core modules were updated to get rid of these kind of
expressions in its source, documentation and tests.

I'm not sure it's already in 5.8.8 docs but " don't use it [the
indirect notation]! " is what you will hear from many people.




Robert

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Exporter query

2007-06-06 Thread Adriano Ferreira

On 6/6/07, jeevs <[EMAIL PROTECTED]> wrote:

#!c:/perl/bin/perl.exe
#Calculator.pm

package calc;

use strict;
use warnings;
use Exporter;

our @ISA = qw(Exporter);
our @EXPORT = qw(add);

sub add
{
my ($num1,$num2) = @_;
$num1+$num2;
}

1;

>>>>>>>>>>>>>>>>>>>

#!c:/perl/bin/perl.exe
#adcalculator.pl

use strict;
use warnings;
use Calculator;

my $addn = add(1,9);
print $addn;

>>>>>>>>>>>>>>

it says
undefined subroutine &main::add called at adcalculator,pl line 8.


Where am I going wrong???


Your sin was these two lines:


#Calculator.pm
package calc;


You stuffed the package calc into a file named "Calculator.pm". When you say

   use Calculator;

you do

   BEGIN {
require Calculator; # which loads Calculator.pm
Calculator->import; # if the Calculator package has an import sub
   }

The &add sub is exported by the calc package, which inherited the
import from Exporter to get these exporting abilities. But this import
was never called.

 require Calculator;
 calc->import;

would work. But what you probably want is to use

 package Calculator; # in your Calculator.pm file

Cheers,
Adriano Ferreira

P.S. As a stylistical note, usually you provide exporting capabilities
to a module via Exporter with code like that:

  require Exporter; # no need to use
  our @ISA qw(Exporter);

or

   use base qw(Exporter);



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Convert german umlaut to ascii

2007-05-22 Thread Adriano Ferreira

On 5/21/07, Andreas Moroder <[EMAIL PROTECTED]> wrote:

Hello,

in our application I have to convert all german Umlaute in a string to a
two char combination ä to ae, Ö to OE and so on.

Can anyone please tell me how to do this ?


Use Lingua::DE::ASCII.

   http://search.cpan.org/dist/Lingua-DE-ASCII/

I learned it existed in the PerlMonks thread "RFC: How to unaccent text?"

   http://www.perlmonks.org/?node_id=609319

when [salva] made this comment

   http://www.perlmonks.org/?node_id=609332

Regards,
Adriano Ferreira



Thanks
Andreas


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Redirecting STDOUT & STDERR

2007-05-07 Thread Adriano Ferreira

On 5/7/07, Karyn Williams <[EMAIL PROTECTED]> wrote:

I have this script I have been working on where I need to redirect STDOUT
and STDERR to files at the beginning of the script and then back to default
(terminal) at the end of the script. I found an example on-line and used it
and it works, however it generates a warning when running my script. I
would prefer to make that warning go away. This is the output of the script:


IIRC, you may get rid of these warnings with at least two different solutions:

(1) cheat, and tell Perl not to warn on things it "thinks" to have
been used only once

no warnings "once";  # would be enough


alum# ./match.pl
Name "main::OLDERR" used only once: possible typo at ./match.pl line 38.
Name "main::OLDOUT" used only once: possible typo at ./match.pl line 37.


Because the warnings are just that: the Perl interpreter thinks OLDERR
and OLDOUT were used just once, because they show up in the open
statements and again when you restore the STDOUT and STDERR.


open(STDOUT, ">&OLDOUT");
open(STDERR, ">&OLDERR");


But in these, they are part of a string and the interpreter could not
detect by syntactical means that they will be used again.

(2) As you're duping, I think you may close the handles explicitly
after the restoration of STDOUT and STDERR.

close OLDOUT;
close OLDERR;

In this case, Perl would see a second use of these handles and will
not complain.

Regards,
Adriano Ferreira.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Perl versus other scripting language

2007-03-30 Thread Adriano Ferreira

On 3/30/07, Rob Dixon <[EMAIL PROTECTED]> wrote:

Jean-Rene David wrote:
> * Rob Dixon [2007.03.30 08:30]:
>> - You could add Lua to the list. But then remove it - it's awful.
>
> FYI, I have read much harsher comments about perl on the lua mailing
> list.

I'm not surprised. People will always tend to take sides, however
senseless it may be.

> I ignored them at the time and will do the same here, though I
> wouldn't mind hearing more substantive criticisms. That is, if people
> are able to discuss such thing without losing their calm.

My main criticism of Lua is its bizarre generic for construct, which
hides the application of an iterator function and state variable in a
deceptively simple syntax. Apart from that there is only the C-type
for loop.

I also dislike the 'everything is a hash' approach, which could be OK
except that data can have /both/ string and integer indices. And there
is the anomaly that, in the case of sparse arrays, the length operator
can arbitrarily pick any undefined element in a structure and
nominate it as the end (and therefore the size) of the array.

> As far as I can understand, the two languages are not primarily
> targeted at the same kind of application. I'm not an expert in
> either, but neither looks "awful" to me in its own primary
> application domain, though each may be a bit of a stretch in the
> *other's* domain.

It is an embedded language, and needs a host program to be useful. It is
usable as a stand-alone language embedded in a shell program, but that
is not it's primary environment. I only mentioned it as it often comes up
in a discussion with Ruby, Python and Perl.

This thread is relevant on this newsgroup only insofar as it relates to
Perl programming, and I don't really want to say more here for fear of
getting too far off topic. I would, however, welcome a reference for a
Lua mailing list so that I can see the comments for myself.


I didn't understand exactly if the reference you want is about
arguments of Lua developers on Perl or for a Lua mailing list for
itself. Anyway, lua-l is the official mailing list for this language:

http://www.lua.org/lua-l.html (Homepage)
http://bazar2.conectiva.com.br/mailman/listinfo/lua (to join - via
Mailman interface)

Adriano Ferreira


Cheers,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: what does a lone percent sign mean?

2007-03-06 Thread Adriano Ferreira

On 3/6/07, Tony Heal <[EMAIL PROTECTED]> wrote:

I am trying to determine how this does what it does.



sub IsLeapYear

{

   my $year = shift;

   return 0 if $year % 4;

   return 1 if $year % 100;

   return 0 if $year % 400;

   return 1;

}


The binary operator % is the modulo or remainder operation.

perl -e 'print 10 % 5'
0

perl -e 'print  11 % 5'
1

perl -e 'print 12 % 5'
2

perl -e 'print 13.2 % 5'
3

Read more about it in "perldoc perlop", section "Multiplicative Operators".


But I do not understand, and I can not find what a single, lone % means.



Anyone know?



Tony




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: slurp hash from file

2007-02-27 Thread Adriano Ferreira

On 2/27/07, Jorge Almeida <[EMAIL PROTECTED]> wrote:

I want to define a hash reference like this:

my $h={
 a => 'a',
 b => 'aa &&\
 bbb',
};

(Note the string containing escaped newlines.)

Now, the point is that I have the block
 a => 'a',
 b => 'aa &&\
 bbb',
in a text file. It would be nice to be able to just slurp the file as-is
to define $h.

Is there any way to do this? The best workaround I can think of is to have a
modified file, with entries separated by empty lines:
 a => 'a',

 b => 'aa &&\
 bbb',

I could then slurp the file as a single string, split the string on
/\n\n/, etc., because I know the hash values will not contain empty
lines. But this leaves an uncomfortable feeling, since the original file
contents are already as we would write them in the main program...

Any idea?


Let's say your data is in the file "data.pl". Then

 my %hash = do "data.pl";
 my $hash_ref = \%hash;


--
Jorge Almeida

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: converting to mixed case

2007-02-26 Thread Adriano Ferreira

On 2/26/07, jm <[EMAIL PROTECTED]> wrote:

is there a function, module, script, etc. that converts all uppercase to
proper mixed case.  this particular need is for an address list that is all
uppercase


Doing it blindly, can be easily achieved with regexes:

$address =~ s/(\w)(\w*)/\u$1\L$2/g;

which applied over each line of


1370 W 14TH ST
ADA,OK
74837


results in

1370 W 14th St
Ada,Ok
74837

which is not perfect, because it is pretty dumb as I said. To do a
better job, you need to sophisticate the recognition of the address
pieces and then apply s/(\w)(\w+)/\u$1/\L$2/ selectively to the parts
(plus your extra tidyings like a trailing dot and extra spaces).

Note. Converting a word into first letter in upper case and the
remaining in lower case, can also be done with s/(\w+)/\L\u$1/



1370 W. 14th St.
Ada, OK
74837

thanks for any help,
joe

--
since this is a gmail account, please verify the mailing list is included in
the reply to addresses



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: BInding operator fails

2007-02-26 Thread Adriano Ferreira

On 2/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:


Thank you both.  I am trying to find out why "!~"  operator fails.  It is due to the 
whitespaces.  but I am using "six" to ignore spaces.


It has nothing to do with whitespaces. As Tom said:

On 2/26/07, Tom Phoenix <[EMAIL PROTECTED]> wrote:

> if ($result !~ /$rdns/ix) {

That's checking whether $rdns, as a pattern, does not match the string
in $result. (Was that supposed to be $result1?) But I think you're
asking for this, maybe:


To check that $result1 is not a part of $rdns, you must say

   $rdns   !~  /\Q$result1\E/ix
   # which reads as:
   #  this stringdoes not match   the literal content
of $result1

If you exchange the pieces, it will always fail to find that the
smaller $result1 has a large piece $rdns within it.


Sorry guys.  Below is the actual code.  I made the changes that A.R. Ferreira 
suggested and it fails.

use strict;
use warnings;

my $rdns="cn=Exchange Sites,cn=Proxy Views,cn=JoinEngine Configuration,ou=Conf,o
u=InJoin,ou=applications,dc=marriott,dc=com";

my $result="cn=Exchange Sites";

if ($result !~ /\Q$rdns\E/six) {
  print "\nresult: '$result'";
  print "\nrdn: '$rdns'\n";
} else {
  print "String is there\n";
}
OUTPUT is:
$ ./test.pl
result: 'cn=Exchange Sites'
rdn: 'cn=Exchange Sites,cn=Proxy Views,cn=JoinEngine 
Configuration,ou=Conf,ou=InJoin,ou=applications,dc=marriott,dc=com'

Tom your code works fine. But I was tring to understand why "!~" fails above.

use strict;
use warnings;

my $rdns="cn=Exchange Sites,cn=Proxy Views,cn=JoinEngine Configuration,ou=Conf,o
u=InJoin,ou=applications,dc=marriott,dc=com";

my $result="cn=Exchange Sites";

if ($result !~ /\Q$rdns\E/six) {
  print "\nresult: '$result'";
  print "\nrdn: '$rdns'\n";
} else {
  print "String is there\n";
}
OUTPUT is:

String is there



-Original Message-
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: beginners@perl.org
Sent: Mon, 26 Feb 2007 12:29 PM
Subject: Re: BInding operator fails


On 2/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> Hi. I have a problem with the below code. I have two strings, $rdns and 
$result1.
> I want to make sure $result 1 is NOT part of $rdns. But the below fails...thus
> instead of printing the else part of the if-else-loop. It print the main 
part. Does
> anyone know what coudl cause this.

> if ($result !~ /$rdns/ix) {

That's checking whether $rdns, as a pattern, does not match the string
in $result. (Was that supposed to be $result1?) But I think you're
asking for this, maybe:

 if (index($rdns, $result) == -1) {
  print "\$result isn't part of \$rdns.\n";
 }

The index function is covered in perlfunc. Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

-- To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Check out the new AOL.  Most comprehensive set of free safety and security 
tools, free access to millions of high-quality videos from across the web, free 
AOL Mail and more.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: BInding operator fails

2007-02-26 Thread Adriano Ferreira

On 2/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

All,

Hi.  I have a problem with the below code.  I have two strings, $rdns and 
$result1.  I want to make sure $result 1 is NOT part of $rdns.  But the below 
fails...thus instead of printing the else part of the if-else-loop.  It print 
the main part.  Does anyone know what coudl cause this.

$rdns="cn=Exchange Sites,cn=Proxy Views,cn=JoinEngine 
Configuration,ou=Conf,ou=InJoin,ou=applications,dc=marriott,dc=com
pwdChangedTime=2007010112.00Z";

$result1="Exchange";

if ($result !~ /$rdns/ix) {
  print "\nresult: '$result'";
  print "\nrdn: '$rdns'\n";
} else {
  print "it is not there\n";
}



I think that you want to say that instead:

if ($rdns !~ /\Q$result1\E/ix) {

to make sure you can't find the contents of $result1 inside $rdns. You
may use the Perl built-in index as well, which will be even faster.

And don't forget to run your code under

  use strict;
  use warnings;

because your piece of code assigns to $result1 and test $result. That
would be obvious with strict and warnings.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: concatenation

2007-02-12 Thread Adriano Ferreira

On 2/12/07, Sayed, Irfan (Irfan) <[EMAIL PROTECTED]> wrote:

Hi All,

I need to concatenate specific string for each element in the array. I
tried in the following way with the help of join operator.

foreach (@mail)
{
 my $str1=$_;
 $str1=$str1 . "@abc.com";


"@abc.com" is an interpolating string, which tries to interpolate the
content of an array variable called @abc into the resulting string.
You must use escaping

"[EMAIL PROTECTED]"

or single quotes (as suggested by Jeff Pang):

'@abc.com'

You may find faster this type of errors if you insist on starting your
Perl scripts with

use strict;
use warnings;

This way a mistake like

$ perl -e '$a = "@abc.com"; print $a'
.com

won't pass unnoticed. "use warnings" makes it complain with useful hint:

$ perl -e 'use warnings; $a = "@abc.com"; print $a'
Possible unintended interpolation of @abc in string at -e line 1.
Name "main::abc" used only once: possible typo at -e line 1.
.com

and "use strict" makes it stop because you never declared an @a
variable in the current scope:

$ perl -e 'use strict; use warnings; $a = "@abc.com"; print $a'
Possible unintended interpolation of @abc in string at -e line 1.
Global symbol "@abc" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors.


 print "$str1\n";

}

But somehow it is not getting concateneted.

please help.

Regards
Irfan.




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Extract user from email address

2007-02-08 Thread Adriano Ferreira

On 2/8/07, Mathew Snyder <[EMAIL PROTECTED]> wrote:

Does this look like it *should* work?

while ($data->get_tag("small")) {
my $email   = $data->get_trimmed_text("/small");
my $addr= new Email::Address1(undef, $email);


What's this Email::Address1 ?


my $addrUser= $addr->user;
if ($email =~ m/^ids-tripwire/gmx or $email =~ m/^tripwire/gmx or
exists($userID{$addrUser})) {
next;
}
else {
push @emails, $email if $email =~ m/[EMAIL PROTECTED]/gmx;
}
}


ids-tripwire and tripwire does not look like e-mail addresses, so you
should test them before using Email::Address (or $addr->user will not
be very useful, returning undef). Otherwise, something that looks like
a valid address doesn't need to be checked with m/[EMAIL PROTECTED]/ -- it would
be equivalent to asking "if $addr->user" to make sure you have an
address that was successfully parsed.



I have filled the %userID hash with the usernames of people that are authorized
to use the system I'm writing this script for (usernames match user portion of
email addresses).  What it is doing is extracting email addresses from a webpage
returned by HTML::TokeParser and WWW::Mechanize.  What I am expecting it to do
is pull the user portion of each email address extracted, compare it to my hash
of user IDs and move on to the next if it is found.  Is that what you see?

On an unrelated note, will the regexes that I use for ids-tripwire and tripwire
work as they are or do I need to put the '@domain.com' portion in too?  The
domain will never change and I only need to worry about those two addresses
outside of the users.

Adriano Ferreira wrote:
> On 2/2/07, Mathew Snyder <[EMAIL PROTECTED]> wrote:
>> I have a script which extracts email addresses from a web page, pushes
>> them into
>> an array and then prints them out before asking if I wish to perform
>> the work on
>> them that is required.
>>
>> What I would like to do is compare the username portion of the email
>> address to
>> a list of usernames in a hash to determine if the email address should be
>> skipped.  I just don't know how to write out the regex for that.  The
>> line I
>> have so far is
>> push @emails, $email if $email =~ m/[EMAIL PROTECTED]/gmx unless ($email =~ 
m/^
>>
>> I don't know how to further this to accomplish what I need.  Can
>> someone please
>> help.
>
> Be lazy. Use Email::Address to take care of the parsing of the e-mail
> addresses and many subtleties in the specification you even didn't
> want to know about.
>
> use Email::Address;
> my $addr = Email::Address->new(undef, '[EMAIL PROTECTED]');
> my $user = $addr->user; # this is "casey"
>
> Regards,
> Adriano Ferreira.
>
>>
>> Thanks,
>> Mathew
>>
>> --
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>> http://learn.perl.org/
>>
>>
>>
>



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: while(1) or redo [was: Re: IPC problem]

2007-02-07 Thread Adriano Ferreira

On 2/7/07, Rob Dixon <[EMAIL PROTECTED]> wrote:

Igor Sutton wrote:
> Hi fellows,
>
>> Dave, you wanted to use
>>
>> while (1) {
>>   ...
>>   the code to be repeated
>>   ..
>> }
>>
>
> The above code could be written like this:
>
> {
>...
># the code to be repeated
>...
>redo;
> }
>
> Do you think this is better or worse than the other idiom? I like the
> last more.

You are welcome to use it, but beware that people reading your code may not
understand what you are doing. 'redo' is uncommon and not universally known.
Furthermore it is easy to miss as it camouflaged at the same indent level as and
at the end of the block of code to be repeated. The first example proclaims
loudly that the following block is to be repeated indefinitely, while the second
mutters the same thing about the block it is part of.


I think Rob got the point here. This subtle construction may be made
more explicit by using explicit labels like this:

LOOP: {
   ...
   # the code to be repeated
   ...
   redo LOOP;
}

It helps readability, but not that much for people not used to Perl.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: how to embed data in perl programs

2007-02-07 Thread Adriano Ferreira

On 2/7/07, Sharan Basappa <[EMAIL PROTECTED]> wrote:

Hi Tom,

What if I wanted to have multiple embedded (and separate) texts embedded
in my program. Are you saying that I can have only one text section and that
should have keyword DATA.
Actually when I wrote example, I assumed that double underscore tell the
parser
that a text section starts (so used my own name - my_block)


So you have to take a look at Inline::Files, as suggested by John Krahn.


Thanks ..


On 2/6/07, Tom Phoenix <[EMAIL PROTECTED]> wrote:
>
> On 2/6/07, Sharan Basappa <[EMAIL PROTECTED]> wrote:
>
> > Question is how to embed text in a perl program instead of reading it
> from a
> > file
> > or initializing the text in a string variable.
>
> Are you looking for here-documents? Look in perlop under Quote and
> Quote-like Operators to see the different ways of putting text data
> into your program.
>
> > Another question is whether perl will replace the variable defined in
> > the embedded text with actual values ?
>
> Do you mean double-quote interpolation? Here-docs normally
> interpolate, but you can disable that (akin to single-quoting instead
> of double-quoting).
>
> > while ()
>
> > __MY_BLOCK__
>
> It looks as if you've seen the special DATA filehandle and the
> __DATA__ marker; but those don't generalize like that. Nice try,
> though. (If you change those back to DATA in your program, I think it
> will do what you expected. Consider adding 'use strict' and 'use
> warnings', though.)
>
> Hope this helps!
>
> --Tom Phoenix
> Stonehenge Perl Training
>



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Does Minimal Perl works for beginners?

2007-02-02 Thread Adriano Ferreira

On 2/2/07, Hoffmann <[EMAIL PROTECTED]> wrote:

Dear All,

I am a Perl beginners, and I have heard about Minimal Perl. Could you,
please, let me know if that would be a good option for a beginners start
learning/practice Perl? Or that 'flavour' of the language would work
better for more advanced programmers.


I don't think there is such thing as a recognized subset of Perl that
is worthy for beginners or advanced users. You may always use how much
Perl you are comfortable with. This is something recurring in what
Perl authors and developers say all the time.

Well, there could be some "Minimal Perl" that one author or other
tried to define and then said "this is what beginners should look for
at first". But this is no consensus among Perl programmers and
probably not adequate for everyone.

While we're on this, there is a miniperl that is compiled during the
compilation of the Perl interpreter itself that implements a useful
subset of the language, strong enough to equip the build process with
advanced capabilities. This is a tool for the developers of the Perl
core and not useful outside this context IIRC.

Kind regards,
Adriano Ferreira.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Extract user from email address

2007-02-02 Thread Adriano Ferreira

On 2/2/07, Mathew Snyder <[EMAIL PROTECTED]> wrote:

I have a script which extracts email addresses from a web page, pushes them into
an array and then prints them out before asking if I wish to perform the work on
them that is required.

What I would like to do is compare the username portion of the email address to
a list of usernames in a hash to determine if the email address should be
skipped.  I just don't know how to write out the regex for that.  The line I
have so far is
push @emails, $email if $email =~ m/[EMAIL PROTECTED]/gmx unless ($email =~ m/^

I don't know how to further this to accomplish what I need.  Can someone please
help.


Be lazy. Use Email::Address to take care of the parsing of the e-mail
addresses and many subtleties in the specification you even didn't
want to know about.

use Email::Address;
my $addr = Email::Address->new(undef, '[EMAIL PROTECTED]');
my $user = $addr->user; # this is "casey"

Regards,
Adriano Ferreira.



Thanks,
Mathew

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Use of uninitialized value in string eq

2007-01-26 Thread Adriano Ferreira

On 1/26/07, Jen Spinney <[EMAIL PROTECTED]> wrote:

Hello list!

I apologize in advance for not posting a complete sample script that
shows my problem, but I can't isolate it outside of my (rather large)
perl application.

My problem is that I'm hit with a barrage of warnings that tell me I'm
using uninitialized values.  The first warning that occurs complains
of a "use of uninitialized value in string eq" at line 505 of my
script.  Line 505 (I've triple-checked the line number and the correct
source) reads:

if ($exploit_name eq 'ALL') # <-- line 505

I had no idea how $exploit_name could be undefined, so I added the
following two statements right before the if statement:

print "\$exploit_name is not any sort of false\n" if $exploit_name;
print "String literal is not any sort of false\n" if 'ALL';
if ($exploit_name eq 'ALL') # <-- now line 507


To see what you really got at $exploit_name, use Data::Dumper,
Data::Dump or any of your favourite dumpers:

   use Data::Dump qw(dump);
   print "\$exploit_name =", dump($exploit_name), "\n";

In some circumstances, the line of the warning may be wrong. So the
problem can be around line 507 instead of exactly there.


I originally only check if the two strings were defined, but then I
read in perldiag that "An undefined value was used as if it were
already defined. It was interpreted as a "" or a 0, but maybe it was a
mistake. To suppress this warning assign a defined value to your
variables."  So, to be safe, I verified that neither $exploit_name nor
'ALL' could be any kind of false value.

But still, this is my output:

$exploit_name is not any sort of false
String literal is not any sort of false
[*] WARNING: Use of uninitialized value in string eq at spinsploit.pl
line 507,  line 2.

The '[*] WARNING: " bit comes from a module I'm using, which catches
SIG{__WARN__} and just prepends that string.  I stepped through the
module's warning catcher with the debugger, and it was definitely sent
"Use of uninitialized value in string eq at spinsploit.pl line 507,
 line 2." as a $_[0] value.  I don't see how it could affect
the warning it was sent.

How is this possible?  Any suggestions of other tests I could print
the output of or things to step through with the debugger?

- Jen

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: perl modules

2006-12-18 Thread Adriano Ferreira

On 12/18/06, positive mind <[EMAIL PROTECTED]> wrote:

In Linux, how do I check if a particular Perl module is installed or not on
my system?


$ perl -MSome::Module\ 99 -e ''

will usually tell you something like

$ perl -MYAML\ 99 -e ''
YAML version 99 required--this is only version 0.62.
BEGIN failed--compilation aborted. ^^

which means you have version 0.62 of YAML.

You could try other modules in CPAN as well. Module::Find,
Module::Which, etc., etc.


thanks
pm




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: my, my...

2006-12-15 Thread Adriano Ferreira

On 12/15/06, Jorge Almeida <[EMAIL PROTECTED]> wrote:

On Fri, 15 Dec 2006, Adriano Ferreira wrote:

>
> More differences will show up if you use packages. The my() variables
> will have the scoping from the point they are declared to the end of

But they can be redefined with "my" inside a routine belonging to the
same package, right?


Yes. While another  "our" declaration in the same file (even within
blocks or subs) will cause a warning about redeclaring -- because
there is only one package variable. Lexical variables are different
and may correspond to the lexical scopes you open up.



Thanks.
--
Jorge Almeida



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: my, my...

2006-12-15 Thread Adriano Ferreira

On 12/15/06, John W. Krahn <[EMAIL PROTECTED]> wrote:

Jorge Almeida wrote:
> I thought I already knew a few things about Perl, but I just found out I
> don't:
> #!/usr/bin/perl -w
> use strict;
> use diagnostics;
> my $a="27";
> doit();
> sub doit{
> print "$a\n";
> }
>
> The output of this program is:
> 27
>
> Just what I would expect if line 4 had "our" instead of "my".
> What am I missing?

my() and our() have the same scoping so they will behave the same.  my()
variables are scoped from the point they are declared up to the end of the
current file/block.  Since your variable is not inside a block it is visible
throughout the rest of the file.  By the way, you shouldn't use $a or $b as
they are "special" variables.


More differences will show up if you use packages. The my() variables
will have the scoping from the point they are declared to the end of
the package. The our() variables have the same scoping, but may be
reached by other packages.

$ perl -e 'use strict; use warnings;
package foo;
our $VAR = 0;
sub p_var { print "$VAR\n" }
package main;
$foo::VAR = 1; # this is the same variable above
foo::p_var;
'
1

$ perl -e 'use strict; use warnings;
package foo;
my $VAR = 0;
sub p_var { print "$VAR\n" }
package main;
$foo::VAR = 1; # this is NOT the same variable above
foo::p_var;
'
Name "foo::VAR" used only once: possible typo at -e line 6.
0

There is more to tell the truth. For instance, the lexical variables
created by my() can't be localized. You may read about it at:

perldoc -f my
perldoc -f our
perldoc perlsub (section "Private variables via my()")

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: declaring a zero size hash

2006-12-12 Thread Adriano Ferreira

On 12/12/06, Helliwell, Kim <[EMAIL PROTECTED]> wrote:

I think you need to do:

my %loginhash = {};


That's not right. {} is a hash ref, not a hash. It stands for a scalar value.

When you do that

   my %h = {}

or, for the same result,

   my %h = 1;
   my %h = "abacate";

you end with a hash with one pair, whose key is the given scalar and
the value is undef.

See the output of

  $ perl -MData::Dumper -e '%h = {}; print Dumper(\%h)'
  $VAR1 = {
'HASH(0x10240170)' => undef
  };


Kim Helliwell
LSI Logic Corporation
Work: 408 433 8475
Cell: 408 832 5365
[EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: declaring a zero size hash

2006-12-12 Thread Adriano Ferreira

On 12/12/06, Dukelow, Don <[EMAIL PROTECTED]> wrote:

I'm trying to declare a zero size hash so a sub function can populate it and
be see by all other sub's.

my %loginHash();


 my %loginHash;

should be enough.


But the "use strict" doesn't like it.


It is not "use strict" that does not like it. It is Perl itself --
this is a syntax error:

 $ perl -e 'my %h();'
 syntax error at -e line 1, near "%h("
 Execution of -e aborted due to compilation errors.


All examples of making a hash
structure is hard coded in the program or is made reading from a file.  When
I try to run the script all I get is syntax error near "%loginHash("
What am I missing?


Something like this might do what you want:


# read a file and store each line at a bucket of a hash
sub pop_hash {
  my $h = shift; # the hash ref
  my $f = shift; # the filehandle
  while (<$f>) {
  $h->{$.} = $_;
  }
  return $h; # but it was already changed in-place
}

my %h;
pop_hash(\%h, *STDOUT);
use Data::Dumper;
print Dumper(\%h);

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: CYGWIN Uninstall

2006-12-08 Thread Adriano Ferreira

On 12/8/06, Charith Hettige <[EMAIL PROTECTED]> wrote:

Hi All,

I am having trouble uninstalling the current Cygwin installation. Since
there doesn't seem to be an entry in Add/Remove of windows. Please be kind
enough to help me with this.


This list is not about Cygwin. We may be interested in Perl on Cygwin,
but Cygwin only is off topic.


My installation was not a successful installation and I need to remove and
reinstall Also if anyone can send me the instruction to reinstall this I
would be really glad.


You may find your way out of this by reading

   http://www.cygwin.com/faq/faq_2.html#SEC20

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Latest Perl in Cygwin is 5.8.7?

2006-12-07 Thread Adriano Ferreira

Does anyone know why the latest Perl in Cygwin packages is 5.8.7, and
not 5.8.8? I know I can compile Perl by myself and I did it. But when
it becomes a package in the standard Cygwin distribution it becomes
more widely available. So what's keeping 5.8.8 to enter the Cygwin
package repository? Anyone has clues about it?

Adriano Ferreira

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: no number return

2006-11-30 Thread Adriano Ferreira

On 11/30/06, Chris Parker <[EMAIL PROTECTED]> wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Adriano Ferreira wrote:
> On 11/30/06, Chris Parker <[EMAIL PROTECTED]> wrote:
>> while(@numbers = <>) {
>>
>> # Extract widths @width = split(" ", $numbers);
>
> Here at this piece of code, @numbers and $numbers are different
> variables. And you never assign anything to $numbers. Probably you
> want this:
>
> while (<>) { # read a line my @numbers = split /\s+/, $_; # split
> the line (using spaces as the delimiter)
>
>
I added what you suggested and this is what I get now:

Enter Total Square Footage: 1200
Enter widths separated by spaces:
3 4
Argument "3 4" isn't numeric in division (/) at calc.pl line 27, <>
line 2.
size =  amount needed = 300


Sorry. I pointed the immediate problems but hasn't look deeply into
what you were trying to do. You want to read many numbers input from
STDIN and then make a loop for them. So you should remove the
construction of @numbers from the loop, doing


I am missing something, probably very obvious.  It isn't getting the
split numbers.

Code is:
while(<>)
{
# Extract widths
chomp();
my @numbers = split /\s+/, $_;
my $result = &calculate;
print("size =  amount needed = $result \n");
}



my @numbers = split /\s+/, <>;
for my $width (@numbers)
my $result = &calculate($width);
print("size =  amount needed = $result \n");
}

I hope it helps more this time.


while(<>)
{
# Extract widths
chomp();
my @numbers = split /\s+/, $_;
my $result = &calculate;
print("size =  amount needed = $result \n");
}


sub calculate {
my $a = $_;
my $value = $a / 12;
my $b = $value * $squareft;
return $b;
}

thanks again for your help


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFbtlkmGeA9U+OoOcRApbxAJ4qR/h9YEjsOa3/pwtWyFKTzgbELgCgjvG7
wQsCL1u3pf+xsicNGds8ixA=
=hq8M
-END PGP SIGNATURE-


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: no number return

2006-11-30 Thread Adriano Ferreira

On 11/30/06, Chris Parker <[EMAIL PROTECTED]> wrote:

while(@numbers = <>)
{

# Extract widths
@width = split(" ", $numbers);


Here at this piece of code, @numbers and $numbers are different
variables. And you never assign anything to $numbers. Probably you
want this:

while (<>) { # read a line
   my @numbers = split /\s+/, $_; # split the line (using spaces as
the delimiter)

Hint: Always use at the start of the script,

   use strict;
   use warnings;

and introduce 'my' variable declarations.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Who can help me to explain the reason? about regex `m' modifier.

2006-11-28 Thread Adriano Ferreira

On 11/28/06, flw <[EMAIL PROTECTED]> wrote:

Who cabeginnersn help me to explain the reason?

$ perl -e '$_="a11\nb22\nc33\n"; print $_, "-"x15, "\n";s/^a.*^b.*/x/m; print'


The problem here is that \m allows "^" to match after any newline
within the string, but does not change "." which matches any character
(except newline). The following can do what you want -- not pretty,
but works

$ perl -e '$_="a11\nb22\nc33\n"; print $_, "-"x15,
"\n";s/^a(.|\n)*^b.*/x/m; print'
a11
b22
c33
---
x
c33

You may read about it in 'perldoc perlre' in the first four paragraphs
of the section "Regular Expressions" (perl 5.8.8).

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Commenting Perl code

2006-11-28 Thread Adriano Ferreira

On 11/28/06, Robert Hicks <[EMAIL PROTECTED]> wrote:

Do you use the regular "#" or inline POD statements?


Both. # is proper for intimate comments of the implementation code,
like:

   $META ||= CPAN->new; # In case we re-eval ourselves we need the ||
   # from http://search.cpan.org/src/ANDK/CPAN-1.8802/lib/CPAN.pm

but some authors use it as well for multi-line comments
which are to be kept private to the documentation.

POD is good for documentation and multi-line comments. For example,
you see often things like

=begin comment

blah, blah,

=end comment

It is a way to deactivate pieces of code which are not ready yet or
which have been replaced by something else. Depending on the editor
you use and your skills with it, POD may be handier to comment such
blocks.

Regards,
Adriano Ferreira.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: unique hash keys

2006-10-23 Thread Adriano Ferreira

On 10/23/06, Romeo Theriault <[EMAIL PROTECTED]> wrote:

Thank you Adriano, that works nicely after I added:

use Memoize::AnyDBM_File;

before that I was getting this error:

AnyDBM_File doesn't define an EXISTS method at 


I had not payed much attention to the fact that your code were using
ties rather than simple hashes. I did not know either AnyDBM_File ties
missed EXISTS method (if it had an EXISTS, it should have been
transparent to you). But there must be some good reason, like not
caching by default to avoid performance penalties.


But I do have a question about your solution.
> foreach $key_h (keys %hash) {
>print "$key_h\n" unless exists $dbmhash{$key_h};
> }

I don't understand why $dbmhash{$key_h} refers to the key whereas
earlier in  the code when I do:

if ($hash{$key_h} <= 788) {
$dbmhash{"$key_h"} = $hash{$key_h};
}

$hash{$key_h} <= 788   is looking at the key value?


* A simple thing like $hash{foo} looks at the value of %hash stored at
"foo" value.
* $hash{'foo'} does the same.
* $hash{"foo"} does the same.
* $hash{$foo} uses what's stored at $foo as the key.
* $hash{"$foo"} uses the result of "$foo" (an interpolation) as the key

But if $key_h is a string, "$key_h" is just the same as $key_h.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: unique hash keys

2006-10-23 Thread Adriano Ferreira

On 10/23/06, Romeo Theriault <[EMAIL PROTECTED]> wrote:

This all works fine, but in
the last step of the program I am trying to get the program to tell
me key's that are unique to only the first hash. No matter what I do
it always prints out all of the values in the first hash, not the
keys that are unique to only the first hash.



foreach $key_h (keys %hash) {
foreach $key_dbm (keys %dbmhash) {
unless ($key_h eq $key_dbm) {
print "$key_h\n";
}

}
}


Romeo,

You are not doing what you said. The loop above prints the keys of the
first hash which differs from every key of the second hash. That
explains why it seemingly prints out all of the values.

foreach $key_h (keys %hash) {
   print "$key_h\n" unless exists $dbmhash{$key_h};
}

will work better.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: why Perl complaints my script

2006-09-28 Thread Adriano Ferreira

On 9/28/06, chen li <[EMAIL PROTECTED]> wrote:

Hi all,

I write a small script for permutation. When I use
version 1) Perl always complaint it although I get the
result. If I use version 2) it never says a word about
it. Any comments?


Perl always complain (provided you called for that with -w or "use
warnings") when you do something like that:

$ perl -w -e 'my $a; $a'
Useless use of a variable in void context at -e line 1

This is meant to warn you about a probable mistake:
you may have meant
 $a++
 a# to invoke a sub
or something like that. As Igor has said the first statement in the
for is often used for declaring loop variables or, more generally, for
loop initialization statements. If you don't have these initialization
statements, you may omit it.

Regards,
Adriano Ferreira

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: temporarily change a function, sort of like doing a local $var;

2006-09-12 Thread Adriano Ferreira

On 9/12/06, JupiterHost.Net <[EMAIL PROTECTED]> wrote:

I'm trying to change the behavior of a function (whose use of and call I
have no control over) to avoid some nasty behavior in certain circumstances.



Its easy enough to redefine it but after the hairy part is done I want
to change it back.

Similar to how you can:
 local $var;


What you need is just a "local *What::ever = \&new_sub;" I tried to
write similar to what you need. The code below overrides
File::Copy::copy so that it dumps the arguments before copying. This
is done inside a block:

  #!/usr/bin/perl

  use strict;
  use warnings;

  use File::Copy ();

  my ($source, $target) = @ARGV;

  {
  my $copy = \&File::Copy::copy; # save it
  #no warnings qw(redefine);
  local *File::Copy::copy = sub {
  warn "copy(@_)\n";
  $copy->(@_);
  };

  File::Copy::copy($source, $target);


  }

  # File::Copy::copy is magically restored here

If you don't use the "no warnings" bit you will see a "Subroutine
File::Copy::copy redefined".

You don't need to save it like I did at "my $copy =
\&File::Copy::copy; # save it" if you don't need the old code. In the
example, I just added behavior and invoked the old code to do the hard
work.

What the statement does

local *What::ever = \&my_sub; # with a named sub
or
local *What::ever = sub { }; # with a closure

is to locally redefine the *What::ever{CODE} slot of the glob.

Regards,
Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: perl built in function for mean

2006-09-10 Thread Adriano Ferreira

On 9/10/06, Jen Spinney <[EMAIL PROTECTED]> wrote:

On 9/10/06, Dr.Ruud <[EMAIL PROTECTED]> wrote:
>   my$mean;mean+=$_/@data [EMAIL PROTECTED];

Don't you need another dollar sign?
my$mean;$mean+=$_/@data [EMAIL PROTECTED];


Where is Rob to tell Dr. Ruud if one must test the code for him after
he posts? Of course, Dr. Ruud meant the latter. We commit such errors
all the time, but we fix them even faster.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: regular expression question

2006-09-07 Thread Adriano Ferreira

On 9/7/06, Rob Dixon <[EMAIL PROTECTED]> wrote:

It's very bad form to post something to the list that simply doesn't work. This
won't even compile:

   Type of arg 1 to shift must be array (not concatenation (.) or string) at
E:\Perl\source\xx.pl line 2, near "" ")"


Ok, my fault. I was hasty to offer a solution to Li. But fortunately
it provided a clue that Li used it to find one way towards his
solution.

On 9/7/06, chen li <[EMAIL PROTECTED]> wrote:

Hi Adriano,

The line code you provide doesn't work on my computer
but based on what you say I change it into this line
code and it works.



On 9/7/06, Rob Dixon <[EMAIL PROTECTED]> wrote:

Why did I have to test this code for you?


You don't. The bad code was not intentional, but it worked as a
how-not-to-do-it that Li (to whom the code was addressed) turned out
for good. That was a case of "learning by bad example", that I do not
intend to advocate here. I will be more careful in the next posts.

Adriano Ferreira.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: How to write an integer to socket

2006-09-06 Thread Adriano Ferreira

On 9/7/06, Adriano Ferreira <[EMAIL PROTECTED]> wrote:

On 9/6/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi, guys
> In a udp socket test routine, I want to write some integers to server in 
network
> order. But unfortunately, my server receive just chars! how can I do?

Take a look at 'perldoc pack'


I meant 'perldoc -f pack'

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: How to write an integer to socket

2006-09-06 Thread Adriano Ferreira

On 9/6/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Hi, guys
In a udp socket test routine, I want to write some integers to server in network
order. But unfortunately, my server receive just chars! how can I do?


Take a look at 'perldoc pack'

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: regular expression question

2006-09-06 Thread Adriano Ferreira

On 9/6/06, chen li <[EMAIL PROTECTED]> wrote:

I need a regular expression to process some data but
get stuck. I wonder if anyone here might have a clue.

 input:
 my $line='group A 1 2 3 4';# separated by space

 results:
 my @data=("group A ",1,2,3,4);


You barely need a regular expression for this. A split followed by a
join of the first two items would do.

   @data = split ' ', $line;
   unshift @data, (shift @data . " " . shift @data . " ");

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: arithmetic expression while substituting

2006-09-06 Thread Adriano Ferreira

On 9/6/06, Michael Alipio <[EMAIL PROTECTED]> wrote:

I want to adjust the last two digits to less 1:



perhaps something like this.
s/\d+$/(regexp being lookup minus 1/


s/(\d+)$/$1-1/e

is going to work, even though it is convoluted and not robust. For
example, '06.00' will become '06.-1'

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Regex not working as expected

2006-09-04 Thread Adriano Ferreira

Chris,

I found your solution to work alright, with the exception that you
probably don't want to escape | as in

   (?:http\|ftp\|file)

but only

   (?:http|ftp|file)

So that the test script below succeeds:

   use Test::More tests => 3;

   {
   my $url = "http://foo.org/";
   $url =~s#>((?:http|ftp|file)://.{50}).+#>$1...#g;
   is($url, "http://foo.org/");
   }

   {
   my $url = 
"http://www.washingtonpost.com/wp-srv/opinions/cartoonsandvideos/toles_main.html?name=Toles&date=09012006";
   $url =~s#>((?:http|ftp|file)://.{50}).+#>$1...#g;
   is($url, 
"http://www.washingtonpost.com/wp-srv/opinions/cartoonsand...");
   }

   {
   my $url = 
"http://www.washingtonpost.com/wp-srv/opinions/cartoonsandvideos/toles_main.html?name=Toles";
   $url =~s#>((?:http|ftp|file)://.{50}).+#>$1...#g;
   is($url, 
"http://www.washingtonpost.com/wp-srv/opinions/cartoonsand...");
   }


On 9/4/06, Chris Schults <[EMAIL PROTECTED]> wrote:

I have a regular expression that is suppose to truncate long URLs at 50
characters and add "...", but can't figure out why it is not working with a
particular URL.

Here is the regex:

$url =~s#>((?:http\|ftp\|file)://.{50}).+#>$1...#g;

And here is the problem URL:

http://www.washingtonpost.com/wp-srv/opinions/cartoonsandvideos/toles_
main.html?name=Toles&date=09012006">http://www.washingtonpost.com/wp-srv
/opinions/cartoonsandvideos/toles_main.html?name=Toles&date=09012006

Here is what the regex should return:

http://www.washingtonpost.com/wp-srv/opinions/cartoonsandvideos/toles_
main.html?name=Toles&date=09012006">http://www.washingtonpost.com/wp-srv
/opinions/cartoonsand...

Interestingly, the regex works fine on this modified version of the URL:

http://www.washingtonpost.com/wp-srv/opinions/cartoonsandvideos/toles_main.h
tml?name=Toles

I think the digits might have something to do with it, but not sure.

Any thoughts?


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: general subroutine question

2006-08-30 Thread Adriano Ferreira

On 8/30/06, Derek B. Smith <[EMAIL PROTECTED]> wrote:


Why is it so many people on the list are sarcastic???


Many enjoy being that way. Some enjoy helping people at this list and
others, but get tired sometimes and forget they can only ignore what
they thought to be a not-so-clear question and leave others to answer
(if they feel so) and save flames to a stronger argument.

 Is there an inheriant Perl

rule, one that does not require you to code one up,
that disallows a subroutine to pass too may arguments
to another subrountine or scalar?



Likewise, is there a inheriant Perl rule, one that
does not require you to code one up, that disallows a
subroutine to store too many arguments in @_?


No. There's nothing like that in Perl. Even prototypes can be
circumvented. It is all there where Christian pointed to


perldoc perlsub



Look there for "Prototypes".


Regards.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Time::Local let me faint

2006-08-29 Thread Adriano Ferreira

On 8/29/06, Practical Perl <[EMAIL PROTECTED]> wrote:

But when I translate the time of '2006-8-31 00:00:00' to unix timestamp,it
said '31 out of range'.
I'm so faint that August doesn't have 31th day?Please tell me why this
happen and how to resolve it.


from "perldoc Time::Local"

  It is worth drawing particular attention to the expected ranges for the
  values provided.  The value for the day of the month is the actual day
  (ie 1..31), while the month is the number of months since January
  (0..11).  This is consistent with the values returned from localtime()
  and gmtime().

That means

$ perl -Mstrict -MTime::Local -le 'print timelocal(0,0,0,31,8,2006)'
Day '31' out of range 1..30 at -e line 1

is trying to get "31/Sep/2006" which does not exist

$ perl -Mstrict -MTime::Local -le 'print timelocal(0,0,0,31,7,2006)'
1156953600

is getting "31/Aug/2006" which is alright.

Regards,
Adriano Ferreira.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: number rounding problem

2006-08-28 Thread Adriano Ferreira

Chris,


printf "credit %s,  amount %12.12d\n", $credit, $amount;


What really went wrong was to use a %d specifier. It says to truncate
a floating number into integer. Like it happens in

$ perl -e 'print int 1000*shift' 64.63
64629

If you use %f, it may improve

$ perl -e 'printf "%f",  1000*shift' 64.63
64630.00

But I am not sure you would like %12.12f

$ perl -e 'printf "%12.12f",  1000*shift' 64.63
64629.9993

Maybe %12.2f

$ perl -e 'printf "%12.2f",  1000*shift' 64.63
   64630.00

Regards,
Adriano Ferreira

On 8/28/06, Howard, Chris <[EMAIL PROTECTED]> wrote:

I don't know if this is the right mailing list for this question.
Let me know if I should go somewhere else.

The issue is a number rounding problem.

Here is my perl snippet:


$credit = "64.63";
$amount = $credit * 1000;

printf "credit %s,  amount %12.12d\n", $credit, $amount;

$amount = $amount / 10;

printf "credit %s,  amount %12.12d\n", $credit, $amount;



What starts out as 64.63  ends up being 0006462

That's bad.  Any ideas on how to fix, work around etc?


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: [OT] perldoc typo

2006-08-25 Thread Adriano Ferreira

Many, many fixes have been done to docs in bleadperl (and some already
found their way to the more recent stable version - 5.8.8). A bug
report (even in docs) is more valuable when an accurate description of
how to reproduce the issue is given (and that includes knowing the
perl version you are using). Chances are that the thing that annoys
you has already been taken care of.

As Tom said, perlbug is one of the most promising ways to go - it
already takes care of including your version info into the bug report.

I found that you meant

 perldoc -q filehandle

and the problem is probably at perlfaq5 - but I could not found a
version of Perl with the problem you pointed ("the dash of the arrow
missing").

Regards,
Adriano Ferreira.

On 8/24/06, Klaus Jantzen <[EMAIL PROTECTED]> wrote:

I would like to inform whoever feels responsible for perldoc that the
output of
 perldoc -f filehandle
contains a small typo.
Before anybody says "it does not work" here the the info:
Line 85 should say  "$fh = IO::Handle -> new();"  i.e. the dash of the
arrow is missing


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: is there a path enviroment parameter that can tell perl where to find files?

2006-08-23 Thread Adriano Ferreira

On 8/23/06, zhihua li <[EMAIL PROTECTED]> wrote:

now when I'm writing some perl script that needs to open some files, I
alwayse have to put the script in the same directory of these files, or
I'll have to give the full path to these files in my script. if I do not do
so, perl wouldn't be able to find the files I called up in the script.

is there some way to change some enviromental parameter so that when I call
up a file in the script, perl will go to the directories I specified in
searching for the file?


You may learn a lot about invoking the perl interpreter with

perldoc perlrun

or

http://perldoc.perl.org/perlrun.html

You will probably like the -S switch (for finding your script files
via path) and PERL5LIB.

Regards,
Adriano Ferreira

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Intersection for each pair of arrays

2006-08-23 Thread Adriano Ferreira

On 8/23/06, Derek B. Smith <[EMAIL PROTECTED]> wrote:

From the previous emails, I do not understand what
parts of this code is doing and why is this practical?
The part is $union{$e} = 1  and $isect{$e} = 1 .
Also %count is never used.


It seems like Andrej made some mistakes in his code. I think he could
try something like this:

   =item B

   ($union, $isect) = set_op([EMAIL PROTECTED], [EMAIL PROTECTED]);

Computes the union and intersection of two arrays
of strings C<@a> and C<@b>, returning array refs

=cut

   sub unisect {
   my $a = shift;
   my $b = shift;
   my %c;
   my %h;
   %h = (); foreach (@$a) { $c{$_}++ unless $h{$_}++ };
   %h = (); foreach (@$b) { $c{$_}++ unless $h{$_}++ };
#$c{$_}++ foreach @$a;
#$c{$_}++ foreach @$b;
   my (@union, @isect);
   while (my ($k, $v) = each %c) {
   push @union, $k;
   push @isect, $k if $v>1;
   }
   return ([EMAIL PROTECTED], [EMAIL PROTECTED]);
   }

The reason I needed
   %h = (); foreach (@$a) { $c{$_}++ unless $h{$_}++ };

is to prevent the case where the arrays may have duplicates. If they
are known to have distinct elements,  this may be replaced by

   $c{$_}++ foreach @$a;

And then I suggest Math::Combinatorics to generate each pair of arrays
in a loop like

   use Math::Combinatorics;
   my $c = Math::Combinatorics->new(count => 2, data => [EMAIL PROTECTED]);

   while (@pair = $c->next_combination) {
   my ($a, $b) = @pair;
   my ($u, $i) = unisect(@pair);
   print "(@$a) U (@$b) = (@$u)\n(@$a) A (@$b) = (@$i)\n\n";
   }

Kind regards,
Adriano Ferreira.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Fwd: hello Sir, I have an issue with the case insensitive characters, would you plz help me

2006-08-23 Thread Adriano Ferreira

Mukthar,

I am not sure I understood your problem, but let me give a try. The
user input a value for $MACHINE_TYPE and you want to test if there
exists a file "$first.trc.$MACHINE_TYPE" regardless of case in the
variable. This is it?

It depends: if the filesystem is case-insensitive (like in Windows),

 -e "$first.trc.$MACHINE_TYPE"

would find it out for you, regardless of how the filename appears. If
you are in Unix which is case-aware, you may try a glob like
"$first.trc.*" that would match all your interesting files and more,
and then select the ones you care about. Like this

for (glob "$first.trc.*") {
print "FOUND: $_" if /$first.trc.$MACHINE_TYPE/i;
}

Adriano Ferreira

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Can't locate object method - weirdness

2006-06-07 Thread Adriano Ferreira

Graeme,

(Send your messages to the list beginners@perl.org so that more people
can help you out.)

I still don't know where your problem is. The files you sent look ok,
with some remarks:

   em_log.pm should contain the statement "package SI::eventmaster::em_log;"
   rather than "package em_log;" (prevents namespace conflicts)
   and objects should be created with "SI::eventmaster::em_log->new"
   instead of "em_log->new"
   (this is the common convention)

   em_log.pm should not trust others to load classes for it ("use
HTML::Template"
   in the scope of module).

As Shawn said, don't you have other "package em_log;" statement in another file?

Take a look at the innards of your object with

use Data::Dumper;
print Dumper $log

Is this what you expect to see? Maybe old code is being invoked and
not the one you expect. For example, the statement

 use SI::event_master::em_log;

would cause the file "SI/event_master/em_log.pm" (in the library path)
to be read/loaded and not just "em_log.pm". Print something in
"em_log.pm" so that you know that the control flow passed through your
file.



On 6/7/06, Graeme McLaren <[EMAIL PROTECTED]> wrote:

Hi there, when inserting that line of code I get the following printed:

em_log


I'm using strict and warnings on my script and strict on my class.


I've attached the class and the script - might make it easier, I appreciate
the help on this.  Trying to improve some old code.


Cheers,

G :)


#class em_log
package em_log;
use strict;
use Data::Dumper;

#constructor
sub new{
my ($class) = @_;
my $self = {
_table => undef,
_id  => undef, # this refers to the column named 
"pkey_updated_record" in the log table
_dbh => undef,
};
bless $self, $class;
return $self;
}

#accessor method for em_log table
sub table{
my $self = shift;
my $table= shift;

$self->{_table} = $table if defined($table);
return $self->{_table};
}

#accessor method for em_log id
sub id{
my $self = shift;
my $id   = shift;

$self->{_id} = $id if defined($id);
return $self->{_id};
}

sub dbh{
my $self = shift;
my $dbh  = shift;

$self->{_dbh} = $dbh if defined($dbh);
return $self->{_dbh};
}
sub view{
my $self=shift;
my $dbh = $self->dbh;
#   my $sth = $dbh->prepare('SELECT date_record_changed, message, 
user_id 
FROM log WHERE pkey_updated_record=1086 ORDER BY date_record_changed DESC');
#$sth->execute;

my $log_template_data = [];
#while(my $log_data = $sth->fetchrow_hashref){
#print "$log_data->{'message'}";

##  $log_data->{'date_record_changed'} = 
&SI::eventmaster::stdlib::secs_to_timestamp($log_data->{'date_record_changed'});
##
##  if( $#$log_template_data % 2){
#   $log_data->{'odd_even'} = 'odd';
##  $log_data->{'colour'} = $EM_CONF{'odd'};
#   $log_data->{'colour'} = "white";
##  }else{
#   $log_data->{'odd_even'} = 'even';
##  $log_data->{'colour'} = $EM_CONF{'even'};
#   $log_data->{'colour'} = "white";
##  }
##
my $log_data='test';
push @$log_template_data, $log_data;
#}
#$sth->finish;

my $no_log_data = "no log data";

##
##  my $no_log_data='';
#   if([EMAIL PROTECTED]){
#   $no_log_data='Nothing added to log for this record';
#   }
##
my $template=HTML::Template->new(filename => 
'/var/www/mi-eventmaster/html/templates/em/admin/general/view_log.tmpl');
   $template->param(
VIEW_LOG => $log_template_data,
NO_LOG_DATA => $no_log_data,
ID => '1086'

   );
#

#print $template->output;
}

sub print{
my $self = shift;

#print Log info
   # print "";
print( "Log table and id:", $self->table, $self->id);
print Dumper($self->dbh);
#print "";
}

1;

use HTML::Template;
use Data::Dumper;
use warnings;
use strict;
use SI::eventmaster::em_log;
use CGI qw/:standard :html3/;
use CGI::Carp qw(fatalsToBrowser);
use SI::eventmaster::stdlib;

#print "Content-type: text/html\n\n";

my $dbh = &SI::eventmaster::stdlib::get_db_handle({'dbname' =>'emdbv3', 
'sslmode' => 'disable'});

my $log = em_log->new($dbh);
print ref $log;
$log->dbh($dbh);


$log->table('locations');
$log->id('1086');


$log->view;


#$log->print;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


Re: Can't locate object method - weirdness

2006-06-07 Thread Adriano Ferreira

On 6/7/06, Graeme McLaren <[EMAIL PROTECTED]> wrote:

Hi there, thanks for your reply, here is my constructor:

sub new{
my ($class) = @_;
my $self = {
_table => undef,
_id  => undef, # this refers to the column named
"pkey_updated_record" in the log table
_dbh => undef,
};
bless $self, $class;
return $self;
}


as far as I know this is decent enough.


What do you get when you inserting "print ref $log;" at this point of your code

my $log = em_log->new;
print ref $log;  # <= HERE
$log->dbh($dbh);

"em_log" is expected. And, by chance, are you using

use strict;
use warnings;

It helps a lot to find many programming errors.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Can't locate object method - weirdness

2006-06-07 Thread Adriano Ferreira

On 6/7/06, Graeme McLaren <[EMAIL PROTECTED]> wrote:

Hi all, I have a weird error:

Can't locate object method "dbh" via package "em_log" at
/path/log.cgi line 15.


line 15 is the second of these two lines:

my $log = em_log->new;
$log->dbh($dbh);


Does your code define a suitable new() ? The bare minimum would be in
a file with

   package em_log;

   sub new { return bless {}, shift; }


so why is it saying it can't find it?


Also have you "use"d or "require"d your code? (But that not seems the
problem, since the error is after building an instance of em_log.)

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Search for a Word in a file

2006-06-07 Thread Adriano Ferreira

It seems like I did not read enough of your message to give you a
sensible answer to your problem.

   # write a function to do what the one-liner did, but stopping at
the first row

   sub find_first {
 my $regex = shift;
 local @ARGV = @_;
 while (<>) {
  return $_ if /$regex/
 }
   }

   my $line = find_first(qr//, 'temp.txt');
   my @fields = split /\s+/, $line;

Maybe that would help.

On 6/7/06, anu p <[EMAIL PROTECTED]> wrote:

Hi All,

I have a requirement where I need to check if a word
exists in a text file and if so, get the whole line of
text which contains the word. I also need to split the
line on space.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Search for a Word in a file

2006-06-07 Thread Adriano Ferreira

This one-liner works a bit like a (Unix) grep:

  perl -n -e 'print if //' temp.txt

and is probably efficient enough for most cases.

On 6/7/06, anu p <[EMAIL PROTECTED]> wrote:

Hi All,

I have a requirement where I need to check if a word
exists in a text file and if so, get the whole line of
text which contains the word. I also need to split the
line on space.

Example:

   1  1  0  0  P 6/6
 -
Code:

open (FIN, "temp.txt") || die "Cannot open file for
read $!\n";
@table = ;
close(FIN);

@row_val = grep (//, @table);

This works fine but I cannot the split the values in
@row_val since the whole line is taken as one element
of array.

So, I'm using another approach now which works fine
but I think it might not be very efficient

Code:

open (FIN, "temp.txt") || die "Cannot open file for
read $!\n";
while () {
   if (/http://mail.yahoo.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: ksh in a perl program

2006-06-06 Thread Adriano Ferreira

On 6/6/06, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote:

I wanted to include the shell script, abc, as I want to access a variable.
The shell script, abc, actually takes a value (val) from the user.
I want to use that value (val) in my perl porgram. Is that possible?


Perl may take a value from the user as well, and probably with more
sophistication than a shell script.


ie., I will now call abc in my perl program using system
"/home/xxx/yyy/abc";
The script, abc, asks for a value, val, from the user. After its execution,
I want to use val in my perl program.

Can you suggest the procedure to use val in my Perl program?


But if you insist, one of the more simple ways would be to make the
shell script echo the value just entered by the user, which would be
caught by Perl in a backquote construction:

`/home/xxx/yyy/abc`

which replaces the call to system.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: ksh in a perl program

2006-06-06 Thread Adriano Ferreira

On 6/6/06, Lakshmi Sailaja <[EMAIL PROTECTED]> wrote:

Can I include a korn shell script in a perl program?


Not include, but you certainly can execute a shell script from within
a Perl program.


I have done the following but I get a compilation failed error.
abc is the ksh script.
-
require "/home/xxx/yyy/abc";


'require' is to load *Perl* modules - your script as you said is for
ksh. Even though Perl has a lot of the natural feeling of shell
scripts, it does not parse shell scripting language. Many scripts may
be translated to Perl with little additional work (possibly adding a
bunch of quotes and colons).

You may try something like

system "/home/xxx/yyy/abc";

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: reading Perl syntax

2006-06-06 Thread Adriano Ferreira

The line below was folded, and


 $self->{'fookey'} = 'some value here'; #hashref accessible only
within Package Foo;


the Perl interpreter is seeing

  within Package Foo;


Outputs:
Can't locate object method "within" via package "Package" (perhaps you forgot to load 
"Package"?) at ./myOOP.pl line 15.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Accessing page using Mechanize, have to go thr' proxy

2006-06-02 Thread Adriano Ferreira

Adding to what Tom said, if you are behind an annoying authenticating
proxy like Squid, you will find that something like this works:

$mech->proxy(['http', 'ftp'], 'http://proxy_user:[EMAIL PROTECTED]:/');

Have fun.
Adriano.

On 6/2/06, Shalaka <[EMAIL PROTECTED]> wrote:

I've used the WWW::Mechanize module to access web
pages. ( On windows, using ActivePerl )
But i am able to do that only for links that don't
require me to via proxy.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: problem with whitespace not splitting on split.

2006-04-26 Thread Adriano Ferreira
On 4/26/06, Rance Hall <[EMAIL PROTECTED]> wrote:
> @domain = split(' ',$domainlist);

This usage of split only splits at spaces. For example, if $domaintlist contains
'a b c', you will get ('a', 'b', 'c'). It has nothing to do with other
kinds of spaces.

If you meant

@domain = split /\s+/, $domanlist;

then you got it right.

> what happens is that the whitespace that is in the string is stripped
> out and only one array element is returned after the split even though
> there should have been several.

Maybe you're trying to see the result in @domain like this

print @domain

and print in this case uses no delimiter between the array elements.
If you do something like

print "@domain" # will use ' ' between array elements

print join "-", @domain # will use '-' between array elements

maybe you will discover it is working, but you just didn't choose well
how to show it to you.

Best regards,
Adriano

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: regarding panic error message.

2006-01-31 Thread Adriano Ferreira
On 1/31/06, Nischitha <[EMAIL PROTECTED]> wrote:
>   Can any one please explain me what are these panic error message. When will 
> they be generated.

Panic error messages are usually triggered by Perl core code. I have
seen them when some piece of the interpreter (like the parser)
produced an inconsistent state which the next piece (for example, the
optimizer) can't handle. So it panics, instead of going further - and
possibly generate a SEGV. I think the general rule is that Perl should
not panic, but it does sometimes. Some panic errors are guards that
were coded to avoid issues that caused SEGV, but which were not
resolved yet. I think you may direct samples that caused panic to the
perl5-porters where you may learn this is a known issue, when it is
expected to be fixed, which are the workarounds or where this will be
appropriately filed and enter the queue to be fixed when someone got
the tuits to do it.

Regards,
Adriano Ferreira.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: the 'tail' problem

2006-01-14 Thread Adriano Ferreira
On 1/14/06, Jeff Pang <[EMAIL PROTECTED]> wrote:
> Thanks for Adriano.I have tried the way that mentioned by you,and  found it's 
> no use for me.
> should the '-F' option  have no effect for symlinks maybe?
>

Well, that way would be easier if it worked. But I think with some
extra logic you can do it with help of the Perl builtin "readlink",
which is able to give you the filename the symbolic link points to.
Probably something can be written that checks to see if the link
changed or not.

Surely there's a CPAN module out there to help you do this. I also
made a few hasty tests, and if you got hard links rather symbolic
ones, it looks like "tail -F" would do the magic without hassle.

Cheers,
Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: the 'tail' problem

2006-01-14 Thread Adriano Ferreira
Jeff,

Maybe all you have to do is make some adjustments to the pipe you're
opening. Besides the well known "-f" switch, some tail's (like gnu
tail) support "-F" which means a file is followed by its name and the
opening is retried from time to time. From "man tail" (GNU):

   -F same as --follow=name --retry

  With  --follow  (-f),  tail  defaults to following the file descriptor,
  which means that even if a tail'ed file is renamed, tail will  continue
  to  track  its  end.   This  default behavior is not desirable when you
  really want to track the actual name of the file, not the file descrip-
  tor (e.g., log rotation).  Use --follow=name in that case.  That causes
  tail to track the named file by reopening it periodically to see if  it
  has been removed and recreated by some other program.

If you found it works for symlinks, all you have to do is use

> open (TAIL,"tail -F $log|") or die "can't open pipe:$!";

Regards,
Adriano Ferreira.

On 1/14/06, Jeff Pang <[EMAIL PROTECTED]> wrote:
> I have a log file which is a symbol link to the real logfile,shown as 
> following:

> I have to access this file in perl script with unix 'tail -f' command.Part of 
> the code is below:
>
> open (TAIL,"tail -f $log|") or die "can't open pipe:$!";

> This script is a daemon script which run permanently.There is no problem when 
> in the same day.But when the date changed,the symbol link file will point to 
> another real logfile automatically (which decided by other application 
> program),such as:
>
[snip]
>
> How can I adjust this problem?Thanks a lot.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: The "@" symbol

2006-01-13 Thread Adriano Ferreira
On 1/13/06, Adriano Ferreira <[EMAIL PROTECTED]> wrote:
> It is in core documentation somewhere, even though I could not locate
> it right now.

Here it is: try C in the section "Regexp Quote-Like
Operators", search for the item <http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: The "@" symbol

2006-01-13 Thread Adriano Ferreira
A here document (like the one you wrote in your script between
"< wrote:
> trying to include the following code with the abc.pl script...
>
> the snippet works in an html/css environment
>
> print <
> 
> @import url("theta.css");
> @media print {
> body {background: white; color: black; font: 12pt Times,
> serif;}
> #noprnt {display: none !important;}
> }
> 
>
> EOF
>
> The "@" symbols are misread and thus this cause errors...  escaping the
> "@" symbols doesn't work
>
> anyone with a solution??
>
> Thanks
>
> Jerry
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: How to improve speed of returning value from calling method on an array of objects?

2006-01-06 Thread Adriano Ferreira
On 1/6/06, Sai Tong <[EMAIL PROTECTED]> wrote:
> I have an array of many objects and I want to call a method on
> each of these objects and the save the returned values into an array:

> my @return_values;
> foreach my $retrievedObject (@array_of_objects) {
> push (@return_values , $retrievedObject->method );
> }

Maybe you can use C

   my @return_values = map { $_->method } @array_of_objects;

But that's not going to be fast (as well as the for construction) if
the repeated calls of C<$_->method> aren't fast enough (for your
purposes).

Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Use of uninitialized value Error

2005-12-30 Thread Adriano Ferreira
On 12/30/05, David Gilden <[EMAIL PROTECTED]> wrote:
> In the Script below the line:  last if ($num >= 35)
> is giving me this error: Use of uninitialized value in int

That's not an error, but a warning. You will find that execution goes
after this.

> How do I avoid this error?
@files probably contain a name which does not match /(\d+)/. In this
case, $1 turns to be undef, and so happens with $num (because
int(undef) -> undef) up to the numeric comparison which (under -w)
emits the warning.

To avoid the warning, maybe you don't need to process such filenames

  ...
  $_ =~ /(\d+)/;
  next unless $1; # skip to the next item
  $num = int($1);
  ...

or you consider $num as 0 in this case, by replacing C<$num = int($1)>
with C<$num = int($1 || 0)

>
>
> my @files contains: Gambia001.tiff through Gambia100.tiff
>
> #!/usr/bin/perl -w
>
> my @files =<*>;
> $tmp= 1;
>
>
> for (@files){
> my $old = $_;
> $_ =~ /(\d+)/;
> $num = int($1);
> #$_ =~s/Gambia_Pa_Bobo_kuliyo_\d+/Gambia_Pa_Bobo_kuliyo_$tmp/i;
> print "$num\n";
> #$tmp++;
> last if ($num >= 35);
> # rename($old,$_);
> }

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: checking gzip files

2005-12-30 Thread Adriano Ferreira
On 12/30/05, Xavier Noria <[EMAIL PROTECTED]> wrote:
> Even if gzipped files have always more than 0 bytes, wouldn't it be
> true than all empty gzipped files have the same size, and that non-
> empty gzipped files are greater than that minimum? In this Mac that
> size seems to be 24 bytes.

Nope. Gzipped files have a header which may include filename.

$ touch foo
$ ls -l foo
-rw-r--r--  1 me mine 0 Dec 30  2005 foo
$ gzip foo
$ ls -l foo.gz
-rw-r--r--  1 me mine 24 Dec 30 18:04 foo.gz
$ touch foobar
$ ls -l foobar
-rw-r--r--  1 me mine 0 Dec 30  2005 foobar
$ gzip foobar
$ ls -l foobar.gz
-rw-r--r--  1 me mine 27 Dec 30 18:04 foobar.gz

Well - it looks like an empty gzipped file with a name takes C<21 +
length($name)> but that's not reliable since the header size may vary.

$ touch foo
$ ls -l foo
-rw-r--r--  1 me mine 0 Dec 30  2005 foo
$ gzip -n foo # omit name from header
$ ls -l foo.gz
-rw-r--r--  1 me mine 20 Dec 30  2005 foo.gz

To be true, in gzip file specifications, there is a field with the
size of the uncompressed data - but that's what
zlib/zcat/Compress::Zlib access for us to know the file is empty.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: A "sub" question...

2005-12-30 Thread Adriano Ferreira
On 12/30/05, Robert Hicks <[EMAIL PROTECTED]> wrote:
> Note the leading underscore in the sub name. What does that mean? Is that
> like making it "private"?

Yes. But as a convention: that means: you sensible reader, don't you
try to rely on this function outside of this immediate realm of code.
But you can cheat as you like - at your risk.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: checking gzip files

2005-12-30 Thread Adriano Ferreira
On 12/30/05, S Khadar <[EMAIL PROTECTED]> wrote:
> #!/usr/bin/perl
> use Shell;
...
> $dmchk=zless(  "$dir/$_/foo.gz");

As an aside note, C advises against this style [ use
Shell  ; ]. Prefer this:

  use Shell qw(zless);

so that you know that you are not calling some program by mistake/typo.

>From the man page of gzip, the command

  zcat $gzfile | wc -c

is recommended to get the uncompressed file size.

You can use it in backticks, like `zcat $gzfile | wc -l` and then
check the returned number.
But this is rather expensive for large files, since you just want to
know if it has zero bytes or not. Ah, you can use 'zcat' where you are
using 'zless' with the same effect but without a pipe to the unix
command 'less'.

A pure Perl solution would be to use Compress::Zlib (which you
probably has already - for example if you use CPAN) and use a function
like

use Compress::Zlib;

sub zz {
my $f = shift;
my $gz = gzopen($f, 'r') or die; # error handling left as an exercize
return ! $gz->gzread(my $buf, 1); # just one or zero bytes read and dumped
# only return
matters - true for empty, false otherwise
}

my $f = 'a.gz';
print zz($f) ? 'zero bytes' : 'non-empty';

In this case, no need anymore for "use Shell", unless you use some
other external utility.

Regards,
Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Each char / letter --> array from string value

2005-12-28 Thread Adriano Ferreira
On 12/28/05, Umesh T G <[EMAIL PROTECTED]> wrote:
> I need to put each letter from a string to an array.

The usual way to tear apart a string into an array with characters is

@chars = split '', $string;

It is documented at C.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: problem passing argument to function

2005-12-28 Thread Adriano Ferreira
On 12/28/05, Khairul Azmi <[EMAIL PROTECTED]> wrote:
> That one works using a solution
> I found on the web but the problem is when I tried to pass the argument to a
> function declared in the same file, the argument somehow became null.

> sub sample_function {
> print "go in $_\n";   <-  $_ is not the first argument, which 
> is $_[0]
> }

> sample_function($line);< when passing the arguments,
   the callee will
see @_ = ($line)

So you probably fix your code, by doing

sub sample_function {
print "go in $_[0]\n";
}

or

sub sample_function {
my $arg = shift; #  removes the first element of @_ and returns it
print "go in $arg\n";
}

It is all there in C.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: [PATCH] Test that constant overloading is propagated into eval

2005-12-27 Thread Adriano Ferreira
On 12/26/05, Robin Houston <[EMAIL PROTECTED]> wrote:
> +# Check that constant overloading propagates into evals

As a further confirmation of the fact, the following one-liner (using
bigint and eval with strings) that used to output

$ perl -Mbigint -e "my $x = eval '1+2'; use Data::Dumper; print Dumper $x"
$VAR1 = undef;

now outputs "$VAR1 = 3" as expected. No contortion to get a proper answer.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: why is 0 first?

2005-12-27 Thread Adriano Ferreira
>I am curious what the reasoning behind the first element of
> something being zero is ($array[0]).  I know I've read it before, but
> I can't remember.  Thanks!

Using indices 0 .. n make it possible to work with them like offsets
from the beginning of the array. More important from a C point of
view, where it may even improve performance. Ah, and for loops are
shorter by one character ;)

for ( $i=0; $i<$n; $i++ ) { .. }

rather than

for ( $i=1; $i<=$n; $i++ ) { ... }

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: maximum int value

2005-12-27 Thread Adriano Ferreira
On 12/27/05, Alon Marx <[EMAIL PROTECTED]> wrote:
> Is there a constant or a definition for a maximum number in perl? And
> the same question for a minimum value?

This may work for you

the biggest unsigned integer

$ perl -e 'print ~0'
18446744073709551615 # 64-bit integers

the maximum signed integer

$ perl -MConfig -e 'print( (1<<$Config{ivsize}*8-1)-1 )'
9223372036854775807

the minimum signed integer

$ perl -MConfig -e 'print -(1<<$Config{ivsize}*8-1)'
-9223372036854775808

I am not sure how general these expressions are. The illustrated
values are for 64bit integers.

Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: How to check for a file already opened

2005-12-23 Thread Adriano Ferreira
On 12/22/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> How can I check inside a script to see if a file has already been
> opened early and is still open?  Does the perl interpreter keep track
> of that kind of stuff.

Maybe what you want is the function C from C
module. See

perldoc Scalar::Util

if you use 5.8 or install the module from CPAN first and then use perldoc.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: for send an email

2005-12-23 Thread Adriano Ferreira
On 12/23/05, Rafael Morales <[EMAIL PROTECTED]> wrote:
> I need to send an email to some clients, so I need to know if their mail 
> client can accept html format or just text format. How can know that ???, I 
> think that there is, some cpan module to do that however I haven't found it.

When you send email, you send it via/to a SMTP server. And then via
PO3/IMAP, they retrieve these messages, making difficult, to say the
least, that you know something about the clients used to read the
received messages. I think you need to get this information directly
from your clients -- even if extracted automatically. That is, if you
have a way to make them send a message to you, the message headers
usually contain the mail client identification - which can be mapped
to the probably acceptable formats. (Well, if they change clients,
that information goes outdated.)

Regards,
Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: encode base64 password

2005-12-22 Thread Adriano Ferreira
On 12/22/05, Ken Perl <[EMAIL PROTECTED]> wrote:
> Is the MIME::Base64 support unicode?

MIME::Base64 supports conversion of binary data into a limited character set,
convenient for transmission by e-mail and other means that prefer pure ASCII
data.

> I am trying to use the module to encode the  a password.

Passwords protected by such a straightforward encoding/decoding are
not protected. If you have serious concerns about security, try
something like the Digest::* modules (available at CPAN).

> In the doc http://support.microsoft.com/default.aspx?scid=kb;en-us;263991
> there is one line like this unicodePwd::IgBuAGUAdwBQAGEAcwBzAHcAbwByAGQAIgA=
> the encoded string is what I want to produce using the module, I tried this,

The point is:
(1) first they took the string "newPassword" (including the quotes)

 $s = q{"newPassword"};

(2) converted it to bytes via utf-16le (take a look at "perldoc perlunicode")

 use Encode;
 $octets = encode("utf-16le", $s);

(3) and then applied base64 encoding

 $encoded = encode_base64($octets);

(4) which resulted in

 print $encoded;

 > IgBuAGUAdwBQAGEAcwBzAHcAbwByAGQAIgA=

So the code you want is

#!/usr/bin/perl

use MIME::Base64;
use Encode;

$s = q{welcome};
$octets = encode("utf-16le", $s);
$encoded = encode_base64($octets);
print $encoded;

__END__
below is the output,
dwBlAGwAYwBvAG0AZQA=

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: use vars

2005-12-15 Thread Adriano Ferreira
On 12/15/05, Beast <[EMAIL PROTECTED]> wrote:
> In perlmodlib :
> varsPredeclare global variable names (obsolete)

> If this is obselete then what is the newer version of predeclare global
> variables?

Replace things like

   use vars qw($FOO)

with

   our $FOO;

(unless you need to assure compatibility for versions before 5.6).

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: A Strange Syntax

2005-12-06 Thread Adriano Ferreira
On 12/5/05, Jennifer Garner <[EMAIL PROTECTED]> wrote:
> As we know, $::{sym} == *main::sym, it's a typeglob.
> but what is **main::sym? and the same,what is *{$glob}?thanks.

**main::sym is a syntax error, but *{*main::sym}==*main::sym.

But don't be fooled by the equality $::{sym} == *main::sym. It just
means they numerically compare the same. Taking references you get
that $::{sym} returns a scalar and *main::sym a glob.

$ perl -e 'print \($::sym, *main::sym)'
SCALAR(0x1002f094)GLOB(0x10010fa8)

So *{$glob} is the way to tell Perl to go from the scalar to the glob,
when we'll be able to access its HASH part.

That's why

$ perl -e 'our %sym = (name => "flower"); print ${*{$::{sym}}{HASH}}{name};"

prints "flower", but

$ perl -e 'our %sym = (name => "flower"); print ${$::{sym}{HASH}}{name};"

prints nothing ($::{sym}{HASH} returns undef). As Wiggins wisely said,
$sym->{name} is more sane.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: A Strange Syntax

2005-12-05 Thread Adriano Ferreira
On 12/5/05, Jennifer Garner <[EMAIL PROTECTED]> wrote:
> print ${*{$::{sym}}{HASH}}{name};

> How to analyse the last sentence of that code?Thanks.

>From "perldoc perlref"

   7.  A reference can be created by using a special syntax, lovingly
   known as the *foo{THING} syntax.  *foo{THING} returns a reference
   to the THING slot in *foo (which is the symbol table entry which
   holds everything known as foo).

   $scalarref = *foo{SCALAR};
   $arrayref  = *ARGV{ARRAY};
   $hashref   = *ENV{HASH};
   $coderef   = *handler{CODE};
   $ioref = *STDIN{IO};
   $globref   = *foo{GLOB};

So $::{sym} returns the glob symbol "sym" on the main package ($main::
or $::), takes a reference to its HASH part, and returns what it got
in the key "name". Piece of cake, ain't it?

Regards,
Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl executable pathname needs to be hardwired?

2005-12-02 Thread Adriano Ferreira
On 12/2/05, Chris Devers <[EMAIL PROTECTED]> wrote:
> My understanding is that the Python idiom is to avoid putting the full
> path, in favor of something like
>
> #!/usr/bin/env python
> #!env python
>
> on grounds that Python may not be quite as common, but you could depend
> on the `env` command being available, so as long as `python` was in the
> $PATH somewhere, invoking it this way should work. That makes sense, but
> now that I think about it I'm not clear why they don't just use
>
> #!python
>
> which seems like it should amount to the same thing.

Just for the record, I found with the help of the people at
python-list@python.org that the difference about "#!/usr/bin/env
python", "#!env python" and "#!python" is that not every shell looks
up the shebang executable in the path, and the last two forms ("#!env
python" and "#!python" ) will be generally met with an error like

 bash: hello.pl: perl: bad interpreter: No such file or directory

even though

 $ perl hello.pl

may work at the shell prompt. This ("!/usr/bin/env perl") may be a
useful device if you trust the interpreter you want will be the first
found in the path. Perl scripts installed by the common MakeMaker
mantra won't have such issues as the shebang line is automatically
updated (and that prevents mixing code installed with one version to
run with another).

Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Archive

2005-12-02 Thread Adriano Ferreira
On 12/2/05, Brent Clark <[EMAIL PROTECTED]> wrote:
> Anyone know if theres an archive link for this mailing list.

You can find The Perl Mailing List Database at
  http://lists.perl.org
and from there
  http://lists.cpan.org/showlist.cgi?name=beginners
where you will find the archives
  http://www.mail-archive.com/beginners%40perl.org/
  http://nntp.perl.org/group/perl.beginners

Cheers,
Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl executable pathname needs to be hardwired?

2005-12-02 Thread Adriano Ferreira
On 12/2/05, Chris Devers <[EMAIL PROTECTED]> wrote:
> But anyway, yeah. In general, you can't depend on things working
> consistently if you just start randomly moving around compiled programs
> and libraries. Sometimes it won't matter, but other times, the results
> just won't be predictable.

Ok. I will try to be less lazy. What I was trying to workaround is to
place perl binaries at a place available to my user, using a
distribution which was supposed to be installed by 'root' (which I am
not). The machine I was working at had no 'gcc' and I thought it would
be a good idea to get a shortcut rather than building/installing gcc
and then perl.

Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl executable pathname needs to be hardwired?

2005-12-02 Thread Adriano Ferreira
On 12/2/05, Chris Devers <[EMAIL PROTECTED]> wrote:
> Historically, Unix users could depend on a copy of Perl in /usr/bin from
> their vendor, and maybe a custom-installed one somewhere like /opt/bin
> or /usr/local/bin. With that in mind, using one of those paths usually
> would do something useful.
>
> Anyway, there isn't anything stopping you from doing the same sort of
> thing with your Perl scripts, but, out of habit as much as anything
> else, this isn't how most Perl hackers write their code. I don't see
> much harm in it though, and I could picture it making some scripts more
> portable if they're going to be running on systems where you can't
> depend on a copy of the Perl binary being in one of the usual places.

I see your point, Chris. What I was thinking about was the trouble to
realocate the interpreter if you have a perl binary instead of
compiling it from the source. If you use a perl compiled to be in
"/usr/local/bin" in a different path like '/home/me/bin', it works
sometimes and other times it will fail because of path assumptions,
which I don't know exactly what they are. This mostly happens with
Perl modules dependent on shared libraries.

Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Perl executable pathname needs to be hardwired?

2005-12-02 Thread Adriano Ferreira
What's the rationale for hardwiring the Perl executable pathname into
the Perl interpreter? It is some oddity to guarantee Perl can find its
library via a relative path? Is it a safety thing?

Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: max value of an integer scalar

2005-11-03 Thread Adriano Ferreira
On 11/3/05, JeeBee <[EMAIL PROTECTED]> wrote:
>
> Thank you, John!
> I see the limit is 32 bits now.
> I just added 'use bigint', how easy!
>
> Further, I was wondering about why you said I wasn't just multiplying by
> 2 using $p<<=1. Isn't it exactly equal to $p*=2 ???

It is equal just up to the moment the result goes over the maximum
integer value. This is a build-dependent parameter, being 2**32 - 1 or
2**64 - 1, according to the Config value ivsize.

   perl -V:ivsize

That is, the maximum integer is something like 2**(ivsize*8) - 1.

The shift is an integer-type operation and will produce the same weird
results you see in programming C with an integer of the same type. For
example, in a perl which uses 64-bit integers:

   $ perl -e 'print 1<<63, " ", 1<<64'
   9223372036854775808 1

But the multiplication operator (*) is smarter and does an upgrade
from integer to floating point when needed, (possibly) increasing the
range of the correct results.

Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: finding the first non digit character in a string

2005-10-28 Thread Adriano Ferreira
On 10/28/05, Bowen, Bruce <[EMAIL PROTECTED]> wrote:
> The data may look like this:
> $DD = "5000|SIHHTEXT"

> I've tried $d = index($DD, m/[^\d]/);
> $d = index($DD, /[^\d]/);
> $d = index($DD, [^\d]);

C doesn't work with regexes. But you can use C

$ perl -e '$DD = "5000|SIHHTEXT"; print pos($DD) if $DD =~ /\D/g'
5

Read about this usage at C.

Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Digest::MD5 hexdigest() and md5_hex() differ

2005-10-18 Thread Adriano Ferreira
On 10/18/05, Gert <[EMAIL PROTECTED]> wrote:
> in the example below I am using Digest::MD5 for computing the md5-checksum
> for a string. The first solution uses the function md5_hex, the second way
> uses the OO method hexdigest. The results are not equal. Shouldn't they be
> equal? I think they should?

If you run your script under -w or add "use warnings", you will see

  &Digest::MD5::md5_hex function probably called as class
method at try.pl line 8.

What means that what you really want is

  my $cs= Digest::MD5::md5_hex($text);

where -> between "Digest::MD5" and "md5_hex" gives place to "::". With
this simple change, the output turns to

172b442fcbe775a552d8afda30ac6821
172b442fcbe775a552d8afda30ac6821

Your original code were computing the MD5 digest of the bareword
"Digest::MD5" plus the text. It is all there in the synopsis of
Digest::MD5 docs.

Regards,
Adriano.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




  1   2   >