slurp not working? ideas please!

G

Geoff Cox

Hello

Several hours of trying and I cannot see what is wrong with the code
below ... I am new to OOP so may have got some of that wrong?

The sub classroomnotes slurp is not finding the $curr, $next1, $next2,
$next3 values. I get error messages re "use of uninitialized value in
pattern match"

The basic idea is that a series of html files in the oldshort2 folder
is parsed and when an option value is found, the intro text is found
from the total-160404.txt file and the links to the full documents are
found from the allphp2.php file. These links are not being found.

Any ideas please?

Thanks

Geoff


package MyParser;
use base qw(HTML::parser);
use File::Find;

my $in_heading;
my $p;

my $dir = ("d:/a-keep9/short-nondb/oldshort2");

find sub {

my $name = $_;

open (OUT, ">>d:/a-keep9/short-nondb/short/members2/$name");

print OUT ("<html><head><title>test</title></head><body> \n");
print OUT ("<table width='100%' border='1'> \n");

sub start {

my ($self, $tagname, $attr, undef, $origtext) = @_;

if ($tagname eq 'h2') {
$in_heading = 1;
return;
}

if ($tagname eq 'p') {
$p = 1;
return;
}

if ($tagname eq 'option') {

choice($attr->{ value });

}

}

sub end {
my ($self, $tagname, $origtext) = @_;
if ($tagname eq 'h2') {
$in_heading = 0;
return;
}


if ($tagname eq 'p') {
$p = 0;
return;
}
}

sub text {
my ($self, $origtext) = @_;
print OUT ("<h2>$origtext</h2> \n") if $in_heading;
print OUT ("<p>$origtext</p> \n") if $p;

}

sub choice {
my ($path) = @_;

if ($path =~ /docs\/aslevel\/classroom-notes/) {
intro($path);
classroomnotes($path);
}

}

sub intro {

my ($pathhere) = @_;
open (INN, "d:/a-keep9/short-nondb/db/total-160404.txt");
my $lineintro;

while (defined ($lineintro = <INN>)) {
if ($lineintro =~ /$pathhere','(.*?)'\)\;/) {
print OUT ("<tr><td>$1 <p> </td>\n");
}
}
}



sub classroomnotes {

my ($pattern) = @_;

open (INNN, "d:/a-keep9/short-nondb/allphp/allphp2.php");

my $line = <INNN>;

while (<INNN>){
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
close (INNN);

if ($next3 =~ /\$i\<(\d+);/) {
my $nn = $1;
print OUT ("<td valign='top'> \n");
for ($c=1;$c<$nn;$c++) {
print OUT ('<a href="'. $pattern . "-doc" . $c . ".zip" . '">' .
"Document$c" . "</a><br>" . "\n");
}
print OUT ("</td></tr>\n");
}
}


print OUT ("</body></html> \n");

package main;
open (IN, $name);
undef $/;
my $html = <IN>;
my $parser = MyParser->new;
$parser->parse($html);

}, $dir;
 
A

Anno Siegel

Geoff Cox said:
Hello

Several hours of trying and I cannot see what is wrong with the code
below ... I am new to OOP so may have got some of that wrong?

The sub classroomnotes slurp is not finding the $curr, $next1, $next2,
$next3 values. I get error messages re "use of uninitialized value in
pattern match"

The basic idea is that a series of html files in the oldshort2 folder
is parsed and when an option value is found, the intro text is found
from the total-160404.txt file and the links to the full documents are
found from the allphp2.php file. These links are not being found.

Any ideas please?

Thanks

Geoff


package MyParser;
use base qw(HTML::parser);
use File::Find;

my $in_heading;
my $p;

my $dir = ("d:/a-keep9/short-nondb/oldshort2");

find sub {

my $name = $_;

open (OUT, ">>d:/a-keep9/short-nondb/short/members2/$name");

print OUT ("<html><head><title>test</title></head><body> \n");
print OUT ("<table width='100%' border='1'> \n");

sub start {

[rest of code snipped]

I don't know what else wrong, but defining other subs inside a "wanted"
routine for File::Find is certainly not something you want to do.

Anno
 
G

Geoff Cox

print OUT ("<table width='100%' border='1'> \n");

sub start {

[rest of code snipped]

I don't know what else wrong, but defining other subs inside a "wanted"
routine for File::Find is certainly not something you want to do.

Anno

thanks for your reply ... but which part of the OOP code, if any,
would go in the Fiel::Find sub?

Cheers

Geoff
 
G

Geoff Cox

[rest of code snipped]

I don't know what else wrong, but defining other subs inside a "wanted"
routine for File::Find is certainly not something you want to do.

Anno

have taken all the other sub parts out of the File::Find sub but still
get same error!?

Geoff
 
A

Anno Siegel

Geoff Cox said:
print OUT ("<table width='100%' border='1'> \n");

sub start {

[rest of code snipped]

I don't know what else wrong, but defining other subs inside a "wanted"
routine for File::Find is certainly not something you want to do.

Anno

thanks for your reply ... but which part of the OOP code, if any,
would go in the Fiel::Find sub?

I have no idea. Your code is too much of a mess to repair, so that
would amount to writing the program for you. This is something we
rarely do.

Anno
 
G

Geoff Cox

On 20 Apr 2004 11:24:01 GMT, (e-mail address removed)-berlin.de (Anno
Siegel) wrote:

..>> thanks for your reply ... but which part of the OOP code, if any,
I have no idea. Your code is too much of a mess to repair, so that
would amount to writing the program for you. This is something we
rarely do.

Anno,

hey! don't mind my feelings will you!!

I don't expect you to rewrite my code - just to point out, if you can,
why I am getting the particular error message, "use of uninitialized
value in pattern match at line (below)".

if ($next3 =~ /\$i\<(\d+);/) {

I am quite prepared to admit that the code is not very well written
but apart from this particular problem. it does work. I have left out
large parts of the code which do work ...


Cheers

Geoff
 
A

Anno Siegel

Geoff Cox said:
On 20 Apr 2004 11:24:01 GMT, (e-mail address removed)-berlin.de (Anno
Siegel) wrote:

.>> thanks for your reply ... but which part of the OOP code, if any,

Anno,

hey! don't mind my feelings will you!!

I don't expect you to rewrite my code - just to point out, if you can,

I can't. That's the whole point!
why I am getting the particular error message, "use of uninitialized
value in pattern match at line (below)".

if ($next3 =~ /\$i\<(\d+);/) {

I am quite prepared to admit that the code is not very well written
but apart from this particular problem. it does work. I have left out
large parts of the code which do work ...

Then show your code as it is now. A sub that defines (non-anonymous)
subs in its body is so much off kilter, it's impossible to guess what
it should and shouldn't do.

Anno
 
T

Tad McClellan

Geoff Cox said:
I get error messages re "use of uninitialized value in ^^^^^^^^^^^^^^^
pattern match"


That is *not* an "error message".

It is a "warning message".

There is a difference.

The basic idea is that a series of html files in the oldshort2 folder


File::Find is for recursive directory searching.

You don't need it if the files are all in the same directory.

open (OUT, ">>d:/a-keep9/short-nondb/short/members2/$name");


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

This has been pointed out to you before.

Do you actually read the followups to your posts?
 
G

Geoff Cox

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

This has been pointed out to you before.

Do you actually read the followups to your posts?

Tad,

I am not quite so bad as my post indicated! I do check for opened
files etc but have been moving arround so much trying to find out what
is wrong that this got missed out....The code below works for the file
indicated except that for some reason the slurp does not work

ie in the sub classroomnotes part ...

my $line = <INNN>;

while (<INNN>){
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
close (INNN);

if ($next3 =~ /\$i\<(\d+);/) {

etc - the last line giving the warning. Can you see why?!

Thanks

Geoff



package MyParser;
use base qw(HTML::parser);

my $in_heading;
my $p;

my $name = "as-left.htm";
open (OUT, ">>d:/a-keep9/short-nondb/short/members2/$name") ||
die "cannot open >>d:/a-keep9/short-nondb/short/members2/$name \n";

print OUT ("<html><head><title>test</title></head><body> \n");
print OUT ("<table width='100%' border='1'> \n");

sub start {

my ($self, $tagname, $attr, undef, $origtext) = @_;

if ($tagname eq 'h2') {
$in_heading = 1;
return;
}

if ($tagname eq 'p') {
$p = 1;
return;
}

if ($tagname eq 'option') {

choice($attr->{ value });
}

}

sub end {
my ($self, $tagname, $origtext) = @_;
if ($tagname eq 'h2') {
$in_heading = 0;
return;
}


if ($tagname eq 'p') {
$p = 0;
return;
}
}

sub text {
my ($self, $origtext) = @_;
print OUT ("<h2>$origtext</h2> \n") if $in_heading;
print OUT ("<p>$origtext</p> \n") if $p;

}

sub choice {
my ($path) = @_;

if ($path =~ /docs\/aslevel\/classroom-notes/) {
intro($path);
classroomnotes($path);
}

}

sub intro {

my ($pathhere) = @_;
open (INN, "d:/a-keep9/short-nondb/db/total-160404.txt") ||
die "cannot open d:/a-keep9/short-nondb/db/total-160404.txt \n";
my $lineintro;

while (defined ($lineintro = <INN>)) {
if ($lineintro =~ /$pathhere','(.*?)'\)\;/) {
print OUT ("<tr><td>$1 <p> </td>\n");
}
}
}



sub classroomnotes {

my ($pattern) = @_;

# print ("\$pattern has value $pattern \n");

open (INNN, "d:/a-keep9/short-nondb/allphp/allphp2.php") ||
die "cannot open d:/a-keep9/short-nondb/allphp/allphp2.php \n";

my $line = <INNN>;

while (<INNN>){
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
close (INNN);

if ($next3 =~ /\$i\<(\d+);/) {
my $nn = $1;
print OUT ("<td valign='top'> \n");
for ($c=1;$c<$nn;$c++) {
print OUT ('<a href="'. $pattern . "-doc" . $c . ".zip" . '">' .
"Document$c" . "</a><br>" . "\n");
}
print OUT ("</td></tr>\n");
}
}


package main;
open (IN, "d:/a-keep9/short-nondb/oldshort2/$name") ||
die "cannot open package main d:/a-keep9/short-nondb/oldshort2/$name
\n";
undef $/;
my $html = <IN>;
my $parser = MyParser->new;
$parser->parse($html);

print OUT ("</tr></table> \n");
print OUT ("</body></html> \n");
 
U

Uri Guttman

GC> I am not quite so bad as my post indicated! I do check for opened
GC> files etc but have been moving arround so much trying to find out
GC> what is wrong that this got missed out....The code below works for
GC> the file indicated except that for some reason the slurp does not
GC> work

your code does indicate your badness.

and this code does not slurp. that means reading the entire file in one
operation and you do a loop and you can even stop reading before the end
of the file.

GC> ie in the sub classroomnotes part ...

GC> my $line = <INNN>;

what happens to this line?

GC> while (<INNN>){
GC> last if /$pattern/;
GC> }
GC> my ($curr, $next1, $next2, $next3) = <INNN>;

that will read to the end of the file and not just the next four lines.

if you have less than 4 lines left, then some of those vars will be undef.

GC> if ($next3 =~ /\$i\<(\d+);/) {

GC> etc - the last line giving the warning. Can you see why?!

no, i can't see why because i can't see your data nor your intent. i can
say you have an undef value there.

and learn to properly indent your code. it is unreadable and i won't
apologise if your feelings are hurt. you post code here, you get
feedback here. programming is not for the overly sensitive.

uri
 
A

Ala Qumsieh

Geoff said:
my $line = <INNN>;

while (<INNN>){
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
close (INNN);

if ($next3 =~ /\$i\<(\d+);/) {

etc - the last line giving the warning. Can you see why?!

Because INNN doesn't have enough lines to be read?

--Ala
 
J

Joe Smith

Geoff said:
is wrong that this got missed out....The code below works for the file
indicated except that for some reason the slurp does not work

ie in the sub classroomnotes part ...

my $line = <INNN>;
while (<INNN>){
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
close (INNN);
if ($next3 =~ /\$i\<(\d+);/) {

etc - the last line giving the warning. Can you see why?!

Have you tried using print() statements for debugging?

my $pattern_line = "NOTHING MATCHED!!\n"
my $line = <INNN>;
while (<INNN>) {
$pattern_line = $_;
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
print "First line: $line";
print "Line with pattern or last line of file: $pattern_line";
print " curr=$curr next1=$next1 next2=$next2";
print " eof()=", eof() ? "true\n" : "false\n";
 
G

Geoff Cox

Then show your code as it is now. A sub that defines (non-anonymous)
subs in its body is so much off kilter, it's impossible to guess what
it should and shouldn't do.


Anno

the code as of now follows - I am confused re how the OOP fits in with
the File::Find ... but as I am using html files in the 1 folder have
removed the File::Find part .. but still get the warning re
uninitialized value in pattern match for the

if ($next3 =~ /\$i\<(\d+);/) {

in sub classroomnotes

any ideas why?

Cheers

Geoff

package MyParser;
use base qw(HTML::parser);

my $in_heading;
my $p;

my $name = "as-left.htm";
open (OUT, ">>d:/a-keep9/short-nondb/short/members2/$name") ||
die "cannot open >>d:/a-keep9/short-nondb/short/members2/$name \n";

print OUT ("<html><head><title>test</title></head><body> \n");
print OUT ("<table width='100%' border='1'> \n");

sub start {

my ($self, $tagname, $attr, undef, $origtext) = @_;

if ($tagname eq 'h2') {
$in_heading = 1;
return;
}

if ($tagname eq 'p') {
$p = 1;
return;
}

if ($tagname eq 'option') {

choice($attr->{ value });
}

}

sub end {
my ($self, $tagname, $origtext) = @_;
if ($tagname eq 'h2') {
$in_heading = 0;
return;
}


if ($tagname eq 'p') {
$p = 0;
return;
}
}

sub text {
my ($self, $origtext) = @_;
print OUT ("<h2>$origtext</h2> \n") if $in_heading;
print OUT ("<p>$origtext</p> \n") if $p;

}

sub choice {
my ($path) = @_;

if ($path =~ /docs\/aslevel\/classroom-notes/) {
intro($path);
classroomnotes($path);
}

}

sub intro {

my ($pathhere) = @_;
open (INN, "d:/a-keep9/short-nondb/db/total-160404.txt") ||
die "cannot open d:/a-keep9/short-nondb/db/total-160404.txt \n";
my $lineintro;

while (defined ($lineintro = <INN>)) {
if ($lineintro =~ /$pathhere','(.*?)'\)\;/) {
print OUT ("<tr><td>$1 <p> </td>\n");
}
}
}



sub classroomnotes {

my ($pattern) = @_;

# print ("\$pattern has value $pattern \n");

open (INNN, "d:/a-keep9/short-nondb/allphp/allphp2.php") ||
die "cannot open d:/a-keep9/short-nondb/allphp/allphp2.php \n";

my $line = <INNN>;

while (<INNN>){
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
close (INNN);

if ($next3 =~ /\$i\<(\d+);/) {
my $nn = $1;
print OUT ("<td valign='top'> \n");
for ($c=1;$c<$nn;$c++) {
print OUT ('<a href="'. $pattern . "-doc" . $c . ".zip" . '">' .
"Document$c" . "</a><br>" . "\n");
}
print OUT ("</td></tr>\n");
}
}


package main;
open (IN, "d:/a-keep9/short-nondb/oldshort2/$name") ||
die "cannot open package main d:/a-keep9/short-nondb/oldshort2/$name
\n";
undef $/;
my $html = <IN>;
my $parser = MyParser->new;
$parser->parse($html);

print OUT ("</tr></table> \n");
print OUT ("</body></html> \n");
 
G

Geoff Cox

Uri
GC> my $line = <INNN>;

what happens to this line?

my mistake - the above line should not be there.

The following code does work when in a separate script in which I
provide the path for the sub classroomnotes but is not working in the
script in the second section below

Geoff

--------------------------------------------------------

while (<INNN>) {
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
print ("$curr - $next1 - $next2 - $next3 \n");
close (INNN);

if ($next3 =~ /\$i\<(\d+);/) {
my $nn = $1;
print OUT ("<td valign='top'> \n");
for ($c=1;$c<$nn;$c++) {
print OUT ('<a href="'. $pattern . "-doc" . $c . ".zip" .
'">' . "Document$c" . "</a><br>" . "\n");
}
print OUT ("</td></tr>\n");
}

---------------------------------------------------------------------

package MyParser;
use base qw(HTML::parser);

my $in_heading;
my $p;

my $name = "as-left.htm";
open (OUT, ">>d:/a-keep9/short-nondb/short/members2/$name") ||
die "cannot open >>d:/a-keep9/short-nondb/short/members2/$name \n";

print OUT ("<html><head><title>test</title></head><body> \n");
print OUT ("<table width='100%' border='1'> \n");

sub start {

my ($self, $tagname, $attr, undef, $origtext) = @_;

if ($tagname eq 'h2') {
$in_heading = 1;
return;
}

if ($tagname eq 'p') {
$p = 1;
return;
}

if ($tagname eq 'option') {

choice($attr->{ value });
}

}

sub end {
my ($self, $tagname, $origtext) = @_;
if ($tagname eq 'h2') {
$in_heading = 0;
return;
}


if ($tagname eq 'p') {
$p = 0;
return;
}
}

sub text {
my ($self, $origtext) = @_;
print OUT ("<h2>$origtext</h2> \n") if $in_heading;
print OUT ("<p>$origtext</p> \n") if $p;

}

sub choice {
my ($path) = @_;

if ($path =~ /docs\/aslevel\/classroom-notes/) {
intro($path);
classroomnotes($path);
}

}

sub intro {

my ($pathhere) = @_;
open (INN, "d:/a-keep9/short-nondb/db/total-160404.txt") ||
die "cannot open d:/a-keep9/short-nondb/db/total-160404.txt \n";
my $lineintro;

while (defined ($lineintro = <INN>)) {
if ($lineintro =~ /$pathhere','(.*?)'\)\;/) {
print OUT ("<tr><td>$1 <p> </td>\n");
}
}
}



sub classroomnotes {

my ($pattern) = @_;

# print ("\$pattern has value $pattern \n");

open (INNN, "d:/a-keep9/short-nondb/allphp/allphp2.php") ||
die "cannot open d:/a-keep9/short-nondb/allphp/allphp2.php \n";

while (<INNN>){
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
close (INNN);

if ($next3 =~ /\$i\<(\d+);/) {
my $nn = $1;
print OUT ("<td valign='top'> \n");
for ($c=1;$c<$nn;$c++) {
print OUT ('<a href="'. $pattern . "-doc" . $c . ".zip" . '">' .
"Document$c" . "</a><br>" . "\n");
}
print OUT ("</td></tr>\n");
}
}


package main;
open (IN, "d:/a-keep9/short-nondb/oldshort2/$name") ||
die "cannot open package main d:/a-keep9/short-nondb/oldshort2/$name
\n";
undef $/;
my $html = <IN>;
my $parser = MyParser->new;
$parser->parse($html);

print OUT ("</tr></table> \n");
print OUT ("</body></html> \n");
 
G

Geoff Cox

Have you tried using print() statements for debugging?

my $pattern_line = "NOTHING MATCHED!!\n"
my $line = <INNN>;
while (<INNN>) {
$pattern_line = $_;
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
print "First line: $line";
print "Line with pattern or last line of file: $pattern_line";
print " curr=$curr next1=$next1 next2=$next2";
print " eof()=", eof() ? "true\n" : "false\n";


Joe

Yes, have tried some of the above but not the eof one !

Thanks

Geoff
 
G

Geoff Cox

On Tue, 20 Apr 2004 15:32:01 GMT, Geoff Cox

the following code works when on its own but when in the longer script
as a sub it does not!?

Geoff

my $pattern = "docs/aslevel/classroom-notes/finance/finance";

open (INNN, "d:/a-keep9/short-nondb/allphp/allphp2.php");
open (OUT, ">>d:/a-keep9/short-nondb/short/members2/test.htm");

while (<INNN>) {
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
close (INNN);

if ($next3 =~ /\$i\<(\d+);/) {
my $nn = $1;
print ("\$nn = $nn \n");
print OUT ("<td valign='top'> \n");
for ($c=1;$c<$nn;$c++) {
print OUT ('<a href="'. $pattern . "-doc" . $c . ".zip" .
'">' . "Document$c" . "</a><br>" . "\n");
}
print OUT ("</td></tr>\n");
}

----------------------------------------------------------------------------------

in the following context it does not work ...

package MyParser;
use base qw(HTML::parser);

my $in_heading;
my $p;

my $name = "as-left.htm";
open (OUT, ">>d:/a-keep9/short-nondb/short/members2/$name") ||
die "cannot open >>d:/a-keep9/short-nondb/short/members2/$name \n";

print OUT ("<html><head><title>test</title></head><body> \n");
print OUT ("<table width='100%' border='1'> \n");

sub start {

my ($self, $tagname, $attr, undef, $origtext) = @_;

if ($tagname eq 'h2') {
$in_heading = 1;
return;
}

if ($tagname eq 'p') {
$p = 1;
return;
}

if ($tagname eq 'option') {

choice($attr->{ value });
}

}

sub end {
my ($self, $tagname, $origtext) = @_;
if ($tagname eq 'h2') {
$in_heading = 0;
return;
}


if ($tagname eq 'p') {
$p = 0;
return;
}
}

sub text {
my ($self, $origtext) = @_;
print OUT ("<h2>$origtext</h2> \n") if $in_heading;
print OUT ("<p>$origtext</p> \n") if $p;

}

sub choice {
my ($path) = @_;

if ($path =~ /docs\/aslevel\/classroom-notes/) {
intro($path);
classroomnotes($path);
}

}

sub intro {

my ($pathhere) = @_;
open (INN, "d:/a-keep9/short-nondb/db/total-160404.txt") ||
die "cannot open d:/a-keep9/short-nondb/db/total-160404.txt \n";
my $lineintro;

while (defined ($lineintro = <INN>)) {
if ($lineintro =~ /$pathhere','(.*?)'\)\;/) {
print OUT ("<tr><td>$1 <p> </td>\n");
}
}
}

sub classroomnotes {

my ($pattern) = @_;

open (INNN, "d:/a-keep9/short-nondb/allphp/allphp2.php") ||
die "cannot open d:/a-keep9/short-nondb/allphp/allphp2.php \n";

while (<INNN>) {
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
close (INNN);

if ($next3 =~ /\$i\<(\d+);/) {
my $nn = $1;
print OUT ("<td valign='top'> \n");
for ($c=1;$c<$nn;$c++) {
print OUT ('<a href="'. $pattern . "-doc" . $c .
".zip" . '">' . "Document$c" . "</a><br>" . "\n");
}
print OUT ("</td></tr>\n");

}
}

package main;
open (IN, "d:/a-keep9/short-nondb/oldshort2/$name") ||
die "cannot open package main d:/a-keep9/short-nondb/oldshort2/$name
\n";
undef $/;
my $html = <IN>;
my $parser = MyParser->new;
$parser->parse($html);

print OUT ("</tr></table> \n");
print OUT ("</body></html> \n");
 
T

Tassilo v. Parseval

Also sprach Anno Siegel:
Then show your code as it is now. A sub that defines (non-anonymous)
subs in its body is so much off kilter, it's impossible to guess what
it should and shouldn't do.

Actually, the code doesn't define functions inside others. The indenting
merely suggests it does. :) The code is probably a bit better than it
looks on first sight (after all, it was in major parts written by me in
a previous thread;-).

To the OP: Please fix the indenting first (just as Uri has told you). As
it currently is, it is deliberately misleading its readers. Maybe this
will already help you to spot the problem yourself.

Tassilo
 
J

J. Gleixner

Geoff said:
On Tue, 20 Apr 2004 15:32:01 GMT, Geoff Cox

the following code works when on its own but when in the longer script
as a sub it does not!?


If you really want others to help, then please do what many have
suggested.. FORMAT YOUR FLIPPIN CODE! For guidelines see:

perldoc perlstyle

Print the value of $next3 before the following line

if ($next3 =~ /\$i\<(\d+);/)

so you/we can see its value. Obviously it's not what you think it is.
 
G

Geoff Cox

If you really want others to help, then please do what many have
suggested.. FORMAT YOUR FLIPPIN CODE! For guidelines see:

perldoc perlstyle

will check this..
Print the value of $next3 before the following line

if ($next3 =~ /\$i\<(\d+);/)

so you/we can see its value. Obviously it's not what you think it is.

I have done that and $next3 is empty ... but am not clear where to go
from there!?

Cheers

Geoff
 
J

J. Gleixner

Geoff said:
will check this..

Could also use "perltidy" which does a pretty good job.
I have done that and $next3 is empty ... but am not clear where to go
from there!?

$next3 is 'undef'ined.

What are the 4 lines of allphp2.php following the line with the
$pattern? Compare them to the values of $curr, $next1, $next2, and
$next3. Do they match?

Possibly, $pattern isn't found, and the "last" is never performed,
probably want a flag there.

my $found;
while (<INNN>) {
if (/$pattern/) { $found=1; last; }
}

return if !$found; # Or print some error message..
my ( $curr, $next1, $next2, $next3 ) = <INNN>;

Or possibly you're off by one line.

If $pattern is found, then the second <INNN> starts with the line after
the line with the match. Meaning, $curr would be the line after the
match. Guessing by the names of your variables, maybe you want:

my ($next1, $next2, $next3 ) = <INNN>;

Also, you don't need the ()'s for print.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top