Re: assigning back to an array

rxl124_at_hehe.com
Date: 02/26/04


Date: 25 Feb 2004 17:15:04 -0800


"Jürgen Exner" <jurgenex@hotmail.com> wrote in message news:<xQ2%b.6703$921.3436@nwrddc02.gnilink.net>...
> rxl124@hehe.com wrote:
> > I have files that I only need one field that I need to grep it out and
> > I am trying to assign that to another file.
> >
> > (It happens that one field that I am looking for has some other
> > character that I dont need so I am pulling it out w/ substr commands).
> >
> > However --> @real_num = substr($num, 91,10) is only pulling the last
> > line of the file(not the 100 other lines).
> >
> > Can someone please tell me what I am doing wrong here?
> >
> > Please Please help as I am driving myself mad on this one.
> >
> >
> > #!/usr/bin/perl -w
> The more idiomatic way nowadays is to
> use warnings;
>
> Also, strictures are missing
> use strict;
>
> > open(FH, "files.txt") || die;
>
> You may want to add a message to your die() statement with an explanation of
> the error:
> open(FH, "files.txt") or die "Cannot open files.txt because $!\n";
>
> > @yahoo = <FH>;
> > foreach $num (@yahoo){
>
> That doesn't make sense. Why are you reading the whole file into an array
> when in the very next statement you are looping through that array (and
> don't use the array anywhere else). Better use the idiomatic loop
>
> while (<FH>) {
>
> > @real_num = substr($num ,91, 10);
>
> In each iteration you are re-assigning @real_num, throwing away whatever
> data was in there before. Probably you meant
>
> push @real_num, substr($_, 91, 10);
>
> > }
> > open(NF, ">hanabbs2.log") || die;
>
> Again, you really should add some text and the actual error reason to the
> die() statement
>
> > foreach $num (@real_num){
> > print NF "$num\n";
>
> Oh, that's all you do with @real_num?
> Then why not open both file handles up front and process the file line by
> line, printing each line as you process the line?
>
> open(FH, "files.txt") or die "Cannot open files.txt because $!\n";
> open(NF, ">hanabbs2.log") or die "Cannot open hanabbs2.log because $!\n";
>
> while (<FH>) {
> print NF substr($_, 91, 10);
> }
> close FH;
> close NF;
>
> jue

You guys are the best. Last night, I was up until wee hours trying to
figure this out. I am going to give these a try and let you know
sometime during the course of night.

Thank you!!



Relevant Pages

  • Re: assigning back to an array
    ... Also, strictures are missing ... You may want to add a message to your die() statement with an explanation of ... Why are you reading the whole file into an array ... you really should add some text and the actual error reason to the ...
    (comp.lang.perl)
  • Re: Successor function in LISP
    ... anybody gets undergrad courses in Lisp. ... let's say I represent a die using a list itself in the following ... Thus we can make a 24 x 6 sized static array, valid-die-combinations, ... Where S can be retrieved using aref on puzzle-space array with the ...
    (comp.lang.lisp)
  • Re: Successor function in LISP
    ... anybody gets undergrad courses in Lisp. ... valid moves given a die state and the direction. ... (setf vdc-right (getf die:right)) ... where vdc is the valid-die-combination array ...
    (comp.lang.lisp)
  • Re: Array to String
    ... sun hat seit Version 1.5 endlich mitgedacht was die ... * Returns a fixed-size list backed by the specified array. ... * Null safe version by Heiner. ...
    (de.comp.lang.java)
  • Re: delimited data into nested array
    ... > file) into Perl as a two dimensional nested array. ... not declared your variables and enabled strictures. ... Here you are using symbolic references, ...
    (comp.lang.perl.misc)