[31659] in Perl-Users-Digest
Perl-Users Digest, Issue: 2922 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 26 11:09:23 2010
Date: Mon, 26 Apr 2010 08:09:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 26 Apr 2010 Volume: 11 Number: 2922
Today's topics:
alternative for ctime <rengaprasath@gmail.com>
Re: alternative for ctime <mvdwege@mail.com>
Re: alternative for ctime <someone@example.com>
Re: alternative for ctime <rengaprasath@gmail.com>
Re: alternative for ctime <mvdwege@mail.com>
Re: alternative for ctime sln@netherlands.com
Re: FAQ 4.34 How do I extract selected columns from a s <jurgenex@hotmail.com>
Re: FAQ 7.26 How can I find out my current or calling p <brian.d.foy@gmail.com>
Re: FAQ 7.26 How can I find out my current or calling p <ben@morrow.me.uk>
Re: How to ignore newline in Parse::RecDescent <derykus@gmail.com>
Re: Problems with "show tech" using the Net::Telnet Mod sln@netherlands.com
Re: Problems with "show tech" using the Net::Telnet Mod sln@netherlands.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 26 Apr 2010 00:56:29 -0700 (PDT)
From: GRP <rengaprasath@gmail.com>
Subject: alternative for ctime
Message-Id: <154a47d5-2001-46b6-8da4-661c8822329a@u31g2000pra.googlegroups.com>
hi,
I would like to write a script to grep some pattern in few set of log
files and alert it...
In order to avoid duplicate alert i plan to store the "FILENAME:ERR-
LINE-NUMBER:FILE-CREATION-TIME" in a flat file (colon delimiter) , so
that next time if the same pattern found in same line it will check
against the flat file and won't alert. At the same time if it happens
in different line number it wud check in flat file & the 2nd filed
would be different so it will alert.
Since i can't find a way to get ctime in unix (i tried with perl as
well), would be there any other way to achieve this or better logic?
Your help will be greatly appreciated..
thks
------------------------------
Date: Mon, 26 Apr 2010 10:30:53 +0200
From: Mart van de Wege <mvdwege@mail.com>
Subject: Re: alternative for ctime
Message-Id: <8639yimx8i.fsf@gareth.avalon.lan>
GRP <rengaprasath@gmail.com> writes:
>
> Since i can't find a way to get ctime in unix (i tried with perl as
> well), would be there any other way to achieve this or better logic?
>
What's wrong with
($ctime) = (stat($filename))[10];
?
Mart
--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
------------------------------
Date: Mon, 26 Apr 2010 01:44:39 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: alternative for ctime
Message-Id: <YncBn.44893$0_7.30408@newsfe25.iad>
GRP wrote:
>
> I would like to write a script to grep some pattern in few set of log
> files and alert it...
>
> In order to avoid duplicate alert i plan to store the "FILENAME:ERR-
> LINE-NUMBER:FILE-CREATION-TIME" in a flat file (colon delimiter) , so
> that next time if the same pattern found in same line it will check
> against the flat file and won't alert. At the same time if it happens
> in different line number it wud check in flat file & the 2nd filed
> would be different so it will alert.
>
> Since i can't find a way to get ctime in unix (i tried with perl as
> well), would be there any other way to achieve this or better logic?
You can get the ctime, that is easy, but you can't get the
"FILE-CREATION-TIME" because unix doesn't store that anywhere.
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
------------------------------
Date: Mon, 26 Apr 2010 02:13:23 -0700 (PDT)
From: GRP <rengaprasath@gmail.com>
Subject: Re: alternative for ctime
Message-Id: <a4f904f0-1c40-4142-a556-9926dce83f5f@x18g2000prk.googlegroups.com>
On Apr 26, 4:44=A0pm, "John W. Krahn" <some...@example.com> wrote:
> GRP wrote:
>
> > I would like to write a script to grep some pattern in few set of log
> > files and alert it...
>
> > In order to avoid duplicate alert i plan to store the "FILENAME:ERR-
> > LINE-NUMBER:FILE-CREATION-TIME" =A0in a flat file (colon delimiter) , s=
o
> > that next time if the same pattern found in same line it will check
> > against the flat file and won't alert. At the same time if it happens
> > in different line number it wud check in flat file & the 2nd filed
> > would be different so it will alert.
>
> > Since i can't find a way to get ctime in unix (i tried with perl as
> > well), would be there any other way to achieve this or better logic?
>
> You can get the ctime, that is easy, but you can't get the
> "FILE-CREATION-TIME" because unix doesn't store that anywhere.
>
> John
> --
> The programmer is fighting against the two most
> destructive forces in the universe: entropy and
> human stupidity. =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- Damian Conway
Mart,
Thks for the feedback.
I've tried
($ctime) =3D (stat($filename))[10];
where that will give only file changed time not creation time
Source : http://perldoc.perl.org/functions/stat.html
10 ctime inode change time in seconds since the epoch (*)
John,
After google it , found Unix wont be storing creation time, just
thought of checking with you all would there be any other way to
attain my requirement?
Basically better logic ;)
Cheers
------------------------------
Date: Mon, 26 Apr 2010 11:55:09 +0200
From: Mart van de Wege <mvdwege@mail.com>
Subject: Re: alternative for ctime
Message-Id: <86y6galerm.fsf@gareth.avalon.lan>
GRP <rengaprasath@gmail.com> writes:
> On Apr 26, 4:44Â pm, "John W. Krahn" <some...@example.com> wrote:
>> GRP wrote:
>>
>> > I would like to write a script to grep some pattern in few set of log
>> > files and alert it...
>>
>> > In order to avoid duplicate alert i plan to store the "FILENAME:ERR-
>> > LINE-NUMBER:FILE-CREATION-TIME" Â in a flat file (colon delimiter) , so
>> > that next time if the same pattern found in same line it will check
>> > against the flat file and won't alert. At the same time if it happens
>> > in different line number it wud check in flat file & the 2nd filed
>> > would be different so it will alert.
>>
>> > Since i can't find a way to get ctime in unix (i tried with perl as
>> > well), would be there any other way to achieve this or better logic?
>>
>> You can get the ctime, that is easy, but you can't get the
>> "FILE-CREATION-TIME" because unix doesn't store that anywhere.
>>
>> John
Note: Don't quote sigs, it's considered impolite.
>
> Mart,
> Thks for the feedback.
>
> I've tried
> ($ctime) = (stat($filename))[10];
>
> where that will give only file changed time not creation time
>
Ah.
I *was* wondering about that. Your use of creation time was inconsistent
with your asking for ctime. On Unix, these *are* different things, and
as pointed out, creation time is not saved.
Regards,
Mart
--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
------------------------------
Date: Mon, 26 Apr 2010 07:56:00 -0700
From: sln@netherlands.com
Subject: Re: alternative for ctime
Message-Id: <gv9bt51r5f1rgo22agapd9gk2c81957g9q@4ax.com>
On Mon, 26 Apr 2010 02:13:23 -0700 (PDT), GRP <rengaprasath@gmail.com> wrote:
>On Apr 26, 4:44 pm, "John W. Krahn" <some...@example.com> wrote:
>> GRP wrote:
>>
>> > I would like to write a script to grep some pattern in few set of log
>> > files and alert it...
>>
>> > In order to avoid duplicate alert i plan to store the "FILENAME:ERR-
>> > LINE-NUMBER:FILE-CREATION-TIME" in a flat file (colon delimiter) , so
>> > that next time if the same pattern found in same line it will check
>> > against the flat file and won't alert. At the same time if it happens
>> > in different line number it wud check in flat file & the 2nd filed
>> > would be different so it will alert.
>>
>> > Since i can't find a way to get ctime in unix (i tried with perl as
>> > well), would be there any other way to achieve this or better logic?
>>
>> You can get the ctime, that is easy, but you can't get the
>> "FILE-CREATION-TIME" because unix doesn't store that anywhere.
>>
>> John
>> --
>> The programmer is fighting against the two most
>> destructive forces in the universe: entropy and
>> human stupidity. -- Damian Conway
>
>Mart,
>Thks for the feedback.
>
>I've tried
>($ctime) = (stat($filename))[10];
>
>where that will give only file changed time not creation time
>
>Source : http://perldoc.perl.org/functions/stat.html
> 10 ctime inode change time in seconds since the epoch (*)
>
>John,
>After google it , found Unix wont be storing creation time, just
>thought of checking with you all would there be any other way to
>attain my requirement?
>Basically better logic ;)
>
>Cheers
You can get the current time I assume but why do you need
any time or timestamp at all? You do have modify time in unix
don't you? Thats the creation time the first time.
So, forget about the time. Post some algo that you want this to do.
-sln
------------------------------
Date: Sun, 25 Apr 2010 21:32:26 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: FAQ 4.34 How do I extract selected columns from a string?
Message-Id: <6p5at5dok54j88jjehstce5n6nhmv92d9q@4ax.com>
PerlFAQ Server <brian@theperlreview.com> wrote:
> If you know where the columns that contain the data, [...]
This sentence a verb.
jue
------------------------------
Date: Sun, 25 Apr 2010 15:43:11 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 7.26 How can I find out my current or calling package?
Message-Id: <250420101543118220%brian.d.foy@gmail.com>
In article <qma4a7-scj2.ln1@osiris.mauzo.dyndns.org>, Ben Morrow
<ben@morrow.me.uk> wrote:
> Quoth PerlFAQ Server <brian@theperlreview.com>:
> >
> > Most of the time, you shouldn't care what package an object is blessed
> > into, however, as long as it claims to inherit from that class:
> >
> > my $is_right_class = eval { $object->isa( $package ) }; #
> > true or false
>
> Should this answer mention ->DOES at this point? AIUI, most of the time
> it's a more appropriate test than ->isa, but I must admit I'm not
> entirely clear on the difference between the two.
Yes, that should be DOES now.
The difference between the two is that isa() checks for inheritance
while DOES() checks that the object performs a role despite
inheritance. Roles, traits, and mixins want to provide functionality
without inheritance.
------------------------------
Date: Sun, 25 Apr 2010 23:08:26 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 7.26 How can I find out my current or calling package?
Message-Id: <q3rea7-dt91.ln1@osiris.mauzo.dyndns.org>
Quoth brian d foy <brian.d.foy@gmail.com>:
> In article <qma4a7-scj2.ln1@osiris.mauzo.dyndns.org>, Ben Morrow
> <ben@morrow.me.uk> wrote:
> >
> > Should this answer mention ->DOES at this point? AIUI, most of the time
> > it's a more appropriate test than ->isa, but I must admit I'm not
> > entirely clear on the difference between the two.
>
> Yes, that should be DOES now.
>
> The difference between the two is that isa() checks for inheritance
> while DOES() checks that the object performs a role despite
> inheritance. Roles, traits, and mixins want to provide functionality
> without inheritance.
Yes, but when do you care? If an object conforms to a given interface,
what difference does it make (from outside the object) whether those
methods are implemented through inheritance, delegation, mixins, or
whatever?
Ben
------------------------------
Date: Sat, 24 Apr 2010 15:11:40 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: How to ignore newline in Parse::RecDescent
Message-Id: <d00703d1-bd19-46c4-9ae5-7fa3001b80d4@g1g2000pre.googlegroups.com>
On Apr 24, 12:04=A0pm, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> On 2010-04-24 18:45, C.DeRykus <dery...@gmail.com> wrote:
>
> [...]
> > And you don't really need to slurp:
>
> > while (<IN>)
> > {
> > =A0 =A0 =A0 =A0 defined $parser->start($_)
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 or die "Didn't match anything";
> > }
>
> That parses every line separately which is in general not the same as
> parsing a whole file.
>
Right, a simple example like the OP's, doesn't but even
a slightly more complex grammar could. For instance, if
the grammar required a blank line too:
start: identifier(s) blank
identifier : /\S+/
{ print $item[1],"\n"; }
blank: /^$/
{ print "blank...\n"; }
Then, you'd need to slurp... I think.
--
Charles DeRykus
------------------------------
Date: Sun, 25 Apr 2010 11:15:27 -0700
From: sln@netherlands.com
Subject: Re: Problems with "show tech" using the Net::Telnet Module
Message-Id: <2n09t5p79kmcg5kngnbo2pa9h1ifhq1pc0@4ax.com>
On Sat, 24 Apr 2010 11:28:55 -0700 (PDT), Asterix <lange.gerhard@gmail.com> wrote:
>I've figured out the problem. It was not a problem regarding TELNET
>but regarding the flushing of the
>Buffer verso STDOUT:
>
>Instead of this printf OUTPUT_FILE "@output\n\n";
>I've used print OUTPUT_FILE "@output\n\n";
>
>At the top of the script I also inserted "Autoflush":
>local $| = 1; # Default is 0
>
>http://perldoc.perl.org/perlvar.html
>
It always amazes me that people write all-encompassing
complete code and look for problem solutions at the
ends of the chain instead of the links themselves.
In list context, on sucess of cmd(), the sizeof @output is at least 1,
otherwise there was an error, and with errormode set to "return",
its size is 0.
Debugging is subtle. People usually develop a sixth sense
over time, unless they write perfect code.
You should have found this earlier.
-sln
------------------------------
Date: Sun, 25 Apr 2010 12:27:04 -0700
From: sln@netherlands.com
Subject: Re: Problems with "show tech" using the Net::Telnet Module
Message-Id: <5559t59udr549kjelqvk1h7el9gtmcfq41@4ax.com>
On Sat, 24 Apr 2010 11:28:55 -0700 (PDT), Asterix <lange.gerhard@gmail.com> wrote:
>I've figured out the problem. It was not a problem regarding TELNET
>but regarding the flushing of the
>Buffer verso STDOUT:
>
>Instead of this printf OUTPUT_FILE "@output\n\n";
>I've used print OUTPUT_FILE "@output\n\n";
>
>At the top of the script I also inserted "Autoflush":
>local $| = 1; # Default is 0
>
>http://perldoc.perl.org/perlvar.html
>
The docs say $| only sets the current selected filehandle,
which is usually STDOUT, which is line buffered anyway if its output
goes to a terminal.
To tell it to autoflush your handle you could do it a couple
of ways:
my $oldfh = select(OUTPUT_FILE); $| = 1; select($oldfh);
## or ..
use IO::Handle;
OUTPUT_FILE->autoflush(1);
========================
use strict;
use warnings;
my $oldfh = select(OUTPUT_FILE); $| = 1; select($oldfh);
open (OUTPUT_FILE,'>', 'some.txt') or die $!;
my @output = qw(one two three);
printf OUTPUT_FILE "@output\n\n";
<>;
__END__
-sln
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2922
***************************************