Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Perl Newbie

by aitap (Deacon)
on Aug 24, 2012 at 17:44 UTC ( #989597=note: print w/ replies, xml ) Need Help??


in reply to Perl Newbie

my ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ) = stat($file); my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) + = localtime($mtime); # make a MySQL compatible date my $mysqlDate = strftime( "%F %T", $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst );
Try replacing this code with acquiring of the date you parsed from <data> tags ($j::date). You may need to parse and reformat the date, have a look at Date::Parse, localtime and strftime.
Sorry if my advice was wrong.


Comment on Re: Perl Newbie
Select or Download Code
Replies are listed 'Best First'.
Re^2: Perl Newbie
by zeroc00l (Initiate) on Aug 28, 2012 at 08:39 UTC
    Hi, thank you for the reply, but perhaps my question was malformed, I try to be more clear: With that script everything goes well except the return of the date inside the tag <date>...</date> I presume that the problem is in this subfunction I replicated from the subfunction that try to get the Title of the page:
    # this first bit is right out of the HTML::Parser perldoc sub title_handler { return if shift ne "title"; my $self = shift; $self->handler( text => sub { $j::title = shift }, "dtext" ); $self->handler( end => sub { shift->eof if shift eq "title"; }, "tagname,self" ); } sub date_handler { return if shift ne "date"; my $self = shift; $self->handler( text => sub { $j::date = shift }, "dtext" ); $self->handler( end => sub { shift->eof if shift eq "date"; }, "tagname,self" ); }
    And then when I call it:
    sub insertFile { my $file = shift; my $p = HTML::Parser->new( api_version => 3 ); $p->handler( start => \&title_handler, "tagname,self" ); $p->handler( start => \&date_handler, "tagname,self" ); $p->parse_file($file); .................
    If I delete the call to date, the Title subfunction goes well, but I lost the date, on the other side if I left everything as I modified, the date goes well but I lost the Title. I hope that now is more clear.....:)
      Try running your code in the debugger. Does the $j::date variable get assigned? Perhaps you need it to look like the old one (I mean, the same format, try Date::Parse and strftime("%F %T",str2time($j::date))).
      Sorry if my advice was wrong.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989597]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2015-07-28 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls