Perl Inheritance

2006-11-03 Thread Muttley Meen

Hi!

In the attached script I implement two packages:
Package1 and Package2.

Package2 is derived from Package1, which I guess I dont well.
Now Package1 has a method called IncErr which increments a variable named $err.

If I call something like:

$a = Package1::new();
$a-IncErr();
print ERR1: $a-{err}\n; # should print 1

all goes well, but if I call something like:

$a = Package1::new();
$a-Package2-Create(); # this should call IncErr too
print ERR1: $a-{err}\n; # should print 1
doent't work as I expected.

Is there something wrong with the way I `bless`-ed the class Package2 ?


--
Regards.
#! /usr/bin/perl
package Package1 ;
sub new {
my ($class) = @_;
$class  = __PACKAGE__ ;

print Call new [.$class.]\n ;
$r  = [];
$this   = {};
$class-{err} = 0 ;

$r-[0] = Package2::new($this-{sock_fd} );

bless $this, $class;
return $this ;
}

sub IncErr {
my $this = shift ;
$this-{err} += 1 ;
}

sub Package2 {
my $this = shift ;
@_ ? ($r-[0] = shift) : $r-[0];
}






package Package2 ;
@ISA = (Package1);
sub new {
my ( $this, $sock ) = @_ ;
$class = __PACKAGE__ unless @_;
$this-{sock_fd}= $sock ;
bless $this;
return $this ;
}

sub Create {
my $this = shift;
print Call Create\n ;
print ERR2: $this-{err} ( this should print 2 )\n ;
$this-IncErr() ;
print ERR2: $this-{err} ( this should print 3 )\n ;
}

my $a = Package1::new();
$a-IncErr();
$a-IncErr();
$a-Package2-Create();
print ERR1: $a-{err} ( this should print 3 )\n ;

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


Perl Inheritance(take-2)

2006-11-03 Thread Muttley Meen

Hi!
Sorry if I double post, but the maillserver seems to have something against
perl scripts attachements, so my first email was droped by the MTA : /
Maybe if I put the code inline will be ok

In the attached script I implement two packages:
Package1 and Package2.

Package2 is derived from Package1, which I guess I dont well.
Now Package1 has a method called IncErr which increments a variable named $err.

If I call something like:

$a = Package1::new();
$a-IncErr();
print ERR1: $a-{err}\n; # should print 1

all goes well, but if I call something like:

$a = Package1::new();
$a-Package2-Create(); # this should call IncErr too
print ERR1: $a-{err}\n; # should print 1
doent't work as I expected.

Is there something wrong with the way I `bless`-ed the class Package2 ?



--8---
#! /usr/bin/perl
package Package1 ;
sub new {
   my ($class) = @_;
   $class  = __PACKAGE__ ;

   print Call new [.$class.]\n ;
   $r  = [];
   $this   = {};
   $class-{err} = 0 ;

   $r-[0] = Package2::new($this-{sock_fd} );

   bless $this, $class;
   return $this ;
}

sub IncErr {
   my $this = shift ;
   $this-{err} += 1 ;
}

sub Package2 {
   my $this = shift ;
   @_ ? ($r-[0] = shift) : $r-[0];
}






package Package2 ;
@ISA = (Package1);
sub new {
   my ( $this, $sock ) = @_ ;
   $class = __PACKAGE__ unless @_;
   $this-{sock_fd}= $sock ;
   bless $this;
   return $this ;
}

sub Create {
   my $this = shift;
   print Call Create\n ;
   print ERR2: $this-{err} ( this should print 2 )\n ;
   $this-IncErr() ;
   print ERR2: $this-{err} ( this should print 3 )\n ;
}

my $a = Package1::new();
$a-IncErr();
$a-IncErr();
$a-Package2-Create();
print ERR1: $a-{err} ( this should print 3 )\n ;

---8

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




Re: classification algorithms

2006-11-03 Thread Saurabh Singhvi

Yes, the two I mentioned above were searches from CPAN only.

On 11/2/06, Tom Phoenix [EMAIL PROTECTED] wrote:


On 11/2/06, Saurabh Singhvi [EMAIL PROTECTED] wrote:

 What all classification algorithms exist like Algorithm::Naivebayes ?

Have you seen what's on CPAN?

http://search.cpan.org/

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training



Re: Perl Inheritance(take-2)

2006-11-03 Thread Mumia W.

On 11/03/2006 02:23 AM, Muttley Meen wrote:

Hi!
Sorry if I double post, but the maillserver seems to have something against
perl scripts attachements, so my first email was droped by the MTA : /
Maybe if I put the code inline will be ok

In the attached script I implement two packages:
Package1 and Package2.

Package2 is derived from Package1, which I guess I dont well.
Now Package1 has a method called IncErr which increments a variable 
named $err.


If I call something like:

$a = Package1::new();
$a-IncErr();
print ERR1: $a-{err}\n; # should print 1

all goes well, but if I call something like:

$a = Package1::new();
$a-Package2-Create(); # this should call IncErr too


This is not allowed because Package2 is not a method within the class 
Package1. You want this:


my $b = Package2-new();
$b-Create();
print ERR(\$b): $b-{err}\n;


print ERR1: $a-{err}\n; # should print 1
doent't work as I expected.

Is there something wrong with the way I `bless`-ed the class Package2 ?



--8---
#! /usr/bin/perl


use strict;
use warnings;
# Modify your program to work with these.


package Package1 ;
sub new {
   my ($class) = @_;
   $class  = __PACKAGE__ ;

   print Call new [.$class.]\n ;
   $r  = [];
   $this   = {};
   $class-{err} = 0 ;

   $r-[0] = Package2::new($this-{sock_fd} );

   bless $this, $class;
   return $this ;
}

sub IncErr {
   my $this = shift ;
   $this-{err} += 1 ;
}

sub Package2 {
   my $this = shift ;
   @_ ? ($r-[0] = shift) : $r-[0];
}






package Package2 ;
@ISA = (Package1);
sub new {
   my ( $this, $sock ) = @_ ;
   $class = __PACKAGE__ unless @_;
   $this-{sock_fd}= $sock ;
   bless $this;
   return $this ;
}

sub Create {
   my $this = shift;
   print Call Create\n ;
   print ERR2: $this-{err} ( this should print 2 )\n ;
   $this-IncErr() ;
   print ERR2: $this-{err} ( this should print 3 )\n ;
}

my $a = Package1::new();
$a-IncErr();
$a-IncErr();
$a-Package2-Create();
print ERR1: $a-{err} ( this should print 3 )\n ;

---8



I didn't look in detail at your program, but I also see that you use a 
suboptimal syntax for creating objects; don't use ::; use -, e.g.


my $a = Package1-new();

Using :: will work, but it creates problems that will make you
sad--such as preventing inheritance.

Using use strict and use warnings will help you catch errors like 
the one above where you do $a-Package2-Create()




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




Re: Perl Inheritance(take-2)

2006-11-03 Thread Rob Dixon

Muttley Meen wrote:

 Hi!
 Sorry if I double post, but the maillserver seems to have something against
 perl scripts attachements, so my first email was droped by the MTA : /
 Maybe if I put the code inline will be ok

 In the attached script I implement two packages:
 Package1 and Package2.

 Package2 is derived from Package1, which I guess I dont well.
 Now Package1 has a method called IncErr which increments a variable
 named $err.

 If I call something like:

 $a = Package1::new();
 $a-IncErr();
 print ERR1: $a-{err}\n; # should print 1

 all goes well, but if I call something like:

 $a = Package1::new();
 $a-Package2-Create(); # this should call IncErr too
 print ERR1: $a-{err}\n; # should print 1
 doent't work as I expected.

 Is there something wrong with the way I `bless`-ed the class Package2 ?

Your thinking is unclear in a number of areas, and you've made the classic
mistake of writing far too much before you start testing. It's also clearer and
easier for you to put your class definitions into modules and 'use' them into
the main program; it will compartmentalize your program and protect you from
making some simple mistakes. It is also the usual way in which classes are
implemented in Perl.

I've had trouble understanding your thinking in some areas, but here are some
comments which I hope will help you on your way.

 --8---
 #! /usr/bin/perl

