help with regular expressions

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default help with regular expressions

    Hello,

    just getting grips with Perl and RE, but need your help.

    I am trying to open a file, print its contents to a textbox, but
    extract certain bits of information before outputing them to the
    textbox. LAter I want to save the contents back to the same file with
    the bits added back to the file. All this done without the user even
    realising. The bits I want to take out (and put back) are always
    located at the beginning and end of each file.

    This is what I have come up with so far:

    # places a specified file into the textarea to be edited
    sub get_file
    {
    open(FILE, "< $selected_file") or die "Cannot open file\n";
    while ()($thisrow = <FILE>))
    {
    $thisrow =~ s/\<\/textarea\>/\<\*textarea\>/;
    if ($thisrow !~ m/<^TMPL_INCLUDE/)
    # "<TMPL_INCLUDE" is the string to be removed
    {
    print $thisrow;
    }
    }
    close FILE;

    This obviously doesn't work and I was wondering if any of you guys
    could shed some light to the darkness that I am experiencing.

    Thanks so much!!
    Jay Guest

  2. Similar Questions and Discussions

    1. RE : RE : Regular expressions
      I think I begin to understand... I begin by fetching the results of the ps -efA command and split it into many variables ($uid, $pid, etc.) ...
    2. PHP regular expressions
      Hello, I am writing an elearning software with php. I need a script to recognize any inut of the type ab,aabb,aaabbb,aaaabbbb..... And so on....
    3. [PHP] Q on Regular Expressions
      * Thus wrote jsWalter (jsWalter@torres.ws): have you looked at strtotime()? http://php.net/strtotime The Date formats it can find are defined...
    4. [PHP-DEV] PHP regular expressions
      Hello. In regex/utils.h there is a definition for DUPMAX: #ifdef _POSIX2_RE_DUP_MAX #define DUPMAX _POSIX2_RE_DUP_MAX #else #define DUPMAX 255...
    5. Help with regular expressions.
      Apples and Oranges: I think your format string is wrong, try: {0:d} "Pablo Pecora" <pablo.pecora@itau.com.ar> wrote in message...
  3. #2

    Default Re: help with regular expressions

    Jay <jranchordas@hotmail.com> wrote:
    > while ()($thisrow = <FILE>))

    What's with all those (unbalanced) parenthesis?

    > $thisrow =~ s/\<\/textarea\>/\<\*textarea\>/;
    ^ ^ ^ ^ ^
    ^ ^ ^ ^ ^

    What's with all those unnecessary backslashes?


    > This obviously doesn't work and I was wondering if any of you guys
    > could shed some light to the darkness that I am experiencing.

    You have a syntax error in the while statement.


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  4. #3

    Default Re: help with regular expressions

    You description is a bit vague, but you could try this for starters:

    perl -i -ne 's/foo/bar/;print if !/whatever/;' myfilename.dat

    [email]jranchordas@hotmail.com[/email] (Jay) wrote in message news:<15724ad0.0307030111.5642894c@posting.google. com>...
    > Hello,
    >
    > just getting grips with Perl and RE, but need your help.
    >
    > I am trying to open a file, print its contents to a textbox, but
    > extract certain bits of information before outputing them to the
    > textbox. LAter I want to save the contents back to the same file with
    > the bits added back to the file. All this done without the user even
    > realising. The bits I want to take out (and put back) are always
    > located at the beginning and end of each file.
    >
    > This is what I have come up with so far:
    >
    j355 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139