LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 02: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, 03:10 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
What have you tried?
 
Old 03-18-2012, 03: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: 988
Blog Entries: 4

Rep: Reputation: 254Reputation: 254Reputation: 254
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, 08: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, 08:38 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
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



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 07:35 AM
Warning: [fnn_insert] Column count doesn't match value count at row 1 in bondoq Programming 2 09-27-2011 04:11 PM
DBD::mysql::st execute failed: Column count doesn't match value count at row 1 shifter Programming 2 02-24-2010 07:42 PM
Need a way to count sub-directories and get a total count Mo-regard Linux - Newbie 1 08-14-2009 09:10 AM
Should posts in general count on your post count? Joey.Dale General 16 01-27-2004 01:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:58 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
Open Source Consulting | Domain Registration