Jump to content

Boolean Validation in regards to $_

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
inenigma

inenigma

    Newbie

  • Members
  • Pip
  • 3 posts
Hey,

I'm a bit confused with this (I'm a dinosaur..old dog, new tricks). Am I correct in thinking that, in the strict absence of being stated otherwise, any boolean comparisions are performed against $_ ?? In the example below "$_" is used as the basis of comparision for "if (/$pattern/)", ???

$_ = q("I wonder what the Entish is for 'yes' and 'no'," he thought.);

print "Enter some text to find: "; my $pattern = <STDIN>; chomp($pattern);

if (/$pattern/) {
print "The text matches the pattern '$pattern'.\n";
} else {
print "'$pattern' was not found.\n";
}


#2
hodge-podge

hodge-podge

    Learning Programmer

  • Members
  • PipPipPip
  • 47 posts
Yes, I'm pretty sure $_ is used to compare by default. But why not use $_ =~ m/ etc just to be safe?

#3
inenigma

inenigma

    Newbie

  • Members
  • Pip
  • 3 posts
Cheers. It's just that the example is from a text that I'm reading and I wanted to confirm my understanding of what it was comparing against to decide if it was TRUE or FALSE..