Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Simple regexp question

by Samy_rio (Vicar)
on Mar 31, 2006 at 04:17 UTC ( [id://540362]=note: print w/replies, xml ) Need Help??

in reply to Simple regexp question

Hi droog114, Try this,


use strict; use warnings; open(FILE, shift) || die($!); while(<FILE>){ my $hah = $_ =~ s/\#/$&/g; my $ast = $_ =~ s/\*/$&/g; print '*' x 70, "\nLine No. $.\n",'*' x 70, "\n"; $hah = 0 if (!($hah)); $ast = 0 if (!($ast)); print "Number of #'s\t$hah\n"; print "Number of *'s\t$ast\n"; } close(FILE);

You should view this How (Not) To Ask A Question

Velusamy R.

eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Replies are listed 'Best First'.
Re^2: Simple regexp question
by SamCG (Hermit) on Mar 31, 2006 at 18:17 UTC

    I'd change my $ast = $_ =~ s/\*/$&/g; to my $ast = tr/*//;, and do similarly for the $hah variable. Or, leaving the default variable intact, my $ast = tr/*/*/;. To each their own.

    Of course, the code doesn't "filter out lines with *'s and #'s" -- it prints a line of asterisks with the line number, and then prints the number of asterisks and number of hashes. I take it you simply intended to give the OP some code to work on without giving everything, while pointing out the question should have indicated some effort on his part.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://540362]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-22 16:59 GMT
Find Nodes?
    Voting Booth?

    No recent polls found