Mac has asked for the wisdom of the Perl Monks concerning the following question:

Ok, I want to match a string that can possibly go over multiple lines.

Also, I want to print all lines between 23 and 56 (say...)

Also, how about printing everything between <BLAH> and </BLAH> tags? Over multiple lines..

Also, how can you get a mac address from a network pc?

code snippets?
  • Comment on A few things, mac addresses, file lines..

Replies are listed 'Best First'.
Re: A few things, mac addresses, file lines..
by tachyon (Chancellor) on Aug 09, 2001 at 05:20 UTC

    How about:

    Ok, I want to match a string that can possibly go over multiple lines.

    $string =~ m/.*/s This will match everything. You will have to be a little more precise.

    Also, I want to print all lines between 23 and 56 (say...)

    open FILE, "<$file" or "Oops Perl says $!\n"; @file = <FILE>; close FILE; print @file[22..55]; # or without glbbing in the whole file $. has line number we are at open FILE, "<$file" or "Oops Perl says $!\n"; while(<FILE>) { next if $. < 23; last if $. > 56; print; } close FILE;

    Also, how about printing everything between and tags? Over multiple lines..

    I suggest this as the best solution HTML::TokeParser Tutorial by crazyinsomniac

    Update

    Fixed array slice typo s/$/@/ Thanks abstracts

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: A few things, mac addresses, file lines..
by blakem (Monsignor) on Aug 09, 2001 at 05:22 UTC
    He helps them who help themselves....

    Hints: You might want to look at the flip flop operator. The /m and /s regex modifiers might be helpful. You might also want to check into to $. variable.

    If you get stuck after following up on these hints, let us know, but don't expect us to put more work into the answer than you have. ;-)

    -Blake