[28943] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 187 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 2 11:09:41 2007

Date: Fri, 2 Mar 2007 08:09:04 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 2 Mar 2007     Volume: 11 Number: 187

Today's topics:
    Re: changed to OT Re: DocumentHTML ? <tadmc@augustmail.com>
    Re: changed to OT Re: DocumentHTML ? <tadmc@augustmail.com>
    Re: changed to OT Re: DocumentHTML ? <g_m@remove-comcast.net>
        Footnote Moving Problem <sahoo.byomokesh@gmail.com>
    Re: Footnote Moving Problem <thepoet_nospam@arcor.de>
    Re: guestbook.cgi :p :p <john.swilting@wanadoo.fr>
        guestbook.cgi :p <john.swilting@wanadoo.fr>
    Re: guestbook.cgi :p <john.swilting@wanadoo.fr>
    Re: how to find the "yesterday" logfile name? <mritty@gmail.com>
    Re: how to find the "yesterday" logfile name? <tzz@lifelogs.com>
    Re: mod_perl error:  (120000) exit was called at <sean115=at@=reeve.nl>
    Re: Perl and MySQL <DJStunks@gmail.com>
    Re: Q on regex of LWP::Simple data <len@philpot.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 2 Mar 2007 06:09:05 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: changed to OT Re: DocumentHTML ?
Message-Id: <slrneug4v1.ca7.tadmc@tadmc30.august.net>

~greg <g_m@remove-comcast.net> wrote:

