On Sat, 20 Feb 1999, Raider wrote:

 #      I plann to make a script which will give me a report about my ppp
 # connection and about mail trafic.  I think I can do that with the usual
 # *nix tools.  But I see this as an excelent idea to learn perl.  I have the
 # HTML perl documentation for 5.005 (I have perl 5.003).  But it seems I
 # need some interctive help as well.
 #      Could someone tell me hwo this script line:
 # y=`grep "some string" file | tail -n 1 | cut -b5-10`

In perl? Without using external commands? Hmm, I would probably do
something like this:

        #!/usr/bin/perl

        $y=substr((grep /some string/,<>)[$#_],5,10);

or from the command line

        cat file | perl -e 'print substr((grep /some string/,<>)[$#_],5,10)'


But a clearer example would probably be something like:

        #!/usr/bin/perl
        #   - just remember the last match

        open IN,"< infile" || die $!;
        while (<IN>) {
                $y=substr $_,5,10 if /some string/;
        }
        close IN;

        print $y;

or even

        #!/usr/bin/perl
        #   - store all the matches and pick out the last one
        #     $#matched is the last element that exists in @matched

        open IN,"< infile" || die $!;
        @matched=grep /some string/,<IN>;
        close IN;

        print substr $matched[$#matched],5,10;




 #      BTW: Can you tell me if there is some perl-newbie list?  I have
 # only mail so it's pretty hard to search (so far no result).

Not that I'm aware of. But I'm always happy to help with a perl newbie.

 # 
 #      Raider
 # --
 #              ``Liberate tu-temet ex inferis''
 # 


G'day!
--                                             n i c h o l a s  j  l e o n
elegance through simplicity*http://mrnick.binary9.net*[EMAIL PROTECTED]
good fortune through truth*roaming:[EMAIL PROTECTED]*ICQ#2170994*U+($++)
TRA#6805*not all questions have answers*pseudogeek:P+++($++)L+($++)W=lm@b9
trust no-one with an iq under 150*understand yourself before trying others

Reply via email to