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

Hi guys, I am new babie in perl. I happened to come across an issue of finding a string in 'non-regular' log file. I know how to use like if(/*/) {code} to find a string "*" in .txt file, but I could not use this to find a string in the file generated by command 'tmboot -y'. The string actually is there and I am able to use notepad++ search function to find it. so the only reason I could think of is that the file is not the regular txt file. any input? thanks!

Replies are listed 'Best First'.
Re: search a string in a non-regular file
by choroba (Cardinal) on Jul 18, 2017 at 19:48 UTC
    Asterisk has a special meaning in regular expressions. To match it literally, you need to backslash it, or enclose it in a character class.
    $ perl -e '/*/' Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HER +E / at -e line 1. $ perl -e '/\*/'

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: search a string in a non-regular file
by hippo (Archbishop) on Jul 18, 2017 at 21:14 UTC
    use strict; use warnings; use Test::More; my @good = ( '* leading asterisk', 'trailing asterisk *', 'multiple *** asterisk' ); my @bad = ( 'foo', '', '^' ); my $re = qr/\*/; plan tests => @good + @bad; for my $str (@good) { like ($str, $re, "$str matched"); } for my $str (@bad) { unlike ($str, $re, "$str not matched"); }

    See How to ask better questions using Test::More and sample data for how to write tests like this and formulate your question to fully illustrate the problem.

    I happened to come across an issue of finding a string in 'non-regular' log file.

    Define "non-regular". Do you just mean the lines have different lengths?

Re: search a string in a non-regular file
by BillKSmith (Monsignor) on Jul 18, 2017 at 20:15 UTC
    I suspect that you are having a problem with multi-line strings. A period does not match a newline (unless you use the /s flag). The anchors ^ and $ refer to beginning and end of the string, not the line (unless you specify /m)
    Bill
Re: search a string in a non-regular file
by Laurent_R (Canon) on Jul 19, 2017 at 08:13 UTC
    You've been given come interesting clues already, but the lack of details leads us to pretty much shoot in the dark.

    Please show the input for your string (i.e. the file generated by 'tmboot -y'). And also show the code you currently have and does not match your expectations (and in which sens it does not fo what you want).

Re: search a string in a non-regular file
by ytjPerl (Scribe) on Jul 19, 2017 at 17:34 UTC

    Hi guys, Thank you for all the replies. It did not work yesterday for some reason, but it works now using /*/s.

      but it works now using /*/s.

      Again a Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE / - did you read the answers above?

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
A reply falls below the community's threshold of quality. You may see it by logging in.