Always, always, always

use strict;
use warnings;

especially if you're on unfamiliar territory and especially if you have bugs
that you can't fix. It's free, computerized debugging!

 package Package1 ;
 sub new {
my ($class) = @_;
$class  = __PACKAGE__ ;

You've clearly found that the package name isn't in @_ as you expected so you've
put it in explicitly. Bad idea. If something isn't as you expect then find out
why and fix it. It may be that your expectations are wrong, but just as often,
as in this case, something is at fault somewhere else. You are calling the
package method new() as

$a = Package1::new();

which isn't a method call at all it's just a subroutine call, so Perl won't do
its magic of adding the package name as an implicit parameter. Use

$a = Package1-new;

and you won't have to 'fix' what Perl passes to you.

print Call new [.$class.]\n ;
$r  = [];

What's $r, and what's wrong with using @r? I'm afraid I don't understand what
you're trying to do here, and there's some nasty stuff going on later on
involving $r too. Don't forget you're writing a class here, not main code.

$this   = {};
$class-{err} = 0 ;

Perl has allowed you to do this as you haven't used 'strict', but it's a very
bad idea and clearly doesn't do what you think it does. $class holds the name of
the current package, 'Package1', and you're now using it as a symbolic reference
to a hash, so you're manipulating a package hash element, and this line is
equivalent to

$Package1::Package1{err} = 0;

What you mean is

  $this-{err} = 0;

and 'use warnings' and 'use strict' would have helped you find this on your own.

$r-[0] = Package2::new($this-{sock_fd} );

Hmm. Package2 depends on Package1 and also vice-versa. We could have a lot of
fun here! Remember that you're manipulating package variable $Package1::r, which
almost certainly isn't what you want.

bless $this, $class;
return $this ;
 }

Fine. Your blessing is correct, despite your misgivings!

 sub IncErr {
my $this = shift ;
$this-{err} += 1 ;
 }

Also correct.

 sub Package2 {
my $this = shift ;
@_ ? ($r-[0] = shift) : $r-[0];
 }

Spooky! Package1 not only builds an array of Package2 objects but also has a
method called Package2! I want to stop you doing this, but doesn't the fact that
you're assigning to $this and never using the value give you a clue? An object
method should normally manipulate only object data, so you need an element of
%$this to provide your $r thing. But, like I said, don't do that anyway!

 package Package2 ;

 @ISA = (Package1);

Correct again.

 sub new {
my ( $this, $sock ) = @_ ;

my ($class, $sock) = @_;

$class = __PACKAGE__ unless @_;

Same thing as before. Two wrongs don't make a right, especially here where you'r
expecting an explicit parameter to the method ($sock). Defaulting the class name
won't happen here unless no parameters at all are passed in.

$this-{sock_fd}= $sock ;
bless $this;

Presumably you left the package name off the bless because you found it wasn't
being set up properly? bless() will bless the reference into the current package
unless you say otherwise, which in this case is what you want.

return $this ;
 }

 sub Create {
my $this = shift;
print Call Create\n ;
print ERR2: $this-{err} ( this should print 2 )\n ;
$this-IncErr() ;
print ERR2: $this-{err} ( this should print 3 )\n ;
 }

You should write an accessor method in Package1 to retrieve the value of the
error field, rather than using the hash element directly:

sub err {
  my $this = shift;
  

Re: Perl Inheritance(take-2)

2006-11-03 Thread Rob Dixon

Mumia W. wrote:


On 11/03/2006 02:23 AM, Muttley Meen wrote:


In the attached script I implement two packages:
Package1 and Package2.

Package2 is derived from Package1, which I guess I dont well.
Now Package1 has a method called IncErr which increments a variable 
named $err.


If I call something like:

$a = Package1::new();
$a-IncErr();
print ERR1: $a-{err}\n; # should print 1

all goes well, but if I call something like:

$a = Package1::new();
$a-Package2-Create(); # this should call IncErr too


This is not allowed because Package2 is not a method within the class 
Package1. You want this:


Yes it is! It's an accessor method (albeit written wrongly). This is indeed a
very tangled web!


my $b = Package2-new();
$b-Create();
print ERR(\$b): $b-{err}\n;


print ERR1: $a-{err}\n; # should print 1
doent't work as I expected.

Is there something wrong with the way I `bless`-ed the class Package2 ?



--8---
#! /usr/bin/perl


use strict;
use warnings;
# Modify your program to work with these.


Amen.


package Package1 ;
sub new {
   my ($class) = @_;
   $class  = __PACKAGE__ ;

   print Call new [.$class.]\n ;
   $r  = [];
   $this   = {};
   $class-{err} = 0 ;

   $r-[0] = Package2::new($this-{sock_fd} );

   bless $this, $class;
   return $this ;
}

sub IncErr {
   my $this = shift ;
   $this-{err} += 1 ;
}

sub Package2 {
   my $this = shift ;
   @_ ? ($r-[0] = shift) : $r-[0];
}






package Package2 ;
@ISA = (Package1);
sub new {
   my ( $this, $sock ) = @_ ;
   $class = __PACKAGE__ unless @_;
   $this-{sock_fd}= $sock ;
   bless $this;
   return $this ;
}

sub Create {
   my $this = shift;
   print Call Create\n ;
   print ERR2: $this-{err} ( this should print 2 )\n ;
   $this-IncErr() ;
   print ERR2: $this-{err} ( this should print 3 )\n ;
}

my $a = Package1::new();
$a-IncErr();
$a-IncErr();
$a-Package2-Create();
print ERR1: $a-{err} ( this should print 3 )\n ;

---8



I didn't look in detail at your program, but I also see that you use a 
suboptimal syntax for creating objects; don't use ::; use -, e.g.


my $a = Package1-new();



Using :: will work, but it creates problems that will make you
sad--such as preventing inheritance.


Is worse than suboptimal - it's wrong! Package1::new() won't pass the package
name as the first parameter. You could write the constructor differently of
course so that it fixes the call, but that's not how it's supposed to work.

Using use strict and use warnings will help you catch errors like 
the one above where you do $a-Package2-Create()


Not true, but still an essential technique.

Rob

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




Re: Where to Run Program?

2006-11-03 Thread Oleg V. Volkov
Richmond Platz [EMAIL PROTECTED] wrote:
 What application do I need to be in to have it actually run for me, to 
 see the output.

Just name it as something.pl and run it. AS Perl sets up associations to
run Perl programs automatically.

 I'm wondering if I may have some config prob or something, because at 
 times I will run a simple Perl program, and the DOS type screen 
 scrolls by real fast and disappears.  It appeared to have had a full 
 screen of something  !

Unless your console window is set up to stay on screen after program
ends, you will have to either add something to program to keep it there
(reading a line from stdin, system call to pause, anything) or first
open window with cmd.exe and run it from there. Better yet, if you have
experience with PC from a years ago you may remember DOS shells like
Norton Commander, so you may like to install similar Windows text-mode
shell, like FAR Manager (http://www.farmanager.com/?l=en) and run your
stuff from there.

-- 
Oleg Rowaa[SR13] V. Volkov

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




date and file comparison

2006-11-03 Thread Tim Wolak
Morning all,

I need to compare the current date with that of a file, if the file is
older than the current date remove it and replace it with a new one from
new data.  Below I have the code set for getting the date but can't come
up with an easy way to compare it against the file date.  Can anyone
tell me the best way to compare the current date with that of the
date/time stamp on a file?

Thanks,
Tim

my $date;
my ($sec,$min,$hour,$mday,$mon,$year) = (localtime) [0,1,2,3,4,5];
$year=$year+1900;
$mon=$mon+1;
$date = sprintf(%02d%02d%02d\_%02d\:%02d\:%02d,
$year,$mon,$mday,$hour,$min,$sec);


RE: Question on using http rather than ftp

2006-11-03 Thread Paul King
Thanks again Zentara.  I appreciate the help; the information you've
provided will give me a big jump in getting this going.

Regards,
Paul


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of zentara
Sent: Friday, November 03, 2006 6:45 AM
To: beginners@perl.org
Subject: Re: Question on using http rather than ftp

On Thu, 2 Nov 2006 12:08:41 -0600, [EMAIL PROTECTED] (Paul King) wrote:


  The sample scripts you provided will be quite helpful in
providing me with a place to start.  I'm almost positive I won't be
able
to provide the vendor with my own script to be invoked on their server.
Consequently, will I be able to call a script written in some arbitrary
language from the POST function provided they are using CGI?

Sure. They will have to provide you with the URL of the cgi script
that accepts the uploads. After that, it dosn't matter if they
are using Perl, they will have to follow the CGI protocol, so your
lwp-upload script will work.

There are some possible pitfalls though, like they may require
you send in a couple of form fields along with the file, or they
may want you to allow them to set a cookie first, or have javascript
enabled, or some other stupid Microsoft trick to force you to
use a Microsoft browser or system.

But you won't know that until they give you they URL. A decent
company would have a test URL setup for you to practice with,
maybe ask them.

If it gets too complex of an interaction, you will probably have to
switch to WWW::Mechanize from LWP. 
Mechanize, will let you get around any obstacle, by exactly simulating
the behavior of a real browser.

Mechanize comes with a cookbook of examples, you can google
for example scripts, or go to http://perlmonks.org and search
their site for WWW::Mechanize.

Such as:
http://perlmonks.org?node_id=469979
http://perlmonks.org?node_id=521497
http://perlmonks.org?node_id=437928


If you do run into a problem, and need help with
Mechanize, you will get better answers at
http://perlmonks.org   signup, it's free


See also this tutorial:
http://www.developer.com/lang/other/article.php/10942_3454041_2

Goodluck, zentara


-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

-- 
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: date and file comparison

2006-11-03 Thread Dr.Ruud
Tim Wolak schreef:

 I need to compare the current date with that of a file, if the file is
 older than the current date remove it and replace it with a new one
 from new data.  Below I have the code set for getting the date but
 can't come up with an easy way to compare it against the file date.
 Can anyone tell me the best way to compare the current date with that
 of the date/time stamp on a file?

See `perldoc -f time` and `perldoc -f stat` (mtime).
Both in number of seconds since the epoch.

-- 
Affijn, Ruud

Gewoon is een tijger.


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




Re: Perl Inheritance(take-2)

2006-11-03 Thread Muttley Meen

Well , here is what I come up with:

#! /usr/bin/perl
use strict;
use warnings;

package Package1 ;
sub new {
   my ($class) = @_ ;

   print Call new [.$class.]\n ;
   my @r  = [];
   my $this   = {};
   $this-{err} = 0 ;

   $this-{r}-[0] = Package2-new();
   $this-{r}-[0]-{err} = $this-{err} ;

   bless $this, $class  ;
   return $this ;
}


sub IncErr {
   print [IncErr]\n;
   my $this = shift ;
   $this-{err} += 1 ;
}

#accessor method for Package2
sub Package2 {
   my $this = shift ;
   print [Package2]\n ;
   @_ ? ($this-{r}-[0] = shift) : $this-{r}-[0];
}


#accessor method for err
sub err {
 my $this = shift;
 $this-{err};
}




package Package2 ;
our @ISA = (Package1);
sub new {
   my ( $class, $sock ) = @_ ;
   my $this = {} ;
   bless $this, $class;
   return $this ;
}

sub Create {
   my $this = shift;
   print [Package2-Create]\n ;
   print CREATE:[EMAIL PROTECTED]err]} \t\t( this should print 2 )\n ;
   $this-IncErr() ;
   print CREATE:[EMAIL PROTECTED]err]} \t\t( this should print 3 )\n ;
}

