CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [omega] pattern matching (not expressions): Edit Log



omega
Novice

Dec 28, 2012, 6:09 PM


Views: 1589
Re: [omega] pattern matching (not expressions)

so after some tinkering i got it to a one line i need fixing...with your help ;)


Code
#!/usr/bin/perl 

use 5.010;
use warnings;

open DD, '<', 'file.txt';
while ( <DD> ) {
chomp;
if ( /(\w+)/ ) {
$pattern .= "_$1";
}
$matches{"$pattern"} = 1;
}
close DD;

open DDX, '<', 'file.txt';
while ( <DDX> ) {
chomp;
if ( /(\w+)/ ) {
$patternx .= "_$1";
}

foreach $m ( keys %matches ) {
$count = 1;
while ( $count > 0 ) {
if ( ( "$m" =~ /"$patternx"/ ) x $count ) { # expression thats failing
$count += 1;
} else {
$matched{"$m"} = $count;
$count = 0;
}
}
}
}
close DDX;

foreach ( sort keys %matched ) {
print "$matched{$_}: $_\n";
}

[\code]


(This post was edited by omega on Dec 28, 2012, 6:45 PM)


Edit Log:
Post edited by omega (Novice) on Dec 28, 2012, 6:45 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives