Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No output after reading text file.........hummm

Status
Not open for further replies.

quan

Programmer
Oct 3, 2001
58
US
It's totally odd. I am building a database. Here is the code...

#!/usr/bin/perl

require "../library/one.lib"; #pulls perl library
require "../library/html.lib"; #pulls perl library
&mime; #lets browser know its html output
&parse;
$user = $ENV{'QUERY_STRING'}; #GET USERS LOGIN


$item = $formdata {'item'}; #pull data from form

#SPLIT ITEMS IN ARRAY OF DESIRED ITEMS TO BE DELETED
@delete = split(/,/, $item); #INDIVIDUAL ITEMS ACCESSIBLE WITH DUMMY VARIABLE
$numitems = @delete; #STORE NUMBER OF ITEMS TO BE DELETED

#RETRIEVE DATA IN ITEMSLOG AND SINGLE OUT ITEM FOR COMPARISION
open (MASS, &quot;<../../$user/items/items.log&quot;) || &errormes; #READ CONTENTS OF MEMBERS ITEMS
flock (MASS, 2); #CREATE EXCLUSIVE ACCESS
@original = <MASS>; #DUMP ALL ITEMS TO ARRAY
flock (MASS, 8); #RELEASE EXCLUSIVE ACCESS
close (MASS); CLOSE FILE

#SPLIT ORIGINAL ARRAY TO SEPARATE ITEMS
$orig = @original[0]; #DUMP CONTENTS OR ARRAY TO SCALOR TO SPLIT
@compare = split(/:/, $orig); #INDIVIDUAL ITEMS ACCESSIBLE WITH DUMMY VARIABLE
$numitems2 = @compare; #STORE NUMBER OF ITEMS TO VARIABLE

print &quot;hello&quot;;


For some odd reason, File opens fine and is read, but hello doesn't print. If I remove the code that opens the file, hello prints fine. This is part of a routine that is going to delete items from a comma delimited text file, it's odd, I am decently familiar with perl, I just run into this output problem sometimes when I open a file. What causes this? Thanks
 
I can't say that I understand why &quot;hello&quot; isn't being printed. Shouldn't have anything to do with opening the file for input. Are you running this script from the command line?

Try putting in more print's - are you sure execution is progressing all the way until the end of the script?
Hardy Merrill
Mission Critical Linux, Inc.
 
I am trying to read the file contents, not write to them. I have tried additional print statements.
 
Explorer says done in bottom right corner and screen is blank
 
Doing some code busting, seems that if I remove the second split

ITEMS
$orig = @original[0]; #DUMP CONTENTS OR ARRAY TO SCALOR TO SPLIT
@compare = split(/:/, $orig); #INDIVIDUAL ITEMS ACCESSIBLE WITH DUMMY VARIABLE

I get my print output, now to figure out why this is hanging on this statement
 
Have you tried running this under the -w switch or even add the line;

use diagnostics -verbose;

The line -

$orig = @original[0];

doesn't make sense since @original[0] will be a scalar i.e. $original[0] - from the file reading operation, each line that goes into @original will be a scalar - not an array. I suspect this is causing the problem.

If your programme starts

#!/usr/bin/perl -w
use strict;

you'll pick things like this up.

 
The way I have it set up is the I have 2 lists items double delimited.

monkey,cow,dog,cat:house,dog,monkey:

I split once to separate the two lists by the colon, I then split again to access individual elements in each list. The reason I use $orig = @orignal[0] is so that it accesses the first member of array original which is the entire
monkey,cow,dog,cat:house,dog,monkey:
which I split to access the two lists.

I dumped the @original and dumped files read to a scalor. Tested by printing the scalor. As soon as I put the split in I am back to zip outout. Not sure what you meant by &quot;use strict;&quot;? or the perl switch &quot;-w&quot;, If you don't mind could you give a little more explanation. Thanks
 
use strict; # turns on strict usage of variables, and doesn't allow you to use unsafe constructs.
The -w switch turns on warnings.

If you want to access the first member of an array you MUST use $array[0] - NOT @array[0].
If all you have is one line from the file do this;

$line = <FILE>;

($first, $second) = split(/:/, $line);


hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top