and more questions

and more questions

am 16.01.2006 17:36:39 von FJRussonc

1) I have a data file cvs type. No problem opening & reading. But when I
rewrtie the file I pick up leading space on each line each and everytime I
rewrite the file, and the spaces accumulate.
So how do I remove leading spaces?

-- Before ( no rewrites) --
,N/A, 1, 30, N/A
,,1,fumc1cm,N/A
,,2,fumc2cm,N/A

-- After 5x rewrites--
,N/A, 1, 30, N/A
,,1,fumc1cm,N/A
,,2,fumc2cm,N/A

2) This same file has 2 trailing characters (hex 0d0a) on the end of each
line. When reading in I srtip them off with chop; chop; Is there a better
way to do it?

3) print "Location: $cm_list_access\n\n"; This works transferring to the
web page stored in the variable. But I want it to open in a NEW Window. So
how do I do it?

Frank

Re: and more questions

am 16.01.2006 18:16:22 von Matt Garrish

"Frank J. Russo" wrote in message
news:rYPyf.159$rH5.99@newsread2.news.atl.earthlink.net...
> 1) I have a data file cvs type. No problem opening & reading. But when I
> rewrtie the file I pick up leading space on each line each and everytime I
> rewrite the file, and the spaces accumulate.
> So how do I remove leading spaces?
>
> -- Before ( no rewrites) --
> ,N/A, 1, 30, N/A
> ,,1,fumc1cm,N/A
> ,,2,fumc2cm,N/A
>
> -- After 5x rewrites--
> ,N/A, 1, 30, N/A
> ,,1,fumc1cm,N/A
> ,,2,fumc2cm,N/A
>

Where are these spaces coming from? I can't imagine they magically appear,
so hunt down the source and correct that. As a last resort you could try

$line =~ s/^\s+//;

But not knowing how you're writing these lines out to file (are you using a
module or formatting the text yourself?), I don't know if that's an option.

> 2) This same file has 2 trailing characters (hex 0d0a) on the end of each
> line. When reading in I srtip them off with chop; chop; Is there a
> better way to do it?
>

If you know there are always two, then no. Using chop is faster than using a
regular expression. You could set $/ and use chomp, but that would be more
useful if the number varied.

> 3) print "Location: $cm_list_access\n\n"; This works transferring to
> the web page stored in the variable. But I want it to open in a NEW
> Window. So how do I do it?
>

You open the window on the client side either using the target attribute or
javascript. You can't open new browser windows from the server.

Matt

Re: and more questions

am 16.01.2006 18:51:31 von FJRussonc

Regarding the spaces -

Data read in as:
############################################################ #################
open (HEADERS,"<$customer_file") || die "Can't Open Customer.csv: $!\n";
@HEADERLINES = ;
close(HEADERS);

and written back out as :
open (HEADERS,">$customer_file") || die "Can't Open Customer.csv: $!\n";
print HEADERS "@HEADERLINES";
close(HEADERS);

All the lines even those not manipulated or changed pick up a leading space.
I do believe it occurs on the reading in of the file.

Ideas?

Frank

Re: and more questions

am 16.01.2006 23:32:15 von Paul Lalli

Frank J. Russo wrote:
> 1) I have a data file cvs type. No problem opening & reading. But when I
> rewrtie the file I pick up leading space on each line each and everytime I
> rewrite the file, and the spaces accumulate.
> So how do I remove leading spaces?

Can you please explain what makes you think that either:
1) We know what code you've written, or
2) The code you've written isn't at all relevant to this problem, and
Perl is just doing something to annoy you independent of your program?

Either way, please see:
perldoc -q spaces

Because that's my first guess as to what you're doing wrong.

Paul Lalli

Re: and more questions

am 16.01.2006 23:34:14 von Paul Lalli

Frank J. Russo wrote:
> Regarding the spaces -

What spaces?

Please quote some context when posting a reply to Usenet. Please keep
in mind you are not posting to a forum, a bulletin board, or a Google
Group.

> Data read in as:
> ############################################################ #################
> open (HEADERS,"<$customer_file") || die "Can't Open Customer.csv: $!\n";
> @HEADERLINES = ;
> close(HEADERS);
>
> and written back out as :
> open (HEADERS,">$customer_file") || die "Can't Open Customer.csv: $!\n";
> print HEADERS "@HEADERLINES";

Please check the Perl FAQ *before* posting to Usenet:
perldoc -q spaces
"Why do I get weird spaces when I print an array of lines?"

Paul Lalli