Hi Ben

You're not soing what you think you're doing. See below.

"Ben Siders" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> To expand, I wrote a brief sample program to figure this out, since I
> actually had no idea how to do it.  Here it is:
>
> #!/usr/bin/perl
>
> $myVariable = "blorg";
>
> $line = <STDIN>;
>
> if ( $line =~ /$myVariable/ ) {
>         print "1. Line contains my variable.\n";
> }
>

This is the same as

    if ( $line =~ /blorg/ ) { .. }

which will fail, since your data line doesn't contain that string.

>
> if ( $line =~ /$$myVariable/ ) {
>         print "2. Line contains by variable.\n";
> }
>

This is that same as

    if ( $line =~ /${$myVariable}/ ) { .. }
or
    if ( $line =~ /$blorg/ ) { .. }
which doesn't exist, so evaluates to the empty string
    if ( $line =~ // ) { .. }

Now every string is deemed to contain the empty string, and so your test
succeeds. It's nothing to do with having the text 'myVariable' in there.

>
> And here's the runlog:
>
> [bsiders@lysol perl]$ ./test.pl
> asdlkjasdkljmyVariableasdlkjasd
> 2. Line contains by variable.
> [bsiders@lysol perl]$
>

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to