Re: Single Quotes, Double Quotes [message #11673] |
Mon, 18 May 1998 00:00 |
offenbrg
Messages: 31 Registered: August 1993
|
Member |
|
|
Charles Cavanaugh <cavanaug@nicole.eos.ucar.edu> writes:
> --------------F486C25E1BA64765FD765959
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit
> Can anyone please explain to me why the line
> asciiutc = "1993-09-19T06:30:00.000000Z"
> fails compilation with the error message
> asciiutc = "1993-09-19T06:30:00.000000Z"
> ^
> % Syntax error.
> but the same line, using single quotes instead of double
> quotes, compiles.
The problem has to do with the way IDL creates octal (base-8) numbers.
To indicate that a number is octal, it is preceded by a double quote.
The problem arises when the leading character of your string is a numeral.
In your example, the "1 indicates an octal expression, which it processes
as a number (the 9s are confusing it a little); then it subtracts 09, a
decimal number, subtracts 19, and then comes to a T, which makes no sense
at all in an arithmetic expression, so it stops.
In short, the ' and the " are not interchangble WHEN the first character
of your string constant is a numeral.
Examples:
;
;Octal expression --- leading "
;
IDL> help,"123
<Expression> INT = 83
;
;String expression --- leading '
;
IDL> help,'123
<Expression> STRING = '123'
;
;Hexadecimal expression --- surrounded by '' with trailing x.
;
IDL> help,'123'x
<Expression> INT = 291
Hope all this helps!
Joel Offenberg
--
"...And I am unanimous in this" - Mrs. Slocumbe
------------------------------------------------------------ -----------------
| Joel D Offenberg | Joel.D.Offenbrg.1@gsfc.nasa.gov |
| Raytheon STX, NASA/GSFC/LASP & STScI | UIT & NGST (301) 286-5801 |
|
|
|
|
Re: Single Quotes, Double Quotes [message #11758 is a reply to message #11757] |
Thu, 14 May 1998 00:00  |
korpela
Messages: 59 Registered: September 1993
|
Member |
|
|
In article <MPG.fc4d67beb3ea90d989792@news.frii.com>,
David Fanning <davidf@dfanning.com> wrote:
> I don't know the "official" answer, but I suspect it has
> to do with the way octal and hexadecimal numbers are
> specified in IDL.
I thought this at first, but proved myself wrong.
> For example, to create a hexadecimal number:
> IDL> a = "f4"x
> Thus, if the "thing" you are assigning to a variable
> is a number (but you want it as a string), you must use
> single quotes or it will be mistaken for a hexadecimal
> or octal number.
The proof that this is wrong is that attempting to create a
hexidecimal number with "number"x fails if the string starts
with a number.
IDL> a="1f"x
a="1f"x
^
% Syntax error.
Even hex and octal numbers must be created with 'number'x
to ensure success.
An interesting aside is that the following succeeds.
(IDL doesn't check that the string converted can actually
be converted sucessfully).
IDL> a="mmmm"x
IDL> print,a
-278606233
Eric
--
Eric Korpela | An object at rest can never be
korpela@ssl.berkeley.edu | stopped.
<a href="http://sag-www.ssl.berkeley.edu/~korpela">Click for home page.</a>
|
|
|
Re: Single Quotes, Double Quotes [message #11760 is a reply to message #11757] |
Thu, 14 May 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Charles Cavanaugh (cavanaug@nicole.eos.ucar.edu) writes:
> Can anyone please explain to me why the line
>
> asciiutc = "1993-09-19T06:30:00.000000Z"
>
> fails compilation with the error message
>
> asciiutc = "1993-09-19T06:30:00.000000Z"
> ^
> % Syntax error.
>
> but the same line, using single quotes instead of double
> quotes, compiles.
I don't know the "official" answer, but I suspect it has
to do with the way octal and hexadecimal numbers are
specified in IDL.
For example, to create a hexadecimal number:
IDL> a = "f4"x
IDL> print, a
244
Or, an octal number 12:
IDL> a = "12
IDL> print,a
10
Thus, if the "thing" you are assigning to a variable
is a number (but you want it as a string), you must use
single quotes or it will be mistaken for a hexadecimal
or octal number. For example, this fails:
IDL> a = "5"
a = "5"
^
% Syntax error.
But this works:
IDL> a = '5'
And this works, because the first thing after the double
quote is a letter:
IDL> a = "A5"
Not sure this "explains" it. But perhaps it illuminates the
problem enough to suggest a solution. :-)
Cheers,
David
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|