Re: assigning back to an array
rxl124_at_hehe.com
Date: 02/26/04
- Next message: JD Vernon: "Perl, Oracle, LWP, and PDF's"
- Previous message: Hon Seng Phuah: "Re: Substract numeric from a string."
- In reply to: Jürgen Exner: "Re: assigning back to an array"
- Next in thread: rxl124_at_hehe.com: "Re: assigning back to an array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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!!
- Next message: JD Vernon: "Perl, Oracle, LWP, and PDF's"
- Previous message: Hon Seng Phuah: "Re: Substract numeric from a string."
- In reply to: Jürgen Exner: "Re: assigning back to an array"
- Next in thread: rxl124_at_hehe.com: "Re: assigning back to an array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|