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

Re: [PBML] ignore white space and text

Expand Messages
  • Tom Barron
    ... read a line and throw it away. Eg., open(DATA,
    Message 1 of 7 , Jan 15, 2001
    • 0 Attachment
      Tham Huei Hwan wrote:
      > ...
      > I am using "split" function by space on building my hash array form
      > this data file.
      >
      > -- sample --
      >
      > dbnum chksize freesize <--- would like to ignore this
      > text, how ?

      read a line and throw it away. Eg.,

      open(DATA, "< $filename");
      <DATA>; # throw first line away
      while ($line = <DATA>) # process rest of file
      ...

      If the line to be ignored is not the first one in the file, or if it
      occurs more than once, you could do

      open(DATA, "< $filename");
      while ($line = <DATA>) # process rest of file
      {
      if ($line !~ /dbnum\s*chksize/)
      {
      # process other lines
      }
      }
      ...

      >
      > 1 100 10
      > 2 400 50
      > 3 300 20
      > |
      > ignore white space in front, how ?

      If you have to use split(), just skip the first element of the returned
      array. If you want to just get back the data, you'll have to do
      something other than split. Eg., if a line has been read into variable
      $line,

      ($dbnum, $chksize, $freesize) = ($line =~
      /^\s*(\d+)\s*(\d+)\s*(\d+)/);

      hth...
      --
      Tom
    • Smith, Sheldon
      That is exactly what split does. What is wrong with while ( ) { ($dbnum, $chksize, $freesize) = split; print $dbnum, $chksize,
      Message 2 of 7 , Jan 18, 2001
      • 0 Attachment
        That is exactly what "split" does. What is wrong with

        while (<file-handle-here>) {
        ($dbnum, $chksize, $freesize) = split;
        print "$dbnum, $chksize, $freesize\n";
        }

        Good luck!

        > -----Original Message-----
        > From: Tham Huei Hwan [mailto:hhtham@...]
        > Sent: Sunday, January 14, 2001 11:47 PM
        > To: perl-beginner@egroups.com
        > Subject: [PBML] ignore white space and text
        >
        >
        > Hi all,
        >
        > How do ignore white space and also text (row and column) of the data
        > file ?
        >
        > I am using "split" function by space on building my hash array form
        > this data file.
        >
        > -- sample --
        >
        >
        > dbnum chksize freesize <--- would like to
        > ignore this
        > text, how ?
        >
        > 1 100 10
        > 2 400 50
        > 3 300 20
        > |
        > ignore white space in front, how ?
        >
        >
        > Regards,
        >
        > Tham
      • Foster, Russell J.
        Tham, When I read in a text file to be parsed, I usually do it like this: @x = split (/ t+/,$line); This splits the items on the line by anything seperated by
        Message 3 of 7 , Feb 1, 2001
        • 0 Attachment
          Tham,

          When I read in a text file to be parsed, I usually do it like this:

          @x = split (/\t+/,$line);

          This splits the items on the line by anything seperated by one or more tabs.
          This allows me to use 1 or more tabs in the text file so that I can line
          things up to make them easier to read.

          If you want to ignore the space it front, just throw away the first item of
          the split.

          -rjf


          > From: Tham Huei Hwan [mailto:hhtham@...]
          > Subject: [PBML] ignore white space and text
          >
          >
          > Hi all,
          >
          > How do ignore white space and also text (row and column) of the data
          > file ?
          >
          > I am using "split" function by space on building my hash array form
          > this data file.
          >
          > -- sample --
          >
          >
          > dbnum chksize freesize <--- would like to
          > ignore this
          > text, how ?
          >
          > 1 100 10
          > 2 400 50
          > 3 300 20
          > |
          > ignore white space in front, how ?
          >
          >
          > Regards,
          >
          > Tham




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

          This e-mail is sent by a law firm and may contain information that is privileged or confidential. If you are not the intended recipient, please delete the e-mail and any attachments and notify us immediately.
        • Franki
          $sc_scart_index_of_quantity = $scart{ quantity }; The line above is in a script I am working on... Now this is simple I think Does it now state that this:
          Message 4 of 7 , Feb 1, 2001
          • 0 Attachment
            $sc_scart_index_of_quantity = $scart{"quantity"};

            The line above is in a script I am working on...


            Now this is simple I think

            Does it now state that this: $sc_scart_index_of_quantity
            Is set to be equal to: $scart{"quantity"};

            I didn't think that setting a variable could possibly responsible for a
            server 500 error..

            And yet in this script, ANYTHING that is set to $scart{"quantity"};

            Like so, $some_variable = $scart{"quantity"};

            Will cause a server 500 error....

            Can anyone tell me why this could be?

            How could setting a variable be responsible for a 500 error if that variable
            doesn't exist anywhere else?

            Many thanks

            Frank Hauptle
            http://www.gshop.com.au/
            franki@...

            -----Original Message-----
            From: Foster, Russell J. [mailto:RFoster@...]
            Sent: Thursday, 1 February 2001 11:48 PM
            To: perl-beginner@yahoogroups.com
            Subject: RE: [PBML] ignore white space and text

            Tham,

            When I read in a text file to be parsed, I usually do it like this:

            @x = split (/\t+/,$line);

            This splits the items on the line by anything seperated by one or more tabs.
            This allows me to use 1 or more tabs in the text file so that I can line
            things up to make them easier to read.

            If you want to ignore the space it front, just throw away the first item of
            the split.

            -rjf


            > From: Tham Huei Hwan [mailto:hhtham@...]
            > Subject: [PBML] ignore white space and text
            >
            >
            > Hi all,
            >
            > How do ignore white space and also text (row and column) of the data
            > file ?
            >
            > I am using "split" function by space on building my hash array form
            > this data file.
            >
            > -- sample --
            >
            >
            > dbnum chksize freesize <--- would like to
            > ignore this
            > text, how ?
            >
            > 1 100 10
            > 2 400 50
            > 3 300 20
            > |
            > ignore white space in front, how ?
            >
            >
            > Regards,
            >
            > Tham




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

            This e-mail is sent by a law firm and may contain information that is
            privileged or confidential. If you are not the intended recipient, please
            delete the e-mail and any attachments and notify us immediately.
          • Charles K. Clarkson
            split /PATTERN/,EXPR,LIMIT split /PATTERN/,EXPR split /PATTERN/ split If EXPR is omitted, splits the $_ string. If PATTERN is also omitted, splits on
            Message 5 of 7 , Feb 1, 2001
            • 0 Attachment
              split /PATTERN/,EXPR,LIMIT
              split /PATTERN/,EXPR
              split /PATTERN/
              split

              If EXPR is omitted, splits the $_ string. If PATTERN is also
              omitted, splits on whitespace (after skipping any leading
              whitespace).

              HTH,
              Charles K. Clarkson



              ----- Original Message -----
              From: "Foster, Russell J." <RFoster@...>
              > Tham,
              >
              > When I read in a text file to be parsed, I usually do it like this:
              >
              > @x = split (/\t+/,$line);
              >
              > This splits the items on the line by anything seperated by one or more
              tabs.
              > This allows me to use 1 or more tabs in the text file so that I can line
              > things up to make them easier to read.
              >
              > If you want to ignore the space it front, just throw away the first item
              of
              > the split.
              >
              > -rjf
              >
              >
              > > From: Tham Huei Hwan [mailto:hhtham@...]
              > > Subject: [PBML] ignore white space and text
              > >
              > >
              > > Hi all,
              > >
              > > How do ignore white space and also text (row and column) of the data
              > > file ?
              > >
              > > I am using "split" function by space on building my hash array form
              > > this data file.
              > >
              > > -- sample --
              > >
              > >
              > > dbnum chksize freesize <--- would like to
              > > ignore this
              > > text, how ?
              > >
              > > 1 100 10
              > > 2 400 50
              > > 3 300 20
              > > |
              > > ignore white space in front, how ?
              > >
              > >
              > > Regards,
              > >
              > > Tham
              >
              >
              >
              >
              > --------------------------------------------------------------------------
              ----------------------------------
              >
              > This e-mail is sent by a law firm and may contain information that is
              privileged or confidential. If you are not the intended recipient, please
              delete the e-mail and any attachments and notify us immediately.
              >
              >
              >
              >
              >
              >
              >
            • daymobrew@yahoo.com
              Can you run the script from the command line to see what the real error is (or look in the error log)? Does the script compile okay? (run: perl -w -c
              Message 6 of 7 , Feb 1, 2001
              • 0 Attachment
                Can you run the script from the command line to see what the real
                error is (or look in the error log)?
                Does the script compile okay? (run: perl -w -c script.pl)
                What error report/message is pointing you to this line?

                --- In perl-beginner@y..., "Franki" <frankieh@v...> wrote:
                > $sc_scart_index_of_quantity = $scart{"quantity"};
                >
                > The line above is in a script I am working on...
                >
                >
                > Now this is simple I think
                >
                > Does it now state that this: $sc_scart_index_of_quantity
                > Is set to be equal to: $scart{"quantity"};
                >
                > I didn't think that setting a variable could possibly responsible
                for a
                > server 500 error..
                >
                > And yet in this script, ANYTHING that is set to $scart{"quantity"};
                >
                > Like so, $some_variable = $scart{"quantity"};
                >
                > Will cause a server 500 error....
                >
                > Can anyone tell me why this could be?
                >
                > How could setting a variable be responsible for a 500 error if that
                variable
                > doesn't exist anywhere else?
                >
                > Many thanks
                >
                > Frank Hauptle
                > http://www.gshop.com.au/
                > franki@g...
                >
                > -----Original Message-----
                > From: Foster, Russell J. [mailto:RFoster@S...]
                > Sent: Thursday, 1 February 2001 11:48 PM
                > To: perl-beginner@y...
                > Subject: RE: [PBML] ignore white space and text
                >
                > Tham,
                >
                > When I read in a text file to be parsed, I usually do it like this:
                >
                > @x = split (/\t+/,$line);
                >
                > This splits the items on the line by anything seperated by one or
                more tabs.
                > This allows me to use 1 or more tabs in the text file so that I can
                line
                > things up to make them easier to read.
                >
                > If you want to ignore the space it front, just throw away the first
                item of
                > the split.
                >
                > -rjf
                >
                >
                > > From: Tham Huei Hwan [mailto:hhtham@a...]
                > > Subject: [PBML] ignore white space and text
                > >
                > >
                > > Hi all,
                > >
                > > How do ignore white space and also text (row and column) of the
                data
                > > file ?
                > >
                > > I am using "split" function by space on building my hash array
                form
                > > this data file.
                > >
                > > -- sample --
                > >
                > >
                > > dbnum chksize freesize <--- would like to
                > > ignore this
                > > text, how ?
                > >
                > > 1 100 10
                > > 2 400 50
                > > 3 300 20
                > > |
                > > ignore white space in front, how ?
                > >
                > >
                > > Regards,
                > >
                > > Tham
                >
                >
                >
                >
                >
                ----------------------------------------------------------------------
                ------
                > --------------------------------
                >
                > This e-mail is sent by a law firm and may contain information that
                is
                > privileged or confidential. If you are not the intended recipient,
                please
                > delete the e-mail and any attachments and notify us immediately.
              • Charles K. Clarkson
                ... To ignore that specific line place this in your processing loop: while { next if /^d/i; # skip if line starts with d or D . . . . } HTH,
                Message 7 of 7 , Feb 1, 2001
                • 0 Attachment
                  > From: "Foster, Russell J." <RFoster@...>
                  > > Tham,
                  > >
                  > > When I read in a text file to be parsed, I usually do it like this:
                  > >
                  > > @x = split (/\t+/,$line);
                  > >
                  > > This splits the items on the line by anything seperated by one or more
                  > tabs.
                  > > This allows me to use 1 or more tabs in the text file so that I can line
                  > > things up to make them easier to read.
                  > >
                  > > If you want to ignore the space it front, just throw away the first item
                  > of
                  > > the split.
                  > >
                  > > -rjf
                  > >
                  > >
                  > > > From: Tham Huei Hwan [mailto:hhtham@...]
                  > > > Subject: [PBML] ignore white space and text
                  > > >
                  > > >
                  > > > Hi all,
                  > > >
                  > > > How do ignore white space and also text (row and column) of the data
                  > > > file ?
                  > > >
                  > > > I am using "split" function by space on building my hash array form
                  > > > this data file.
                  > > >
                  > > > -- sample --
                  > > >
                  > > >
                  > > > dbnum chksize freesize <--- would like to
                  > > > ignore this
                  > > > text, how ?
                  > > >
                  > > > 1 100 10
                  > > > 2 400 50
                  > > > 3 300 20
                  > > > |
                  > > > ignore white space in front, how ?
                  > > >
                  > > >

                  To ignore that specific line place this in your
                  processing loop:

                  while <DATA> {
                  next if /^d/i; # skip if line starts with 'd' or 'D'.
                  . . .
                  }

                  HTH,
                  Charles K. Clarkson
                Your message has been successfully submitted and would be delivered to recipients shortly.