![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| regex question | xiamin | Shell Programming and Scripting | 3 | 03-05-2009 02:53 AM |
| Perl regex help - matching parentheses | cvp | Shell Programming and Scripting | 7 | 02-27-2009 05:38 PM |
| how do i strip this line using perl regex. | ramky79 | Shell Programming and Scripting | 1 | 03-18-2008 12:10 PM |
| regex question | arushunter | Shell Programming and Scripting | 8 | 01-04-2007 05:49 PM |
| regex question | rocketkids | UNIX for Dummies Questions & Answers | 6 | 02-12-2004 05:49 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Perl regex question
I have the following code: Code:
#!/usr/bin/perl -w
@files = <*.csv>;
foreach $file (@files) {
open(FH, $file) || die("Error: Cannot open file $file for reading.");
my @dt = ($file =~ /^(\w+).(\d{6})\.csv$/);
while (<FH>) {
print "@dt[0] $_\n";
}
close(FH);
}
There is redundancy in this code as it first checks for all files ending in ".csv" (line 3) and subsequently parses the filename (line 6) looking for characters and digits. How do I change line 3 into a regular expression, such that line 6 can be removed and the array @dt be determined there? |
| Bookmarks |
| Tags |
| perl, perl regex, regex |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|