$a = Package1-new();
$a-IncErr();
$a-IncErr();
print ERR1:\t$a-{err} \t\t( this should print 2 )\n ;
$a-Package2-Create();
print ERR1:\t$a-{err} \t\t( this should print 3 )\n ;



On 11/3/06, Rob Dixon [EMAIL PROTECTED] wrote:

Mumia W. wrote:
 
 On 11/03/2006 02:23 AM, Muttley Meen wrote:

 In the attached script I implement two packages:
 Package1 and Package2.

 Package2 is derived from Package1, which I guess I dont well.
 Now Package1 has a method called IncErr which increments a variable
 named $err.

 If I call something like:

 $a = Package1::new();
 $a-IncErr();
 print ERR1: $a-{err}\n; # should print 1

 all goes well, but if I call something like:

 $a = Package1::new();
 $a-Package2-Create(); # this should call IncErr too

 This is not allowed because Package2 is not a method within the class
 Package1. You want this:

Yes it is! It's an accessor method (albeit written wrongly). This is indeed
a
very tangled web!

 my $b = Package2-new();
 $b-Create();
 print ERR(\$b): $b-{err}\n;

 print ERR1: $a-{err}\n; # should print 1
 doent't work as I expected.

 Is there something wrong with the way I `bless`-ed the class Package2 ?



 --8---
 #! /usr/bin/perl

 use strict;
 use warnings;
 # Modify your program to work with these.

Amen.

 package Package1 ;
 sub new {
my ($class) = @_;
$class  = __PACKAGE__ ;

print Call new [.$class.]\n ;
$r  = [];
$this   = {};
$class-{err} = 0 ;

$r-[0] = Package2::new($this-{sock_fd} );

bless $this, $class;
return $this ;
 }

 sub IncErr {
my $this = shift ;
$this-{err} += 1 ;
 }

 sub Package2 {
my $this = shift ;
@_ ? ($r-[0] = shift) : $r-[0];
 }






 package Package2 ;
 @ISA = (Package1);
 sub new {
my ( $this, $sock ) = @_ ;
$class = __PACKAGE__ unless @_;
$this-{sock_fd}= $sock ;
bless $this;
return $this ;
 }

 sub Create {
my $this = shift;
print Call Create\n ;
print ERR2: $this-{err} ( this should print 2 )\n ;
$this-IncErr() ;
print ERR2: $this-{err} ( this should print 3 )\n ;
 }

 my $a = Package1::new();
 $a-IncErr();
 $a-IncErr();
 $a-Package2-Create();
 print ERR1: $a-{err} ( this should print 3 )\n ;

 ---8


 I didn't look in detail at your program, but I also see that you use a
 suboptimal syntax for creating objects; don't use ::; use -, e.g.

 my $a = Package1-new();
 
 Using :: will work, but it creates problems that will make you
 sad--such as preventing inheritance.

Is worse than suboptimal - it's wrong! Package1::new() won't pass the
package
name as the first parameter. You could write the constructor differently of
course so that it fixes the call, but that's not how it's supposed to work.

 Using use strict and use warnings will help you catch errors like
 the one above where you do $a-Package2-Create()

Not true, but still an essential technique.

Rob

--
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




line position

2006-11-03 Thread Tim Wolak
All,

I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file.  As I have never done
this before, can someone point me in the right direction as to get
started?

Thanks for the help!
Tim


RE: line position

2006-11-03 Thread Wagner, David --- Senior Programmer Analyst --- WGO
 If you provide some data and/or what you have attempted, it will go
much farther in getting some assistance. Otherwise the list is guessing
at what you are really trying to do.

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 09:38
To: beginners@perl.org
Subject: line position

All,

I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file.  As I have never done
this before, can someone point me in the right direction as to get
started?

Thanks for the help!
Tim

**
This message contains information that is confidential and proprietary to FedEx 
Freight or its affiliates.  It is intended only for the recipient named and for 
the express  purpose(s) described therein.  Any other use is prohibited.
**


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




Re: line position

2006-11-03 Thread Tom Smith

Tim Wolak wrote:

All,

I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file.  As I have never done
this before, can someone point me in the right direction as to get
started?

Thanks for the help!
Tim
  
I think part of what you're looking for is seek(). This will allow you 
to move the cursor to a specific position within a file in relation to 
the cursor's current position.


I'm still quite new to Perl, so I'll leave the more complicated answers 
to those with more experience in this area. :-D



~ Tom

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




RE: line position

2006-11-03 Thread Tim Wolak
Here is an example of the lines I am reading in below.  This is one
continuous line.  I need information from positions 70-71, if they match
what I want then print that and position 92(also sub-positions C,P,D).

