Gossamer Forum
Home : General : Perl Programming :

How to convert a short javascript to perl

Quote Reply
How to convert a short javascript to perl
Hi,

I have this short javascript code:

date = '1.2.2002';
cc = (date.length) - 4;
year = (date.substr(cc,4));

It removes the text before the year and returns only the year. The string may be for example '12.12.2002' or 'January 2003' or only '2003'.

And I need it in perl. I have already this:

$julkpvm = $rec{'date'};
$cc = (length($julkpvm) - 4);

But the last part is missing, and I don't know how to do it...?

maco
Quote Reply
Re: [maco] How to convert a short javascript to perl In reply to
Code:
my ($year) = $julkpvm =~ /(\d{4})$/;

or:

Code:
my ($year) = substr($julkpvm, -4);

Last edited by:

Paul: Apr 16, 2003, 1:00 PM