[pm-h] Eclipse Perl module

G. Wade Johnson gwadej at anomaly.org
Thu Sep 15 05:26:15 PDT 2005


On Wed, 14 Sep 2005 22:50:29 -0500
Vijay Choubey <vijay.choubey at gmail.com> wrote:

> wade,
> 
> as per tuesday nights discussion, here is something I thought about but now 
> sure how to implement it
> 
> Say I have a file and the first line contains this
> aaaaa,05/09/14.gdgdgd,dsdsd,05/09/11,gdgdgdg,/05/09/10
> 
> I have a argument thats is a string like this "YY/MM/DD'
> 
> what i really want is i shd be able to leave the "/" (or - or | whatever it 
> may be ) in this format as it is and change the YY DD MM to \d\d format so 
> that it looks like this \d\d/\d\d/\d\d

TMTOWTDI.
# Given this
$fmt = "YY/MM/DD";

# Pick one of...

# This forces the year, month, and day to be in this position
$fmt =~ s/^YY(.)MM(.)DD/\\d\\d$1\\d\\d$2\\d\\d/;

# This would fail if the delimiter is '_'.
$fmt =~ s/^\w+(.)\w+(.)\w+/\\d\\d$1\\d\\d$2\\d\\d/;

# This only matches those patterns
$fmt =~ s/(YY|MM|DD)/\\d\\d/g;

> and thn search for this pattern in the first line of the file at the 2nd 
> position and change it.

Do you want to search the line?

# Might catch a date embedded in a field.
if($line =~ s/($fmt)/reformat_date( $1 )/e)
{
    # substitute was successful.
}


or split the line and match the second column

# Requires that you know the delimiter
my @fields = split( /,/, $line );

if($fields[1] =~ s/^($fmt)$/reformat_date( $1 )/e)
{
    # substitute was successful.
}

$line = join( ',', @fields );

or something else?

> can you tell me how I can achieve this.

It's possible.

G. Wade
-- 
That's what I love about GUIs: They make simple tasks easier, and complex
tasks impossible.
           -- John William Chambless, <39v25i$2rbc at whale.st.usm.edu>


More information about the Houston mailing list