Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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;


Comment on Re: Regular Expression
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://978627]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (13)
As of 2014-07-28 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (207 votes), past polls