regex help with 'log*' in it

Discussion in 'Perl Misc' started by ebm, Mar 16, 2006.

  1. ebm

    ebm Guest

    Does anybody know who to get this to work if the $sufix has a * in it.
    Would I have to have the script do something like this?
    if ($sufix =~ /\*/) {
    if( /^\Q$prefix/ && /$sufix*$/ ) {
    print("$_ \n");
    }
    }

    Any ideas?


    # look for files
    my $sufix = '.log*'; #added for testing, normally read in from a
    config file
    my $prefix = 'blah'; #added for testing, normally read in from a
    config file

    my @files;
    opendir(LOCALLOG,$path) || die("Unable to open $path, Verify the path
    exists:$!"); #open Local Path log directory
    @files = grep {-f "$path/$_"} readdir(LOCALLOG); # get array of
    files
    close(LOCALLOG);

    foreach(@files){
    if( /^\Q$prefix/ && /$sufix$/ ) {
    print("$_ \n");
    }
    }
    ebm, Mar 16, 2006
    #1
    1. Advertising

  2. ebm wrote:
    > Does anybody know who to get this to work if the $sufix has a * in it.
    > Would I have to have the script do something like this?
    > if ($sufix =~ /\*/) {
    > if( /^\Q$prefix/ && /$sufix*$/ ) {
    > print("$_ \n");
    > }
    > }


    No, just use \Q for both the prefix and the sufix:

    if ( /^\Q$prefix\E/ && /\Q$sufix*\E$/ ) {
    print "$_\n";
    }



    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Mar 16, 2006
    #2
    1. Advertising

  3. ebm

    ebm Guest

    Re: regex help with 'log*' in it

    I tried adding the /\Q$sufix*\E$/
    and it does not pickup any of the file names.
    If I set the $sufix = '.log' I still get nothing. When I had it like
    this /^\Q$prefix\E/ && /$sufix$/ I would get my the exact make but not
    the *.

    blah20060312.log
    ebm, Mar 16, 2006
    #3
  4. ebm

    ebm Guest

    Re: regex help with 'log*' in it

    I tried it like this and I get results with $sufix = '.log' but not
    '.log*'
    /^\Q$prefix\E/ && /\Q$sufix\E$/
    ebm, Mar 16, 2006
    #4
  5. ebm

    Anno Siegel Guest

    Re: regex help with 'log*' in it

    ebm <> wrote in comp.lang.perl.misc:
    > I tried it like this and I get results with $sufix = '.log' but not
    > '.log*'
    > /^\Q$prefix\E/ && /\Q$sufix\E$/


    What are the file names you expect it to match that it doesn't? Do you
    actually have files ending in a literal asterisk?

    Anno
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
    Anno Siegel, Mar 16, 2006
    #5
  6. Re: regex help with 'log*' in it

    Anno Siegel wrote:
    > ebm <> wrote in comp.lang.perl.misc:
    > > I tried it like this and I get results with $sufix = '.log' but not
    > > '.log*'
    > > /^\Q$prefix\E/ && /\Q$sufix\E$/

    >
    > What are the file names you expect it to match that it doesn't? Do you
    > actually have files ending in a literal asterisk?



    to Anno's point, check out man ls, the -F option:

    -F Marks directories with a trailing slash (/), doors
    with a trailing greater-than sign (>), executable
    files with a trailing asterisk (*), FIFOs with a
    trailing vertical bar (|), symbolic links with a
    trailing at-sign (@), and AF_UNIX address family sock-
    ets with a trailing equals sign (=).


    ....check out your aliases...
    it_says_BALLS_on_your forehead, Mar 16, 2006
    #6
  7. ebm

    ebm Guest

    Re: regex help with 'log*' in it

    I don't expect the file name to end in * but I'm expected for the code
    to hand a requset to search for .log* (greedy wildcard)

    exYYYYMMDD.log
    exYYYYMMDD.log-other-data
    The * should try and catch this kind of stuff.

    the sufix name will be collected from a config file and I need to
    expect somebody using * to look for everything after .log
    ebm, Mar 16, 2006
    #7
  8. Re: regex help with 'log*' in it

    ebm wrote:
    > Anno Siegel wrote:
    >> ebm <> wrote in comp.lang.perl.misc:
    >>>I tried it like this and I get results with $sufix = '.log' but not
    >>>'.log*'
    >>>/^\Q$prefix\E/ && /\Q$sufix\E$/

    >>
    >> What are the file names you expect it to match that it doesn't? Do you
    >> actually have files ending in a literal asterisk?

    >
    > I don't expect the file name to end in * but I'm expected for the code
    > to hand a requset to search for .log* (greedy wildcard)
    >
    > exYYYYMMDD.log
    > exYYYYMMDD.log-other-data
    > The * should try and catch this kind of stuff.
    >
    > the sufix name will be collected from a config file and I need to
    > expect somebody using * to look for everything after .log



    $sufix = s/\*/[^.]*/;

    if ( /^\Q$prefix\E/ && /$sufix$/ ) {
    print "$_\n";
    }


    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Mar 16, 2006
    #8
  9. ebm

    Kraven Guest

    Re: regex help with 'log*' in it

    ebm wrote:
    > I don't expect the file name to end in * but I'm expected for the code
    > to hand a requset to search for .log* (greedy wildcard)
    >
    > exYYYYMMDD.log
    > exYYYYMMDD.log-other-data
    > The * should try and catch this kind of stuff.
    >
    > the sufix name will be collected from a config file and I need to
    > expect somebody using * to look for everything after .log
    >


    and now for something completely different...

    foreach $file (<$path/log*>) {
    print $file,"\n";
    }
    Kraven, Mar 17, 2006
    #9
    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. Henrik_the_boss
    Replies:
    0
    Views:
    2,627
    Henrik_the_boss
    Nov 5, 2003
  2. Amratash
    Replies:
    0
    Views:
    497
    Amratash
    Apr 13, 2004
  3. =?Utf-8?B?VG9tIFdpbmdlcnQ=?=

    My.Log.Writeexception not writing to Application Event Log.

    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=, Jan 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,352
    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=
    Jan 20, 2006
  4. unomystEz
    Replies:
    0
    Views:
    529
    unomystEz
    Nov 19, 2006
  5. Replies:
    3
    Views:
    726
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page