Re: Need to Grep only fail count from the Pattern.

2014-06-30 Thread Uday Vernekar
please Explain next if $line =~ /^-/; my @f = split('\s*\|\s*',$line); next unless scalar @f == 8; On Fri, Jun 27, 2014 at 6:44 PM, Uday Vernekar vernekaru...@gmail.com wrote: Thanks to allcheers On Thu, Jun 26, 2014 at 10:28 PM, Jim Gibson jimsgib...@gmail.com wrote: On

Re: Need to Grep only fail count from the Pattern.

2014-06-30 Thread Jim Gibson
On Jun 30, 2014, at 2:44 AM, Uday Vernekar vernekaru...@gmail.com wrote: please Explain next if $line =~ /^-/; “Skip this input line if it starts with a dash ‘-‘ character.” my @f = split('\s*\|\s*',$line); Break the input line into files separated by the vertical pipe character ‘|’

one line script for word count

2014-06-30 Thread Sunita Pradhan
Hi I want to count number of occurrences of one word in a line within one single line of perl script . My code : $c++ if ($line =~ /\s+$w\s+/g); print count $c\n; It always return one even if $line contains same word twice . It does not do the global match. It works if I split the line but

Re: one line script for word count

2014-06-30 Thread Jim Gibson
On Jun 30, 2014, at 11:57 AM, Sunita Pradhan wrote: Hi I want to count number of occurrences of one word in a line within one single line of perl script . My code : $c++ if ($line =~ /\s+$w\s+/g); print count $c\n; Try this: $c = () = $line =~ /\b$w\b/g; -- To unsubscribe,

Re: one line script for word count

2014-06-30 Thread Charles DeRykus
On Mon, Jun 30, 2014 at 11:57 AM, Sunita Pradhan sunita.pradhan.2...@hotmail.com wrote: Hi I want to count number of occurrences of one word in a line within one single line of perl script . My code : $c++ if ($line =~ /\s+$w\s+/g); print count $c\n; It always return one even if $line

Re: one line script for word count

2014-06-30 Thread Charles DeRykus
On Mon, Jun 30, 2014 at 1:41 PM, Charles DeRykus dery...@gmail.com wrote: On Mon, Jun 30, 2014 at 11:57 AM, Sunita Pradhan sunita.pradhan.2...@hotmail.com wrote: Hi I want to count number of occurrences of one word in a line within one single line of perl script . My code : $c++ if

Re: one line script for word count

2014-06-30 Thread Charles DeRykus
On Mon, Jun 30, 2014 at 1:53 PM, Charles DeRykus dery...@gmail.com wrote: On Mon, Jun 30, 2014 at 1:41 PM, Charles DeRykus dery...@gmail.com wrote: On Mon, Jun 30, 2014 at 11:57 AM, Sunita Pradhan sunita.pradhan.2...@hotmail.com wrote: You could alter context, ie, change if to while,

Re: one line script for word count

2014-06-30 Thread Jim Gibson
On Jun 30, 2014, at 12:17 PM, Sunita Pradhan wrote: Thanks Jim. It is working but why a array is required here? Please respond to the list and not to me personally. That way, everybody will see your question, and somebody else can answer. Try this: $c = () = $line =~ /\b$w\b/g;

Re: one line script for word count

2014-06-30 Thread John Delacour
On 30 Jun 2014, at 20:05, Jim Gibson jimsgib...@gmail.com wrote: Try this: $c = () = $line =~ /\b$w\b/g; Or, slightly less obscure: #!/usr/bin/perl use strict; my $line = one potato two potato three potato four; my @hits = $line =~ /potato/g; print scalar @hits; # = 3 #JD -- To