1820299 Members
2975 Online
109622 Solutions
New Discussion

Perl question

 
Jeff Picton
Regular Advisor

Perl question

Hi all

I have the following file to be processed :-

jube99_04070806

I need to process the file for pattern recognition so that I am left with the following :-

jube99_........

i.e substitute everything after the _ with dots. The dots should be substituted as a partial string with th ~= notation.

I just cannot seem to be able to get the right substitution.

Thanks for any help

Jeff


1 REPLY 1
R. Allan Hicks
Trusted Contributor

Re: Perl question

I'm not sure what you mean by the following file ot be processed?

#!/bin/contrib/bin/perl -w
{

$foo = "jube_04070806";
$foo = s/jube_.*/jube_......../;
print "$foo \n"l
}

Produces

jube_......

Or do you mean you want to read a directory and process all files like

jube_05070806
jube_04070808
.
.
.


Then you might

#!/usr/contrib/bin/perl -w
{
opendir (DIRECTORY,$myDirectory) or
die "cannot open $myDirectory;

@myFiles = readdir(DIRECTORY);

foreach $file(@myFiles){

## You might want to anchor to the first
## position with the ^ so that you get
## jube_stuff and not stuff_jube_morestuff


if ($file =~ /^jube_.*/) {
############################################
# Your File Processing Logic Here ############################################
}

}

closedir DIRECTORY;
}

-Good Luck
"Only he who attempts the absurd is capable of achieving the impossible