Actually, I have no idea how to write the script. This is actually my first time.
I wrote the code like this:
Code:
#!/usr/local/bin/perl
MAIN:
{
while(<>)
{
$counts{$1} = 0 if (/\[(\d{4}-\d{2}-\d{2})/ ) && (! defined $cou
nts{$1})
$counts{$1}++ if /\[(\d{4}-\d{2}-\d{2}).+STATUS/;
}
for $date (sort keys %counts)
{
print "$date , $counts{$date}\n";
}
}
On running the code, I am getting following error:
Code:
bash-3.00$ perl test.pl license.log > status.log
Scalar found where operator expected at test.pl line 9, near ")
$counts"
(Missing operator before $counts?)
syntax error at test.pl line 9, near ")
$counts"
syntax error at test.pl line 9, near "++ if"
syntax error at test.pl line 16, near "}"
Execution of test.pl aborted due to compilation errors.
Can you help me in this?
Last edited by Franklin52; 12-17-2012 at 10:46 AM..
Reason: Code tags
Depending upon the occurence of string 'xyz', I want to remove -t from the input file.
There is not a fixed length input file.
Any suggestions
Input file:
this is xyz line -t of the data
this is line 2 of -t of the data
xyz this is line 3 of -t the file
this is line xyz of the -t file... (1 Reply)
Hi All,
I want to search the string for vowel's occurence and find the no of occurence of each vowels, Could anyone help me out? This is urgent to me...I m new to Shell programming..
Thanks and Regards,
Nids:b: (4 Replies)
I need to find the index of last '|' (highlighted in bold) in awk :
|ifOraDatabase.Lastservererr<>0then|iferr_flag<>0then|end if
Please suggest a way... Thanks (5 Replies)
this is my assignment question. i'm supposed to submit it tommorow. can somebody please help me with it?
Do not post homework questions in the main forums. Please post in the homework forum using the correct template. (0 Replies)
Hi guys,
I like to find the Line number of Nth Occurence of a Search string in a file.
If possible, if it will land the cursor to that particualar line will be great.
Cheers!! (3 Replies)
Hi,
I need to split a file based on last occurece of a string. PFB the explanation
I have a file in following format
aaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbb
ccccccccccccccccccccccccccc
ddddddddddddddddddddddddddd
3186rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr... (4 Replies)
example:
i have the following text file...
i am very tired.
i am busy
i am hungry
i have to find the number of occurence of a particular word 'am' from the text file.. can any one give the shell script for it (34 Replies)
I created script (sh shell) to generate vlc playlist based on some data files. All works fine so far except one string I do not know how to handle with.
VLCSTART='<vlc:id>'
VLCV=0
VLCEND='</vlc:id>'
echo -e $'\n'$'\t'$'\t'$'\t'$'\t'\$VLCSTART$VLCV$VLCENDOutput file contains several occurences... (10 Replies)
I have file in which the data looks like this,
01,0000000,xxxxxxx/
02,xxxxxxxx,yyyyyy/
03,test1,41203016,,/
01,0000000,xxxxxxx/
02,xxxxxxxx,yyyyyy/ ... (16 Replies)
Hello
I would like to get know how to do this:
I got a big file (about 1GB) and I need to find a string (for instance by grep )
and then find all records in this file based on a string.
Thanks for advice.
Martin (12 Replies)
Discussion started by: mape
12 Replies
LEARN ABOUT MOJAVE
test::subcalls5.18
Test::SubCalls(3) User Contributed Perl Documentation Test::SubCalls(3)NAME
Test::SubCalls - Track the number of times subs are called
SYNOPSIS
use Test::SubCalls;
# Start tracking calls to a named sub
sub_track( 'Foo::foo' );
# Run some test code
...
# Test that some sub deep in the codebase was called
# a specific number of times.
sub_calls( 'Foo::foo', 5 );
sub_calls( 'Foo::foo', 5, 'Use a custom test message' );
# Reset the counts for one or all subs
sub_reset( 'Foo::foo' );
sub_reset_all();
DESCRIPTION
There are a number of different situations (like testing caching code) where you want to want to do a number of tests, and then verify that
some underlying subroutine deep within the code was called a specific number of times.
This module provides a number of functions for doing testing in this way in association with your normal Test::More (or similar) test
scripts.
FUNCTIONS
In the nature of test modules, all functions are exported by default.
sub_track $subname
The "sub_track" function creates a new call tracker for a named function.
The sub to track must be provided by name, references to the function itself are insufficient.
Returns true if added, or dies on error.
sub_calls $subname, $expected_calls [, $message ]
The "sub_calls" function is the primary (and only) testing function provided by "Test::SubCalls". A single call will represent one test in
your plan.
It takes the subroutine name as originally provided to "sub_track", the expected number of times the subroutine should have been called,
and an optional test message.
If no message is provided, a default message will be provided for you.
Test is ok if the number of times the sub has been called matches the expected number, or not ok if not.
sub_reset $subname
To prevent repeat users from having to take before and after counts when they start testing from after zero, the "sub_reset" function has
been provided to reset a sub call counter to zero.
Returns true or dies if the sub name is invalid or not currently tracked.
sub_reset_all
Provided mainly as a convenience, the "sub_reset_all" function will reset all the counters currently defined.
Returns true.
SUPPORT
Bugs should be submitted via the CPAN bug tracker, located at
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-SubCalls>
For other issues, or commercial enhancement or support, contact the author.
AUTHOR
Adam Kennedy <adamk@cpan.org>
SEE ALSO
<http://ali.as/>, Test::Builder, Test::More, Hook::LexWrap
COPYRIGHT
Copyright 2005 - 2009 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
perl v5.18.2 2009-04-19 Test::SubCalls(3)