Tuesday, December 14, 2010

Values “extraction” in Perl

To extract values from a variable.

Say,


$var = “10WW51”;
($yy,$ww) = ($var =~ /(\d\d)WW(\d\d)/);


You’ll have $yy = 10, and $ww = 51.

For this example, you can use split function, but for more complicated pattern, say,


$var = “This WW data is from 10WW51.”;


You’ll have a more complex way to extract the year and week information if you are using split function.

No comments:

Post a Comment