help with regular expressions

Discussion in 'Perl Misc' started by Jay, Jul 3, 2003.

  1. Jay

    Jay Guest

    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, Jul 3, 2003
    #1
    1. Advertising

  2. Jay <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jul 3, 2003
    #2
    1. Advertising

  3. Jay

    j355 Guest

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

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

    (Jay) wrote in message news:<>...
    > 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, Jul 3, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris R. Timmons

    Re: Help with regular expressions.

    Chris R. Timmons, Jul 4, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    410
    Chris R. Timmons
    Jul 4, 2003
  2. David Waz...

    Re: Help with regular expressions.

    David Waz..., Jul 4, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    398
    David Waz...
    Jul 4, 2003
  3. Stephajn Craig

    Regular Expressions....HELP!

    Stephajn Craig, Jul 16, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    3,044
    Cowboy \(Gregory A. Beamer\)
    Jul 16, 2003
  4. Jay Douglas
    Replies:
    0
    Views:
    635
    Jay Douglas
    Aug 15, 2003
  5. Noman Shapiro
    Replies:
    0
    Views:
    254
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page