LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-24-2002, 12:05 PM   #1
bobjones
LQ Newbie
 
Registered: Jun 2002
Location: Houston, Texas (U.S.)
Distribution: mandrake 7.0, redhat 6.2, 7.0, 7.1, 7.2
Posts: 6

Rep: Reputation: 0
Question perl expression Q


i am trying to write something that will define the amount of periods in a line. i have just started learning perl, but im broad in c++.

i have no idea what the syntax is, but i want something to the affect of:

$i=0;
$period = /.;
foreach $period ($line)
{$i++}

print "this line has $i periods.\n\n";

am i anywhere close???

thanx! Bob Jones
 
Old 07-24-2002, 12:22 PM   #2
lackluster
Member
 
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Rep: Reputation: 30
first off, your / slashes should be \ slashes (escape). Next up, I have found in many languages it is easy (not always the best way though) to split() the string by what you're looking for then count the array returned and that is your number . give it a try.
 
Old 07-24-2002, 12:22 PM   #3
stromgol
LQ Newbie
 
Registered: Feb 2002
Location: Levis, Quebec, Canada
Distribution: Red Hat
Posts: 2

Rep: Reputation: 0
Simply like this.

$nb_period = ( $line =~ tr/.//);
 
Old 07-24-2002, 12:31 PM   #4
bobjones
LQ Newbie
 
Registered: Jun 2002
Location: Houston, Texas (U.S.)
Distribution: mandrake 7.0, redhat 6.2, 7.0, 7.1, 7.2
Posts: 6

Original Poster
Rep: Reputation: 0
awesome it wurks!!! thanx GUI's!
 
Old 07-24-2002, 12:51 PM   #5
lackluster
Member
 
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Rep: Reputation: 30
stromgol - thanks, that's a timesaver
 
  


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
perl regular expression problem true_atlantis Programming 4 05-27-2009 06:35 AM
Perl regular expression issue zikhermm Programming 7 09-23-2005 03:48 PM
Perl Regular Expression dilemma GATTACA Programming 1 03-27-2004 07:48 PM
Perl Regular Expression rch Programming 14 07-11-2003 11:00 PM
using a perl regular expression in php markus1982 Programming 5 11-18-2002 02:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:52 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