passing "#" into subroutine

E

ela

I find $commenttag prints out nothing, what's the problem? I have to escape
pound....?


open( my $FPM, '<', "inputfile.txt");
$lineM = <$FPM>;

while (&Nextline($lineM, "#", "<Models>")) {
$lineM = <$FPM>;
}

sub Nextline {
my ($line, $commenttag, $pattern) = @_;
print "C:$commentag"; print $pattern;<STDIN>;

if ($line =~ /^$commenttag/) {
return 1;
}
if ($line =~ /$pattern/) {
return 0;
} else {
return 1;
}
}
 
T

Tad J McClellan

ela said:
I find $commenttag prints out nothing,


Your code does not attempt to output $commenttag.

Your code outputs $commentag.

If you had "use strict" turned on, then perl would have found this bug for you.

what's the problem?


You have not enabled warnings and strictures.

use warnings;
use strict;

This has been pointed out to you before.

You should start doing it.

I have to escape
pound....?


Did it start working when you escaped pound?

No?

Then that is not the problem.

open( my $FPM, '<', "inputfile.txt");


You should always, yes *always*, check the return value from open():

open my $FPM, '<', 'inputfile.txt'
or die "could not open 'inputfile.txt' $!';

while (&Nextline($lineM, "#", "<Models>")) {


You should not use ampersands on subroutine calls unless you know
what it means, and what it means is what you want. It seldom is.

my ($line, $commenttag, $pattern) = @_;
print "C:$commentag"; print $pattern;<STDIN>;


perl would have found the bug for you, if you had only asked it to.


Have you seen the Posting Guidelines that are posted here frequently?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,214
Messages
2,571,111
Members
47,703
Latest member
robert.marryson

Latest Threads

Top