Gossamer Forum
Home : General : Perl Programming :

some perl help

Quote Reply
some perl help
Writing this perl script, and now I have this silly I/O problem. I'm writing to a file, and changing 1 line.
So I have to overwrite the whole file with the new line that has been edited, and then add the old one.

But I get spaces between everyline! I am chomping every line, and I add \n to the end of the line that is being written to the file, but I just can't get the lines to "stick together."

Code:
open(WRITEDATA, ">$members2");
flock(WRITEDATA,2);

foreach $entries2 (@indata2){
chomp($entires2);
($number, $name, $email) = split(/\|/, $entries2);

if ($name2 eq $name) {
print WRITEDATA "$number|$newname|$newemail\n";

This is just an example. My code is slightly different.
So each time I do the action this happens:

Quote:
Number|Name|Email

Number|Name|Email

Number|Name|Email

if I do it again this happens:

Quote:
Number|Name|Email


Number|Name|Email


Number|Name|Email


You see?
I had this kind of error in another file, and I didn't check it for a long time, and suddenly I had 5000(!!) lines! And I only had line 10 lines with actual contents. The others were "|||||||" or " ".

Can anyone help?

Thanks.

- kbtune
Quote Reply
Re: [perlman] some perl help In reply to
Code:
open(WRITEDATA, ">$members2") || die "Cant read. Error: $! on file $members2";
flock(WRITEDATA,2);

foreach $entries2 (@indata2){
$entires2 =~ s/\n$/;
($number, $name, $email) = split(/\|/, $entries2);

if ($name2 eq $name) {
print WRITEDATA "$number|$newname|$newemail\n";


Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] some perl help In reply to
I get an error by that Andy.

Quote:

Backslash found where operator expected at nestedp.cgi line 116, near "($name, $email, $username, $password, $url, $date, $telefonok, $alderok, $nestedp) = split(/\"
(Might be a runaway multi-line // string starting on line 115)
(Missing operator before \?)
syntax error at nestedp.cgi line 116, near "($name, $email, $username, $password, $url, $date, $telefonok, $alderok, $nestedp) = split(/\"
syntax error at nestedp.cgi line 132, near "/;"
syntax error at nestedp.cgi line 142, near "}"
Execution of nestedp.cgi aborted due to compilation errors.

This is the code:

Code:
open (MEMBERS, "$members");
@indata = <MEMBERS>;
close (MEMBERS);
foreach $entries (@indata){
$entires2 =~ s/\n$/;
($name, $email, $username, $password, $url, $date, $telefonok, $alderok, $nestedp) = split(/\|/, $entries);

Seems like it is missing something.
I changed the line to this: $entires2 =~ s/\n$//;
and it fixed the error but not the problem.

Can you help?

- perlman
Quote Reply
Re: [perlman] some perl help In reply to
Sorry, that should be;

$entires2 =~ s/\n$//;

Note the extra / at the end Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] some perl help In reply to
But everything is still being ruined everytime some one access the file...

Thanks.
- perlman
Quote Reply
Re: [perlman] some perl help In reply to
This is why you should use strict Wink

You are looping it, with $entries, yet you were calling it with;

Code:
$entires2 =~ s/\n$//;

But I think it should be something like;

Code:
$entires =~ s/\n$//;

...or even;

Code:
$entires =~ s/\n//;

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates