Perl, regex, extract data from a line

Posted by perlnoob on Stack Overflow See other posts from Stack Overflow or by perlnoob
Published on 2010-04-09T16:13:20Z Indexed on 2010/04/09 17:03 UTC
Read the original article Hit count: 340

Filed under:
|
|

Im trying to extract part of a line with perl

use strict; 
use warnings;


# Set path for my.txt and extract datadir
my @myfile = "C:\backups\MySQL\my.txt";
my @datadir = "";

open READMYFILE, @myfile or die "Error, my.txt not found.\n";
    while (<READMYFILE>) {
        # Read file and extract DataDir path
        if (/C:\backups/gi) {
        push @datadir, $_;
        }
    }

# ensure the path was found
print @datadir . " \n";

Basically at first im trying to set the location of the my.txt file. Next im trying to read it and pull part of the line with regex. The error Im getting is:

Unrecognized escape \m passed through at 1130.pl line 17.

I took a look at http://stackoverflow.com/questions/1040657/how-can-i-grab-multiple-lines-after-a-matching-line-in-perl to get an idea of how to read a file and match a line within it, however im not 100% sure I'm doing this right or in the best way. I also seem to produce the error:

Error, my.txt not found.

But the file does exist in the folder C:\backups\MySQL\

© Stack Overflow or respective owner

Related posts about perl

Related posts about regex