| Author |
What is the difference ?
|
|
|
| Hi:
What is the difference between
my $str_3 = "c:\windows"; <---- (1)
my $str_3 = 'c:\windows'; <---- (2)
If I use (1) the "if" condition fails and if i use (2) the "if" condition is true.
(1) or (2) here followe by this code.
if( $str_3 =~ m!c:\\windows! )
{
print"\n matches";
}
else
{
print"\n It doesn't match";
}
Thakns
| |
|
| Che wrote:
> Hi:
> What is the difference between
Should be obvious from the below example...
my $str_1 = "c:\windows";
my $str_2 = "c:\\windows";
my $str_3 = 'c:\windows';
if( $str_1 =~ m!c:\\windows! )
{
print"\n matches";
}
else
{
print"\n It doesn't match";
}
if( $str_2 =~ m!c:\\windows! )
{
print"\n matches";
}
else
{
print"\n It doesn't match";
}
if( $str_3 =~ m!c:\\windows! )
{
print"\n matches";
}
else
{
print"\n It doesn't match";
}
print "\n";
| |
| Scott Bryce 2004-05-23, 5:34 pm |
| Che wrote:
> Hi:
> What is the difference between
> my $str_3 = "c:\windows"; <---- (1)
> my $str_3 = 'c:\windows'; <---- (2)
Try this and you may get your answer:
use strict;
use warnings;
my $str_3 = "c:\windows";
my $str_4 = 'c:\windows';
print $str_3;
print "\n";
print $str_4;
Do you understand the difference between double quotes and single quotes
in Perl?
| |
| Gunnar Hjalmarsson 2004-05-23, 5:34 pm |
| Che wrote:
> What is the difference between
> my $str_3 = "c:\windows"; <---- (1)
> my $str_3 = 'c:\windows'; <---- (2)
perldoc perlintro
perldoc perlop
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
| |
| Jürgen Exner 2004-05-23, 10:31 pm |
| Che wrote:
> Hi:
> What is the difference between
> my $str_3 = "c:\windows"; <---- (1)
> my $str_3 = 'c:\windows'; <---- (2)
One backslash.
jue
| |
| Tad McClellan 2004-05-24, 1:32 am |
| Che <che@linuxmail.org> wrote:
> What is the difference between
print() the values and see what the difference is for yourself!
You don't really need the help of hundreds of people around the world
to do that you know.
> my $str_3 = "c:\windows"; <---- (1)
print "[$str_3]\n";
> my $str_3 = 'c:\windows'; <---- (2)
print "[$str_3]\n";
>
> If I use (1) the "if" condition fails
The string contains no backslash character, the pattern requires a
backslash character. The match must fail.
If you had asked perl for some help, then perl would have
happily given you some help, and you would have discovered
the cause of the problem in a few microseconds.
How many microseconds have you spent on it so far?
Don't waste human time on a machine's job, just ask the
machine to do the job for you:
use warnings;
> and if i use (2) the "if" condition is true.
As it should be.
> (1) or (2) here followe by this code.
> if( $str_3 =~ m!c:\\windows! )
> {
> print"\n matches";
> }
> else
> {
> print"\n It doesn't match";
> }
You don't have to use \silly\ slashes unless it is destined for
a Win command interpreter. /sane/ slashes work fine on Windows
and it avoids these kinds of problems...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
|
|
|
|