in reply to add new lines to output.

Your code is also missing the match operator. This snippet:

$_ =

should be changed to:

$_ =~

Otherwise you're trying to assign a value to the $_ variable.

Replies are listed 'Best First'.
Re^2: add new lines to output.
by shaludr (Initiate) on May 07, 2010 at 03:01 UTC
    I did whatever you guys said but it is not working, the error is still the same
      Suggestions above do work just fine. I made one small addition, if your are on Perl 5.10 you can use the // operator. This sets a default value of "no match" as shown below if say $4 is undefined. There aren't any write statements below so you shouldn't get your reported error anymore. You will however start getting print of undefined value warnings which the "//" avoids.

      #!/usr/bin/perl -w use strict; open (FILE,"abc345.txt") or die $!; while (<FILE>){ $_ =~ /((^Query = .*)|(^\>.*)|(Length = .*))/i; print $1 // "no match", "\n"; print $2 // "no match", "\n"; print $3 // "no match", "\n"; print $4 // "no match", "\n"; } close (FILE) ;
      For data line of: Query = 345, prints:
      Query = 345 Query = 345 no match no match
      Update: Had wrong file handle above in "while (<FILE>)". I used <DATA> to test my code and that didn't get corrected in the original post. Anyway the above code does run on my AS Perl 5.10.X machine. I had thought that perhaps something weird was happening with the "=" as that does have significance in a regex, but only in combination with for example "?=". Result is that you do not have to "escape" the = sign. Above code is fine. An escape "\" is required for these characters:  {}[]()^$.|*+?\
      Then I suggest you post your corrected program (with line numbers, so we can see what line the error refers to).

      -- 
      Ronald Fischer <ynnor@mm.st>