Being that I have never had to do this before I'm not sure what to use
to step me through this file to get the information that I need.

Tim

CME008885071BIOH72006102816122900MO002006091415300020070316083000BQB
IOH7   FE 50





11 00 00USD1
00010500USD 00 00100100
200610271008258000860800079080
BQF6
000137501605F00 00  F
0002400 1BQ  101100
00 0050200703BIO
0102000500201E00
000

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 12:16 PM
To: Tim Wolak; beginners@perl.org
Subject: RE: line position

 If you provide some data and/or what you have attempted, it will go
much farther in getting some assistance. Otherwise the list is guessing
at what you are really trying to do.

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 09:38
To: beginners@perl.org
Subject: line position

All,

I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file.  As I have never done
this before, can someone point me in the right direction as to get
started?

Thanks for the help!
Tim

**
This message contains information that is confidential and proprietary
to FedEx Freight or its affiliates.  It is intended only for the
recipient named and for the express  purpose(s) described therein.  Any
other use is prohibited.
**




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




RE: line position

2006-11-03 Thread Wagner, David --- Senior Programmer Analyst --- WGO
So what makes up a line? CME through the next CME? You can
concatenate all the data together if desired( do a chomp first) and
check if CME or What denotes the next rcd? Then you could either do a
equal(ie, 
  if ( next rcd ) {
if ( substr($MyData,70,2) eq q[xx] ) {
# now pull what I need, place in another file or
print
 }
$MyData = q[]; # clear the buffer and get ready for next
data
   }

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 10:30
To: Wagner, David --- Senior Programmer Analyst --- WGO;
beginners@perl.org
Subject: RE: line position

Here is an example of the lines I am reading in below.  This is one
continuous line.  I need information from positions 70-71, if they match
what I want then print that and position 92(also sub-positions C,P,D).

Being that I have never had to do this before I'm not sure what to use
to step me through this file to get the information that I need.

Tim

CME008885071BIOH72006102816122900MO002006091415300020070316083000BQB
IOH7   FE 50





11 00 00USD1
00010500USD 00 00100100
200610271008258000860800079080
BQF6
000137501605F00 00  F
0002400 1BQ  101100
00 0050200703BIO
0102000500201E00
000

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 12:16 PM
To: Tim Wolak; beginners@perl.org
Subject: RE: line position

 If you provide some data and/or what you have attempted, it will go
much farther in getting some assistance. Otherwise the list is guessing
at what you are really trying to do.

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 09:38
To: beginners@perl.org
Subject: line position

All,

I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file.  As I have never done
this before, can someone point me in the right direction as to get
started?

Thanks for the help!
Tim

**
This message contains information that is confidential and proprietary
to FedEx Freight or its affiliates.  It is intended only for the
recipient named and for the express  purpose(s) described therein.  Any
other use is prohibited.
**




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




RE: line position

2006-11-03 Thread Tim Wolak
The whole thing below is the line, its just word wrapped in scrt.  I
can't concatenate it because everything is in a specific position for
what I need.  Is the seek module what I need to be using?  I just need
to collect the two characters in position 70 and 71, test if they are
GE,E$,E0,etc.. If they are then I need the data from position 92 and
write the line to a file that consists of positions 70-71 and position
92, then go on to the next line.

Tim

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 12:49 PM
To: Tim Wolak; beginners@perl.org
Cc: Wagner, David --- Senior Programmer Analyst --- WGO
Subject: RE: line position

So what makes up a line? CME through the next CME? You can
concatenate all the data together if desired( do a chomp first) and
check if CME or What denotes the next rcd? Then you could either do a
equal(ie, 
  if ( next rcd ) {
if ( substr($MyData,70,2) eq q[xx] ) {
# now pull what I need, place in another file or
print
 }
$MyData = q[]; # clear the buffer and get ready for next
data
   }

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 10:30
To: Wagner, David --- Senior Programmer Analyst --- WGO;
beginners@perl.org
Subject: RE: line position

Here is an example of the lines I am reading in below.  This is one
continuous line.  I need information from positions 70-71, if they match
what I want then print that and position 92(also sub-positions C,P,D).

Being that I have never had to do this before I'm not sure what to use
to step me through this file to get the information that I need.

Tim

CME008885071BIOH72006102816122900MO002006091415300020070316083000BQB
IOH7   FE 50





11 00 00USD1
00010500USD 00 00100100
200610271008258000860800079080
BQF6
000137501605F00 00  F
0002400 1BQ  101100
00 0050200703BIO
0102000500201E00
000

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 12:16 PM
To: Tim Wolak; beginners@perl.org
Subject: RE: line position

 If you provide some data and/or what you have attempted, it will go
much farther in getting some assistance. Otherwise the list is guessing
at what you are really trying to do.

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 09:38
To: beginners@perl.org
Subject: line position

All,

I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file.  As I have never done
this before, can someone point me in the right direction as to get
started?

Thanks for the help!
Tim

**
This message contains information that is confidential and proprietary
to FedEx Freight or its affiliates.  It is intended only for the
recipient named and for the express  purpose(s) described therein.  Any
other use is prohibited.
**






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




Interpolation of backslash-escapes

2006-11-03 Thread Peter Daum

I am looking for an way to interpolate backslash-sequences
within a string with the usual perl semantics, e.g.
$s='1\t\2\t3\na\ b c' should become:
'1tab2tab3
a b c'

Things I tried were for example
$s= eval('' . $val); # (hoping to trigger the normal interpolation) or
$s=~ s/\\(.)/\\$1/eg;
but somehow i couldn't get it right ...

Can anybody think of an elegant solution?

Regards,
 Peter Daum


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




Re: line position

2006-11-03 Thread D. Bolliger
Tim Wolak am Freitag, 3. November 2006 18:37:
 All,

 I need to parse lines from a file and at a certain position test to see
 if it is what a want, if so I need to grab information from other
 positions in the line and drop it into a file.  As I have never done
 this before, can someone point me in the right direction as to get
 started?

 Thanks for the help!
 Tim

Hello Tim

I've read your second post with some sample data.

Here's one way to do it, certainly not the most efficient, but it's short and 
you can adapt it to your needs. I use shorter sample data and other 
positions, but you get the idea.

I use, for shortness, the DATA filehandle. You may want to adapt it to use 
STDIN for input and print to STDOUT, so you can invoke the script with

 $ script.pl  infile  outfile

What it does: It skips 4 positions, tries to match 'hi' or 'ho' at the next 2, 
then skips 3, retrieves the next 2, skips again 8, and retrieves the next 6.
The retrieve is done via capturing paranthesis, see perldoc perlre.

Hope this helps, 
Dani

#!/usr/bin/perl

use strict;
use warnings;

while (DATA) {
  if (my (@out_fields)= $_ =~ /^ .{4} (hi|ho) .{3} (.{2}) .{8} (.{6}) /x) {
print @out_fields, \n;
  }
}

__DATA__
hi33322first*
ho33322second
no33322third*

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




Re: Unable to compile Perl code

2006-11-03 Thread Kumar, David - IT Department
Hi 

I am writing this email hoping that you can advise to run my perl program
successfully.

when I include any library, such as, locale, or warnings or anyother, I
am facing the following 
error.  

Could you please guide me, how to avoid this problem at all.

Thank you.

Regards

Kumar

_

Can't locate locale.pm in @INC (@INC contains:
/opt/perl5/lib/5.00502/PA-RISC1.1 /opt/perl5/lib/5.00502
/opt/perl5/lib/site_perl/5.005/PA-RISC1.1 /opt/perl5/lib/site_perl/5.005 .)
at welcome.pl line 3.
BEGIN failed--compilation aborted at welcome.pl line 3.

#!/opt/perl/bin -w

use locale;
use warnings;

$where = 'Welcome to perl program';
print hello $where\n;


__


Northampton General Hospital NHS Trust 
Cliftonville, Northampton NN1 5BD 

This e-mail may contain confidential information and/or copyright material
and is intended for the use of the addressee only.   Any unauthorised use
may be unlawful. The contents of this e-mail may be subject to public
disclosure under the NHS Code of Openness or the Freedom of Information Act
2000. Unless legally exempt, the confidentiality of the message and your
reply cannot be guaranteed.If you receive this e-mail by mistake, please
advise the sender immediately. 
Thank you.

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




Re: Interpolation of backslash-escapes

2006-11-03 Thread D. Bolliger
Peter Daum am Freitag, 3. November 2006 20:26:

Hoi Peter,

 I am looking for an way to interpolate backslash-sequences
 within a string with the usual perl semantics, e.g.
 $s='1\t\2\t3\na\ b c' should become:
 '1tab2tab3
 a b c'

With usual perl semantics, the result is different :-)

 Things I tried were for example
  $s= eval('' . $val); # (hoping to trigger the normal interpolation) or
 $s=~ s/\\(.)/\\$1/eg;
 but somehow i couldn't get it right ...

 Can anybody think of an elegant solution?

