Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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]
erix the sun never sets on the CB

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2017-04-24 12:32 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (439 votes). Check out past polls.