> -----Original Message-----
> From: Umesh T G [mailto:[EMAIL PROTECTED]
> Sent: Friday, May 19, 2006 8:54 AM
> To: Perl Beginners
> Subject: Grep a variable
> 
> Hi List,
> 
> I am trying to grep a variable from a scalar value. Here is the
example
> below.
> 
> $var = "mydisk";
> $line = "mydisk is bad";
> 
> if (grep/\$var/,$line) {

\$ tells perl to treat the '$' as a literal character.

Try:

$var = "mydisk";
$line = "mydisk is bad";

if ( grep /$var/, $line ) {
    print "disk is not bad\n";
}

And _always_:

use strict;
use warnings;

And remember to scope your variables:

http://perl.plover.com/FAQs/Namespaces.html

ry

>     print "disk is not bad";
> }
> 
> This does not seems to work.
> 
> Please help me out in figuring out this.
> 
> TIA,
> 
> Cheers,
> Umesh
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to