Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Regular Expression

by moritz (Cardinal)
on Jun 27, 2012 at 11:52 UTC ( #978627=note: print w/replies, xml ) Need Help??

in reply to Regular Expression

I cannot reproduce your problem here. On my machine I ran this code:

use strict; use warnings; my $line = 'Width = 32'; if($line =~ m/^Width[\s]*\=[\s]*(\d+)$/) # to match Width { print "Width found: $1\n" } elsif ($line =~ m/^Descr[\s]*-[\s]*[\w]+$/) # to match Descr { print 'Descr found' } else { printf "Garbage found: \"%s\" \n",$line; }

And it prints out Width found: 32

If it doesn't match for you, maybe $line contains some non-printable characters (maybe because the file is stored in UTF-16?)

To find out, you can use something like

use Data::Dumper; $Data::Dumper::Useqq = 1; print Dumper $line;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978627]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-03-20 20:10 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (259 votes). Check out past polls.