in reply to Robocopy log parsing

I feel like I'm almost there:

use warnings; use strict; my $filename = $ARGV[0]; open(INFILE, "<", $filename) or die "Cannot open $ARGV[0]"; my(@fcont) = <INFILE>; $dir =~ m/[a-z]:\\.*?\n/g; foreach $line (@fcont) { if ($line =~ m/(New File|New Dir)\s+([0-9]+|[0-9].[0-9]\s[a-z]?)\s ++(.*?\n)/g) { print join("|",$ARGV[0],$1,$dir,$2,$3); } } close( INFILE );

but of course it tells me $line and $dir requires explict package name. What am I mising? This will pull out all entries that are New Dir or New File, but I was hoping to bring down my New Dir match so that each New File had its correpondinf directory

Replies are listed 'Best First'.
Re^2: Robocopy log parsing
by choroba (Cardinal) on May 28, 2012 at 15:26 UTC
    What am I mising?
    You are missing my before $line after foreach. You should also declare $dir, but I do not see where this variable gets its value.

      I wanted $dir to get its value from extracting text from the New Dir entry. For each new Dir there will be a x:\....\ string of text to denote a folder path, which for each line where there is New Dir match it assigns the value found to $dir, then for each corresponding line the print join prints the $dir value. Well that was the idea in theory. If I remove the $dir from the print join statement, it works. Ok so $line fixed. but still having probs with $dir. Does the $dir =~ not declare it as an assignment?

        No, assignment operator is =, =~ is a pattern match operator. See perlop.

        Still does not work. can't extract text from a line based on a regexp. It does not get assigned to $dir. What do I need to do to re-write so that for each New File there is a corresponding folder path?