plain-text file parsing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Russell Klopfer

    plain-text file parsing

    Hello. I would like to know how I can parse a plain-text file. All I
    want to do is be able to sequentially extract each word from a
    document. Similar to the StringTokenizer in Java. Is there a module
    for this? or an easy way to do it with regular expressions?

    Thanks!
  • Roger Nordqvist

    #2
    Re: plain-text file parsing

    Russell Klopfer wrote:
    [color=blue]
    > Hello. I would like to know how I can parse a plain-text file. All I
    > want to do is be able to sequentially extract each word from a
    > document. Similar to the StringTokenizer in Java. Is there a module
    > for this? or an easy way to do it with regular expressions?
    >
    > Thanks![/color]

    Dont really know what you want to do with the textfile.

    A usual way to work with file:

    open FILE, "/home/barry/text.txt" or
    die "Cant open file";

    while( $line = <FILE>)
    {
    ... do something with $line ...
    }

    close FILE;


    This parses the textfile line by line

    /Roger

    Comment

    • Jürgen Exner

      #3
      Re: plain-text file parsing

      Roger Nordqvist wrote:[color=blue]
      > Russell Klopfer wrote:[color=green]
      >> Hello. I would like to know how I can parse a plain-text file. All I
      >> want to do is be able to sequentially extract each word from a
      >> document. Similar to the StringTokenizer in Java. Is there a module
      >> for this? or an easy way to do it with regular expressions?[/color]
      >
      > Dont really know what you want to do with the textfile.
      > A usual way to work with file:
      >
      > open FILE, "/home/barry/text.txt" or
      > die "Cant open file";
      > while( $line = <FILE>)
      > {
      > ... do something with $line ...
      > }
      > close FILE;[/color]

      Actually the idiomatic Perl way would be
      while(<FILE>) {
      ... do something with $_ ...
      }

      jue


      Comment

      Working...