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

[PBML] Re: please reply asap (or: concat to 1 line, each line from 3 files)

Expand Messages
  • b_harnish
    # use this: print OUT1 $bid_date n ; # then when you read it in, everyline will have a value # and no extra spaces. open FILE3,
    Message 1 of 16 , Jan 29, 2002
    • 0 Attachment
      # use this:
      print OUT1 "$bid_date\n";

      # then when you read it in, everyline will have a value
      # and no extra spaces.
      open FILE3, '<file3.txt' or die "Cannot open file3 ($!)\n";
      my @file3 = map { chomp; $_; } (<FILE3>);

      - Brian

      --- In perl-beginner@y..., lavanya ravi <ushalavan@y...> wrote:
      <snip>
      > print OUT1 "\n $bid_date \n";
      <snip>
      > this is the code for fetching the auction details from
      ebay.com, the same code with some changes here and there is used
      to get the names and the bid amount.
      >
      > once u go to the URL u will find a table layout printing all
      the names of the bidder, bidder's amount, date of bid. the above
      code is for date of bid.
      >
      > this i am doing it for many auction categories.
      >
      > bye
      >
      > lavanya
      >
      > b_harnish <bharnish@t...> wrote: A peek at your code would
      help figure out the error.
      > try this:
      > open FILE3, '<file3.txt' or die "Cannot open file3 ($!)\n";
      > my @file3;
      > while(<FILE3>) {
      > chomp;
      > next if (/^\s*$/);
      > push(@file3, $_);
      > }
      >
      > - Brian
      >
      > --- In perl-beginner@y..., lavanya ravi <ushalavan@y...> wrote:
      > >
      > > hi,
      > > I have a problem with my file3,
      > > the output is like
      > >
      > > Jan-21-02 08:12:57 PST
      > > Jan-21-02 08:19:52 PST
      > <snip>
      > > Jan-21-02 09:21:04 PST
      > > Jan-21-02 02:30:06 PST
      > > Jan-21-02 07:15:12 PST
      > > I have a new line character, i tried to replace it but i am
      not successful.
      > > the code basically gets these dates from the url.
      > > so i am unable to join these files due to some new line
      characters and blank lines.
      > > please help.
      > > by
      > > lavanya
      > > b_harnish <bharnish@t...> wrote: --- In perl-beginner@y...,
      "ushalavan" <ushalavan@y...> wrote:
      > > > hi,
      > > > I am writing a perl code that will fetch me details from a
      URL.
      > > > I have written the data from this URL into three separate
      files.
      > > > the files have data as shown:
      > > > file 1:
      > > > james
      > > > harry
      > > > ...
      > > > file 2 :
      > > > 30.00
      > > > 20.00
      > > > ..
      > > > file 3
      > > > jan 20,2002
      > > > jan 19,2002
      > > >
      > > > I have opened these files and have stored each file in 3
      different
      > > > arrays.
      > > >
      > > > i want to get the output as
      > > > james,30.00,jan 20,2002
      > > > harry,20.00,jan 19,2002
      > > >
      > > > how do i get it
      > > > please reply asap
      > > >
      > > > bye
      > > > lavanya
      > >
      > > --->8--- Cut ---8<---
      > > # Assuming your files are in @file1, @file2, and @file3.
      > >
      > > # a little sanity check, make sure they all have the
      > > # same number of elements
      > > die "Bad data" if ((@file1 != @file2) || (@file1 != @file3));
      > >
      > > # display the data
      > > for(0..$#file1) {
      > > print join(',', $file1[$_], $file2[$_], $file3[$_]), "\n";
      > > }
      > >
      > > # or, put them in an array:
      > > my @together = map {
      > > join(',', $file1[$_], $file2[$_], $file3[$_]);
      > > } (0..$#file1);
      > > print join("\n", @together);
      > > --->8--- Cut ---8<---
      > >
      > > - Brian
      >
      >
      >
      > Yahoo! Groups Sponsor
      >
      > ---------------------------------
      >
      > Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html
      >
      > Your use of Yahoo! Groups is subject to the Yahoo! Terms of
      Service.
      >
      >
      >
      > ---------------------------------
      > Do You Yahoo!?
      > Send your FREE holiday greetings online at Yahoo! Greetings.
      >
      > [Non-text portions of this message have been removed]
    • b_harnish
      next will move to the next element in the array, and move execution back to the top of the loop. My suggestion is to have an index into the array, increasing
      Message 2 of 16 , Jan 29, 2002
      • 0 Attachment
        next will move to the next element in the array, and move
        execution back to the top of the loop. My suggestion is to have
        an index into the array, increasing it as you go.

        If your counter was $n, then reference each line as $file[$n],
        and increase $n ($n++) when you're ready for the next line.

        Side Note: In your regex's, your asking for global matching, even
        though you are only using one of the returns. Turn off the global
        matching and save perl the trouble of finding more than one match.

        Side Side Note: I would recoment using pushing values onto an
        @dat instead of having $datN. Then when you've collected all your
        data, just print join('|',@dat). (Just personal taste.)

        - Brian

        --- In perl-beginner@y..., "Tony Austin" <tony@u...> wrote:
        > Sorry for a simple question.....
        >
        > I am attempting to collect data from a text file (html page)...
        >
        > The data I am after is embedded within multiple lines of the
        file.
        >
        > For example, from the HTML file:
        >
        > <B>text line1</B>
        > <br>text line 2
        > <br>
        > text line 3
        > <br>
        > text line 4
        >
        > There may be 2 to 50 occurrences of this common string within
        the file. I
        > can write a regex to pull the data I am after but am having
        trouble dealing
        > with the multiple line format of the data.
        >
        > I have attempted
        >
        > ----------
        >
        > foreach $line (@file) {
        > chomp($line);
        > $nn++;
        > if ($line =~ m/<b>([^<.*>]*)<\/b>/ig) {
        > #found name
        > $dat1 = $1;
        > next;
        > $_ =~ m/<br>([a-z0-9]*)/ig;
        > $dat2 = $1;
        > next;
        > next;
        > $_ =~ s/ / /ig;
        > @parts = split(/,/, $_);
        > $dat3 = $parts[0];
        > $parts[1] =~ m/([^\s]*)[\s]*([^\s]*)$/i;
        > $dat4 = $1;
        > $dat5 = $2;
        > next;
        > next;
        > $_ =~ s/ / /ig;
        > $dat6 = $_;
        >
        > print LOG "$dat1|$dat2|$dat3|$dat4|$dat5|$dat6\n";
        >
        > }
        > } # end foreach $line
        >
        > ---------------
        >
        > The problem with the above is that the 'next;' doesn't move to
        the next line
        > of the foreach loop...
        >
        > How would you guys approach this?
        >
        > Again, sorry for such a simple question.
        >
        > Thanks
        >
        > Tony
      • lavanya ravi
        hi, I tried it out it doesnt seem to work. do u want me to open the file in another txt and do the thing ( well i even tried that) the output remains the same.
        Message 3 of 16 , Jan 30, 2002
        • 0 Attachment
          hi,
          I tried it out it doesnt seem to work.
          do u want me to open the file in another txt and do the thing ( well i even tried that)
          the output remains the same.
          please help
          bye
          lavanya
          b_harnish <bharnish@...> wrote: # use this:
          print OUT1 "$bid_date\n";

          # then when you read it in, everyline will have a value
          # and no extra spaces.
          open FILE3, '<file3.txt' or die "Cannot open file3 ($!)\n";
          my @file3 = map { chomp; $_; } (<FILE3>);

          - Brian

          --- In perl-beginner@y..., lavanya ravi <ushalavan@y...> wrote:
          <snip>
          > print OUT1 "\n $bid_date \n";
          <snip>
          > this is the code for fetching the auction details from
          ebay.com, the same code with some changes here and there is used
          to get the names and the bid amount.
          >
          > once u go to the URL u will find a table layout printing all
          the names of the bidder, bidder's amount, date of bid. the above
          code is for date of bid.
          >
          > this i am doing it for many auction categories.
          >
          > bye
          >
          > lavanya
          >
          > b_harnish <bharnish@t...> wrote: A peek at your code would
          help figure out the error.
          > try this:
          > open FILE3, '<file3.txt' or die "Cannot open file3 ($!)\n";
          > my @file3;
          > while(<FILE3>) {
          > chomp;
          > next if (/^\s*$/);
          > push(@file3, $_);
          > }
          >
          > - Brian
          >
          > --- In perl-beginner@y..., lavanya ravi <ushalavan@y...> wrote:
          > >
          > > hi,
          > > I have a problem with my file3,
          > > the output is like
          > >
          > > Jan-21-02 08:12:57 PST
          > > Jan-21-02 08:19:52 PST
          > <snip>
          > > Jan-21-02 09:21:04 PST
          > > Jan-21-02 02:30:06 PST
          > > Jan-21-02 07:15:12 PST
          > > I have a new line character, i tried to replace it but i am
          not successful.
          > > the code basically gets these dates from the url.
          > > so i am unable to join these files due to some new line
          characters and blank lines.
          > > please help.
          > > by
          > > lavanya
          > > b_harnish <bharnish@t...> wrote: --- In perl-beginner@y...,
          "ushalavan" <ushalavan@y...> wrote:
          > > > hi,
          > > > I am writing a perl code that will fetch me details from a
          URL.
          > > > I have written the data from this URL into three separate
          files.
          > > > the files have data as shown:
          > > > file 1:
          > > > james
          > > > harry
          > > > ...
          > > > file 2 :
          > > > 30.00
          > > > 20.00
          > > > ..
          > > > file 3
          > > > jan 20,2002
          > > > jan 19,2002
          > > >
          > > > I have opened these files and have stored each file in 3
          different
          > > > arrays.
          > > >
          > > > i want to get the output as
          > > > james,30.00,jan 20,2002
          > > > harry,20.00,jan 19,2002
          > > >
          > > > how do i get it
          > > > please reply asap
          > > >
          > > > bye
          > > > lavanya
          > >
          > > --->8--- Cut ---8<---
          > > # Assuming your files are in @file1, @file2, and @file3.
          > >
          > > # a little sanity check, make sure they all have the
          > > # same number of elements
          > > die "Bad data" if ((@file1 != @file2) || (@file1 != @file3));
          > >
          > > # display the data
          > > for(0..$#file1) {
          > > print join(',', $file1[$_], $file2[$_], $file3[$_]), "\n";
          > > }
          > >
          > > # or, put them in an array:
          > > my @together = map {
          > > join(',', $file1[$_], $file2[$_], $file3[$_]);
          > > } (0..$#file1);
          > > print join("\n", @together);
          > > --->8--- Cut ---8<---
          > >
          > > - Brian
          >
          >
          >
          > Yahoo! Groups Sponsor
          >
          > ---------------------------------
          >
          > Unsubscribing info is here:
          http://help.yahoo.com/help/us/groups/groups-32.html
          >
          > Your use of Yahoo! Groups is subject to the Yahoo! Terms of
          Service.
          >
          >
          >
          > ---------------------------------
          > Do You Yahoo!?
          > Send your FREE holiday greetings online at Yahoo! Greetings.
          >
          > [Non-text portions of this message have been removed]


          Yahoo! Groups Sponsor

          ---------------------------------

          Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html

          Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



          ---------------------------------
          Do You Yahoo!?
          Yahoo! Auctions Great stuff seeking new owners! Bid now!

          [Non-text portions of this message have been removed]
        • lavanya ravi
          hi, I tried it out it doesnt seem to work. do u want me to open the file in another txt and do the thing ( well i even tried that) the output remains the same.
          Message 4 of 16 , Jan 30, 2002
          • 0 Attachment
            hi,
            I tried it out it doesnt seem to work.
            do u want me to open the file in another txt and do the thing ( well i even tried that)
            the output remains the same.
            please help
            bye
            lavanya
            b_harnish <bharnish@...> wrote: # use this:
            print OUT1 "$bid_date\n";

            # then when you read it in, everyline will have a value
            # and no extra spaces.
            open FILE3, '<file3.txt' or die "Cannot open file3 ($!)\n";
            my @file3 = map { chomp; $_; } (<FILE3>);

            - Brian

            --- In perl-beginner@y..., lavanya ravi <ushalavan@y...> wrote:
            <snip>
            > print OUT1 "\n $bid_date \n";
            <snip>
            > this is the code for fetching the auction details from
            ebay.com, the same code with some changes here and there is used
            to get the names and the bid amount.
            >
            > once u go to the URL u will find a table layout printing all
            the names of the bidder, bidder's amount, date of bid. the above
            code is for date of bid.
            >
            > this i am doing it for many auction categories.
            >
            > bye
            >
            > lavanya
            >
            > b_harnish <bharnish@t...> wrote: A peek at your code would
            help figure out the error.
            > try this:
            > open FILE3, '<file3.txt' or die "Cannot open file3 ($!)\n";
            > my @file3;
            > while(<FILE3>) {
            > chomp;
            > next if (/^\s*$/);
            > push(@file3, $_);
            > }
            >
            > - Brian
            >
            > --- In perl-beginner@y..., lavanya ravi <ushalavan@y...> wrote:
            > >
            > > hi,
            > > I have a problem with my file3,
            > > the output is like
            > >
            > > Jan-21-02 08:12:57 PST
            > > Jan-21-02 08:19:52 PST
            > <snip>
            > > Jan-21-02 09:21:04 PST
            > > Jan-21-02 02:30:06 PST
            > > Jan-21-02 07:15:12 PST
            > > I have a new line character, i tried to replace it but i am
            not successful.
            > > the code basically gets these dates from the url.
            > > so i am unable to join these files due to some new line
            characters and blank lines.
            > > please help.
            > > by
            > > lavanya
            > > b_harnish <bharnish@t...> wrote: --- In perl-beginner@y...,
            "ushalavan" <ushalavan@y...> wrote:
            > > > hi,
            > > > I am writing a perl code that will fetch me details from a
            URL.
            > > > I have written the data from this URL into three separate
            files.
            > > > the files have data as shown:
            > > > file 1:
            > > > james
            > > > harry
            > > > ...
            > > > file 2 :
            > > > 30.00
            > > > 20.00
            > > > ..
            > > > file 3
            > > > jan 20,2002
            > > > jan 19,2002
            > > >
            > > > I have opened these files and have stored each file in 3
            different
            > > > arrays.
            > > >
            > > > i want to get the output as
            > > > james,30.00,jan 20,2002
            > > > harry,20.00,jan 19,2002
            > > >
            > > > how do i get it
            > > > please reply asap
            > > >
            > > > bye
            > > > lavanya
            > >
            > > --->8--- Cut ---8<---
            > > # Assuming your files are in @file1, @file2, and @file3.
            > >
            > > # a little sanity check, make sure they all have the
            > > # same number of elements
            > > die "Bad data" if ((@file1 != @file2) || (@file1 != @file3));
            > >
            > > # display the data
            > > for(0..$#file1) {
            > > print join(',', $file1[$_], $file2[$_], $file3[$_]), "\n";
            > > }
            > >
            > > # or, put them in an array:
            > > my @together = map {
            > > join(',', $file1[$_], $file2[$_], $file3[$_]);
            > > } (0..$#file1);
            > > print join("\n", @together);
            > > --->8--- Cut ---8<---
            > >
            > > - Brian
            >
            >
            >
            > Yahoo! Groups Sponsor
            >
            > ---------------------------------
            >
            > Unsubscribing info is here:
            http://help.yahoo.com/help/us/groups/groups-32.html
            >
            > Your use of Yahoo! Groups is subject to the Yahoo! Terms of
            Service.
            >
            >
            >
            > ---------------------------------
            > Do You Yahoo!?
            > Send your FREE holiday greetings online at Yahoo! Greetings.
            >
            > [Non-text portions of this message have been removed]


            Yahoo! Groups Sponsor

            ---------------------------------

            Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html

            Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



            ---------------------------------
            Do You Yahoo!?
            Yahoo! Auctions Great stuff seeking new owners! Bid now!

            [Non-text portions of this message have been removed]
          • Charles K. Clarkson
            lavanya ravi ... tried that) ... Er, chomp( my @file3 = );
            Message 5 of 16 , Jan 30, 2002
            • 0 Attachment
              "lavanya ravi" <ushalavan@...>

              :
              : hi,
              : I tried it out it doesnt seem to work.
              : do u want me to open the file in another txt and do the thing ( well i even
              tried that)
              : the output remains the same.
              : please help
              : bye
              : lavanya
              : b_harnish <bharnish@...> wrote: # use this:
              : print OUT1 "$bid_date\n";
              :
              : # then when you read it in, everyline will have a value
              : # and no extra spaces.
              : open FILE3, '<file3.txt' or die "Cannot open file3 ($!)\n";
              : my @file3 = map { chomp; $_; } (<FILE3>);

              Er,
              chomp( my @file3 = <FILE3> );
            • b_harnish
              What doesn t work? Does it not read the data in correctly? If not, try sending us some of the output file. - Brian
              Message 6 of 16 , Jan 30, 2002
              • 0 Attachment
                What doesn't work? Does it not read the data in correctly? If not, try sending us some of the output file.

                - Brian

                --- In perl-beginner@y..., lavanya ravi <ushalavan@y...> wrote:
                >
                > hi,
                > I tried it out it doesnt seem to work.
                > do u want me to open the file in another txt and do the thing ( well i even tried that)
                > the output remains the same.
                > please help
                > bye
                > lavanya
                > b_harnish <bharnish@t...> wrote: # use this:
                > print OUT1 "$bid_date\n";
                >
                > # then when you read it in, everyline will have a value
                > # and no extra spaces.
                > open FILE3, '<file3.txt' or die "Cannot open file3 ($!)\n";
                > my @file3 = map { chomp; $_; } (<FILE3>);
                >
                > - Brian
                >
                > --- In perl-beginner@y..., lavanya ravi <ushalavan@y...> wrote:
                > <snip>
                > > print OUT1 "\n $bid_date \n";
                > <snip>
                > > this is the code for fetching the auction details from
                > ebay.com, the same code with some changes here and there is used
                > to get the names and the bid amount.
                > >
                > > once u go to the URL u will find a table layout printing all
                > the names of the bidder, bidder's amount, date of bid. the above
                > code is for date of bid.
                > >
                > > this i am doing it for many auction categories.
                > >
                > > bye
                > >
                > > lavanya
                > >
                > > b_harnish <bharnish@t...> wrote: A peek at your code would
                > help figure out the error.
                > > try this:
                > > open FILE3, '<file3.txt' or die "Cannot open file3 ($!)\n";
                > > my @file3;
                > > while(<FILE3>) {
                > > chomp;
                > > next if (/^\s*$/);
                > > push(@file3, $_);
                > > }
                > >
                > > - Brian
                > >
                > > --- In perl-beginner@y..., lavanya ravi <ushalavan@y...> wrote:
                > > >
                > > > hi,
                > > > I have a problem with my file3,
                > > > the output is like
                > > >
                > > > Jan-21-02 08:12:57 PST
                > > > Jan-21-02 08:19:52 PST
                > > <snip>
                > > > Jan-21-02 09:21:04 PST
                > > > Jan-21-02 02:30:06 PST
                > > > Jan-21-02 07:15:12 PST
                > > > I have a new line character, i tried to replace it but i am
                > not successful.
                > > > the code basically gets these dates from the url.
                > > > so i am unable to join these files due to some new line
                > characters and blank lines.
                > > > please help.
                > > > by
                > > > lavanya
                > > > b_harnish <bharnish@t...> wrote: --- In perl-beginner@y...,
                > "ushalavan" <ushalavan@y...> wrote:
                > > > > hi,
                > > > > I am writing a perl code that will fetch me details from a
                > URL.
                > > > > I have written the data from this URL into three separate
                > files.
                > > > > the files have data as shown:
                > > > > file 1:
                > > > > james
                > > > > harry
                > > > > ...
                > > > > file 2 :
                > > > > 30.00
                > > > > 20.00
                > > > > ..
                > > > > file 3
                > > > > jan 20,2002
                > > > > jan 19,2002
                > > > >
                > > > > I have opened these files and have stored each file in 3
                > different
                > > > > arrays.
                > > > >
                > > > > i want to get the output as
                > > > > james,30.00,jan 20,2002
                > > > > harry,20.00,jan 19,2002
                > > > >
                > > > > how do i get it
                > > > > please reply asap
                > > > >
                > > > > bye
                > > > > lavanya
                > > >
                > > > --->8--- Cut ---8<---
                > > > # Assuming your files are in @file1, @file2, and @file3.
                > > >
                > > > # a little sanity check, make sure they all have the
                > > > # same number of elements
                > > > die "Bad data" if ((@file1 != @file2) || (@file1 != @file3));
                > > >
                > > > # display the data
                > > > for(0..$#file1) {
                > > > print join(',', $file1[$_], $file2[$_], $file3[$_]), "\n";
                > > > }
                > > >
                > > > # or, put them in an array:
                > > > my @together = map {
                > > > join(',', $file1[$_], $file2[$_], $file3[$_]);
                > > > } (0..$#file1);
                > > > print join("\n", @together);
                > > > --->8--- Cut ---8<---
                > > >
                > > > - Brian
                > >
                > >
                > >
                > > Yahoo! Groups Sponsor
                > >
                > > ---------------------------------
                > >
                > > Unsubscribing info is here:
                > http://help.yahoo.com/help/us/groups/groups-32.html
                > >
                > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of
                > Service.
                > >
                > >
                > >
                > > ---------------------------------
                > > Do You Yahoo!?
                > > Send your FREE holiday greetings online at Yahoo! Greetings.
                > >
                > > [Non-text portions of this message have been removed]
                >
                >
                > Yahoo! Groups Sponsor
                >
                > ---------------------------------
                >
                > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
                >
                > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
                >
                >
                >
                > ---------------------------------
                > Do You Yahoo!?
                > Yahoo! Auctions Great stuff seeking new owners! Bid now!
                >
                > [Non-text portions of this message have been removed]
              Your message has been successfully submitted and would be delivered to recipients shortly.