Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2016-10-24 09:34 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (304 votes). Check out past polls.