473,327 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How to comapre the file name in perl ???

hi all,

i am reading the content of the directory & then putting if condition to comapre the file name.

problem is: filename ends with number.
eg :prstat-Lvs-20080118-2100

the first part of the file name is constant but the later part (20080118-2100) is not constant

Expand|Select|Wrap|Line Numbers
  1. my $dir = "C:\\Performance_svap\\INPUT_FILES\\*";
  2. my @file=glob("$dir");
  3. my $f;
  4. my @prstat_Lvs;
  5.  
  6. foreach $f (@file){
  7.     if ($f =~ /prstat-Lvs/){
  8.             push (@prstat_Lvs,$f);
  9. }
  10.  
now my question is how to compare the full file name in if condition ???
do i need to give like this :
Expand|Select|Wrap|Line Numbers
  1. if($f =~/prstat-Lvs-[0..9]-[0..9]/){
  2.  
can anyone help me out ???

Regards,
Vijayarl
Sep 30 '08 #1
6 2303
nithinpes
410 Expert 256MB
If the number of digits/pattern(20080118-2100) remains same, you can use:
Expand|Select|Wrap|Line Numbers
  1. if($f =~/prstat-Lvs-[0..9]{8}-[0..9]{4}/){ 
  2.  
Inside curly brace, you will be specifying the number of occurence. You can even give a range. e.g.
\d{2,8} - minimum 2 digits and a max. of 8
Sep 30 '08 #2
Thanks Nithinpes !!!!!!

This what exaclty i want !!!! :-)
Oct 1 '08 #3
you can try this way also
Expand|Select|Wrap|Line Numbers
  1. if ($f =~ /^prstat-Lvs/){
  2.              push (@prstat_Lvs,$f);
  3.  }
  4.  
Oct 1 '08 #4
KevinADC
4,059 Expert 2GB
does this work?

Expand|Select|Wrap|Line Numbers
  1. if($f =~/prstat-Lvs-[0..9]{8}-[0..9]{4}/){ 
I would think the character classes need to be written like this:

[0-9] instead of [0..9]

that is literally a dot in a character class, not a range operator.
Oct 1 '08 #5
nithinpes
410 Expert 256MB
does this work?

Expand|Select|Wrap|Line Numbers
  1. if($f =~/prstat-Lvs-[0..9]{8}-[0..9]{4}/){ 
I would think the character classes need to be written like this:

[0-9] instead of [0..9]

that is literally a dot in a character class, not a range operator.
Yes, that's right Kevin.I posted it in a hurry. Range operator does not work inside character class. I wonder how it worked for the OP!
Oct 3 '08 #6
KevinADC
4,059 Expert 2GB
I wonder how it worked for the OP!
Not too well I suspect. ;)
Oct 3 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Xah Lee | last post by:
Just bumped into another irresponsibility in perl. the crime in question this time is the module File::Basename. Reproduction: 1. create a directory containing a file of this name:...
3
by: Xah Lee | last post by:
Split File Fullpath Into Parts Xah Lee, 20051016 Often, we are given a file fullpath and we need to split it into the directory name and file name. The file name is often split into a core...
0
by: Eric Li | last post by:
Hi, I used to have a web page with "<input type="file" name="FileName" size=20> field to upload file to one of my Perl program in the server side. Now I would like to use C# program to upload...
1
by: DavidA | last post by:
I have a very simple form and perl script that is to upload a jpg file. I am not familiar with the perl language but copied the code from a text book. It works fine with all browsers except IE....
2
by: Lastknight | last post by:
hi all, i have seen a program from web that is used to upload a file from particular directory.. My problem is that they have mentioned some file directory name in the program but when i am running...
4
by: rsaharia | last post by:
Hello All, I need help with this particular .pl file I picked up from http://www.veritools-usa.com/xnf2vhdl.htm What it's supposed to do is really convert an xnf file to a vhdl file. I need it for...
3
rajiv07
by: rajiv07 | last post by:
Hi to all, I have a script to list the file names in a directory .When i run this script locally (command prompt) it displays the exact file name (even though the file name has two spaces).But i...
4
viktorijakup
by: viktorijakup | last post by:
Hi !!! @rem = '--*-Perl-*-- @echo off if "%OS%" == "Windows_NT" goto WinNT perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 goto endofperl :WinNT perl -x -S %0 %* if NOT "%COMSPEC%" ==...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.