> Please! - Just do me this one favor.
> Answer me this:
>
> Tell me why Tad responded to my:
>
>     >> (I'm not a professional)
>     >>  It would never have occurred to me
>     >> that explicit "use strict"
>     >> and "use warnings"
>     >> is a courtesy to others.
>
> with
>
> >Please see the Posting Guidelines that are posted
> > here frequently.


Because you displayed "good attitude" in your 1st followup, which
is a depressingly rare response, most people gripe about netiquette
rather than responding with the expected "Oh, i didn't know that".

I had actually added you to the "nice people to help" (scored up)
in my scorefile (that changed later).


> When there is nothing whatever
> in his guidelines about "use strict"
> and "use warnings'!

    Ask perl to help you
        You can ask perl itself to help you find common programming mistakes
        by doing two things: enable warnings (perldoc warnings) and enable
        "strict"ures (perldoc strict).

> --and when I had immediately added : ...
>     >> I will do it from now on


And I did not point you to the guidelines so that you could learn
about those pragmas, you already knew about them.

I figured, here's a guy that _wants_ to be socially acceptable. Oh,
but he doesn't know about top-posting (TOFU), so he probably wants
to know that folks don't like that either...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 2 Mar 2007 06:38:23 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: changed to OT Re: DocumentHTML ?
Message-Id: <slrneug6lv.ca7.tadmc@tadmc30.august.net>

~greg <g_m@remove-comcast.net> wrote:
> Sinan > wrote
>> I don't know what to make of you.


> But please understand me --the temperament that
> appears here is not anything that ever lasts in me
> for more than a minute.


Unfortunately, once the message is sent, you can't undo it.

  Be extra cautious when you get upset
    Count to ten before composing a followup when you are upset
        This is recommended in all Usenet newsgroups. Here in clpmisc, most
        flaming sub-threads are not about any feature of Perl at all! They
        are most often for what was seen as a breach of netiquette. If you
        have lurked for a bit, then you will know what is expected and won't
        make such posts in the first place.

        But if you get upset, wait a while before writing your followup. I
        recommend waiting at least 30 minutes.

    Count to ten after composing and before posting when you are upset
        After you have written your followup, wait *another* 30 minutes
        before committing yourself by posting it. You cannot take it back
        once it has been said.


>>>>  -- 
>>>>    Tad McClellan
>>>>    SGML consulting
>>>>    tadmc@augustmail.com
>>>>    Perl programming
>>>>    Fort Worth, Texas
>>>>
>>>
>>>  please don't spam.


Including what you do for a living in a .sig is not spam, it is
perfectly acceptable tenant of general netiquette.


>> What is the point of that remark?
>
> Well, Sinan,
>   What is the point of Tad's contribution to this thread?


You found out one of the group's expectations the hard way.

My point was that you could find out most of the rest of them
the easy way.


> Please break out of the little world here for a second
> and read it objectively.
>
> It is a nasty, insulting, trivializing, pontificating,
> officious  


Sorry, it was surely not intended as such.


> -- and - content-wise - a completely
> empty thing.


While using warnings/strict is a Perl-specific element of netiquette
and therefore of limited applicability, avoiding top-posting is
universally accepted across all of Usenet.

I wanted you to know about TOFU before you experienced angst
in other newsgroups as well.


>     ~greg t> wrote:
>     > Gentlemen, I'm old.
>     Me too. Bummer eh?
>     >  It would never have occurred to me that explicit
>     > "use strict"
>     > and "use warnings" is a courtesy to others.
>     Please see the Posting Guidelines that are posted
>     here frequently.
>     > I will do it from now on.
>     Thank you.
>     [ snip TOFU.
>       Please don't do that either.
>     ]
>
>
> I had said to you (Sinan) that I will
> use the "use..." stuff from now on.
>
> So what was Tad's point in bringing it up again?
> right after I said I would?,


I thought you'd smack your head and say:

   If only I had known about warnings/strict before posting.


> - in his quoting me saying so?,
> --and in his chiming-in with  (--what emoticon?)
> "Thank you" ?


That was truly sincere.

The most common response to "you should use warnings/strict" is:

   Don't tell me what to do.

I expected a more pleasant response from you though, based on
the attitude displayed in your first followup.


> (The answer is that he was being passive agressive.)


A "conclusion" does not correspond directly to an "answer".

We have experienced yet more miscommunication it would appear.


> Is there something, - anything, - specific in his guidelines
> that he wanted me to see?

    Use an effective followup style
        When composing a followup, quote only enough text to establish the
        context for the comments that you will add. Always indicate who
        wrote the quoted material. Never quote an entire article. Never
        quote a .signature (unless that is what you are commenting on).

        Intersperse your comments *following* each section of quoted text to
        which they relate. Unappreciated followup styles are referred to as
        "top-posting", "Jeopardy" (because the answer comes before the
        question), or "TOFU" (Text Over, Fullquote Under).

        Reversing the chronology of the dialog makes it much harder to
        understand (some folks won't even read it if written in that style).
        For more information on quoting style, see:

         http://web.presby.edu/~nnqadmin/nnq/nquote.html


> Some generality, perhaps, of obvious applicability
> to "use strict" "use warnings"??


Besides knowing the syntax for them, it might be nice
to peruse their documentation (referenced in the guidelines).


> Right near the very top of Tad's
> "Posting Guidelines for comp.lang.perl.misc ($Revision: 1.7 $)"


They are not "my" guidelines, they are "our" guidelines.

They were discussed, and agreed upon, over several weeks here.


> it says:
>
>   "This newsgroup, commonly called clpmisc,
>     is a technical newsgroup intended to be used for discussion
>     of Perl related issues  (except job postings), ..."
>
> And near the middle it says:
>    "Never quote a .signature
>     (unless that is what you are commenting on)."
>
> And near the bottom it says:
>
>   "AUTHOR
>    Tad McClellan <tadmc@augustmail.com>
>    and many others on the
>    comp.lang.perl.misc newsgroup. "
>
> ~~
>
>
> I am now commenting on Tad's .signature.
>
> Note especially the specifically-mentioned parenthetical exception:
>     "(except job postings)"
>
> Note how it is given pride of place,
> right near the very top of Tad's document.
>
> So apparently Tad has written just for himself
> some kind of secret-exemption to this rule.


I did not post a job posting.


> Why does Tad tell everybody to go read his guidelines?


So that they can avoid being silently killfiled.


> And why does he put "except job postings" right at the top of it?


Because even Perl-related job postings are not welcomed here.


> Well, this is the reason: ...
> It's so that any other "SGML consultant" who chances by,
> and who wants to follow all "the rules", to be polite,
> - will decide not to advertise himself
> in the same way that (only) Tad is permitted to do,
> in his .signature.


Everyone is permitted to include their job title in their .sig.

They are even permitted outright advertising in their .sig.

If you don't know much about Usenet netiquette, then commenting
on Usenet netiquette is talking out of place...


> What, pray tell, was Tad's point in commenting to me
> the way he did?
> --this way? : ...
>
>>  ~greg > wrote:
>> > Gentlemen, I'm old.
>> Me too. Bummer eh?


It was meant as a witty aside.


> That remark would have sounded very different
> if it had a clear purpose. Or if it had been
> elaborated in some friendly way.


But I can see how it could be interpreted that way. Let me rephrase:

   I feel your pain.

   I am old too, and it is a drag (but much preferable to the alternative!)


> As it stands, though, it is pure monkey business.
> It's a razz.


No it isn't. I actually _am_ old.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 2 Mar 2007 08:07:07 -0500
From: "~greg" <g_m@remove-comcast.net>
Subject: Re: changed to OT Re: DocumentHTML ?
Message-Id: <mvydnVU2sfblvHXYnZ2dnUVZ_r6vnZ2d@comcast.com>


Tad> wrote ...

> I figured, here's a guy that _wants_ to be socially acceptable. Oh,
> but he doesn't know about top-posting (TOFU), so he probably wants
> to know that folks don't like that either...

Well, I didn't know.

That instance was a mistake. However,
I have deliberately posted in every which way
in a different, very informal newsgroup.

Google shows the first 3 or 4 lines of posts
in their search-results-listings, so the only
rule that ever made logical sense to me
was to try to make the first few lines
as informative as possible about the rest of the content.

I guess that *would* normally mean from the quoted text!

In any case, I will of course abide.

~~~

But hey, man! - I just wanted to say thank you!

I don't myself have much of it, but I know
real wisdom when I see it.

And it is real wisdom to see when somebody
else's tantrum has nothing to do with you,
-you just happened to be there that's all.

Thank you!

Greg.















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

Date: 2 Mar 2007 03:36:58 -0800
From: "Rahul" <sahoo.byomokesh@gmail.com>
Subject: Footnote Moving Problem
Message-Id: <1172835418.809135.323070@n33g2000cwc.googlegroups.com>

Hi All,

I have problem about footnote. i want to move footnote to Chapter end.
Footnote text also in pargraph.

Examp.
<chap>
<para>Some text <note type="fn">footnote text here</note>
text...text...here</p>
<para>Some text text...text...here</p>
<para>Some text text...text...here</p>
</chap>

I need footnote text move to end of the chapter tag. Is it possible?
Anyone advice me.

thanks
Byomokesh



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

Date: Fri, 02 Mar 2007 16:27:07 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Footnote Moving Problem
Message-Id: <45e8424a$0$23142$9b4e6d93@newsspool1.arcor-online.net>

Rahul wrote:
> Hi All,
> 
> I have problem about footnote. i want to move footnote to Chapter end.
> Footnote text also in pargraph.
> 
> Examp.
> <chap>
> <para>Some text <note type="fn">footnote text here</note>
> text...text...here</p>
> <para>Some text text...text...here</p>
> <para>Some text text...text...here</p>
> </chap>
> 
> I need footnote text move to end of the chapter tag. Is it possible?

Assuming that the example you gave here is just some badly typed
random text (your opening and closing tag names don't even match)
and your real XML data is in fact well-formed, it should be easy
to do with XML::TreeBuilder:

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

use strict;
use warnings;
use XML::TreeBuilder;

my $tree = XML::TreeBuilder->new();
$tree->parse( join '', <DATA> ); # or use "parsefile($filename)"

# Process each <chap> element:
foreach ( $tree->look_down('_tag', 'chap') )
{
	# Search it for the <note> element that has a
	# type attribute of "fn":
	my $fn = $_->look_down(
		'_tag',
		'note',
		sub {
			$_[0]->attr('type') &&
			$_[0]->attr('type') eq "fn"
		}
	) || next; # If not found, process next chapter
	# Remove the note element from its parent:
	$fn->detach;
	# And append it to the end of the chapter's contents
	$_->push_content($fn);
}

print $tree->as_XML;

__DATA__
<?xml version="1.0"?>

<document>
<chap>
<para>Some text <note type="fn">footnote text here</note>
text...text...here</para>
<para>Some text text...text...here</para>
<para>Some text text...text...here</para>
</chap>
<chap>
<para>Some text <note type="fn">footnote text here</note>
text...text...here</para>
<para>Some text text...text...here</para>
<para>Some text text...text...here</para>
</chap>
</document>
--------------------------------------------------------------------------

HTH
-Chris


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

Date: Fri, 02 Mar 2007 12:50:41 +0100
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: Re: guestbook.cgi :p :p
Message-Id: <45e80f8f$0$25909$ba4acef3@news.orange.fr>

john.swilting wrote:


> I post. it is my code. you can say to me what you think that will make me
> progress.
I read posts with small images very to complicate. I cannot do it. somebody
knows


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

Date: Fri, 02 Mar 2007 12:43:04 +0100
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: guestbook.cgi :p
Message-Id: <45e80dc7$0$25915$ba4acef3@news.orange.fr>

#!/usr/bin/perl -Tw
use strict;
use CGI qw/:standard escapeHTML/;
use Fcntl qw/:flock/;
$|++;

# Config
my $GUESTBOOK = '/var/www/cgi-bin/guestbook.txt'; 
my $TITLE = 'Guestbook';  # Title of guestbook
my $MAX_MSGS = 5;         # Maximum number of messages displayed
my $MAX_NAME = 50;        # Maximum length of name field
my $MAX_EMAIL = 50;       # Maximum length of email field
my $MAX_COMMENTS = 300;   # Maximum length of comments field
# End Config

# Print header
print header,
      start_html(-title=>$TITLE, -bgcolor=>'white'),
      h1($TITLE);

# Get action
my $action = param('action');

# Check action
if ($action =~ /^sign/i) {
    # Sign guestbook
    sign_guestbook();
} elsif ($action =~ /^view/i) {
    # View guestbook
    view_guestbook();
} else {
    print_form();
}

# End html
print end_html;

#######################################

sub print_form {
    print hr,
          start_form,
          '<STRONG>Name: </STRONG>',
          br,
          textfield(-name=>'name', -size=>50),
          br,
          '<STRONG>E-Mail: </STRONG>',
          br,
          textfield(-name=>'email', -size=>50),
          br,
          '<STRONG>Comments: </STRONG>',
          br,
          textarea(-name=>'comments', -rows=>10,
                   -columns=>50, -wrap=>1),
          br,
          submit(-name=>'action', -value=>'Sign Guestbook'),
          submit(-name=>'action', -value=>'View Guestbook'),
          reset,
          end_form;

}

sub sign_guestbook {
    my $time = localtime;
    my $name = param('name');
    my $email = param('email');
    my $comments = param('comments');

    # Check that name was entered
    if ($name eq '' or $name =~ /^\s+$/) {
        print_error('You must enter a name');
    }

    # Check lenghts of user input
    $name = substr($name, 0, $MAX_NAME);
    $email = substr($email, 0, $MAX_EMAIL);
    $comments = substr($comments, 0, $MAX_COMMENTS);

    # Remove leading/trailing white space
    $comments =~ s/^\s+//;
    $comments =~ s/\s+$//;

    # Escape HTML 
    $name = escapeHTML($name);
    $email = escapeHTML($email);
    $comments = escapeHTML($comments);

    # Deal with line breaks
    $comments =~ s/(?:\015\012?|\012)/<BR>/g;

    open(FILE, ">>$GUESTBOOK") or
      die "Can't open $GUESTBOOK: $!\n";
    flock(FILE, LOCK_EX); # Exclusive lock for writing

    print FILE $time, ':::', $name, ':::', $email, ':::', $comments, "\n";

    flock(FILE, LOCK_UN); # Unlock the file
    close FILE;

    # Check size of message file
    max_msgs();

    my $script = url();
    print hr,
          'Thank you for signing my guestbook',
          p,
          a({-href=>"${script}?action=view"},'View Guestbook');

}

sub view_guestbook {
    my $script = url();

    print a({-href=>$script}, 'Sign Guestbook'),
          hr;

    # Check size of message file
    max_msgs();

    # Read message file
    open(FILE, "$GUESTBOOK") or 
      die "Cannot open $GUESTBOOK: $!\n";
    flock(FILE, LOCK_SH); # Shared lock for reading

    my @messages = <FILE>;

    flock(FILE, LOCK_UN); # Unlock the file
    close (FILE);

    @messages = reverse (@messages);
    foreach my $item (@messages) {
        my($time, $name, $email, $comments) = split(':::', $item);

        # Format fields
        my $f_name = "<STRONG>$name</STRONG>";
        my $f_email = "<A HREF=mailto:$email>$email</A>";

        # Output a record
        print "$time - $f_name - $f_email",
              p(blockquote($comments)),
              hr;
    }

}

sub max_msgs {
    # If more than MAX_MSGS messages, delete oldest

    # Read message file
    open(FILE, "$GUESTBOOK") or 
      die "Cannot open $GUESTBOOK: $!\n";
    flock(FILE, LOCK_SH); # Shared lock for reading

    my @messages = <FILE>;

    flock(FILE, LOCK_UN); # Unlock the file
    close (FILE);


    if(@messages > $MAX_MSGS) {
        open(FILE, ">$GUESTBOOK") or 
          die "Cannot open $GUESTBOOK: $!\n";
        flock(FILE, LOCK_EX); # Exclusive lock for writing

        shift @messages while @messages > $MAX_MSGS;

        print FILE @messages;

        flock(FILE, LOCK_UN); # Unlock the file
        close FILE;
    }


}
    
sub print_error {
    my $error = shift;
    my $script = url();
    print hr,
          h2('Error'), 
          p($error),
          a({href=>$script}, 'Try Again'),
          end_html;
    die $error;
}



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

Date: Fri, 02 Mar 2007 12:46:19 +0100
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: Re: guestbook.cgi :p
Message-Id: <45e80e89$0$25915$ba4acef3@news.orange.fr>

john.swilting wrote:

> #!/usr/bin/perl -Tw
> use strict;
> use CGI qw/:standard escapeHTML/;
> use Fcntl qw/:flock/;
> $|++;
> 
> # Config
> my $GUESTBOOK = '/var/www/cgi-bin/guestbook.txt';
> my $TITLE = 'Guestbook';  # Title of guestbook
> my $MAX_MSGS = 5;         # Maximum number of messages displayed
> my $MAX_NAME = 50;        # Maximum length of name field
> my $MAX_EMAIL = 50;       # Maximum length of email field
> my $MAX_COMMENTS = 300;   # Maximum length of comments field
> # End Config
> 
> # Print header
> print header,
>       start_html(-title=>$TITLE, -bgcolor=>'white'),
>       h1($TITLE);
> 
> # Get action
> my $action = param('action');
> 
> # Check action
> if ($action =~ /^sign/i) {
>     # Sign guestbook
>     sign_guestbook();
> } elsif ($action =~ /^view/i) {
>     # View guestbook
>     view_guestbook();
> } else {
>     print_form();
> }
> 
> # End html
> print end_html;
> 
> #######################################
> 
> sub print_form {
>     print hr,
>           start_form,
>           '<STRONG>Name: </STRONG>',
>           br,
>           textfield(-name=>'name', -size=>50),
>           br,
>           '<STRONG>E-Mail: </STRONG>',
>           br,
>           textfield(-name=>'email', -size=>50),
>           br,
>           '<STRONG>Comments: </STRONG>',
>           br,
>           textarea(-name=>'comments', -rows=>10,
>                    -columns=>50, -wrap=>1),
>           br,
>           submit(-name=>'action', -value=>'Sign Guestbook'),
>           submit(-name=>'action', -value=>'View Guestbook'),
>           reset,
>           end_form;
> 
> }
> 
> sub sign_guestbook {
>     my $time = localtime;
>     my $name = param('name');
>     my $email = param('email');
>     my $comments = param('comments');
> 
>     # Check that name was entered
>     if ($name eq '' or $name =~ /^\s+$/) {
>         print_error('You must enter a name');
>     }
> 
>     # Check lenghts of user input
>     $name = substr($name, 0, $MAX_NAME);
>     $email = substr($email, 0, $MAX_EMAIL);
>     $comments = substr($comments, 0, $MAX_COMMENTS);
> 
>     # Remove leading/trailing white space
>     $comments =~ s/^\s+//;
>     $comments =~ s/\s+$//;
> 
>     # Escape HTML
>     $name = escapeHTML($name);
>     $email = escapeHTML($email);
>     $comments = escapeHTML($comments);
> 
>     # Deal with line breaks
>     $comments =~ s/(?:\015\012?|\012)/<BR>/g;
> 
>     open(FILE, ">>$GUESTBOOK") or
>       die "Can't open $GUESTBOOK: $!\n";
>     flock(FILE, LOCK_EX); # Exclusive lock for writing
> 
>     print FILE $time, ':::', $name, ':::', $email, ':::', $comments, "\n";
> 
>     flock(FILE, LOCK_UN); # Unlock the file
>     close FILE;
> 
>     # Check size of message file
>     max_msgs();
> 
>     my $script = url();
>     print hr,
>           'Thank you for signing my guestbook',
>           p,
>           a({-href=>"${script}?action=view"},'View Guestbook');
> 
> }
> 
> sub view_guestbook {
>     my $script = url();
> 
>     print a({-href=>$script}, 'Sign Guestbook'),
>           hr;
> 
>     # Check size of message file
>     max_msgs();
> 
>     # Read message file
>     open(FILE, "$GUESTBOOK") or
>       die "Cannot open $GUESTBOOK: $!\n";
>     flock(FILE, LOCK_SH); # Shared lock for reading
> 
>     my @messages = <FILE>;
> 
>     flock(FILE, LOCK_UN); # Unlock the file
>     close (FILE);
> 
>     @messages = reverse (@messages);
>     foreach my $item (@messages) {
>         my($time, $name, $email, $comments) = split(':::', $item);
> 
>         # Format fields
>         my $f_name = "<STRONG>$name</STRONG>";
>         my $f_email = "<A HREF=mailto:$email>$email</A>";
> 
>         # Output a record
>         print "$time - $f_name - $f_email",
>               p(blockquote($comments)),
>               hr;
>     }
> 
> }
> 
> sub max_msgs {
>     # If more than MAX_MSGS messages, delete oldest
> 
>     # Read message file
>     open(FILE, "$GUESTBOOK") or
>       die "Cannot open $GUESTBOOK: $!\n";
>     flock(FILE, LOCK_SH); # Shared lock for reading
> 
>     my @messages = <FILE>;
> 
>     flock(FILE, LOCK_UN); # Unlock the file
>     close (FILE);
> 
> 
>     if(@messages > $MAX_MSGS) {
>         open(FILE, ">$GUESTBOOK") or
>           die "Cannot open $GUESTBOOK: $!\n";
>         flock(FILE, LOCK_EX); # Exclusive lock for writing
> 
>         shift @messages while @messages > $MAX_MSGS;
> 
>         print FILE @messages;
> 
>         flock(FILE, LOCK_UN); # Unlock the file
>         close FILE;
>     }
> 
> 
> }
>     
> sub print_error {
>     my $error = shift;
>     my $script = url();
>     print hr,
>           h2('Error'),
>           p($error),
>           a({href=>$script}, 'Try Again'),
>           end_html;
>     die $error;
> }
I post. it is my code. you can say to me what you think that will make me
progress.


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

Date: 2 Mar 2007 05:38:13 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: how to find the "yesterday" logfile name?
Message-Id: <1172842693.462366.274040@30g2000cwc.googlegroups.com>

On Mar 2, 4:04 am, "robertchen...@gmail.com" <robertchen...@gmail.com>
wrote:
> see if my directory has many logfiles like this:
>
> log022607.log
> log022707.log
> log022807.log
> log030107.log
>
> today is 030207(03/02/07), I want to find the "yesterday" log, how
> could I do in perl?
> When time is 04/01/07, to get the "yesterday' log, which is
> log033107.log maybe need some special handle, also when process for
> year end...?

Either use one of the bazillion Date parsing/modifying modules
available on CPAN (for example, Date::Calc), or just calculate the
timestamp yourself, subtract 24*60*60, and get the new date:

#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
use POSIX qw/strftime/;
my $today = '040107';
my ($m, $d, $y) = $today =~ /(\d\d)(\d\d)(\d\d)/;
my $timestamp = timelocal(0,0,12,$d,$m-1,$y);
my $yesterday = $timestamp - 24*60*60;
my $newdate = strftime("%m%d%y", localtime($yesterday));
print "$newdate\n";
__END__


Paul Lalli



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

Date: Fri, 02 Mar 2007 10:53:55 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: how to find the "yesterday" logfile name?
Message-Id: <g69ejo77ib0.fsf@dhcp-65-162.kendall.corp.akamai.com>

On 2 Mar 2007 05:38:13 -0800 "Paul Lalli" <mritty@gmail.com> wrote: 

PL> On Mar 2, 4:04 am, "robertchen...@gmail.com" <robertchen...@gmail.com>
PL> wrote:
>> see if my directory has many logfiles like this:
>> 
>> log022607.log
>> log022707.log
>> log022807.log
>> log030107.log
>> 
>> today is 030207(03/02/07), I want to find the "yesterday" log, how
>> could I do in perl?
>> When time is 04/01/07, to get the "yesterday' log, which is
>> log033107.log maybe need some special handle, also when process for
>> year end...?

PL> Either use one of the bazillion Date parsing/modifying modules
PL> available on CPAN (for example, Date::Calc), or just calculate the
PL> timestamp yourself, subtract 24*60*60, and get the new date:

PL> #!/usr/bin/perl
PL> use strict;
PL> use warnings;
PL> use Time::Local;
PL> use POSIX qw/strftime/;
PL> my $today = '040107';
PL> my ($m, $d, $y) = $today =~ /(\d\d)(\d\d)(\d\d)/;
PL> my $timestamp = timelocal(0,0,12,$d,$m-1,$y);
PL> my $yesterday = $timestamp - 24*60*60;
PL> my $newdate = strftime("%m%d%y", localtime($yesterday));
PL> print "$newdate\n";
PL> __END__

To find the next-to-last log, you don't necessarily need to do date
arithmetic.  On the downside, this approach will be wrong when a log
is missing:

ls -t $dir | tail -2 | head -1

Another approach is to find the time period you want ('yesterday' is
usually defined as the period from midnight 1 day ago to midnight
tonight, excluding 00:00 tonight).  If any file creation times fall
within that time period (assuming the logs are produced during
"yesterday") you have a hit.

It all comes down to what you are looking for: the file *stamped*
yesterday in the file name (Paul's solution), or the file *produced*
yesterday (my second suggestion), or the next-to-last file (my first
suggestion).

My personal favorite solution to this and most other timestamp issues
is to use Unix timestamps, which don't have the annoying problem of
date arithmetic (and they are timezone-neutral, which is something you
should consider).  You then just need to pipe timestamps through a
simple filter like this (I call it t.pl and alias it to `t'):

#!/usr/bin/perl -p

use POSIX;

s/(\D?)(\d{10})(\D?)/$1 . strftime('%Y-%m-%d_%H:%M:%S', localtime($2)) . $3/e;

This will rewrite Unix timestamps as normal dates in your local
timezone.  So if you stamp your files like this, just do 'ls|t'

Ted


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

Date: Fri, 02 Mar 2007 17:00:02 +0100
From: Seansan <sean115=at@=reeve.nl>
Subject: Re: mod_perl error:  (120000) exit was called at
Message-Id: <45e84a18$0$95697$dbd4b001@news.wanadoo.nl>

Gunnar Hjalmarsson wrote:
> Seansan wrote:
>> I have just moved my server to an new hosting provider. Now I am 
>> seeing a lot of error messages in the server log related to "([error] 
>> ModPerl::Util::exit: (120000) exit was called at  ...". I have pasted 
>> the coded below that causes the error.
>>
>> The error is caused at the line "exit 1;". I have always used this 
>> code before, only now it causes an error. This code come from a PM 
>> module that I call from my main .PL file/program.
>>
>> How would I do this correctly so that ModPerl does not complain?
>>
>> <code>
>> sub PRINT_ERROR($) {
>>  my ($msg) = shift; $msg = 'Unknown error' if (!$msg);
>>  my $tmp=&READ_FILE($error_tmp);
>>  print $tmp;
>>  exit 1; # <== ERROR HERE
>> }
>> </code>
> 
> I'm using this function to prevent exit() issues in mod_perl:
> 
>   sub myexit {
>     if ($ENV{MOD_PERL}) {
>       if ($] < 5.006)    {
>         require Apache;
>         Apache::exit();
>       }
>     }
>     exit;
>   }
> 
> It may or may not address the issue you are experiencing.
> 


Thanks, I will try this. But I am also wondering what the correct way is 
that mod_perl expects

regards, Seansan


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

Date: 2 Mar 2007 07:20:15 -0800
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Perl and MySQL
Message-Id: <1172848814.400653.150530@8g2000cwh.googlegroups.com>

On Mar 2, 12:37 am, kra...@visto.com wrote:
> On Feb 28, 11:44 am, "Charles A. Landemaine" <landema...@gmail.com>
> wrote:
>
> > I have a MySQL table that is used to store comments on my blog. I just
> > found out it's filled with spam.
> > The table itself is 2 GB big, with
> > more than half a million spam backlinks.
>
> Since you have to check row by row, indexes aren't important. So, at 3
> am run this query:
>
> DELETE FROM myTable WHERE myColumn = '%<a href%';

ITYM "... WHERE myColumn LIKE '%<a href%';"

-jp




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

Date: Fri, 2 Mar 2007 07:15:08 -0600
From: Len Philpot <len@philpot.org>
Subject: Re: Q on regex of LWP::Simple data
Message-Id: <1o7yc9n7o7emm.1fbelphhn1hlx$.dlg@40tude.net>

On Fri, 02 Mar 2007 17:39:51 +1100, Iain Chalmers wrote:

> In article <epdxww5gfd0l.5psw3jcl6it4$.dlg@40tude.net>,
>  Len Philpot <len@philpot.org> wrote:
>> Or am I looking at this wrong? 
> 
> Yep. LWP::Simple::get doesn't return an array of lines no matter _how_ 
> much you want it too.
> 
> Either split the scalar you get into an array of lines yourself
> 
> @cachepage=split(/\n/,$scalar_version_ofOcachepage);
> 
> or throw the whole scalar at an appropriate regex.

That's what I thought about after posting.

 
> Unless the file you're getting is very well defined, the usual advice is 
> to parse html using an html parser. Regexs are not the right tool to 
> deal with arbitrary html (though your case might be far enough from 
> "arbitrary html" that regexs will work for you).

At this point, I'm very low on the Perl learning cliff (oh, for the
simplicity and clarity of C! :-), so I'll probably take an
incrementally-complex approach to parsing it. This whole exercise is for
my own use and edification, anyway.

Thanks.
-- 

 ---- Len Philpot -------- l e n @ p h i l p o t . o r g  (no spaces)
 ------- ><> ------------- http://pages.suddenlink.net/lenphilpot/


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

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:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#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 187
**************************************


home help back first fref pref prev next nref lref last post