I think there are more elegant solutions, but in the following you have full 
control over what translates to what:

#!/usr/bin/perl

use strict;
use warnings;

my %trans=(
  '\t'=\t,
  '\n'=\n,
  '\ '=' ',
  '\2'='2',
  q(\\)=qw( \ ), # ;-)
);

my $s='1\t\2\t3\na\ b c \\\ '; # last space: ;-)

$s=~s; (\\.) ; $trans{$1} || $1 ;gex;

print $s\n;

# Note the usual perl semantics:
print \2\ \n;

__END__

Dani

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




Re: Interpolation of backslash-escapes

2006-11-03 Thread Tom Phoenix

On 11/3/06, Peter Daum [EMAIL PROTECTED] wrote:


I am looking for an way to interpolate backslash-sequences
within a string with the usual perl semantics


That's what eval does, although you have to build your string with
care. Don't let the user put their own data into that string; they can
(accidentally or intentionally) crash your program or worse, if you
use eval.

A better way would be to interpolate only the sequences that you need
to support. I'd write a subroutine to do that, returning the converted
string. It's simple to loop over the input string and build the new
string as you go, and it completely avoids the riskiness of eval.

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/ http://learn.perl.org/first-response




Re: Interpolation of backslash-escapes

2006-11-03 Thread Rob Dixon

Peter Daum wrote:


I am looking for an way to interpolate backslash-sequences
within a string with the usual perl semantics, e.g.
$s='1\t\2\t3\na\ b c' should become:
'1tab2tab3
a b c'

Things I tried were for example
$s= eval('' . $val); # (hoping to trigger the normal interpolation) or
$s=~ s/\\(.)/\\$1/eg;
but somehow i couldn't get it right ...

Can anybody think of an elegant solution?


eval qq($val);

But note that the \2 in your string (I don't know if it's a typo) will become
a character with an octal value of 2, i.e. the ASCII STX control character.

HTH,

Rob

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




Re: Re: Unable to compile Perl code

2006-11-03 Thread Tom Phoenix

On 11/3/06, Kumar, David - IT Department [EMAIL PROTECTED] wrote:


Can't locate locale.pm in @INC (@INC contains:


Your perl is mis-configured or mis-installed. Redo the installation,
make sure that all tests pass, and you'll be back on track.

Cheers!

--Tom Phoenix
Stonehenge Perl Training


This e-mail may contain confidential information and/or copyright material
and is intended for the use of the addressee only.   Any unauthorised use
may be unlawful. The contents of this e-mail may be subject to public
disclosure under the NHS Code of Openness or the Freedom of Information Act
2000. Unless legally exempt, the confidentiality of the message and your
reply cannot be guaranteed.If you receive this e-mail by mistake, please
advise the sender immediately.


This e-mail may contain a sarcastic disclaimer and/or allegedly
humorous material and is intended to be read, republished, and quoted
as the author's meager bid toward immortality. Any unauthorized use of
anything may be unlawful. Duh. The contents of this e-mail are subject
to public disclosure under the fair use doctrine, and may be used as
an example of an unenforceable waste of bandwidth masquerading as a
license. When a message is sent to a mailing list, the confidentiality
of the message is phhhtt. If you receive this e-mail by mistake,
please remember: If it weren't for all the lawyers, we wouldn't need
so many lawyers.

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




RE: line position

2006-11-03 Thread Wagner, David --- Senior Programmer Analyst --- WGO
If it is only one line and it is record separator is carriage
return as defined by your system, then a simple loop like:

while: ( MYFILEIN ) { 
chomp;
if ( substr($_,70,2) =~ /(xx|xy|xz)/I ) {
# substr starts at zero vs 1
print MYFILEOUT substr($),70,2) .
Substr($_,91,1) . \n;
 }
 }

simple format and should be straight forward.

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 11:05
To: Wagner, David --- Senior Programmer Analyst --- WGO;
beginners@perl.org
Subject: RE: line position

The whole thing below is the line, its just word wrapped in scrt.  I
can't concatenate it because everything is in a specific position for
what I need.  Is the seek module what I need to be using?  I just need
to collect the two characters in position 70 and 71, test if they are
GE,E$,E0,etc.. If they are then I need the data from position 92 and
write the line to a file that consists of positions 70-71 and position
92, then go on to the next line.

Tim

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 12:49 PM
To: Tim Wolak; beginners@perl.org
Cc: Wagner, David --- Senior Programmer Analyst --- WGO
Subject: RE: line position

