Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

RE: RE: required explicit package error.

by nuance (Hermit)
on Jun 15, 2000 at 23:43 UTC ( #18376=note: print w/replies, xml ) Need Help??


in reply to RE: required explicit package error.
in thread required explicit package error.

You never actually print to anywhere, try opening another file for output. I've rewritten your example above, call this with

progname.pl datafile results

#!/usr/bin/perl -w use strict; my($in, $out, @rest) = @ARGV; open (INFILE, "<$in") or die "can't open $in $!"; open (OUTFILE,">$out") or die "can't open $out $!"; while (<INFILE>) { print OUTFILE "$1 $2\n" if /^total.*(\d+)\s+(\d+)\s*$/; } close INFILE; close OUTFILE;

Notice you can use the same regular expression to match the line and extract the data, also the regular expression is more general and will catch lines that aren't formatted exactly as you anticipated.

Update: I should probably explain the regular expression, just in case you aren't totally familiar with them. It matches any line that begins with total, has anything at all in the middle, but ends with tw0 numbers separated by whitespace. It also has optional whitespace at the end (spaces at the ends of lines can be a real pain). Note the use of + for items that definitely have to be there and * for things taht are optional.

Nuance

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2022-05-23 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?