LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-18-2012, 03:54 AM   #1
imran042
Member
 
Registered: Feb 2012
Posts: 35

Rep: Reputation: Disabled
count


what is the code for building a number pyramid using perl,
and what is the code to count a specific word in the text.
 
Old 03-18-2012, 04:10 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
What have you tried?
 
Old 03-18-2012, 04:12 AM   #3
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
Greetingz!

These kind of sound like homework questions...and asking forums for answers defeats the purpose of homework.
Google also returns a myrid of results for these questions (like this one), so I'm assuming you haven't googled for this either.
 
Old 03-18-2012, 09:07 AM   #4
imran042
Member
 
Registered: Feb 2012
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
What have you tried?
-----------------------------
#!/usr/bin/perl -w

my $count=0;

my $path="/home/perl/field.txt";
open(IN, $path)|| die "INVALID PATH\n";

print "\nEnter word\n";
$word=<stdin>;
chomp($word);

while(<IN>)
{
my @field=split(',',$_);
if ("$_" =~ /$word/)


{
$count++;
}

}

print"\n'$word' appeared :$count times\n\n";

close(IN)

This is what i tried , but the count is not accurate
 
Old 03-18-2012, 09:38 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
hmmm ... first off, you can use [code][/code] tags to display your code properly.

Second, what does this code have to do with a "number pyramid"?

Lastly, without seeing what the format of field.txt and what your current and expected results are, it will be difficult to assist further.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] count Micky12345 Linux - Newbie 4 03-02-2012 08:35 AM
Warning: [fnn_insert] Column count doesn't match value count at row 1 in bondoq Programming 2 09-27-2011 05:11 PM
DBD::mysql::st execute failed: Column count doesn't match value count at row 1 shifter Programming 2 02-24-2010 08:42 PM
Need a way to count sub-directories and get a total count Mo-regard Linux - Newbie 1 08-14-2009 10:10 AM
Should posts in general count on your post count? Joey.Dale General 16 01-27-2004 02:31 AM


All times are GMT -5. The time now is 05:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration