in reply to RE: Re: required explicit package error.
in thread required explicit package error.
There are probably 3 things in this script that are non-intuitive to the budding Perl programmer :#!/usr/local/bin/perl print "Input file name: "; $_ = <>; chop; open(INFILE, $_); while (<INFILE>) { if (m/total/) { s/^total\s[0-9]+\s[0-9]+\s([0-9]+)\s([0-9]+)$/$1 $2/; print; } } close INFILE;
all it does is replace "^total\sA\sB\sC\sD$" with "C D" where ^ (caret) matches start of line, \s matches space, and A B C and D are numbers (1 or more digits). The use of the parenthesis following the first / provides Perl's regular expression engine the ability to do what is called "backreferencing" (using $1 and $2 after the second /).s/^total\s[0-9]+\s[0-9]+\s([0-9]+)\s([0-9]+)$/$1 $2/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: RE: Re: required explicit package error.
by Anonymous Monk on Jun 15, 2000 at 21:16 UTC | |
|
RE: required explicit package error.
by Paav (Novice) on Jun 15, 2000 at 21:20 UTC | |
by nuance (Hermit) on Jun 15, 2000 at 23:43 UTC | |
|
i can input a file, but not parse it
by Paav (Novice) on Jun 15, 2000 at 21:29 UTC |