So what makes up a line? CME through the next CME? You can
concatenate all the data together if desired( do a chomp first) and
check if CME or What denotes the next rcd? Then you could either do a
equal(ie, 
  if ( next rcd ) {
if ( substr($MyData,70,2) eq q[xx] ) {
# now pull what I need, place in another file or
print
 }
$MyData = q[]; # clear the buffer and get ready for next
data
   }

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 10:30
To: Wagner, David --- Senior Programmer Analyst --- WGO;
beginners@perl.org
Subject: RE: line position

Here is an example of the lines I am reading in below.  This is one
continuous line.  I need information from positions 70-71, if they match
what I want then print that and position 92(also sub-positions C,P,D).

Being that I have never had to do this before I'm not sure what to use
to step me through this file to get the information that I need.

Tim

CME008885071BIOH72006102816122900MO002006091415300020070316083000BQB
IOH7   FE 50





11 00 00USD1
00010500USD 00 00100100
200610271008258000860800079080
BQF6
000137501605F00 00  F
0002400 1BQ  101100
00 0050200703BIO
0102000500201E00
000

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 12:16 PM
To: Tim Wolak; beginners@perl.org
Subject: RE: line position

 If you provide some data and/or what you have attempted, it will go
much farther in getting some assistance. Otherwise the list is guessing
at what you are really trying to do.

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 09:38
To: beginners@perl.org
Subject: line position

All,

I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other
positions in the line and drop it into a file.  As I have never done
this before, can someone point me in the right direction as to get
started?

Thanks for the help!
Tim

**
This message contains information that is confidential and proprietary
to 

Re: Interpolation of backslash-escapes

2006-11-03 Thread John W. Krahn
Peter Daum wrote:
 I am looking for an way to interpolate backslash-sequences
 within a string with the usual perl semantics, e.g.
 $s='1\t\2\t3\na\ b c' should become:
 '1tab2tab3
 a b c'
 
 Things I tried were for example
 $s= eval('' . $val); # (hoping to trigger the normal interpolation) or
 $s=~ s/\\(.)/\\$1/eg;
 but somehow i couldn't get it right ...
 
 Can anybody think of an elegant solution?

$ perl -le'
my %translate = (
t = \t,
n = \n,
r = \r,
f = \f,
b = \b,
a = \a,
e = \e,
);
my $s = q[1\t\2\t3\na\ b c];
print $s;
$s =~ s/\\(.)/ exists $translate{ $1 } ? $translate{ $1 } : $1 /seg;
print $s;
'
1\t\2\t3\na\ b c
1   2   3
a b c



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

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




Re: Perl Inheritance(take-2)

2006-11-03 Thread Mumia W.

On 11/03/2006 04:57 AM, Rob Dixon wrote:

Mumia W. wrote:
 

On 11/03/2006 02:23 AM, Muttley Meen wrote:


In the attached script I implement two packages:
Package1 and Package2.

Package2 is derived from Package1, which I guess I dont well.
Now Package1 has a method called IncErr which increments a variable 
named $err.


If I call something like:

$a = Package1::new();
$a-IncErr();
print ERR1: $a-{err}\n; # should print 1

all goes well, but if I call something like:

$a = Package1::new();
$a-Package2-Create(); # this should call IncErr too


This is not allowed because Package2 is not a method within the 
class Package1. You want this:


Yes it is! It's an accessor method (albeit written wrongly). This is 
indeed a

very tangled web!



Yeah, I should've looked more closely at Muttley's program.



my $b = Package2-new();
$b-Create();
print ERR(\$b): $b-{err}\n;


print ERR1: $a-{err}\n; # should print 1
doent't work as I expected.

Is there something wrong with the way I `bless`-ed the class Package2 ?



--8---
#! /usr/bin/perl


use strict;
use warnings;
# Modify your program to work with these.


Amen.


package Package1 ;
sub new {
   my ($class) = @_;
   $class  = __PACKAGE__ ;

   print Call new [.$class.]\n ;
   $r  = [];
   $this   = {};
   $class-{err} = 0 ;

   $r-[0] = Package2::new($this-{sock_fd} );

   bless $this, $class;
   return $this ;
}

sub IncErr {
   my $this = shift ;
   $this-{err} += 1 ;
}

sub Package2 {
   my $this = shift ;
   @_ ? ($r-[0] = shift) : $r-[0];
}






package Package2 ;
@ISA = (Package1);
sub new {
   my ( $this, $sock ) = @_ ;
   $class = __PACKAGE__ unless @_;
   $this-{sock_fd}= $sock ;
   bless $this;
   return $this ;
}

sub Create {
   my $this = shift;
   print Call Create\n ;
   print ERR2: $this-{err} ( this should print 2 )\n ;
   $this-IncErr() ;
   print ERR2: $this-{err} ( this should print 3 )\n ;
}

my $a = Package1::new();
$a-IncErr();
$a-IncErr();
$a-Package2-Create();
print ERR1: $a-{err} ( this should print 3 )\n ;

---8



I didn't look in detail at your program, but I also see that you use a 
suboptimal syntax for creating objects; don't use ::; use -, e.g.


my $a = Package1-new();

 

Using :: will work, but it creates problems that will make you
sad--such as preventing inheritance.


Is worse than suboptimal - it's wrong! Package1::new() won't pass the 
package

name as the first parameter. You could write the constructor differently of
course so that it fixes the call, but that's not how it's supposed to work.

Using use strict and use warnings will help you catch errors like 
the one above where you do $a-Package2-Create()


Not true, but still an essential technique.

Rob



And I should've tested that. :-(



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




Re: Perl Inheritance(take-2)

2006-11-03 Thread Mumia W.

On 11/03/2006 10:16 AM, Muttley Meen wrote:

On 11/3/06, Rob Dixon [EMAIL PROTECTED] wrote:

Mumia W. wrote:
 
 On 11/03/2006 02:23 AM, Muttley Meen wrote:

 In the attached script I implement two packages:
 Package1 and Package2.

 Package2 is derived from Package1, which I guess I dont well.
 Now Package1 has a method called IncErr which increments a variable
 named $err.

 If I call something like:

 $a = Package1::new();
 $a-IncErr();
 print ERR1: $a-{err}\n; # should print 1

 all goes well, but if I call something like:

 $a = Package1::new();
 $a-Package2-Create(); # this should call IncErr too

 This is not allowed because Package2 is not a method within the class
 Package1. You want this:

Yes it is! It's an accessor method (albeit written wrongly). This is 
indeed

a
very tangled web!

 my $b = Package2-new();
 $b-Create();
 print ERR(\$b): $b-{err}\n;

 print ERR1: $a-{err}\n; # should print 1
 doent't work as I expected.

 Is there something wrong with the way I `bless`-ed the class 
Package2 ?




 --8---
 #! /usr/bin/perl

 use strict;
 use warnings;
 # Modify your program to work with these.

Amen.

 package Package1 ;
 sub new {
my ($class) = @_;
$class  = __PACKAGE__ ;

print Call new [.$class.]\n ;
$r  = [];
$this   = {};
$class-{err} = 0 ;

$r-[0] = Package2::new($this-{sock_fd} );

bless $this, $class;
return $this ;
 }

 sub IncErr {
my $this = shift ;
$this-{err} += 1 ;
 }

 sub Package2 {
my $this = shift ;
@_ ? ($r-[0] = shift) : $r-[0];
 }






 package Package2 ;
 @ISA = (Package1);
 sub new {
my ( $this, $sock ) = @_ ;
$class = __PACKAGE__ unless @_;
$this-{sock_fd}= $sock ;
bless $this;
return $this ;
 }

 sub Create {
my $this = shift;
print Call Create\n ;
print ERR2: $this-{err} ( this should print 2 )\n ;
$this-IncErr() ;
print ERR2: $this-{err} ( this should print 3 )\n ;
 }

 my $a = Package1::new();
 $a-IncErr();
 $a-IncErr();
 $a-Package2-Create();
 print ERR1: $a-{err} ( this should print 3 )\n ;

 ---8


 I didn't look in detail at your program, but I also see that you use a
 suboptimal syntax for creating objects; don't use ::; use -, e.g.

 my $a = Package1-new();
 
 Using :: will work, but it creates problems that will make you
 sad--such as preventing inheritance.

Is worse than suboptimal - it's wrong! Package1::new() won't pass the
package
name as the first parameter. You could write the constructor 
differently of
course so that it fixes the call, but that's not how it's supposed to 
work.


 Using use strict and use warnings will help you catch errors like
 the one above where you do $a-Package2-Create()

Not true, but still an essential technique.

Rob



Well , here is what I come up with:

#! /usr/bin/perl
use strict;
use warnings;

package Package1 ;
sub new {
   my ($class) = @_ ;

   print Call new [.$class.]\n ;
   my @r  = [];
   my $this   = {};
   $this-{err} = 0 ;

   $this-{r}-[0] = Package2-new();
   $this-{r}-[0]-{err} = $this-{err} ;

   bless $this, $class  ;
   return $this ;
}


sub IncErr {
   print [IncErr]\n;
   my $this = shift ;
   $this-{err} += 1 ;
}

#accessor method for Package2
sub Package2 {
   my $this = shift ;
   print [Package2]\n ;
   @_ ? ($this-{r}-[0] = shift) : $this-{r}-[0];
}


#accessor method for err
sub err {
 my $this = shift;
 $this-{err};
}




package Package2 ;
our @ISA = (Package1);
sub new {
   my ( $class, $sock ) = @_ ;
   my $this = {} ;
   bless $this, $class;
   return $this ;
}

sub Create {
   my $this = shift;
   print [Package2-Create]\n ;
   print CREATE:[EMAIL PROTECTED]err]} \t\t( this should print 2 )\n ;
   $this-IncErr() ;
   print CREATE:[EMAIL PROTECTED]err]} \t\t( this should print 3 )\n ;
}

$a = Package1-new();
$a-IncErr();
$a-IncErr();
print ERR1:\t$a-{err} \t\t( this should print 2 )\n ;
$a-Package2-Create();
print ERR1:\t$a-{err} \t\t( this should print 3 )\n ;





Please bottom-post.

Why should a call to Create() on an object returned by Package2() 
updatethe object $a ?


It shouldn't normally update the containing object, and it doesn't in 
your program.


For your education, try this,
print Inside ERR:\t, $a-Package2-err, \n;

Also, typically one uses either containment or inheritance but not both.

Please explain what you're trying to do again.





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




Re: Interpolation of backslash-escapes

2006-11-03 Thread Rob Dixon

Rob Dixon wrote:

 Peter Daum wrote:

 I am looking for an way to interpolate backslash-sequences
 within a string with the usual perl semantics, e.g.
 $s='1\t\2\t3\na\ b c' should become:
 '1tab2tab3
 a b c'

 Things I tried were for example
 $s= eval('' . $val); # (hoping to trigger the normal interpolation) or
 $s=~ s/\\(.)/\\$1/eg;
 but somehow i couldn't get it right ...

 Can anybody think of an elegant solution?

 eval qq($val);

 But note that the \2 in your string (I don't know if it's a typo) will
 become
 a character with an octal value of 2, i.e. the ASCII STX control character.

