Loading ...
Sorry, an error occurred while loading the content.

Re: Use split

Expand Messages
  • Alexander Saydakov
    ... I guess your problem is about variable number of spaces between the months and the day depending on if the day is a single or a double digit. If so, just
    Message 1 of 15 , Apr 3, 2008
    • 0 Attachment
      --- In perl-beginner@yahoogroups.com, "perl_beg" <perl_beg@...> wrote:
      >
      > How could I split the following content on the 8th item (username)?
      > I've tried doing the split(/ /); but was not successful.
      >
      > Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25 app=unknown
      > pwd=unknown make -j app
      >

      I guess your problem is about variable number of spaces between the
      months and the day depending on if the day is a single or a double digit.

      If so, just split on whitespace: split(' ', $str) or split(/\s+/, $str)
      instead of exactly one space: split(/ /, $str)

      /sandy
      http://myperlquiz.com/
    • PRAVEEN CHAUHAN
      Hi, You can also use array concept. Below is the scipt. #!/usr/bin/perl print Hello, World... n n n ; my $str= Thu Apr 3 16:15:11 2008 started 18411 user 1
      Message 2 of 15 , Apr 3, 2008
      • 0 Attachment
        Hi,

        You can also use array concept. Below is the scipt.


        #!/usr/bin/perl
        print "Hello, World...\n\n\n";
        my $str="Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25
        app=unknown pwd=unknown make -j app";
        my @array=split(" ",$str);
        my (@array1,@array2)=();
        print "\n Split input by space and store in array: @array\n\n\n";

        for (my $c=0;$c<7 ;$c++)
        {
        $array1[$c]=$array[$c];
        }

        for ($c=7,my $cc=0;$c<15 ;$c++,$cc++)
        {
        $array2[$cc]=$array[$c];
        }

        print "\n\n\n\t Now array split in two array \n\n\n";
        print "Output of Array1: @array1\n\n\n";
        print "Output of Array2: @array2\n\n\n";



        Thanks
        Praveen
        Delhi(India)



        --- In perl-beginner@yahoogroups.com, "perl_beg" <perl_beg@...>
        wrote:
        >
        > How could I split the following content on the 8th item
        (username)?
        > I've tried doing the split(/ /); but was not successful.
        >
        > Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25 app=unknown
        > pwd=unknown make -j app
        >
        > Any help would be appreciated.
        >
      • perl_beg
        Hi Sandy, thanks for the reply which was very helpful. How can I grab just the user name? Would this work? $u_count = split(/ s+/) [7]; ... (username)? ...
        Message 3 of 15 , Apr 4, 2008
        • 0 Attachment
          Hi Sandy, thanks for the reply which was very helpful. How can I
          grab just the user name?

          Would this work?

          $u_count = split(/\s+/) [7];

          --- In perl-beginner@yahoogroups.com, "Alexander Saydakov"
          <sandy_saydakov@...> wrote:
          >
          > --- In perl-beginner@yahoogroups.com, "perl_beg" <perl_beg@> wrote:
          > >
          > > How could I split the following content on the 8th item
          (username)?
          > > I've tried doing the split(/ /); but was not successful.
          > >
          > > Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25
          app=unknown
          > > pwd=unknown make -j app
          > >
          >
          > I guess your problem is about variable number of spaces between the
          > months and the day depending on if the day is a single or a double
          digit.
          >
          > If so, just split on whitespace: split(' ', $str) or split(/\s+/,
          $str)
          > instead of exactly one space: split(/ /, $str)
          >
          > /sandy
          > http://myperlquiz.com/
          >
        • david wright
          ... generally, a perl programmer would prefer something to the affect of: my $str= Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25 app=unknown
          Message 4 of 15 , Apr 4, 2008
          • 0 Attachment
            > You can also use array concept.
            >
            > for (my $c=0;$c<7 ;$c++)
            > {
            > $array1[$c]=$array[$c];
            > }
            > ...

            generally, a perl programmer would prefer something to the affect of:

            my $str='Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25 app=unknown pwd=unknown make -j app';

            push(my @tokes, split(/\s+/, $str));

            or:
            my @tokes = map{ split(/\s+/, $_) } $str;

            or:
            my @tokes = map{ split } $str;

            use Data::Dumper;
            #print Dumper \@tokes;
            print $tokes[7];


            +Dave


            --- On Fri, 4/4/08, PRAVEEN CHAUHAN <best_praveen2006@...> wrote:

            > From: PRAVEEN CHAUHAN <best_praveen2006@...>
            > Subject: [PBML] Re: Use split
            > To: perl-beginner@yahoogroups.com
            > Date: Friday, April 4, 2008, 1:54 AM
            > Hi,
            >
            > You can also use array concept. Below is the scipt.
            >
            >
            > #!/usr/bin/perl
            > print "Hello, World...\n\n\n";
            > my $str="Thu Apr 3 16:15:11 2008 started 18411 user 1
            > 16:14:25
            > app=unknown pwd=unknown make -j app";
            > my @array=split(" ",$str);
            > my (@array1,@array2)=();
            > print "\n Split input by space and store in array:
            > @array\n\n\n";
            >
            > for (my $c=0;$c<7 ;$c++)
            > {
            > $array1[$c]=$array[$c];
            > }
            >
            > for ($c=7,my $cc=0;$c<15 ;$c++,$cc++)
            > {
            > $array2[$cc]=$array[$c];
            > }
            >
            > print "\n\n\n\t Now array split in two
            > array \n\n\n";
            > print "Output of Array1:
            > @array1\n\n\n";
            > print "Output of Array2:
            > @array2\n\n\n";
            >
            >
            >
            > Thanks
            > Praveen
            > Delhi(India)
            >
            >
            >
            > --- In perl-beginner@yahoogroups.com, "perl_beg"
            > <perl_beg@...>
            > wrote:
            > >
            > > How could I split the following content on the 8th
            > item
            > (username)?
            > > I've tried doing the split(/ /); but was not
            > successful.
            > >
            > > Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25
            > app=unknown
            > > pwd=unknown make -j app
            > >
            > > Any help would be appreciated.
            > >
            >
            >
            >
            > ------------------------------------
            >
            > Unsubscribing info is here:
            > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
            > Groups Links
            >
            >
            >
          • Alexander Saydakov
            ... Are you after the substring user in your example string (token #8 with index 7) or after the next token 1 (#9 with index 8)? my $str = Thu Apr 3
            Message 5 of 15 , Apr 4, 2008
            • 0 Attachment
              --- In perl-beginner@yahoogroups.com, "perl_beg" <perl_beg@...> wrote:
              >
              > Hi Sandy, thanks for the reply which was very helpful. How can I
              > grab just the user name?
              >
              > Would this work?
              >
              > $u_count = split(/\s+/) [7];

              Are you after the substring 'user' in your example string (token #8
              with index 7) or after the next token '1' (#9 with index 8)?

              my $str = 'Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25
              app=unknown pwd=unknown make -j app';

              my $user = (split(/\s+/, $str))[7];
              print "$user\n";

              This prints 'user'

              /sandy
              http://myperlquiz.com/
            • perl_beg
              Hi Dave, yeah I would say I m no where near a programmer just do basic scripts. Here is what I m trying to do. I m using a hash so I don t get duplicate names
              Message 6 of 15 , Apr 7, 2008
              • 0 Attachment
                Hi Dave, yeah I would say I'm no where near a programmer just do
                basic scripts. Here is what I'm trying to do. I'm using a hash so I
                don't get duplicate names when I print off usernames that I pull
                from the log file.

                #!/usr/bin/perl -w

                %u_count = ();

                open (LOG,"cat /var/log/app.log | egrep ' -j ' | egrep -v ' -j [0-
                9]' | grep start|") || die "Cannot open file";
                while (<LOG>) {
                chomp();
                @_ = split(/\s+/,7);
                $u_count{$_}++;
                }

                @users = sort keys %u_count;

                foreach $user (@users) {
                print "$user\n";
                }



                --- In perl-beginner@yahoogroups.com, david wright
                <david_v_wright@...> wrote:
                >
                > > You can also use array concept.
                > >
                > > for (my $c=0;$c<7 ;$c++)
                > > {
                > > $array1[$c]=$array[$c];
                > > }
                > > ...
                >
                > generally, a perl programmer would prefer something to the affect
                of:
                >
                > my $str='Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25
                app=unknown pwd=unknown make -j app';
                >
                > push(my @tokes, split(/\s+/, $str));
                >
                > or:
                > my @tokes = map{ split(/\s+/, $_) } $str;
                >
                > or:
                > my @tokes = map{ split } $str;
                >
                > use Data::Dumper;
                > #print Dumper \@tokes;
                > print $tokes[7];
                >
                >
                > +Dave
                >
                >
                > --- On Fri, 4/4/08, PRAVEEN CHAUHAN <best_praveen2006@...> wrote:
                >
                > > From: PRAVEEN CHAUHAN <best_praveen2006@...>
                > > Subject: [PBML] Re: Use split
                > > To: perl-beginner@yahoogroups.com
                > > Date: Friday, April 4, 2008, 1:54 AM
                > > Hi,
                > >
                > > You can also use array concept. Below is the scipt.
                > >
                > >
                > > #!/usr/bin/perl
                > > print "Hello, World...\n\n\n";
                > > my $str="Thu Apr 3 16:15:11 2008 started 18411 user 1
                > > 16:14:25
                > > app=unknown pwd=unknown make -j app";
                > > my @array=split(" ",$str);
                > > my (@array1,@array2)=();
                > > print "\n Split input by space and store in array:
                > > @array\n\n\n";
                > >
                > > for (my $c=0;$c<7 ;$c++)
                > > {
                > > $array1[$c]=$array[$c];
                > > }
                > >
                > > for ($c=7,my $cc=0;$c<15 ;$c++,$cc++)
                > > {
                > > $array2[$cc]=$array[$c];
                > > }
                > >
                > > print "\n\n\n\t Now array split in two
                > > array \n\n\n";
                > > print "Output of Array1:
                > > @array1\n\n\n";
                > > print "Output of Array2:
                > > @array2\n\n\n";
                > >
                > >
                > >
                > > Thanks
                > > Praveen
                > > Delhi(India)
                > >
                > >
                > >
                > > --- In perl-beginner@yahoogroups.com, "perl_beg"
                > > <perl_beg@>
                > > wrote:
                > > >
                > > > How could I split the following content on the 8th
                > > item
                > > (username)?
                > > > I've tried doing the split(/ /); but was not
                > > successful.
                > > >
                > > > Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25
                > > app=unknown
                > > > pwd=unknown make -j app
                > > >
                > > > Any help would be appreciated.
                > > >
                > >
                > >
                > >
                > > ------------------------------------
                > >
                > > Unsubscribing info is here:
                > > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                > > Groups Links
                > >
                > >
                > >
                >
              • perl_beg
                Hi Dave, yeah I would say I m no where near a programmer just do basic scripts. Here is what I m trying to do. I m using a hash so I don t get duplicate names
                Message 7 of 15 , Apr 7, 2008
                • 0 Attachment
                  Hi Dave, yeah I would say I'm no where near a programmer just do
                  basic scripts. Here is what I'm trying to do. I'm using a hash so I
                  don't get duplicate names when I print off usernames that I pull
                  from the log file.

                  #!/usr/bin/perl -w

                  %u_count = ();

                  open (LOG,"cat /var/log/app.log | egrep ' -j ' | egrep -v ' -j [0-
                  9]' | grep start|") || die "Cannot open file";
                  while (<LOG>) {
                  chomp();
                  @_ = split(/\s+/,7);
                  $u_count{$_}++;
                  }

                  @users = sort keys %u_count;

                  foreach $user (@users) {
                  print "$user\n";
                  }



                  --- In perl-beginner@yahoogroups.com, david wright
                  <david_v_wright@...> wrote:
                  >
                  > > You can also use array concept.
                  > >
                  > > for (my $c=0;$c<7 ;$c++)
                  > > {
                  > > $array1[$c]=$array[$c];
                  > > }
                  > > ...
                  >
                  > generally, a perl programmer would prefer something to the affect
                  of:
                  >
                  > my $str='Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25
                  app=unknown pwd=unknown make -j app';
                  >
                  > push(my @tokes, split(/\s+/, $str));
                  >
                  > or:
                  > my @tokes = map{ split(/\s+/, $_) } $str;
                  >
                  > or:
                  > my @tokes = map{ split } $str;
                  >
                  > use Data::Dumper;
                  > #print Dumper \@tokes;
                  > print $tokes[7];
                  >
                  >
                  > +Dave
                  >
                  >
                  > --- On Fri, 4/4/08, PRAVEEN CHAUHAN <best_praveen2006@...> wrote:
                  >
                  > > From: PRAVEEN CHAUHAN <best_praveen2006@...>
                  > > Subject: [PBML] Re: Use split
                  > > To: perl-beginner@yahoogroups.com
                  > > Date: Friday, April 4, 2008, 1:54 AM
                  > > Hi,
                  > >
                  > > You can also use array concept. Below is the scipt.
                  > >
                  > >
                  > > #!/usr/bin/perl
                  > > print "Hello, World...\n\n\n";
                  > > my $str="Thu Apr 3 16:15:11 2008 started 18411 user 1
                  > > 16:14:25
                  > > app=unknown pwd=unknown make -j app";
                  > > my @array=split(" ",$str);
                  > > my (@array1,@array2)=();
                  > > print "\n Split input by space and store in array:
                  > > @array\n\n\n";
                  > >
                  > > for (my $c=0;$c<7 ;$c++)
                  > > {
                  > > $array1[$c]=$array[$c];
                  > > }
                  > >
                  > > for ($c=7,my $cc=0;$c<15 ;$c++,$cc++)
                  > > {
                  > > $array2[$cc]=$array[$c];
                  > > }
                  > >
                  > > print "\n\n\n\t Now array split in two
                  > > array \n\n\n";
                  > > print "Output of Array1:
                  > > @array1\n\n\n";
                  > > print "Output of Array2:
                  > > @array2\n\n\n";
                  > >
                  > >
                  > >
                  > > Thanks
                  > > Praveen
                  > > Delhi(India)
                  > >
                  > >
                  > >
                  > > --- In perl-beginner@yahoogroups.com, "perl_beg"
                  > > <perl_beg@>
                  > > wrote:
                  > > >
                  > > > How could I split the following content on the 8th
                  > > item
                  > > (username)?
                  > > > I've tried doing the split(/ /); but was not
                  > > successful.
                  > > >
                  > > > Thu Apr 3 16:15:11 2008 started 18411 user 1 16:14:25
                  > > app=unknown
                  > > > pwd=unknown make -j app
                  > > >
                  > > > Any help would be appreciated.
                  > > >
                  > >
                  > >
                  > >
                  > > ------------------------------------
                  > >
                  > > Unsubscribing info is here:
                  > > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                  > > Groups Links
                  > >
                  > >
                  > >
                  >
                • david wright
                  Hello perl_beg, I would offer the following suggestions for approaching your task It seems unnecessary in this case to open a pipe to perl open from shell
                  Message 8 of 15 , Apr 8, 2008
                  • 0 Attachment
                    Hello perl_beg,

                    I would offer the following suggestions for approaching your task

                    It seems unnecessary in this case to open a pipe to perl open from shell commands

                    I'm not sure what '/var/log/app.log' looks like but if it's a tab delimited and 'users' is your 7th column, you could use shell commands alone, something such as:

                    awk '{print $7}' | sort | uniq -c | sort -nr

                    however since this is a perl list, lets look at that.


                    just open the file directly:

                    > open (LOG,"cat /var/log/app.log | egrep ' -j ' | egrep -v ' -j [0-
                    9]' | grep start|") || die "Cannot open file";

                    open my $log,'<', '/var/log/app.log' || die "Cannot open file $!";

                    > @_ = split(/\s+/,7);

                    I think you want something like,

                    my $user = (split(/\s+/, $_))[7];
                    $u_count{$user}++;

                    from:
                    perldoc -f split
                    split /PATTERN/,EXPR,LIMIT

                    also I would add use strict; in the beginning of your script.

                    other than that it looks like your on the right track, good work, keep it up :)

                    +Dave



                    --- On Mon, 4/7/08, perl_beg <perl_beg@...> wrote:

                    > From: perl_beg <perl_beg@...>
                    > Subject: [PBML] Re: Use split
                    > To: perl-beginner@yahoogroups.com
                    > Date: Monday, April 7, 2008, 2:17 PM
                    > Hi Dave, yeah I would say I'm no where near a programmer
                    > just do
                    > basic scripts. Here is what I'm trying to do. I'm
                    > using a hash so I
                    > don't get duplicate names when I print off usernames
                    > that I pull
                    > from the log file.
                    >
                    > #!/usr/bin/perl -w
                    >
                    > %u_count = ();
                    >
                    > open (LOG,"cat /var/log/app.log | egrep ' -j '
                    > | egrep -v ' -j [0-
                    > 9]' | grep start|") || die "Cannot open
                    > file";
                    > while (<LOG>) {
                    > chomp();
                    > @_ = split(/\s+/,7);
                    > $u_count{$_}++;
                    > }
                    >
                    > @users = sort keys %u_count;
                    >
                    > foreach $user (@users) {
                    > print "$user\n";
                    > }
                    >
                    >
                    >
                    > --- In perl-beginner@yahoogroups.com, david wright
                    > <david_v_wright@...> wrote:
                    > >
                    > > > You can also use array concept.
                    > > >
                    > > > for (my $c=0;$c<7 ;$c++)
                    > > > {
                    > > > $array1[$c]=$array[$c];
                    > > > }
                    > > > ...
                    > >
                    > > generally, a perl programmer would prefer something to
                    > the affect
                    > of:
                    > >
                    > > my $str='Thu Apr 3 16:15:11 2008 started 18411
                    > user 1 16:14:25
                    > app=unknown pwd=unknown make -j app';
                    > >
                    > > push(my @tokes, split(/\s+/, $str));
                    > >
                    > > or:
                    > > my @tokes = map{ split(/\s+/, $_) } $str;
                    > >
                    > > or:
                    > > my @tokes = map{ split } $str;
                    > >
                    > > use Data::Dumper;
                    > > #print Dumper \@tokes;
                    > > print $tokes[7];
                    > >
                    > >
                    > > +Dave
                    > >
                    > >
                    > > --- On Fri, 4/4/08, PRAVEEN CHAUHAN
                    > <best_praveen2006@...> wrote:
                    > >
                    > > > From: PRAVEEN CHAUHAN
                    > <best_praveen2006@...>
                    > > > Subject: [PBML] Re: Use split
                    > > > To: perl-beginner@yahoogroups.com
                    > > > Date: Friday, April 4, 2008, 1:54 AM
                    > > > Hi,
                    > > >
                    > > > You can also use array concept. Below is the
                    > scipt.
                    > > >
                    > > >
                    > > > #!/usr/bin/perl
                    > > > print "Hello,
                    > World...\n\n\n";
                    > > > my $str="Thu Apr 3 16:15:11 2008 started
                    > 18411 user 1
                    > > > 16:14:25
                    > > > app=unknown pwd=unknown make -j app";
                    > > > my @array=split(" ",$str);
                    > > > my (@array1,@array2)=();
                    > > > print "\n Split input by space and store
                    > in array:
                    > > > @array\n\n\n";
                    > > >
                    > > > for (my $c=0;$c<7 ;$c++)
                    > > > {
                    > > > $array1[$c]=$array[$c];
                    > > > }
                    > > >
                    > > > for ($c=7,my $cc=0;$c<15 ;$c++,$cc++)
                    > > > {
                    > > > $array2[$cc]=$array[$c];
                    > > > }
                    > > >
                    > > > print "\n\n\n\t Now array
                    > split in two
                    > > > array \n\n\n";
                    > > > print "Output of Array1:
                    > > > @array1\n\n\n";
                    > > > print "Output of Array2:
                    > > > @array2\n\n\n";
                    > > >
                    > > >
                    > > >
                    > > > Thanks
                    > > > Praveen
                    > > > Delhi(India)
                    > > >
                    > > >
                    > > >
                    > > > --- In perl-beginner@yahoogroups.com,
                    > "perl_beg"
                    > > > <perl_beg@>
                    > > > wrote:
                    > > > >
                    > > > > How could I split the following content on
                    > the 8th
                    > > > item
                    > > > (username)?
                    > > > > I've tried doing the split(/ /); but was
                    > not
                    > > > successful.
                    > > > >
                    > > > > Thu Apr 3 16:15:11 2008 started 18411 user
                    > 1 16:14:25
                    > > > app=unknown
                    > > > > pwd=unknown make -j app
                    > > > >
                    > > > > Any help would be appreciated.
                    > > > >
                    > > >
                    > > >
                    > > >
                    > > > ------------------------------------
                    > > >
                    > > > Unsubscribing info is here:
                    > > >
                    > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                    > > > Groups Links
                    > > >
                    > > >
                    > > >
                    > >
                    >
                    >
                    >
                    > ------------------------------------
                    >
                    > Unsubscribing info is here:
                    > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                    > Groups Links
                    >
                    >
                    >
                  • perl_beg
                    Hi Dave, I want to use the open with a while loop to grep certain strings out of this log file because it s massive and those are the only usernames I want.
                    Message 9 of 15 , Apr 11, 2008
                    • 0 Attachment
                      Hi Dave, I want to use the open with a while loop to grep certain
                      strings out of this log file because it's massive and those are the
                      only usernames I want. Otherwise I'm grabbing useless info.

                      Your suggestions worked and I now have a working script. Few
                      questions. What if I wanted to grab more than just the 7th column?
                      Would that involve a lot more work or could I just do [2,3,7] in my
                      syntax;?

                      perl_beg

                      --- In perl-beginner@yahoogroups.com, david wright
                      <david_v_wright@...> wrote:
                      >
                      > Hello perl_beg,
                      >
                      > I would offer the following suggestions for approaching your task
                      >
                      > It seems unnecessary in this case to open a pipe to perl open from
                      shell commands
                      >
                      > I'm not sure what '/var/log/app.log' looks like but if it's a tab
                      delimited and 'users' is your 7th column, you could use shell
                      commands alone, something such as:
                      >
                      > awk '{print $7}' | sort | uniq -c | sort -nr
                      >
                      > however since this is a perl list, lets look at that.
                      >
                      >
                      > just open the file directly:
                      >
                      > > open (LOG,"cat /var/log/app.log | egrep ' -j ' | egrep -v ' -j
                      [0-
                      > 9]' | grep start|") || die "Cannot open file";
                      >
                      > open my $log,'<', '/var/log/app.log' || die "Cannot open file $!";
                      >
                      > > @_ = split(/\s+/,7);
                      >
                      > I think you want something like,
                      >
                      > my $user = (split(/\s+/, $_))[7];
                      > $u_count{$user}++;
                      >
                      > from:
                      > perldoc -f split
                      > split /PATTERN/,EXPR,LIMIT
                      >
                      > also I would add use strict; in the beginning of your script.
                      >
                      > other than that it looks like your on the right track, good work,
                      keep it up :)
                      >
                      > +Dave
                      >
                      >
                      >
                      > --- On Mon, 4/7/08, perl_beg <perl_beg@...> wrote:
                      >
                      > > From: perl_beg <perl_beg@...>
                      > > Subject: [PBML] Re: Use split
                      > > To: perl-beginner@yahoogroups.com
                      > > Date: Monday, April 7, 2008, 2:17 PM
                      > > Hi Dave, yeah I would say I'm no where near a programmer
                      > > just do
                      > > basic scripts. Here is what I'm trying to do. I'm
                      > > using a hash so I
                      > > don't get duplicate names when I print off usernames
                      > > that I pull
                      > > from the log file.
                      > >
                      > > #!/usr/bin/perl -w
                      > >
                      > > %u_count = ();
                      > >
                      > > open (LOG,"cat /var/log/app.log | egrep ' -j '
                      > > | egrep -v ' -j [0-
                      > > 9]' | grep start|") || die "Cannot open
                      > > file";
                      > > while (<LOG>) {
                      > > chomp();
                      > > @_ = split(/\s+/,7);
                      > > $u_count{$_}++;
                      > > }
                      > >
                      > > @users = sort keys %u_count;
                      > >
                      > > foreach $user (@users) {
                      > > print "$user\n";
                      > > }
                      > >
                      > >
                      > >
                      > > --- In perl-beginner@yahoogroups.com, david wright
                      > > <david_v_wright@> wrote:
                      > > >
                      > > > > You can also use array concept.
                      > > > >
                      > > > > for (my $c=0;$c<7 ;$c++)
                      > > > > {
                      > > > > $array1[$c]=$array[$c];
                      > > > > }
                      > > > > ...
                      > > >
                      > > > generally, a perl programmer would prefer something to
                      > > the affect
                      > > of:
                      > > >
                      > > > my $str='Thu Apr 3 16:15:11 2008 started 18411
                      > > user 1 16:14:25
                      > > app=unknown pwd=unknown make -j app';
                      > > >
                      > > > push(my @tokes, split(/\s+/, $str));
                      > > >
                      > > > or:
                      > > > my @tokes = map{ split(/\s+/, $_) } $str;
                      > > >
                      > > > or:
                      > > > my @tokes = map{ split } $str;
                      > > >
                      > > > use Data::Dumper;
                      > > > #print Dumper \@tokes;
                      > > > print $tokes[7];
                      > > >
                      > > >
                      > > > +Dave
                      > > >
                      > > >
                      > > > --- On Fri, 4/4/08, PRAVEEN CHAUHAN
                      > > <best_praveen2006@> wrote:
                      > > >
                      > > > > From: PRAVEEN CHAUHAN
                      > > <best_praveen2006@>
                      > > > > Subject: [PBML] Re: Use split
                      > > > > To: perl-beginner@yahoogroups.com
                      > > > > Date: Friday, April 4, 2008, 1:54 AM
                      > > > > Hi,
                      > > > >
                      > > > > You can also use array concept. Below is the
                      > > scipt.
                      > > > >
                      > > > >
                      > > > > #!/usr/bin/perl
                      > > > > print "Hello,
                      > > World...\n\n\n";
                      > > > > my $str="Thu Apr 3 16:15:11 2008 started
                      > > 18411 user 1
                      > > > > 16:14:25
                      > > > > app=unknown pwd=unknown make -j app";
                      > > > > my @array=split(" ",$str);
                      > > > > my (@array1,@array2)=();
                      > > > > print "\n Split input by space and store
                      > > in array:
                      > > > > @array\n\n\n";
                      > > > >
                      > > > > for (my $c=0;$c<7 ;$c++)
                      > > > > {
                      > > > > $array1[$c]=$array[$c];
                      > > > > }
                      > > > >
                      > > > > for ($c=7,my $cc=0;$c<15 ;$c++,$cc++)
                      > > > > {
                      > > > > $array2[$cc]=$array[$c];
                      > > > > }
                      > > > >
                      > > > > print "\n\n\n\t Now array
                      > > split in two
                      > > > > array \n\n\n";
                      > > > > print "Output of Array1:
                      > > > > @array1\n\n\n";
                      > > > > print "Output of Array2:
                      > > > > @array2\n\n\n";
                      > > > >
                      > > > >
                      > > > >
                      > > > > Thanks
                      > > > > Praveen
                      > > > > Delhi(India)
                      > > > >
                      > > > >
                      > > > >
                      > > > > --- In perl-beginner@yahoogroups.com,
                      > > "perl_beg"
                      > > > > <perl_beg@>
                      > > > > wrote:
                      > > > > >
                      > > > > > How could I split the following content on
                      > > the 8th
                      > > > > item
                      > > > > (username)?
                      > > > > > I've tried doing the split(/ /); but was
                      > > not
                      > > > > successful.
                      > > > > >
                      > > > > > Thu Apr 3 16:15:11 2008 started 18411 user
                      > > 1 16:14:25
                      > > > > app=unknown
                      > > > > > pwd=unknown make -j app
                      > > > > >
                      > > > > > Any help would be appreciated.
                      > > > > >
                      > > > >
                      > > > >
                      > > > >
                      > > > > ------------------------------------
                      > > > >
                      > > > > Unsubscribing info is here:
                      > > > >
                      > > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                      > > > > Groups Links
                      > > > >
                      > > > >
                      > > > >
                      > > >
                      > >
                      > >
                      > >
                      > > ------------------------------------
                      > >
                      > > Unsubscribing info is here:
                      > > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                      > > Groups Links
                      > >
                      > >
                      > >
                      >
                    • merlyn@stonehenge.com
                      ... perl open (LOG, cat /var/log/app.log | egrep -j | egrep -v -j [0- perl 9] | grep start| ) || die Cannot open file ; Aha! A useless use of cat .
                      Message 10 of 15 , Apr 11, 2008
                      • 0 Attachment
                        >>>>> "perl" == perl beg <perl_beg@...> writes:

                        perl> open (LOG,"cat /var/log/app.log | egrep ' -j ' | egrep -v ' -j [0-
                        perl> 9]' | grep start|") || die "Cannot open file";

                        Aha! A "useless use of cat". If this had been a posting to
                        comp.unix.questions, I would have issued you a "useless use of cat" award.

                        --
                        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
                        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
                        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
                      • david wright
                        ... did you try it? ;) my ($col3,$col4,$user) = (split(/ s+/, $str))[2,3,7]; perl is a great language for learning by trying stuff, feel free to experiment.
                        Message 11 of 15 , Apr 13, 2008
                        • 0 Attachment
                          > What if I wanted to grab more than just the 7th
                          > column?
                          > Would that involve a lot more work or could I just do
                          > [2,3,7] in my
                          > syntax;?
                          >

                          did you try it? ;)

                          my ($col3,$col4,$user) = (split(/\s+/, $str))[2,3,7];

                          perl is a great language for learning by trying stuff, feel free to experiment.

                          +Dave

                          > --- In perl-beginner@yahoogroups.com, david wright
                          > <david_v_wright@...> wrote:
                          > >
                          > > Hello perl_beg,
                          > >
                          > > I would offer the following suggestions for
                          > approaching your task
                          > >
                          > > It seems unnecessary in this case to open a pipe to
                          > perl open from
                          > shell commands
                          > >
                          > > I'm not sure what '/var/log/app.log' looks
                          > like but if it's a tab
                          > delimited and 'users' is your 7th column, you could
                          > use shell
                          > commands alone, something such as:
                          > >
                          > > awk '{print $7}' | sort | uniq -c | sort -nr
                          > >
                          > > however since this is a perl list, lets look at that.
                          > >
                          > >
                          > > just open the file directly:
                          > >
                          > > > open (LOG,"cat /var/log/app.log | egrep
                          > ' -j ' | egrep -v ' -j
                          > [0-
                          > > 9]' | grep start|") || die "Cannot open
                          > file";
                          > >
                          > > open my $log,'<',
                          > '/var/log/app.log' || die "Cannot open file
                          > $!";
                          > >
                          > > > @_ = split(/\s+/,7);
                          > >
                          > > I think you want something like,
                          > >
                          > > my $user = (split(/\s+/, $_))[7];
                          > > $u_count{$user}++;
                          > >
                          > > from:
                          > > perldoc -f split
                          > > split /PATTERN/,EXPR,LIMIT
                          > >
                          > > also I would add use strict; in the beginning of your
                          > script.
                          > >
                          > > other than that it looks like your on the right track,
                          > good work,
                          > keep it up :)
                          > >
                          > > +Dave
                          > >
                          > >
                          > >
                          > > --- On Mon, 4/7/08, perl_beg <perl_beg@...>
                          > wrote:
                          > >
                          > > > From: perl_beg <perl_beg@...>
                          > > > Subject: [PBML] Re: Use split
                          > > > To: perl-beginner@yahoogroups.com
                          > > > Date: Monday, April 7, 2008, 2:17 PM
                          > > > Hi Dave, yeah I would say I'm no where near a
                          > programmer
                          > > > just do
                          > > > basic scripts. Here is what I'm trying to do.
                          > I'm
                          > > > using a hash so I
                          > > > don't get duplicate names when I print off
                          > usernames
                          > > > that I pull
                          > > > from the log file.
                          > > >
                          > > > #!/usr/bin/perl -w
                          > > >
                          > > > %u_count = ();
                          > > >
                          > > > open (LOG,"cat /var/log/app.log | egrep
                          > ' -j '
                          > > > | egrep -v ' -j [0-
                          > > > 9]' | grep start|") || die "Cannot
                          > open
                          > > > file";
                          > > > while (<LOG>) {
                          > > > chomp();
                          > > > @_ = split(/\s+/,7);
                          > > > $u_count{$_}++;
                          > > > }
                          > > >
                          > > > @users = sort keys %u_count;
                          > > >
                          > > > foreach $user (@users) {
                          > > > print "$user\n";
                          > > > }
                          > > >
                          > > >
                          > > >
                          > > > --- In perl-beginner@yahoogroups.com, david
                          > wright
                          > > > <david_v_wright@> wrote:
                          > > > >
                          > > > > > You can also use array concept.
                          > > > > >
                          > > > > > for (my $c=0;$c<7 ;$c++)
                          > > > > > {
                          > > > > > $array1[$c]=$array[$c];
                          > > > > > }
                          > > > > > ...
                          > > > >
                          > > > > generally, a perl programmer would prefer
                          > something to
                          > > > the affect
                          > > > of:
                          > > > >
                          > > > > my $str='Thu Apr 3 16:15:11 2008
                          > started 18411
                          > > > user 1 16:14:25
                          > > > app=unknown pwd=unknown make -j app';
                          > > > >
                          > > > > push(my @tokes, split(/\s+/, $str));
                          > > > >
                          > > > > or:
                          > > > > my @tokes = map{ split(/\s+/, $_) }
                          > $str;
                          > > > >
                          > > > > or:
                          > > > > my @tokes = map{ split } $str;
                          > > > >
                          > > > > use Data::Dumper;
                          > > > > #print Dumper \@tokes;
                          > > > > print $tokes[7];
                          > > > >
                          > > > >
                          > > > > +Dave
                          > > > >
                          > > > >
                          > > > > --- On Fri, 4/4/08, PRAVEEN CHAUHAN
                          > > > <best_praveen2006@> wrote:
                          > > > >
                          > > > > > From: PRAVEEN CHAUHAN
                          > > > <best_praveen2006@>
                          > > > > > Subject: [PBML] Re: Use split
                          > > > > > To: perl-beginner@yahoogroups.com
                          > > > > > Date: Friday, April 4, 2008, 1:54 AM
                          > > > > > Hi,
                          > > > > >
                          > > > > > You can also use array concept. Below
                          > is the
                          > > > scipt.
                          > > > > >
                          > > > > >
                          > > > > > #!/usr/bin/perl
                          > > > > > print "Hello,
                          > > > World...\n\n\n";
                          > > > > > my $str="Thu Apr 3 16:15:11 2008
                          > started
                          > > > 18411 user 1
                          > > > > > 16:14:25
                          > > > > > app=unknown pwd=unknown make -j
                          > app";
                          > > > > > my @array=split(" ",$str);
                          > > > > > my (@array1,@array2)=();
                          > > > > > print "\n Split input by space
                          > and store
                          > > > in array:
                          > > > > > @array\n\n\n";
                          > > > > >
                          > > > > > for (my $c=0;$c<7 ;$c++)
                          > > > > > {
                          > > > > > $array1[$c]=$array[$c];
                          > > > > > }
                          > > > > >
                          > > > > > for ($c=7,my $cc=0;$c<15
                          > ;$c++,$cc++)
                          > > > > > {
                          > > > > > $array2[$cc]=$array[$c];
                          > > > > > }
                          > > > > >
                          > > > > > print "\n\n\n\t
                          > Now array
                          > > > split in two
                          > > > > > array \n\n\n";
                          > > > > > print "Output of Array1:
                          > > > > > @array1\n\n\n";
                          > > > > > print "Output of Array2:
                          > > > > > @array2\n\n\n";
                          > > > > >
                          > > > > >
                          > > > > >
                          > > > > > Thanks
                          > > > > > Praveen
                          > > > > > Delhi(India)
                          > > > > >
                          > > > > >
                          > > > > >
                          > > > > > --- In perl-beginner@yahoogroups.com,
                          > > > "perl_beg"
                          > > > > > <perl_beg@>
                          > > > > > wrote:
                          > > > > > >
                          > > > > > > How could I split the following
                          > content on
                          > > > the 8th
                          > > > > > item
                          > > > > > (username)?
                          > > > > > > I've tried doing the split(/
                          > /); but was
                          > > > not
                          > > > > > successful.
                          > > > > > >
                          > > > > > > Thu Apr 3 16:15:11 2008 started
                          > 18411 user
                          > > > 1 16:14:25
                          > > > > > app=unknown
                          > > > > > > pwd=unknown make -j app
                          > > > > > >
                          > > > > > > Any help would be appreciated.
                          > > > > > >
                          > > > > >
                          > > > > >
                          > > > > >
                          > > > > > ------------------------------------
                          > > > > >
                          > > > > > Unsubscribing info is here:
                          > > > > >
                          > > >
                          > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                          > > > > > Groups Links
                          > > > > >
                          > > > > >
                          > > > > >
                          > > > >
                          > > >
                          > > >
                          > > >
                          > > > ------------------------------------
                          > > >
                          > > > Unsubscribing info is here:
                          > > >
                          > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                          > > > Groups Links
                          > > >
                          > > >
                          > > >
                          > >
                          >
                          >
                          >
                          > ------------------------------------
                          >
                          > Unsubscribing info is here:
                          > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                          > Groups Links
                          >
                          >
                          >
                        • perl_beg
                          Hi Dave, I did try it and did not get the results I wanted. That s because I was missing a few scalar variables ($col3 and $col4). Nice it works fine now. I
                          Message 12 of 15 , Apr 15, 2008
                          • 0 Attachment
                            Hi Dave, I did try it and did not get the results I wanted. That's
                            because I was missing a few scalar variables ($col3 and $col4). Nice
                            it works fine now. I appreciate the help.



                            --- In perl-beginner@yahoogroups.com, david wright
                            <david_v_wright@...> wrote:
                            >
                            > > What if I wanted to grab more than just the 7th
                            > > column?
                            > > Would that involve a lot more work or could I just do
                            > > [2,3,7] in my
                            > > syntax;?
                            > >
                            >
                            > did you try it? ;)
                            >
                            > my ($col3,$col4,$user) = (split(/\s+/, $str))[2,3,7];
                            >
                            > perl is a great language for learning by trying stuff, feel free
                            to experiment.
                            >
                            > +Dave
                            >
                            > > --- In perl-beginner@yahoogroups.com, david wright
                            > > <david_v_wright@> wrote:
                            > > >
                            > > > Hello perl_beg,
                            > > >
                            > > > I would offer the following suggestions for
                            > > approaching your task
                            > > >
                            > > > It seems unnecessary in this case to open a pipe to
                            > > perl open from
                            > > shell commands
                            > > >
                            > > > I'm not sure what '/var/log/app.log' looks
                            > > like but if it's a tab
                            > > delimited and 'users' is your 7th column, you could
                            > > use shell
                            > > commands alone, something such as:
                            > > >
                            > > > awk '{print $7}' | sort | uniq -c | sort -nr
                            > > >
                            > > > however since this is a perl list, lets look at that.
                            > > >
                            > > >
                            > > > just open the file directly:
                            > > >
                            > > > > open (LOG,"cat /var/log/app.log | egrep
                            > > ' -j ' | egrep -v ' -j
                            > > [0-
                            > > > 9]' | grep start|") || die "Cannot open
                            > > file";
                            > > >
                            > > > open my $log,'<',
                            > > '/var/log/app.log' || die "Cannot open file
                            > > $!";
                            > > >
                            > > > > @_ = split(/\s+/,7);
                            > > >
                            > > > I think you want something like,
                            > > >
                            > > > my $user = (split(/\s+/, $_))[7];
                            > > > $u_count{$user}++;
                            > > >
                            > > > from:
                            > > > perldoc -f split
                            > > > split /PATTERN/,EXPR,LIMIT
                            > > >
                            > > > also I would add use strict; in the beginning of your
                            > > script.
                            > > >
                            > > > other than that it looks like your on the right track,
                            > > good work,
                            > > keep it up :)
                            > > >
                            > > > +Dave
                            > > >
                            > > >
                            > > >
                            > > > --- On Mon, 4/7/08, perl_beg <perl_beg@>
                            > > wrote:
                            > > >
                            > > > > From: perl_beg <perl_beg@>
                            > > > > Subject: [PBML] Re: Use split
                            > > > > To: perl-beginner@yahoogroups.com
                            > > > > Date: Monday, April 7, 2008, 2:17 PM
                            > > > > Hi Dave, yeah I would say I'm no where near a
                            > > programmer
                            > > > > just do
                            > > > > basic scripts. Here is what I'm trying to do.
                            > > I'm
                            > > > > using a hash so I
                            > > > > don't get duplicate names when I print off
                            > > usernames
                            > > > > that I pull
                            > > > > from the log file.
                            > > > >
                            > > > > #!/usr/bin/perl -w
                            > > > >
                            > > > > %u_count = ();
                            > > > >
                            > > > > open (LOG,"cat /var/log/app.log | egrep
                            > > ' -j '
                            > > > > | egrep -v ' -j [0-
                            > > > > 9]' | grep start|") || die "Cannot
                            > > open
                            > > > > file";
                            > > > > while (<LOG>) {
                            > > > > chomp();
                            > > > > @_ = split(/\s+/,7);
                            > > > > $u_count{$_}++;
                            > > > > }
                            > > > >
                            > > > > @users = sort keys %u_count;
                            > > > >
                            > > > > foreach $user (@users) {
                            > > > > print "$user\n";
                            > > > > }
                            > > > >
                            > > > >
                            > > > >
                            > > > > --- In perl-beginner@yahoogroups.com, david
                            > > wright
                            > > > > <david_v_wright@> wrote:
                            > > > > >
                            > > > > > > You can also use array concept.
                            > > > > > >
                            > > > > > > for (my $c=0;$c<7 ;$c++)
                            > > > > > > {
                            > > > > > > $array1[$c]=$array[$c];
                            > > > > > > }
                            > > > > > > ...
                            > > > > >
                            > > > > > generally, a perl programmer would prefer
                            > > something to
                            > > > > the affect
                            > > > > of:
                            > > > > >
                            > > > > > my $str='Thu Apr 3 16:15:11 2008
                            > > started 18411
                            > > > > user 1 16:14:25
                            > > > > app=unknown pwd=unknown make -j app';
                            > > > > >
                            > > > > > push(my @tokes, split(/\s+/, $str));
                            > > > > >
                            > > > > > or:
                            > > > > > my @tokes = map{ split(/\s+/, $_) }
                            > > $str;
                            > > > > >
                            > > > > > or:
                            > > > > > my @tokes = map{ split } $str;
                            > > > > >
                            > > > > > use Data::Dumper;
                            > > > > > #print Dumper \@tokes;
                            > > > > > print $tokes[7];
                            > > > > >
                            > > > > >
                            > > > > > +Dave
                            > > > > >
                            > > > > >
                            > > > > > --- On Fri, 4/4/08, PRAVEEN CHAUHAN
                            > > > > <best_praveen2006@> wrote:
                            > > > > >
                            > > > > > > From: PRAVEEN CHAUHAN
                            > > > > <best_praveen2006@>
                            > > > > > > Subject: [PBML] Re: Use split
                            > > > > > > To: perl-beginner@yahoogroups.com
                            > > > > > > Date: Friday, April 4, 2008, 1:54 AM
                            > > > > > > Hi,
                            > > > > > >
                            > > > > > > You can also use array concept. Below
                            > > is the
                            > > > > scipt.
                            > > > > > >
                            > > > > > >
                            > > > > > > #!/usr/bin/perl
                            > > > > > > print "Hello,
                            > > > > World...\n\n\n";
                            > > > > > > my $str="Thu Apr 3 16:15:11 2008
                            > > started
                            > > > > 18411 user 1
                            > > > > > > 16:14:25
                            > > > > > > app=unknown pwd=unknown make -j
                            > > app";
                            > > > > > > my @array=split(" ",$str);
                            > > > > > > my (@array1,@array2)=();
                            > > > > > > print "\n Split input by space
                            > > and store
                            > > > > in array:
                            > > > > > > @array\n\n\n";
                            > > > > > >
                            > > > > > > for (my $c=0;$c<7 ;$c++)
                            > > > > > > {
                            > > > > > > $array1[$c]=$array[$c];
                            > > > > > > }
                            > > > > > >
                            > > > > > > for ($c=7,my $cc=0;$c<15
                            > > ;$c++,$cc++)
                            > > > > > > {
                            > > > > > > $array2[$cc]=$array[$c];
                            > > > > > > }
                            > > > > > >
                            > > > > > > print "\n\n\n\t
                            > > Now array
                            > > > > split in two
                            > > > > > > array \n\n\n";
                            > > > > > > print "Output of Array1:
                            > > > > > > @array1\n\n\n";
                            > > > > > > print "Output of Array2:
                            > > > > > > @array2\n\n\n";
                            > > > > > >
                            > > > > > >
                            > > > > > >
                            > > > > > > Thanks
                            > > > > > > Praveen
                            > > > > > > Delhi(India)
                            > > > > > >
                            > > > > > >
                            > > > > > >
                            > > > > > > --- In perl-beginner@yahoogroups.com,
                            > > > > "perl_beg"
                            > > > > > > <perl_beg@>
                            > > > > > > wrote:
                            > > > > > > >
                            > > > > > > > How could I split the following
                            > > content on
                            > > > > the 8th
                            > > > > > > item
                            > > > > > > (username)?
                            > > > > > > > I've tried doing the split(/
                            > > /); but was
                            > > > > not
                            > > > > > > successful.
                            > > > > > > >
                            > > > > > > > Thu Apr 3 16:15:11 2008 started
                            > > 18411 user
                            > > > > 1 16:14:25
                            > > > > > > app=unknown
                            > > > > > > > pwd=unknown make -j app
                            > > > > > > >
                            > > > > > > > Any help would be appreciated.
                            > > > > > > >
                            > > > > > >
                            > > > > > >
                            > > > > > >
                            > > > > > > ------------------------------------
                            > > > > > >
                            > > > > > > Unsubscribing info is here:
                            > > > > > >
                            > > > >
                            > > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                            > > > > > > Groups Links
                            > > > > > >
                            > > > > > >
                            > > > > > >
                            > > > > >
                            > > > >
                            > > > >
                            > > > >
                            > > > > ------------------------------------
                            > > > >
                            > > > > Unsubscribing info is here:
                            > > > >
                            > > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                            > > > > Groups Links
                            > > > >
                            > > > >
                            > > > >
                            > > >
                            > >
                            > >
                            > >
                            > > ------------------------------------
                            > >
                            > > Unsubscribing info is here:
                            > > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                            > > Groups Links
                            > >
                            > >
                            > >
                            >
                          • perl_beg
                            Hi David, here is my piece of code. I got the first part working that you were helping me with originally much thanks. I tried to include the next part of the
                            Message 13 of 15 , Apr 30, 2008
                            • 0 Attachment
                              Hi David, here is my piece of code. I got the first part working
                              that you were helping me with originally much thanks.

                              I tried to include the next part of the code to capture the date in
                              the logfile. For example - "Tue Apr 20 2008" but when I compare what
                              is in the file ($datestr =~ @array) of course it's not working
                              properly. Any suggestions would be great.


                              my $datestr = UnixDate("today","%a %b %e %Y");


                              %abuser_cnt = ();

                              my $file="/var/log/app.log";

                              open (INFILE, "<$file") || die "Cannot open file";
                              while (<INFILE>) {
                              chomp;
                              if ( $_ =~ m/-j\s?[0-9]?/){
                              my @array = ($day, $mth, $daynum, $year) = (split(/
                              \s+/,$_))[0,1,2,4];
                              if ($datestr =~ @array ) {
                              my ($day, $mth, $daynum, $year, $user) = (split(/\s+/,$_))
                              [0,1,2,4,7];
                              $abuser_cnt{$day,$mth,$daynum,$year,$user}++;
                              }
                              }
                              }

                              @abusers = sort keys %abuser_cnt;

                              foreach $user (@abusers) {
                              print "$user\n";
                              }
                            • david wright
                              Hello perl_beg, ... I think your looking for this: ($datestr =~ /@array/) additionally, some of the logic in your code can condensed. ... this doesn t make
                              Message 14 of 15 , May 2 12:48 AM
                              • 0 Attachment
                                Hello perl_beg,

                                > when I compare what is in the file ($datestr =~ @array)

                                I think your looking for this: ($datestr =~ /@array/)

                                additionally, some of the logic in your code can condensed.

                                > my @array = ($day, $mth, $daynum, $year) =
                                > (split(/
                                > \s+/,$_))[0,1,2,4];
                                > if ($datestr =~ @array ) {
                                > my ($day, $mth, $daynum, $year, $user) =
                                > (split(/\s+/,$_))
                                > [0,1,2,4,7];

                                this doesn't make sense to me. why not just split once?

                                > $abuser_cnt{$day,$mth,$daynum,$year,$user}++;

                                I'm not sure what you want to do here...

                                I believe you could refactor to somdthing along these lines:

                                while (<INFILE>) {
                                chomp;
                                if (m/-j\s?[0-9]?/){
                                my ($day, $mth, $daynum, $year, $user) = (split(/\s+/,$_))[0,1,2,4,7];
                                $abuser_cnt{$user}++ if /$datestr/;
                                }
                                }

                                foreach $user (sort keys %abuser_cnt) {
                                print "$user\n";
                                }


                                Best of luck,
                                +Dave


                                --- On Wed, 4/30/08, perl_beg <perl_beg@...> wrote:

                                > From: perl_beg <perl_beg@...>
                                > Subject: [PBML] Re: Use split
                                > To: perl-beginner@yahoogroups.com
                                > Date: Wednesday, April 30, 2008, 1:17 PM
                                > Hi David, here is my piece of code. I got the first part
                                > working
                                > that you were helping me with originally much thanks.
                                >
                                > I tried to include the next part of the code to capture the
                                > date in
                                > the logfile. For example - "Tue Apr 20 2008" but
                                > when I compare what
                                > is in the file ($datestr =~ @array) of course it's not
                                > working
                                > properly. Any suggestions would be great.
                                >
                                >
                                > my $datestr = UnixDate("today","%a %b %e
                                > %Y");
                                >
                                >
                                > %abuser_cnt = ();
                                >
                                > my $file="/var/log/app.log";
                                >
                                > open (INFILE, "<$file") || die "Cannot
                                > open file";
                                > while (<INFILE>) {
                                > chomp;
                                > if ( $_ =~ m/-j\s?[0-9]?/){
                                > my @array = ($day, $mth, $daynum, $year) =
                                > (split(/
                                > \s+/,$_))[0,1,2,4];
                                > if ($datestr =~ @array ) {
                                > my ($day, $mth, $daynum, $year, $user) =
                                > (split(/\s+/,$_))
                                > [0,1,2,4,7];
                                > $abuser_cnt{$day,$mth,$daynum,$year,$user}++;
                                > }
                                > }
                                > }
                                >
                                > @abusers = sort keys %abuser_cnt;
                                >
                                > foreach $user (@abusers) {
                                > print "$user\n";
                                > }
                                >
                                >
                                > ------------------------------------
                                >
                                > Unsubscribing info is here:
                                > http://help.yahoo.com/help/us/groups/groups-32.htmlYahoo!
                                > Groups Links
                                >
                                >
                                >
                              Your message has been successfully submitted and would be delivered to recipients shortly.