Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Auto Carriage Return?

by ImpalaSS (Monk)
on Nov 02, 2000 at 01:06 UTC ( #39498=perlquestion: print w/replies, xml ) Need Help??

ImpalaSS has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Im sure this is a stupid question, but i cant figure out how to make it happen. Again, i stress this is not homework, but a requirement at my job. Anyways, here goes. I have an array, in it is 3 values, long ones. WHen i go to incorporate this array into my code, the output automatically goes to the next line after the value in the array, and hence messes up the output. Here is the normal output :
                      RF Block | DCCH Block | Disp Queue | RF Drop | Erl/BR |
DE-NJ-MD sites          1.40 % |    0.24 %  |    1.39%   |   2.04% |   2.35 |
PA Sites Only           1.68 % |    0.32 %  |    1.79%   |   2.09% |   2.53 |
Philadelphia Market     1.58 % |    0.29 %  |    1.65%   |   2.07% |   2.46 |
and here is the output with the array added. (i want to add the dates at the end of each row, corresponding to when the data was collected)
                      RF Block | DCCH Block | Disp Queue | RF Drop | Erl/BR |
DE-NJ-MD sites          1.40 % |    0.24 %  |    1.39%   |   2.04% |   2.35 |
 Fri Oct 13 2000 20:11:54                                              Page  1
PA Sites Only           1.68 % |    0.32 %  |    1.79%   |   2.09% |   2.53 |
 Fri Oct 13 2000 20:51:41                                              Page  1
Philadelphia Market     1.58 % |    0.29 %  |    1.65%   |   2.07% |   2.46 |
 Fri Oct 13 2000 20:59:56                                              Page  1
ir gets all fouled up. Im sure the code will be helpful, so here that is.
Note: the date array is entitled @indidate
#!/usr/local/bin/perl use strict; # Author: Dipul Patel # Nextel Philadelphia # This script takes the data for 3 markets, and compiles it on one fi +le. ###########################################33 my $time2 = scalar localtime(); my @time3 = split(/ /, $time2); my $one=$time3[1]; my $two=$time3[3]; my $three=$time3[5]; my $fileext = "$one" ."_". "$two" ."_". "$three"; open(WR, ">/usr/local/rf-north/WWW/WeeklyReports/WeeklyReports.$fileex +t"); my @files = ("/usr/local/rf-north/WWW/PHLreports/cellsight/Weekly_Repo +rts/de-nj-md\n", "/usr/local/rf-north/WWW/PHLreports/cellsight/Weekly_Reports/ +pa_only\n", "/usr/local/rf-north/WWW/PHLreports/cellsight/Weekly_Reports/ +phila_market\n"); my $file; my (@data, @lines); for $file (@files){ open (FH, $file) || die "Unable to open file $file\n"; @data = <FH>; close (FH); push (@indidate, $data[1]); push (@lines, $data[$#data]); } my $i=0; my @string =("DE-NJ-MD sites ", "PA Sites Only ", "Philadelphia Market "); printf(WR " RF Block | DCCH Block | Disp +Queue | RF Drop | Erl/BR |\n"); while($i<3){ my $line=$string[$i].@lines[$i].$indidate[$i]; printf(WR "$line"); $i++; } close (WR); undef @data;
as soon as i remove the $indidate[$i] tag, the output prints correctly, but it is essential that i have the dates there. Is there a way to remove everything except the date from each value in the array? Or to make sure there is no carriage return after the |?
Thank You
Dipul Patel

Replies are listed 'Best First'.
Re: Auto Carriage Return?
by Fastolfe (Vicar) on Nov 02, 2000 at 01:12 UTC
    When reading data from a file, it's vital that you remember that each line you read will have a trailing newline, because that's how it is in the file. I think this has been mentioned in at least one of the other threads you've made on the subject, and we've been tossing around words like chomp and chop in the chatterbox. The solution is to use, say, chomp against either a string you want to clip the newline off of, or an array made up of lines that you want to clip newlines off of. Most simply:
    chomp(@lines); chomp(@indidate);
    Hope this helps.
      Oh my, i COMPLETELY forgot that.. well that saves a lot of hassle. Thanks a million Fastolfe :)
      Dipul Patel
Re: Auto Carriage Return?
by redcloud (Parson) on Nov 02, 2000 at 01:12 UTC
    (My previous post deleted because Fastolfe already said it, and got it right, whereas I was confused.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://39498]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2020-08-12 17:51 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (66 votes). Check out past polls.