Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: GMT to PST format

by Krambambuli (Curate)
on Jun 19, 2010 at 10:18 UTC ( [id://845524]=note: print w/replies, xml ) Need Help??


in reply to GMT to PST format

Using Date::Manip and ssuming your local time is PST, you could use something like
#!/usr/bin/perl use strict; use warnings; use Date::Manip; my $date_manip_object = new Date::Manip::Date; $date_manip_object->parse( '2 days ago' ); $date_manip_object->convert( 'GMT' ); my $gmt_ref = $date_manip_object->printf( '%Y%m%d') ; while (<DATA>) { my $err = $date_manip_object->parse_format('.*?\\[%d/%b/%Y:%T\s+%z +\\].*', $_); next if $err; # skip (?) lines that do not match the date format my $input_line_date = $date_manip_object->printf( '%Y%m%d') ; if ($input_line_date eq $gmt_ref) { print; } } __DATA__ 10.1.10.178 - - [15/Jun/2010:23:30:34 +0000] - 10.1.10.178 - - [16/Jun/2010:23:30:34 +0000] -

Replies are listed 'Best First'.
Re^2: GMT to PST format
by Anonymous Monk on Jun 20, 2010 at 07:08 UTC
    Unfortunately we don't have installed this module.
    Can't locate object method "new" via package "Date::Manip::Date" (perh +aps you forgot to load "Date::Manip::Date"?)
    I am getting the error as above. Please tell me is there any other way to do this.
        Not necessarily - it works as is here, Date::Manip::Date is brought in by Date::Manip.
      If you can, install Date::Manip from CPAN. Otherwise, try a solution with one of the modules you have installed, maybe DateTime.
        Date::Manip module is installed. But when I use the code
        #!/usr/bin/perl use strict; use warnings; use Date::Manip; my $date_manip_object = new Date::Manip; $date_manip_object->parse( '2 days ago' ); $date_manip_object->convert( 'GMT' ); my $gmt_ref = $date_manip_object->printf( '%Y%m%d') ; while (<DATA>) { my $err = $date_manip_object->parse_format('.*?\\[%d/%b/%Y:%T\s+%z +\\].*', $_); next if $err; # skip (?) lines that do not match the date format my $input_line_date = $date_manip_object->printf( '%Y%m%d') ; if ($input_line_date eq $gmt_ref) { print; } } __DATA__ 10.1.10.178 - - [15/Jun/2010:23:30:34 +0000] - 10.1.10.178 - - [16/Jun/2010:23:30:34 +0000] -
        Can't locate object method "new" via package "Date::Manip" at

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-24 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found