如何使用perl将输入数字032817103305转换为格式03/28/17 10 33 05?

时间:2017-03-28 14:35:10

标签: perl

我正在尝试转换12位数字,例如032817103305使用Perl?格式03/28/17 10 33 05

2 个答案:

答案 0 :(得分:2)

 $ python threaded_ws.py 
Opened client at ws://172.17.0.2:8081/events
{"Enable":true,"OwnerId":1,"OwnerName":"ASICD","EventName":"PortOperStateDown","Description":"Port Operational State DOWN Event","SrcObjName":"Port","EvtId":2,"TimeStamp":"2017-03-28T14:38:32.881456505Z","SrcObjKey":{"IntfRef":"eth25"},"AdditionalData":null}
Client=False, server=False
258



{"Enable":true,"OwnerId":1,"OwnerName":"ASICD","EventName":"VlanOperStateDown","Description":"Vlan Operational State DOWN Event","SrcObjName":"Vlan","EvtId":4,"TimeStamp":"2017-03-28T14:38:32.882046191Z","SrcObjKey":{"VlanId":3050},"AdditionalData":null}
Client=False, server=False
254



{"Enable":true,"OwnerId":1,"OwnerName":"ASICD","EventName":"IPv4IntfOperStateDown","Description":"IPv4 Interface Operational State DOWN Event","SrcObjName":"IPv4Intf","EvtId":6,"TimeStamp":"2017-03-28T14:38:32.883912357Z","SrcObjKey":{"IntfRef":"eth25"},"AdditionalData":null}
Client=False, server=False
276
Send close signal



{"Enable":true,"OwnerId":1,"OwnerName":"ASICD","EventName":"PortOperStateUp","Description":"Port Operational State UP Event","SrcObjName":"Port","EvtId":1,"TimeStamp":"2017-03-28T14:38:33.38139292Z","SrcObjKey":{"IntfRef":"eth25"},"AdditionalData":null}
Client=True, server=True
253



{"Enable":true,"OwnerId":1,"OwnerName":"ASICD","EventName":"VlanOperStateUp","Description":"Vlan Operational State UP Event","SrcObjName":"Vlan","EvtId":3,"TimeStamp":"2017-03-28T14:38:33.382071856Z","SrcObjKey":{"VlanId":3050},"AdditionalData":null}
Client=True, server=True
250



{"Enable":true,"OwnerId":1,"OwnerName":"ASICD","EventName":"IPv4IntfOperStateUp","Description":"IPv4 Interface Operational State UP Event","SrcObjName":"IPv4Intf","EvtId":5,"TimeStamp":"2017-03-28T14:38:33.382852609Z","SrcObjKey":{"IntfRef":"eth25"},"AdditionalData":null}
Client=True, server=True
272
Send close signal

答案 1 :(得分:0)

正则表达式替换对于重新格式化数字更好,但如果您想要使用单个字段的其他内容(例如,插入数据库等),unpack也可以派上用场:

my $record = '032817103305';
my ($month, $day, $year, $hr, $min, $sec) = unpack 'A2' x 6, $record;