I need to add that that solution relies on any parentheses in the string being 
in matching pairs. If you try


$val = ')(';

then it just won't work. If that's a problem, then you can use different
delimiters, which are guaranteed to be either escaped or not in the string at
all. The tilde is a useful one:

eval qq~$val~;

or if you're relaly stuck, then any character at all will do, including control 
characters:


eval qq\0$val\0;

works fine and delimits the string with null characters,

Cheers,

Rob


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




RE: line position

2006-11-03 Thread Tim Wolak
Thanks David, that is exactly what I did just before receiving your
email!  Thanks for the help!

Tim

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 3:17 PM
To: Tim Wolak; beginners@perl.org
Subject: RE: line position

If it is only one line and it is record separator is carriage
return as defined by your system, then a simple loop like:

while: ( MYFILEIN ) { 
chomp;
if ( substr($_,70,2) =~ /(xx|xy|xz)/I ) {
# substr starts at zero vs 1
print MYFILEOUT substr($),70,2) .
Substr($_,91,1) . \n;
 }
 }

simple format and should be straight forward.

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 11:05
To: Wagner, David --- Senior Programmer Analyst --- WGO;
beginners@perl.org
Subject: RE: line position

The whole thing below is the line, its just word wrapped in scrt.  I
can't concatenate it because everything is in a specific position for
what I need.  Is the seek module what I need to be using?  I just need
to collect the two characters in position 70 and 71, test if they are
GE,E$,E0,etc.. If they are then I need the data from position 92 and
write the line to a file that consists of positions 70-71 and position
92, then go on to the next line.

Tim

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 12:49 PM
To: Tim Wolak; beginners@perl.org
Cc: Wagner, David --- Senior Programmer Analyst --- WGO
Subject: RE: line position

