extracting a chunk with regexp? 
Author Message
 extracting a chunk with regexp?

I'm a newbie perl user, and this has me stumped..  I'm trying to
grab a chunk from a string, using regexp.  In this case, I want
to get the load average on the server and stick it in a variable.

$_ = `uptime` ;
#if (/average: (.\...),/) {
if (/average: (*),/) {
        $loadnow = $1 ;

Quote:
}

The commented line compiles (though it's wrong for my purpose),
the active line does not (but I can't grok the error).  Neither
of them work :)

Any tips?

Much thanks..

--
_____________________________________________________________________________

World Wide Web information with ftp://ftp.netcom.com/pub/jesse/html/home.html



Tue, 07 Jan 1997 14:01:10 GMT  
 extracting a chunk with regexp?
Welcome to perl, Jesse!

Quote:

>I'm a newbie perl user, and this has me stumped..  I'm trying to
>grab a chunk from a string, using regexp.  In this case, I want
>to get the load average on the server and stick it in a variable.

>$_ = `uptime` ;
>#if (/average: (.\...),/) {
>if (/average: (*),/) {
>        $loadnow = $1 ;
>}

You're getting confused by the (slight) differences between shell
regular expression syntax and perl regular expression syntax.  What
you want is something more like:
    if (/average: (\S+),/) {    # get multiple non white space
or:
    if (/average: ([\d.]+),/) { # get multiple digit or period

Have fun!
--
Hal Wine



Tue, 07 Jan 1997 20:45:45 GMT  
 extracting a chunk with regexp?

Quote:

> paren-metacharacter. I suspect you wanted to use (.*) instead, but how
> should I tell you something, not knowing what your concern was?

Quite right, I wasn't clear enough, but that was what I needed anyway :)

I was confusing regexp * with shell *..

Thanks!
--
_____________________________________________________________________________

World Wide Web information with ftp://ftp.netcom.com/pub/jesse/html/home.html



Wed, 08 Jan 1997 02:58:05 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Advice on extracting chunks of HTML documents

2. Extracting strings from postscript in a single regexp?

3. How to extract the toplevel-domain of a domainame from a string with regexp

4. perl regexp to extract table out of HTML

5. Regexp: Extracting HTML img src

6. REGEXP question : Trying to extract title from HTML

7. beginner question regarding extracting email body with regexp

8. regexp - extract substrings

9. more regexp madness extracting data from files.

10. Parsing chunks of data with HTML::TreeBuilder

11. reading LWP in chunks

12. How to print out large chunks of html?

 

 
Powered by phpBB® Forum Software