perl improve regex query
hi,
I want to get rid of the repetitive \s+(\d+) in my pattern.can any one suggest a better way of doing this.Thanks. Code:
#!/usr/bin/perl |
Code:
my @arr=$mem=~m/(?:MemTotal|MemFree|SwapTotal|SwapFree):\s+(\d+)/gxs; Cheers, Tink |
Thanks its works! i had to dig a bit to see what exactly you were doing as i am new to perl & regex
i wanted to clear few things,the reason for using ?: is not to save the matched pattern in the memory?So,if you dont use ?: i guess $1 should contain MemTotal,MemFree,SwapTotal,SwapFree. Is that right? i still find it little tricky how the patterning matching options are xs working,although i understand how g works in the above the example. Thanks again !! |
Quote:
Quote:
in-depth coverage have a look at "Mastering regular expressions" in your local library (or add it to your personal library) ... awesome book, w/ a strong focus on RegEx & perl (while it also covers aspects of RE's in other languages and a variety of regex engines). Cheers, Tink |
Cool.using only g works too.thanks
|
All times are GMT -5. The time now is 08:57 AM. |