Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Apart from that using placeholders is almost certainly the way to go, I think that your reasoning is slightly flawed.

Either you know that this $var contains the value that is maintained as a string field, or you don't. Perl doesn't store the quotes internally and whenever you load a variable, the initial value of the variable is always a string. It doesn't get converted to its binary form until you use it in a numeric context, at which point perl will convert the ascii representation to the binary numeric form. If you then imediately use it in a string context, perl will convert it back. Any simple test you tried to apply for either form is going to always be true because perl will supply the form you are asking for.

You don't say at which point in the process you are trying to make the determination.

When you are writing it to the text file, or when you read it back?

In the former case, you should be able to determine the type of the field from the table schema.

In the latter case, assuming you wrote the string quoted, you could simply not strip them off when you read the file in, and then you would know which was which. ie.

if( substr($var, 0, 1) eq "'" ) { print "It's a string\n" }

HTH?


In reply to Re: Re: Test for number or string by Anonymous Monk
in thread Test for number or string by nedals

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-03-28 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found