[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

Easier way to split a string

Hi
I have got a date in the format "yyyymmdd".
I would like a one liner in PERL that can split the above string into $y,$m and $d.

For example,
if $year is "19810203", then i want a PERL one liner that can split this into 3 parts storing into 3 variables.
That is the 3 variables $y,$m and $d should have "1981","10" and "03" respectively.

Thanks
Vinodh
0
vinny_r78
Asked:
vinny_r78
  • 2
1 Solution
 
DeanHorakCommented:
($y, $m, $d) = (substr($teststr,0,4),substr($teststr,4,2),substr($teststr,6,2));
0
 
DeanHorakCommented:
Or in your example

 ($y, $m, $d) = (substr($year,0,4),substr($year,4,2),substr($year,6,2));
0
 
vinny_r78Author Commented:
Thanks DeanHorak.
It is working.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now