×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

matching more than one line

matching more than one line

matching more than one line

(OP)
I need to match a chunk of data that covers more than 1 line. I've tried using the //m option but I can't get it to work. The data I want to get is in the form:-

   (net (rename bypass "bypass")
      (joined
         (portRef bypass)
         (portRef IPAD (instanceRef IPAD_bypass))
         (portRef I (instanceRef IBUF_bypass))
         (portRef O (instanceRef IBUF_bypass))
         (portRef D (instanceRef FDC_bypass))


Where bypass is a variable. So I've used the match:-

           if(/\(net\s*\(rename\s* $useful/)

to match the first line where $useful has the value bypass but I need to match the whole damn lot so I can operate on it.

Actually what I want to do is cut the last two lines and paste them somewhere else but I think I'll be able to work out how to do that myself.

Thanks

Gordon Bell
gordon.bell@xilinx.com

RE: matching more than one line

I think you want to use

if(/\(net\s*\(rename\s* $useful.*/s)

'.*' at the end to pick up the remaining lines.
The 's' treats the string as a single line, ignoring  line feeds and carriage returns.

This code:

#!/usr/local/bin/perl -w
$str = "this is a \nmultiline string\nmultiline string\nmultiline string\n";
print $str;
if ($str =~ /multi.*/) { print "\n\nprint w\\o 's' - \n$&\n"; }
if ($str =~ /multi.*/s) { print "\n\nprint with 's'- \n$&\n"; }


produces this output:
this is a
multiline string
multiline string
multiline string


print w\o 's' -
multiline string


print with 's'-
multiline string
multiline string
multiline string




keep the rudder amid ship and beware the odd typo

RE: matching more than one line

(OP)
I forgot to mention that the last line mentioned is not the end of the file - will the .* not give me the whole of the remaining file?

Gordon Bell
gordon.bell@xilinx.com

RE: matching more than one line

(OP)
No - actually it doesn't give me the whole of the file - it doesn't actually give  me anything different.

 $& = (net (rename bypass "bypass")


sorry goBoating first time you haven't sorted it for me first time!!!

Thanks anyway.

Gordon Bell
gordon.bell@xilinx.com

RE: matching more than one line

so much for batting 1000.  
How can we identify the end of the string you want to match?  
Will ' (portRef D (instanceRef FDC_bypass))' always be the last line you want to catch?

If so, this works....
#!perl -w
$buffer = '(net (rename bypass "bypass")
(joined
(portRef bypass)
(portRef IPAD (instanceRef IPAD_bypass))
(portRef I (instanceRef IBUF_bypass))
(portRef O (instanceRef IBUF_bypass))
(portRef D (instanceRef FDC_bypass))
more stuff than I need here.....
and more yet.';

$useful = 'bypass';
if($buffer =~ /\(net\s*\(rename\s* $useful.*\(portRef D .*?\)\)/s)
     {
     print "matched \n$&\n";
     }


That prints......
matched
(net (rename bypass "bypass")
        (joined
        (portRef bypass)
        (portRef IPAD (instanceRef IPAD_bypass))
        (portRef I (instanceRef IBUF_bypass))
        (portRef O (instanceRef IBUF_bypass))
        (portRef D (instanceRef FDC_bypass))


If that is not consistently the last line, we will need to find some method of describing the end of what you want to keep.

'hope this helps.




keep the rudder amid ship and beware the odd typo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close