Hi

I am new to perl...I have a file in which sections are seperated by "//************************************************"

How can i search for the asterisk character using regular expressions?

=--------------
open(IN, "<$inFile")
while (<IN>)
{
        if (/^\/\/**/)           #here is the error..search for multiple '*' character
        {
            print "Seperater found"
        }
}

pls help me ...

Recommended Answers

All 3 Replies

I pasted some text into the __DATA__ section at the end of my script for convenience but the following will work just as well if you read from a real text file.

#!/usr/bin/perl
#TestForAsterisks.pl
use strict;
use warnings;

sub is_separator {
    my $line = shift; #Assign passed argument to variable
    if ($line =~ m{^\/\/(\*)+}) {
        return 1; #Return true value
    }
    else{
        return 0; #Return false value
    }
}

while (<DATA>){
    if (is_separator($_)){
        print "Line number $. is a separator.\n";
    }else{
        print "Line number $. is not a separator.\n";
    }
}
__DATA__
Last year, I was based in Sidney while exploring the surrounding Saanich Peninsula’s emerging foodie culture — nascent vineyards and cideries, family enterprises making handcrafted gin and raw chocolate. But I was also pleasantly surprised to discover Sidney’s other angle: Inspired by Hay-on-Wye, the medieval Welsh town known for its many secondhand and antiquarian bookstores, Sidney,  population 11,000, is a bibliophile’s paradise — with no fewer than 12 independent specialty bookstores. There are rare, collectible and bargain books, with topics ranging from military history to gardening. And, yes, there are enough Stieg Larssons to go around.
//*********************************************
Since then, I have been wanting to return and get lost in these shops, perhaps even discuss a book or two over oyster burgers with some literary pals.
Indeed, Sidney seemed like the perfect place for a book club getaway. There is a new hotel, the Sidney Pier, a sleek seaside property with a restaurant that serves inspired local food and enough local colour for any bibliophile: Kenny Podmore, the concierge, also doubles as the Town Crier, and Dave, a black lab (who flunked out of seeing-eye-dog school), acts as a guest greeter. They even have a “Book Butler.”
//*********************************************
So when I knew I was going to be on the island a few weeks ago, I asked a cousin from Vancouver who weekends on nearby Mayne Island, and her mother, who was visiting her, to take the ferry over and join me for an impromptu book club, which would include a book store trawl. It wasn’t a hard sell, as there are few things they like better than to be footloose in a literary realm.
//*********************************************
Read more: http://arts.nationalpost.com/2010/06/25/volumes-of-pleasure-exploring-the-bookshops-of-sidney-b-c/#ixzz0sB76ZuG4

While you want to search the meta characters, you will use the quotemeta function.

Thanks d5e5....it worked

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.