hello,
I stumbled on a weird regex thingie I can't explain.
use strict;
use File::Find;
my $path = "/somwhere/to";
find (sub {
return unless -f;# only files
&followup($File::Find::name);
}, $path);
sub followup {
my $contents = slurp($_[0]);
if ( $contents =~ /line3/g ) {
if ( $contents =~ /(line2-)(\w*)/g
print $2;
}
}
sub slurp {
local $/ = undef;
local *X;
open X, $_[0] or die "Can't open $_[0]: $!";
my $slurp = <X>;
close X or die "Can't close $_[0]: $!";
$slurp;
}
How the file looks like:
line1-11
line2-12
line3-13
And do u know what the $2 doesn't get printed...
Cos line 2 doesn't get found in me regex. Can someone explain this?
--
My opinions may have changed,
but not the fact that I am right
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.