Loading ...
Sorry, an error occurred while loading the content.

RE: [PBML] Re: nested "while"s...(Thanx Charles & Andrew)!!!

Expand Messages
  • Sheldon Smith
    SEEK sets the position within FILEHANDLE. seek UPS, 0, 0; says: reposition file UPS to location (byte?) zero. Look at the SEEK function documentation in your
    Message 1 of 1 , Jan 4, 2001
    • 0 Attachment
      SEEK sets the position within FILEHANDLE.
      "seek UPS, 0, 0;" says: reposition file UPS to location (byte?) zero.

      Look at the SEEK function documentation in your PERLFUNC documentation file.
      Or,
      (http://velocity.activestate.com/docs/ActivePerl/lib/Pod/perlfunc.html)

      Enjoy....

      > -----Original Message-----
      > From: alexrrr@... [mailto:alexrrr@...]
      > Sent: Thursday, January 04, 2001 3:41 PM
      > To: perl-beginner@egroups.com
      > Subject: [PBML] Re: nested "while"s...(Thanx Charles & Andrew)!!!
      >
      >
      > --- In perl-beginner@egroups.com, Andrew Johnson <andrew-
      > johnson@h...> wrote:
      > > ! while ($dex=<FEDEX>) #opening the file
      > > ! {
      > > ! while ($tai=<UPS>
      > > ! {print $dex;
      > > ! print $tai; }}
      > > !
      > > [snip]
      > > ! It never goes on to the "yellow" which is the second line in the
      > > ! color1 file!!!! what am i doing wrong?? HELP!
      > >
      > > It does go on the second (and third) line of FEDEX -- but since
      > > during the first loop we looped all the way to the end of the
      > > UPS file, the inner loop has nothing left to read and doesn't
      > > execute (and thats where the print statements are, so nothing
      > > further gets printed).
      > >
      > > You need to either: use seek() after the inner loop to seek back
      > > to the beginning of the UPS file (so it can be read again):
      > >
      > > open(FEDEX,'color1') || die "Can't open file: $!";
      > > open(UPS, 'color2') || die "Can't open file: $!";
      > > while(my $dex = <FEDEX>){
      > > while(my $tai = <UPS>){
      > > print $dex;
      > > print $tai;
      > > }
      > > seek UPS, 0, 0;
      > > }
      > > close FEDEX;
      > > close UPS;
      > >
      > > or, read both files into arrays (if they aren't too large) and
      > > use nested foreach loops over those arrays:
      > >
      > > open(FEDEX,'color1') || die "Can't open file: $!";
      > > open(UPS, 'color2') || die "Can't open file: $!";
      > > my @dex = <FEDEX>;
      > > my @tai = <UPS>;
      > > close FEDEX;
      > > close UPS;
      > > foreach my $dex (@dex) {
      > > foreach my $tai (@tai) {
      > > print $dex;
      > > print $tai;
      > > }
      > > }
      > >
      > > Hope it helps,
      > > andrew
      > >
      > > --
      > > Andrew L. Johnson http://members.home.net/andrew-johnson/
      >
      > i've just woke up from a great sleep!!1 thanks for the help!
      >
      > Thank you so much guys... I knew i had to be something simple!! It is
      > great that people like you form this newgroup! you make this work!
      > Hope someday, when i've already learned my "seek" and "foreach" well,
      > i get the chance to help someone.
      >
      > Andrew... can you explain a little bit more how that "seek"
      > command works??? Thank you!
      >
      >
      > Once again thank you!!
      >
      > Alejandro.
    Your message has been successfully submitted and would be delivered to recipients shortly.