Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: sub-routines

by Chief of Chaos (Friar)
on Nov 28, 2002 at 12:37 UTC ( [id://216292]=note: print w/replies, xml ) Need Help??


in reply to sub-routines

Hi,
your are using $line too much.
For each individual scope you should add  my $line;.
#!/usr/local/bin/perl -w use strict; use warnings; open (INFILE, "<$ARGV[0]") or die "unable to open file"; open (OUTFILE, ">$ARGV[1]") or die "unable to open file"; while (<INFILE>) { my $line = $_; print OUTFILE replace($line); } sub replace { my $line = shift; chomp ($line); $line =~ s/data//; $line =~ s/=//; $line =~ s/detector//; return $line."\n"; } close(INFILE); close(OUTFILE);
Sorry, pasted the wrong statement.
Now it is correct.

Replies are listed 'Best First'.
Re: sub-routines
by Abigail-II (Bishop) on Nov 28, 2002 at 12:54 UTC
    Your code doesn't make any sense. You're manipulating all the lines of the input, and then you discard them. Also, your replace subroutine just returns the number of arguments passed.

    Abigail

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-24 06:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found