perl subroutine (SEC: UNCLASSIFIED)

Lisman, FLGOFF Jarrad Jarrad.Lisman at
Thu Sep 26 09:00:12 EST 2002

Thanks for you suggestion.

I solved it by using a call to the subroutine like so;

	$line = &subroutine($line)

and in my subroutine I had to reference my variable as $_[0] not $_



-----Original Message-----
From: Michael James [mailto:michael at]
Sent: Thursday, 26 September 2002 1:02
To: Lisman, FLGOFF Jarrad
Subject: Re: perl subroutine (SEC: UNCLASSIFIED)

Dear Jarrad,

Here's a quick rewrite of your code:

open(OUT, "> newfile");
open(IN, "< filename");		# I re-use a lot of code and "IN" is nice
and generic
while(<IN>)			# a line is now in $_
	chomp;		# works on $_ by default
	$newline = subroutine($_);	# need to pick up the returned value
					# trailing() mark it as a subroutine

	print OUT $newline, "\n";

sub subroutine
{	my($line) = shift;	# pull the line off the parameter list

	$line =~ s/oldstring/newstring/;	# transform it
	# Note: if the target string is best identified by character
	#   then you were right to use substr()


Note that all the above is also achieved by

perl -e's/oldstring/newstring/'

The Perl Cookbook (O'Reilly) is so good
 the question is not whether you need one copy
 but whether you need a second for bedtime reading.

A right not exercised is a privilege
a privilege not exercised is illegal.

Michael James			michael at
8 Brennan St			Phone: +61 2 6247 2556
Hackett, ACT 2602		Mobile: +61 4 1747 4065
AUSTRALIA			Fax: +61 2 6278 0011

More information about the linux mailing list