So what makes up a line? CME through the next CME? You can
concatenate all the data together if desired( do a chomp first) and
check if CME or What denotes the next rcd? Then you could either do a
equal(ie, 
  if ( next rcd ) {
if ( substr($MyData,70,2) eq q[xx] ) {
# now pull what I need, place in another file or
print
 }
$MyData = q[]; # clear the buffer and get ready for next
data
   }

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 10:30
To: Wagner, David --- Senior Programmer Analyst --- WGO;
beginners@perl.org
Subject: RE: line position

Here is an example of the lines I am reading in below.  This is one
continuous line.  I need information from positions 70-71, if they match
what I want then print that and position 92(also sub-positions C,P,D).

Being that I have never had to do this before I'm not sure what to use
to step me through this file to get the information that I need.

Tim

CME008885071BIOH72006102816122900MO002006091415300020070316083000BQB
IOH7   FE 50





11 00 00USD1
00010500USD 00 00100100
200610271008258000860800079080
BQF6
000137501605F00 00  F
0002400 1BQ  101100
00 0050200703BIO
0102000500201E00
000

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 12:16 PM
To: Tim Wolak; beginners@perl.org
Subject: RE: line position

 If you provide some data and/or what you have attempted, it will go
much farther in getting some assistance. Otherwise the list is guessing
at what you are really trying to do.

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: Tim Wolak [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 09:38
To: beginners@perl.org
Subject: line position

All,

I need to parse lines from a file and at a certain position test to see
if it is what a want, if so I need to grab information from other

Re: line position

2006-11-03 Thread D. Bolliger
Wagner, David --- Senior Programmer Analyst --- WGO am Freitag, 3. November 
2006 22:16:
   If it is only one line and it is record separator is carriage
 return as defined by your system, then a simple loop like:

Hello David and Tim,

The below code is a good example why one should happily place:

  use strict; 
  use warnings; 

at the beginning.

   while: ( MYFILEIN ) {

You meant: 

  while ( MYFILEIN ) {

   chomp;

Just omit the chomp and the code behaves the same.

   if ( substr($_,70,2) =~ /(xx|xy|xz)/I ) {

The modifier should be /i, not /I. With /I, the code doesn't even compile.

If you want to use a regex, then it might be better to:
- anchor the pattern (not completely shure though if 
  that makes a difference *here*)
- stop the matching process immediately after the first char does 
  not match
- use non-capturing parenthesis (?:) to decrease the work 
  of the regex engine, since the matched string is not used
- Then, since the same substring is used below, it might (not shure) 
  be appropriate to store the extracted string into a variable 

That would leed to [untested]:

  if ( (my $s=substr($_,70,2)) =~ /^x(?:x|y|z)/i ) {

   print MYFILEOUT substr($),70,2) .

You meant '$_', not '$'.

  print MYFILEOUT $s . # see above alternative

 Substr($_,91,1) . \n;

You meant:

  substr ($_,91,1) . \n;

}
}

   simple format and should be straight forward.

Dani

[snipped top-posting history]

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




RE: line position

2006-11-03 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Sorry, but I was just giving quick code and had NOT run. Using
of strict and warnings is the only way to go. I was writing and doing
other things. I apologize for not catching, but was supplying the open
for th input or output, etc. just a inkling on what he could do to get
started. 

  If you have any problems or questions, please let me know.

 Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449   FAX
http://fedex.com/us 

-Original Message-
From: D. Bolliger [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 03, 2006 14:19
To: beginners@perl.org
Subject: Re: line position

Wagner, David --- Senior Programmer Analyst --- WGO am Freitag, 3.
November 
2006 22:16:
   If it is only one line and it is record separator is carriage
 return as defined by your system, then a simple loop like:

Hello David and Tim,

The below code is a good example why one should happily place:

  use strict; 
  use warnings; 

at the beginning.

   while: ( MYFILEIN ) {

You meant: 

  while ( MYFILEIN ) {

   chomp;

Just omit the chomp and the code behaves the same.

   if ( substr($_,70,2) =~ /(xx|xy|xz)/I ) {

The modifier should be /i, not /I. With /I, the code doesn't even
compile.

If you want to use a regex, then it might be better to:
- anchor the pattern (not completely shure though if 
  that makes a difference *here*)
- stop the matching process immediately after the first char does 
  not match
- use non-capturing parenthesis (?:) to decrease the work 
  of the regex engine, since the matched string is not used
- Then, since the same substring is used below, it might (not shure) 
  be appropriate to store the extracted string into a variable 

That would leed to [untested]:

  if ( (my $s=substr($_,70,2)) =~ /^x(?:x|y|z)/i ) {

   print MYFILEOUT substr($),70,2) .

You meant '$_', not '$'.

  print MYFILEOUT $s . # see above alternative

 Substr($_,91,1) . \n;

You meant:

  substr ($_,91,1) . \n;

}
}

   simple format and should be straight forward.

Dani

[snipped top-posting history]

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



**
This message contains information that is confidential and proprietary to FedEx 
Freight or its affiliates.  It is intended only for the recipient named and for 
the express  purpose(s) described therein.  Any other use is prohibited.
**


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




Hi, Everyone, I can't install perl modules correctly using CPAN, why?

2006-11-03 Thread 辉 王
Hi, everyone,

When I want to install perl module WWW::Yahoo::KeywordExtractor in 

my  Ubuntu damper 6.06 OS, it doesn't work properly. The error message 

is listed below:

===

CPAN: Storable loaded ok
Going to read /home/wanghui/.cpan/Metadata
  Database was generated on Mon, 30 Oct 2006 21:24:24 GMT
CPAN: LWP::UserAgent loaded ok
Fetching with LWP:
  ftp://mirrors.hknet.com/CPAN/authors/01mailrc.txt.gz
LWP failed with code[500] message[read timeout]
CPAN: Net::FTP loaded ok
Fetching with Net::FTP:
  ftp://mirrors.hknet.com/CPAN/authors/01mailrc.txt.gz
  Could not connect to host 'mirrors.hknet.com' with Net::FTP
Fetching with LWP:
  http://cpan.linuxforum.net/authors/01mailrc.txt.gz
Going to read /home/wanghui/.cpan/sources/authors/01mailrc.txt.gz
Fetching with LWP:
  ftp://mirrors.hknet.com/CPAN/modules/02packages.details.txt.gz
Going to read /home/wanghui/.cpan/sources/modules/02packages.details.txt.gz
  Database was generated on Wed, 01 Nov 2006 15:24:03 GMT
Fetching with LWP:
  ftp://mirrors.hknet.com/CPAN/modules/03modlist.data.gz
Going to read /home/wanghui/.cpan/sources/modules/03modlist.data.gz
Going to write /home/wanghui/.cpan/Metadata
Running install for module WWW::Yahoo::KeywordExtractor
Running make for S/SO/SOCK/WWW-Yahoo-KeywordExtractor-0.04.tar.gz
cpan install WWW::Yahoo::KeywordExtractorCPAN: Digest::SHA loaded ok
Checksum for 
/home/wanghui/.cpan/sources/authors/id/S/SO/SOCK/WWW-Yahoo-KeywordExtractor-0.04.tar.gz
 ok
Scanning cache /home/wanghui/.cpan/build for sizes
WWW-Yahoo-KeywordExtractor-0.04/
WWW-Yahoo-KeywordExtractor-0.04/Build.PL
WWW-Yahoo-KeywordExtractor-0.04/Changes
WWW-Yahoo-KeywordExtractor-0.04/lib/
WWW-Yahoo-KeywordExtractor-0.04/lib/WWW/
WWW-Yahoo-KeywordExtractor-0.04/lib/WWW/Yahoo/
WWW-Yahoo-KeywordExtractor-0.04/lib/WWW/Yahoo/KeywordExtractor.pm
WWW-Yahoo-KeywordExtractor-0.04/MANIFEST
WWW-Yahoo-KeywordExtractor-0.04/META.yml
WWW-Yahoo-KeywordExtractor-0.04/README
WWW-Yahoo-KeywordExtractor-0.04/t/
WWW-Yahoo-KeywordExtractor-0.04/t/02-pod.t
WWW-Yahoo-KeywordExtractor-0.04/t/03-pod_coverage.t
WWW-Yahoo-KeywordExtractor-0.04/t/04-perl_critic.t
WWW-Yahoo-KeywordExtractor-0.04/t/11-compile.t
Removing previously used 
/home/wanghui/.cpan/build/WWW-Yahoo-KeywordExtractor-0.04

  CPAN.pm: Going to build S/SO/SOCK/WWW-Yahoo-KeywordExtractor-0.04.tar.gz

Checking whether your kit is complete...
Looks good

Checking prerequisites...
 - ERROR: XML::Simple is not installed

ERRORS/WARNINGS FOUND IN PREREQUISITES.  You may wish to install the versions
of the modules indicated above before proceeding with this installation

Creating new 'Build' script for 'WWW-Yahoo-KeywordExtractor' version '0.04'
CPAN: YAML loaded ok
CPAN: Module::Build loaded ok
  Warning: CPAN.pm discovered Module::Build as undeclared prerequisite.
  Adding it now as such.
 Unsatisfied dependencies detected during 
[S/SO/SOCK/WWW-Yahoo-KeywordExtractor-0.04.tar.gz] -
XML::Simple
Shall I follow them and prepend them to the queue
of modules we are processing right now? [yes]
Running Build test
  Delayed until after prerequisites
Running Build install
  Delayed until after prerequisites
Running install for module XML::Simple
Running make for G/GR/GRANTM/XML-Simple-2.16.tar.gz
Checksum for 
/home/wanghui/.cpan/sources/authors/id/G/GR/GRANTM/XML-Simple-2.16.tar.gz ok
XML-Simple-2.16/
XML-Simple-2.16/t/
XML-Simple-2.16/t/1_XMLin.xml
XML-Simple-2.16/t/lib/
XML-Simple-2.16/t/lib/TagsToUpper.pm
XML-Simple-2.16/t/B_Hooks.t
XML-Simple-2.16/t/6_ObjIntf.t
XML-Simple-2.16/t/1_XMLin.t
XML-Simple-2.16/t/srt.xml
XML-Simple-2.16/t/4_MemShare.t
XML-Simple-2.16/t/3_Storable.t
XML-Simple-2.16/t/7_SaxStuff.t
XML-Simple-2.16/t/A_XMLParser.t
XML-Simple-2.16/t/0_Config.t
XML-Simple-2.16/t/subdir/
XML-Simple-2.16/t/subdir/test2.xml
XML-Simple-2.16/t/2_XMLout.t
XML-Simple-2.16/t/5_MemCopy.t
XML-Simple-2.16/t/8_Namespaces.t
XML-Simple-2.16/t/test1.xml
XML-Simple-2.16/t/desertnet.src
XML-Simple-2.16/t/9_Strict.t
XML-Simple-2.16/Changes
XML-Simple-2.16/MANIFEST
XML-Simple-2.16/lib/
XML-Simple-2.16/lib/XML/
XML-Simple-2.16/lib/XML/Simple/
XML-Simple-2.16/lib/XML/Simple/FAQ.pod
XML-Simple-2.16/lib/XML/Simple.pm
XML-Simple-2.16/META.yml
XML-Simple-2.16/maketest
XML-Simple-2.16/README
XML-Simple-2.16/Makefile.PL
Removing previously used /home/wanghui/.cpan/build/XML-Simple-2.16

  CPAN.pm: Going to build G/GR/GRANTM/XML-Simple-2.16.tar.gz

Checking installed modules ...
=

  Fatal error: Your default XML parser (XML::SAX::PurePerl) is broken.

  There are known bugs in the PurePerl parser included with version 0.13
  and 0.14 of XML::SAX.  The XML::Simple tests will fail with this parser.

  One way to avoid the problem is to install XML::SAX::Expat - it will
  install itself as the system default XML parser and then you will be able
  to install XML::Simple successfully.  XML::SAX::Expat is also much faster
  than 

Re: date and file comparison

2006-11-03 Thread Arnaldo Guzman
On Fri, 2006-11-03 at 08:08 -0600, Tim Wolak wrote: 
 Morning all,
 
 I need to compare the current date with that of a file, if the file is
 older than the current date remove it and replace it with a new one from
 new data.  Below I have the code set for getting the date but can't come
 up with an easy way to compare it against the file date.  Can anyone
 tell me the best way to compare the current date with that of the
 date/time stamp on a file?
 
 Thanks,
 Tim
 
 my $date;
 my ($sec,$min,$hour,$mday,$mon,$year) = (localtime) [0,1,2,3,4,5];
 $year=$year+1900;
 $mon=$mon+1;
 $date = sprintf(%02d%02d%02d\_%02d\:%02d\:%02d,
 $year,$mon,$mday,$hour,$min,$sec);

Your list slice:

   my ($sec,$min,$hour,$mday,$mon,$year) = (localtime) [0,1,2,3,4,5];

Is completely unnecessary; you can achieve the same with:

   my ($sec, $min, $hour, $mday, $mon, $year) = localtime();

Use slices for what they're good for. :-)

Now, why not just check how old the file is in days? You can achieve
this in different ways, the file test operators can help you.

Simple example:

if (int(-M $file)  $x) {
# do something
}

Of course this isn't perfect, you can read more about the file test
operators with perldoc -f -X. You should also read perldoc -q
timestamp. I'm sure after reading these specifically the FAQ mentioned
(can be found in perlfaq5), you will be on your way to a good start.

Hope this helps! :-)


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




Re: Hi, Everyone, I can't install perl modules correctly using CPAN, why?

2006-11-03 Thread Jeff Pang


Hi, everyone,

When I want to install perl module WWW::Yahoo::KeywordExtractor in 

my  Ubuntu damper 6.06 OS, it doesn't work properly.


Looks like something with XML is wrong.
Give a try to install XML::SAX::Expat and XML::Simple at first.

--
Books below translated by me to Chinese.
Practical mod_perl: http://home.earthlink.net/~pangj/mod_perl/
Squid the Definitive Guide: http://home.earthlink.net/~pangj/squid/

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