[Lhamo_rin], i dont know what you are really going to achieve, but as per your input and output, i assume, you can accomplish using regex as shown below.
$string = 'FileName.089-09_08_45';
$string =~ s/FileName\.(\d{2})\d/$1/;
print $string;
output:
08-09_08_45
Prasad
$string = 'FileName.089-09_08_45'; $string =~s#([a-z\.]+)([\d\-_]+)#$2#gsi; print $string;
Hi, Give some more information then only we will help you.
Anyway try this, if i understood your question correctly.
use strict; use warnings; my $string = "FileName.089-09_08_45"; $string =~ s/^[^\d]+//g; ##if Filename doesn't contain digits #or $string =~ s/^[^\.]+\.//g; ##if Filename doesn't contain dots print $string; __END__ 089-09_08_45
Regards,
Velusamy R.
$string =~ s/^FileName\.//;
would do the trick.
Cheers,
JohnGG
If your file names are consistently like your example, use split :
use strict;
use warnings;
opendir( DIR, "/home/Lhamo/files" ) or die "painfully: $!";
my @files = readdir DIR;
closedir DIR;
for ( @files ) {
next if ( $_ eq '..' );
next if ( $_ eq '.' );
my ( $filename, $code_number ) = split( /./, $_, 2 );
print "$code_number\n";
}
I made a mistake. I don't know where, but I always do. I haven't tested this code. Someone will point it out shortly :) In any case, you get the idea.
-- -- GhodModeBlessed is he who has found his work; let him ask no other blessedness.
my ($filename, $code_number) = split(/\./, $_, 2);
so that you are splitting on a literal full-stop.
Also, your
next if ( $_ eq '..' );
next if ( $_ eq '.' );
can be more neatly achieved by
next if /^\.\.?$/;
Cheers,
JohnGG
perlmonks.org content © perlmonks.org and GhodMode, johngg, Lhamo_rin, perlsen, prasadbabu, Samy_rio
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03