Professional Web Applications Themes

newbie question about regex - PERL Beginners

Hello, I call my script with the following line $ ./count.pl /var/log/file text this works fine but sometimes the "text" is "foo(bar)" and then my scripts gives an error. syntax error near unexpected token `foo(b' Could somebody give me a hint? I'm working on linux My script ---- #!/usr/bin/perl use strict; # Always use strict use warnings; # Very helpful, especially if you are new to Perl die "No argument\n" if ( ARGV == 0 ); #my $logfile = "/var/log/qmail/smtpd/rejects/00000* /var/log/qmail/smtpd/rejects/current"; my $logfile = $ARGV[0]; my $string = $ARGV[1]; my $tai_cmd = "/usr/local/bin/tai64n2tai"; my $count = 0; my $now = ...

  1. #1

    Default newbie question about regex

    Hello,

    I call my script with the following line
    $ ./count.pl /var/log/file text
    this works fine but sometimes the "text" is "foo(bar)" and then my scripts
    gives an error.
    syntax error near unexpected token `foo(b'

    Could somebody give me a hint?
    I'm working on linux

    My script
    ----
    #!/usr/bin/perl

    use strict; # Always use strict
    use warnings; # Very helpful, especially if you are new to Perl

    die "No argument\n" if ( ARGV == 0 );

    #my $logfile = "/var/log/qmail/smtpd/rejects/\4000000*
    /var/log/qmail/smtpd/rejects/current";
    my $logfile = $ARGV[0];
    my $string = $ARGV[1];
    my $tai_cmd = "/usr/local/bin/tai64n2tai";
    my $count = 0;

    my $now = time;
    my $before = $now-86400;

    # Open a file like this
    open( LOG, "cat $logfile|$tai_cmd|" ) or die "Cannot open '$logfile': $!\n";

    while( <LOG> ) {
    my $line = $_; # $_ contains the current line of LOG
    my $entrytime = substr($line,0,10);
    if ($entrytime <= $now && $entrytime >= $before) {
    ++$count if ( $line =~ m/$string/ );
    }
    }

    print "$string\n$count\n";

    ----

    with kind regards,
    Met vriendelijke groet,

    Maurice Lucas
    TAOS-IT

    Maurice Guest

  2. #2

    Default Re: newbie question about regex

    On Fri, Sep 03, 2004 at 04:33:43PM +0200, Maurice Lucas wrote: 

    That's a shell issue, not a Perl issue. Escape your brackets or
    quite your text so that bash (or sh or whatever) won't try to
    do something special with it.

    --
    David Dorward http://dorward.me.uk

    David Guest

  3. #3

    Default Re: newbie question about regex

    > Hello, 
    scripts 

    I believe the syntax error is from your shell and you can get around
    this by quoting your string to search on...

    $ ./count.pl /var/log/file 'foo(bar)'

    Should do it.

    <snip>

    http://danconia.org
    Wiggins Guest

  4. #4

    Default Re: newbie question about regex

    >> Hello, 
    > scripts 
    >
    > I believe the syntax error is from your shell and you can get around
    > this by quoting your string to search on...
    >
    > $ ./count.pl /var/log/file 'foo(bar)'
    >
    > Should do it.
    >[/ref]

    Sometimes,...
    even the most simple problems could take several hours to understand until
    you ask and somebody's gives th right answer,

    Thanks everybody for the quick and right answer

    With kind regards,

    Maurice Lucas
    TAOS-IT

    Maurice Guest

Similar Threads

  1. regex question
    By Math55 in forum PERL Beginners
    Replies: 19
    Last Post: July 21st, 06:22 PM
  2. [newbie] regex question
    By Luc in forum PHP Development
    Replies: 5
    Last Post: December 30th, 08:43 AM
  3. Another regex question
    By Sebastian in forum PHP Development
    Replies: 2
    Last Post: December 29th, 03:41 PM
  4. Newbie Regex Help
    By Jayanth in forum PERL Miscellaneous
    Replies: 13
    Last Post: October 24th, 01:59 AM
  5. Regex question...
    By Greg Bacon in forum PERL Miscellaneous
    Replies: 1
    Last Post: July 15th, 09:21 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139