RE: From column to row?



Here's a fixed version, not much though into it, you can figure out how
to remove the trailing ,

$source_file = "input.txt";
$result_file = "output.txt";

open (SOURCE, $source_file) || die "cannot open $source_file: $!";
open (RESULT, ">$result_file") || die "cannot open $result_file: $!";

while (<SOURCE>)
{
chomp; #Delete the NL character

# If you don't want the quotation marks in your output remove the \"
from the next line
print RESULT "\"$_\","; # You opened the RESULTS file but did not
write to it...
}
close SOURCE; # Just make sure you close files after you are done with
them...
close RESULT;


+------------------------------------------
| José J. Cintrón
+------------------------------------------

> -----Original Message-----
> From: Andrej Kastrin [mailto:andrej.kastrin@xxxxxxxx]
> Sent: Monday, November 28, 2005 15:24
> To: Perl Beginners List
> Subject: Re: From column to row?
>
> Chris Devers wrote:
>
> >On Mon, 28 Nov 2005, Andrej Kastrin wrote:
> >
> >
> >
> >>Hi, I am totally NOOB in Perl and here is my first problem, which I

> >>couldn't solve...
> >>
> >>I have column data in file xy.txt, which looks like:
> >>
> >>AAAAA
> >>BBBBB
> >>CCCCC
> >>ABCDD
> >>..
> >>.
> >>
> >>Now I have to transform this to row data file in the following way:
> >>"AAAAA","BBBBB","CCCCC","ABCDD"
> >>
> >>Is that possible?
> >>
> >>
> >
> >Yes, it's possible.
> >
> >However, your description of the result you want doesn't
> seem to match
> >with the subject line you used -- I was expecting that you
> want output
> >like "ABCA", "ABCB..", "ABCD.", "ABCD", "ABCD". Which is it?
> >
> >Regardless, either way is possible.
> >
> >What have you tried so far?
> >
> >Anything?
> >
> >We can only help critique code you've attempted yourself.
> >
> >This is not a free script writing service.
> >
> >
> >
> >
> >
> I suppose that above example is not good one; here is the real one:
> Mark
> Francesco
> Ann
> Robert
>
> transform to: "Mark","Francesco","Ann","Robert"
>
> and here is my code:
>
> $source_file = "input.txt";
> $result_file = "output.txt";
>
> open (SOURCE, $source_file) || die "cannot open $source_file:
> $!"; open (RESULT, ">$result_file") || die "cannot open
> $result_file: $!";
>
> while (<SOURCE>)
> {
> my($line) = $_;
> if ($line =~ $) #match to end of line
> {
> print "$line"; #how to make e.g. "Mark",
> }
> }
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx For
> additional commands, e-mail: beginners-help@xxxxxxxx
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
.



Relevant Pages

  • Re: Word 2002 Problem
    ... Word has the features of the International keyboard anyway by pressing Ctrl and the key. ... When I type inverted commas (or quotation marks) the cursor ... >> does not move to the next position and display the character, ... >> where it is and no character is displayed. ...
    (microsoft.public.windowsxp.basics)
  • Re: Word 2002 Problem
    ... When I type inverted commas (or quotation marks) the cursor ... > does not move to the next position and display the character, ... > where it is and no character is displayed. ...
    (microsoft.public.windowsxp.basics)
  • Word 2002 Problem
    ... I have just reformatted and reinstalled Windows XP Pro with Office XP Pro. ... When I type inverted commas (or quotation marks) the cursor ... does not move to the next position and display the character, ... where it is and no character is displayed. ...
    (microsoft.public.windowsxp.basics)
  • Re: punctuation mark problem
    ... When I type in a Word document single or double quotation marks or the ... possessive apostophe, the character looks ok on the screen, but when ...
    (microsoft.public.windowsxp.general)

Loading