in reply to Test RegEx
Here is where I got to before being completely lost.
#!/usr/bin/perl use strict; # turned on strict and warnings. use warnings; # a "#" in front makes them comments my $DFile="/home/infosec/data/RegEx"; open (DATAF, "<$DFile") || die ("Cannot open DATAF file \n"); # don't use DATA as a file handle, that is a reserved word for Perl. # no need to "eval" $regex foreach my $line (<DATAF>) { chomp $line; my ($tname, tvalu, $tfile, $regex) = split(/:/, $line); open (TFILE, "<$tname") || die ("Cannot open Test file $tname\n"); while (<TFILE>) { next unless /$regex/; print $_; # this is so obtuse that my brain hurts! # These super tricky Perl Special Variables like # $& $- $+ are EXTREMELY seldom needed. Get rid of them. # please explain what this is supposed to do.... # $- is a scalar, not an array, what do you intend by $-[0]? # # print "\t\t\$&: ", # substr( $_, $-[0], $+[0] - $-[0] ), # "\n"; # foreach my $i ( 1 .. $#- ) # { # print "\t\t\$$i: ", # substr( $_, $-[$i], $+[$i] - $-[$i] ), # "\n"; # } } print "\n"; } print "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Test RegEx
by AnomalousMonk (Archbishop) on Apr 22, 2010 at 23:11 UTC |